Commit 2d00b49e authored by 崔佳豪's avatar 崔佳豪

fix(EC_HistoryView): 添加网格、滤波配置、单图表十字指示器

parent 93868065
...@@ -70,6 +70,7 @@ const GridChart = memo((props) => { ...@@ -70,6 +70,7 @@ const GridChart = memo((props) => {
const option = optionGenerator(list, cusOption, contrast, contrastOption, smooth, { const option = optionGenerator(list, cusOption, contrast, contrastOption, smooth, {
curveCenter, curveCenter,
nameWithSensor: false, nameWithSensor: false,
showGridLine: false,
}); });
return { return {
key, key,
......
...@@ -10,6 +10,7 @@ const SimgleChart = memo((props) => { ...@@ -10,6 +10,7 @@ const SimgleChart = memo((props) => {
contrastOption = 'day', contrastOption = 'day',
smooth = true, smooth = true,
curveCenter, curveCenter,
showGridLine = false,
} = props; } = props;
const chartRef = useRef(); const chartRef = useRef();
...@@ -17,12 +18,43 @@ const SimgleChart = memo((props) => { ...@@ -17,12 +18,43 @@ const SimgleChart = memo((props) => {
const config = { const config = {
needUnit: true, needUnit: true,
curveCenter, curveCenter,
showGridLine,
}; };
return optionGenerator(dataSource, null, contrast, contrastOption, smooth, config); return optionGenerator(dataSource, null, contrast, contrastOption, smooth, config);
}, [dataSource, smooth, curveCenter]); }, [dataSource, smooth, curveCenter, showGridLine]);
useEffect(() => { useEffect(() => {
chartRef.current?.resize?.(); chartRef.current?.resize?.();
const chart = chartRef.current.getEchartsInstance();
function hander(params) {
const { selected } = params;
const count = Object.values(selected || {}).filter((item) => item).length;
if (count === 1) {
chart.setOption({
tooltip: {
trigger: 'axis',
axisPointer: {
type: 'cross',
},
},
});
} else {
chart.setOption({
tooltip: {
trigger: 'axis',
axisPointer: {
type: 'line',
},
},
});
}
}
if (!chart) return;
chart.on('legendselectchanged', hander);
return () => {
chart.off('legendselectchanged', hander);
};
}, []); }, []);
// 数据都为空显示缺省页 // 数据都为空显示缺省页
......
...@@ -48,18 +48,31 @@ const CheckboxData = [ ...@@ -48,18 +48,31 @@ const CheckboxData = [
key: 'curveCenter', key: 'curveCenter',
label: '曲线居中', label: '曲线居中',
checked: false, checked: false,
showInCurve: true,
showInTable: false,
},
{
key: 'chartGrid',
label: '图表网格',
checked: false,
showInCurve: true,
showInTable: false,
}, },
{ {
key: 'ignoreOutliers', key: 'ignoreOutliers',
label: '过滤异常值', label: '滤波',
type: 'updateIgnoreOutliers', type: 'updateIgnoreOutliers',
checked: false, checked: false,
showInCurve: true,
showInTable: true,
}, },
{ {
key: 'dataThin', key: 'dataThin',
label: '数据抽稀', label: '数据抽稀',
type: 'updateDataThin', type: 'updateDataThin',
checked: true, checked: true,
showInCurve: false,
showInTable: true,
}, },
]; ];
...@@ -218,6 +231,10 @@ const HistoryView = (props) => { ...@@ -218,6 +231,10 @@ const HistoryView = (props) => {
} }
}, [contrastOption, customerChecked, customerTime, datePickerArr, timeValue]); }, [contrastOption, customerChecked, customerTime, datePickerArr, timeValue]);
const configDependence = checkboxData
.filter((item) => ['curveCenter', 'chartGrid'].indexOf(item.key) === -1)
.map((item) => item.checked)
.join(',');
// 数据配置 // 数据配置
const dataConfig = useMemo(() => { const dataConfig = useMemo(() => {
const initial = { const initial = {
...@@ -238,13 +255,14 @@ const HistoryView = (props) => { ...@@ -238,13 +255,14 @@ const HistoryView = (props) => {
config.dataThin = activeTabKey === 'curve' ? true : config.dataThin; // 曲线强制抽稀 config.dataThin = activeTabKey === 'curve' ? true : config.dataThin; // 曲线强制抽稀
return config; return config;
}, [checkboxData, dataThinKey, activeTabKey]); }, [configDependence, dataThinKey, activeTabKey]);
// 图表居中 // 图表居中
const curveCenter = useMemo( const [curveCenter, chartGrid] = useMemo(() => {
() => checkboxData.find((item) => item.key === 'curveCenter')?.checked, const curveCenter = checkboxData.find((item) => item.key === 'curveCenter')?.checked;
[checkboxData], const chartGrid = checkboxData.find((item) => item.key === 'chartGrid')?.checked;
); return [curveCenter, chartGrid];
}, [checkboxData]);
// 自定义模式: 快速选择 // 自定义模式: 快速选择
const onCustomerTimeChange = (key) => { const onCustomerTimeChange = (key) => {
...@@ -385,11 +403,14 @@ const HistoryView = (props) => { ...@@ -385,11 +403,14 @@ const HistoryView = (props) => {
setDataThinKey(value); setDataThinKey(value);
}; };
const renderCheckbox = (child) => ( const renderCheckbox = (child) =>
<Checkbox checked={child.checked} onChange={(e) => onCheckboxChange(e, child.key)}> ((activeTabKey === 'curve' && !grid && child.showInCurve) ||
{child.label} (activeTabKey === 'curve' && grid && child.key === 'curveCenter') ||
</Checkbox> (activeTabKey === 'table' && child.showInTable)) && (
); <Checkbox checked={child.checked} onChange={(e) => onCheckboxChange(e, child.key)}>
{child.label}
</Checkbox>
);
const renderCurveOption = () => { const renderCurveOption = () => {
return ( return (
...@@ -397,8 +418,9 @@ const HistoryView = (props) => { ...@@ -397,8 +418,9 @@ const HistoryView = (props) => {
<div className={classNames(`${prefixCls}-label`)}>曲线设置</div> <div className={classNames(`${prefixCls}-label`)}>曲线设置</div>
{checkboxData.map((child) => ( {checkboxData.map((child) => (
<div key={child.key}> <div key={child.key}>
{activeTabKey === 'curve' && child.key === 'curveCenter' && renderCheckbox(child)} {renderCheckbox(child)}
{activeTabKey === 'table' && child.key !== 'curveCenter' && renderCheckbox(child)} {/* {activeTabKey === 'curve' && child.key === 'curveCenter' && renderCheckbox(child)} */}
{/* {activeTabKey === 'table' && child.key !== 'curveCenter' && renderCheckbox(child)} */}
</div> </div>
))} ))}
{activeTabKey === 'table' && ( {activeTabKey === 'table' && (
...@@ -607,6 +629,7 @@ const HistoryView = (props) => { ...@@ -607,6 +629,7 @@ const HistoryView = (props) => {
) : ( ) : (
<SimgleChart <SimgleChart
curveCenter={curveCenter} curveCenter={curveCenter}
showGridLine={chartGrid}
prefixCls={prefixCls} prefixCls={prefixCls}
dataSource={chartDataSource} dataSource={chartDataSource}
contrast={timeValue === 'contrast'} contrast={timeValue === 'contrast'}
......
...@@ -81,6 +81,7 @@ const optionGenerator = (dataSource, cusOption, contrast, contrastOption, smooth ...@@ -81,6 +81,7 @@ const optionGenerator = (dataSource, cusOption, contrast, contrastOption, smooth
const needUnit = _.get(config, 'needUnit', false); const needUnit = _.get(config, 'needUnit', false);
const curveCenter = _.get(config, 'curveCenter', false); const curveCenter = _.get(config, 'curveCenter', false);
const nameWithSensor = _.get(config, 'nameWithSensor', true); const nameWithSensor = _.get(config, 'nameWithSensor', true);
const showGridLine = _.get(config, 'showGridLine', false);
// 自定义属性 // 自定义属性
const restOption = _.pick(cusOption, ['title', 'legend']); const restOption = _.pick(cusOption, ['title', 'legend']);
...@@ -106,6 +107,17 @@ const optionGenerator = (dataSource, cusOption, contrast, contrastOption, smooth ...@@ -106,6 +107,17 @@ const optionGenerator = (dataSource, cusOption, contrast, contrastOption, smooth
nameTextStyle: { nameTextStyle: {
align: i % 2 === 0 ? 'right' : 'left', align: i % 2 === 0 ? 'right' : 'left',
}, },
minorTick: {
lineStyle: {
color: '#e2e2e2',
},
},
minorSplitLine: {
lineStyle: {
color: '#e2e2e2',
type: 'dashed',
},
},
}; };
yAxisMap.set(key, axis); yAxisMap.set(key, axis);
} }
...@@ -117,6 +129,16 @@ const optionGenerator = (dataSource, cusOption, contrast, contrastOption, smooth ...@@ -117,6 +129,16 @@ const optionGenerator = (dataSource, cusOption, contrast, contrastOption, smooth
axis.min = axis.min === void 0 ? min : Math.min(min, axis.min); axis.min = axis.min === void 0 ? min : Math.min(min, axis.min);
axis.max = axis.max === void 0 ? max : Math.max(max, axis.max); axis.max = axis.max === void 0 ? max : Math.max(max, axis.max);
} }
// 网格显示
if (showGridLine) {
const axis = yAxisMap.get(key);
axis.minorTick ? (axis.minorTick.show = true) : (axis.minorTick = { show: true });
axis.minorSplitLine
? (axis.minorSplitLine.show = true)
: (axis.minorSplitLine = { show: true });
axis.splitLine ? (axis.splitLine.show = true) : (axis.splitLine = { show: true });
}
}); });
const yAxis = yAxisMap.size > 0 ? [...yAxisMap.values()] : { type: 'value' }; const yAxis = yAxisMap.size > 0 ? [...yAxisMap.values()] : { type: 'value' };
...@@ -172,7 +194,13 @@ const optionGenerator = (dataSource, cusOption, contrast, contrastOption, smooth ...@@ -172,7 +194,13 @@ const optionGenerator = (dataSource, cusOption, contrast, contrastOption, smooth
: contrastOption === 'day' : contrastOption === 'day'
? 'HH:mm' ? 'HH:mm'
: 'DD HH:mm'; : 'DD HH:mm';
const tooltip = { timeFormat: tooltipTimeFormat }; const tooltip = {
timeFormat: tooltipTimeFormat,
// trigger: 'axis',
// axisPointer: {
// type: 'cross'
// }
};
return { return {
yAxis, yAxis,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment