更新图例,处理小于零的异常数据显示

This commit is contained in:
JIANG
2025-11-14 17:49:19 +08:00
parent dd93b37685
commit 09684b2171
4 changed files with 42 additions and 22 deletions

View File

@@ -438,7 +438,6 @@ const StyleEditorPanel: React.FC<StyleEditorPanelProps> = ({
// 动态生成颜色条件表达式 // 动态生成颜色条件表达式
const generateColorConditions = (property: string): any[] => { const generateColorConditions = (property: string): any[] => {
const conditions: any[] = ["case"]; const conditions: any[] = ["case"];
for (let i = 0; i < breaks.length; i++) { for (let i = 0; i < breaks.length; i++) {
// 添加条件:属性值 <= 当前断点 // 添加条件:属性值 <= 当前断点
conditions.push(["<=", ["get", property], breaks[i]]); conditions.push(["<=", ["get", property], breaks[i]]);

View File

@@ -32,13 +32,12 @@ const StyleLegend: React.FC<LegendStyleConfig> = ({
<Typography variant="subtitle2" gutterBottom> <Typography variant="subtitle2" gutterBottom>
{layerName} - {property} {layerName} - {property}
</Typography> </Typography>
{breaks.map((breakValue, index) => { {[...Array(breaks.length)].map((_, index) => {
const color = colors[index]; // 默认颜色为黑色 const color = colors[index]; // 默认颜色为黑色
// 获取对应的尺寸和分段值
const dimension = dimensions[index]; // 默认尺寸为16 const dimension = dimensions[index]; // 默认尺寸为16
const nextValue = breaks[index + 1]; // 下一个值或默认0
// 确保分段区间均有意义 // 处理第一个区间(小于 breaks[0]
if (nextValue !== undefined) { if (index === 0) {
return ( return (
<Box key={index} className="flex items-center gap-2 mb-1"> <Box key={index} className="flex items-center gap-2 mb-1">
<Box <Box
@@ -49,7 +48,6 @@ const StyleLegend: React.FC<LegendStyleConfig> = ({
height: dimension, height: dimension,
borderRadius: "50%", borderRadius: "50%",
backgroundColor: color, backgroundColor: color,
// border: `1px solid ${color}`,
} }
: { : {
width: 16, width: 16,
@@ -60,11 +58,43 @@ const StyleLegend: React.FC<LegendStyleConfig> = ({
} }
/> />
<Typography variant="caption" className="text-xs"> <Typography variant="caption" className="text-xs">
{breakValue?.toFixed(1)} - {nextValue?.toFixed(1)} {"<"} {breaks[0]?.toFixed(1)}
</Typography> </Typography>
</Box> </Box>
); );
} }
// 处理中间区间breaks[index-1] - breaks[index]
if (index < breaks.length) {
const prevValue = breaks[index - 1];
const currentValue = breaks[index];
return (
<Box key={index} className="flex items-center gap-2 mb-1">
<Box
sx={
type === "point"
? {
width: dimension,
height: dimension,
borderRadius: "50%",
backgroundColor: color,
}
: {
width: 16,
height: dimension,
backgroundColor: color,
border: `1px solid ${color}`,
}
}
/>
<Typography variant="caption" className="text-xs">
{prevValue?.toFixed(1)} - {currentValue?.toFixed(1)}
</Typography>
</Box>
);
}
return null;
})} })}
</Box> </Box>
); );

View File

@@ -214,17 +214,6 @@ const MapComponent: React.FC<MapComponentProps> = ({ children }) => {
}), }),
}); });
}; };
// 定义 valves 图层的样式函数,使用固定图标
// const valveStyle = () => {
// const valveIcon = "/icons/valve.svg";
// return new Style({
// image: new Icon({
// src: valveIcon,
// scale: 0.1, // 根据需要调整图标大小
// anchor: [0.5, 0.5], // 图标锚点居中
// }),
// });
// };
const valveStyle = { const valveStyle = {
"icon-src": "/icons/valve.svg", "icon-src": "/icons/valve.svg",
"icon-scale": 0.1, "icon-scale": 0.1,
@@ -681,7 +670,7 @@ const MapComponent: React.FC<MapComponentProps> = ({ children }) => {
getPosition: (d: any) => d.position, getPosition: (d: any) => d.position,
fontFamily: "Monaco, monospace", fontFamily: "Monaco, monospace",
getText: (d: any) => getText: (d: any) =>
d[pipeText] ? (d[pipeText] as number).toFixed(3) : "", d[pipeText] ? Math.abs(d[pipeText] as number).toFixed(3) : "",
getSize: 18, getSize: 18,
fontWeight: "bold", fontWeight: "bold",
getColor: [0, 0, 0], getColor: [0, 0, 0],

View File

@@ -10,10 +10,12 @@ function prettyBreaksClassification(data, n_classes) {
// const min_val = Math.min(...data); // const min_val = Math.min(...data);
// const max_val = Math.max(...data); // const max_val = Math.max(...data);
const min_val = data.reduce((min, val) => Math.min(min, val), Infinity); // const min_val = data.reduce((min, val) => Math.min(min, val), Infinity);
// 保证最小值不小于0
const min_val = Math.max(data.reduce((min, val) => Math.min(min, val), Infinity), 0);
const max_val = data.reduce((max, val) => Math.max(max, val), -Infinity); const max_val = data.reduce((max, val) => Math.max(max, val), -Infinity);
const data_range = max_val - min_val; const data_range = max_val - min_val;
// 计算基础间隔 // 计算基础间隔
const raw_interval = data_range / n_classes; const raw_interval = data_range / n_classes;