Commit d35c48a5 authored by 陈龙's avatar 陈龙

feat: 新增箱线图、置信区间功能

parent c180e1d5
import React, { memo, useEffect, useMemo, useRef } from 'react'; import React, {memo, useEffect, useMemo, useRef} from 'react';
import { BasicChart } from '@wisdom-components/basicchart'; import {BasicChart} from '@wisdom-components/basicchart';
import PandaEmpty from '@wisdom-components/empty'; import PandaEmpty from '@wisdom-components/empty';
import optionGenerator, { alarmMarkLine, minMaxMarkPoint, offlineArea } from './utils'; import optionGenerator, {alarmMarkLine, minMaxMarkPoint, offlineArea} from './utils';
import { isArray, cloneDeep } from 'lodash'; import {isArray, cloneDeep} from 'lodash';
const SimgleChart = memo((props) => { const SimgleChart = memo((props) => {
const { const {
dataSource, dataSource,
contrast = false, contrast = false,
contrastOption = 'day', contrastOption = 'day',
smooth = true, smooth = true,
curveCenter, curveCenter,
showGridLine = false, showGridLine = false,
deviceAlarmSchemes, deviceAlarmSchemes,
} = props; chartType,
const chartRef = useRef(); justLine
} = props;
const chartRef = useRef();
const option = useMemo(() => { const option = useMemo(() => {
const config = { const config = {
needUnit: true, needUnit: true,
curveCenter, curveCenter,
showGridLine, showGridLine,
deviceAlarmSchemes, deviceAlarmSchemes,
showMarkLine: true, showMarkLine: true,
showPoint: true, showPoint: true,
}; chartType,
return optionGenerator(dataSource, null, contrast, contrastOption, smooth, config); justLine
}, [dataSource, smooth, curveCenter]); };
return optionGenerator(dataSource, null, contrast, contrastOption, smooth, config);
}, [dataSource, smooth, curveCenter]);
useEffect(() => { useEffect(() => {
chartRef.current?.resize?.(); chartRef.current?.resize?.();
const chart = chartRef.current?.getEchartsInstance?.(); const chart = chartRef.current?.getEchartsInstance?.();
function hander(params) { function hander(params) {
const { selected } = params; const {selected} = params;
const count = Object.values(selected || {}).filter((item) => item).length; const count = Object.values(selected || {}).filter((item) => item).length;
const option = cloneDeep(chart.getOption()); const option = cloneDeep(chart.getOption());
const needMarkLine = count === 1; const needMarkLine = count === 1;
option.series.forEach((item, index) => { option.series.forEach((item, index) => {
let offlineAreas = offlineArea(dataSource[index]); let offlineAreas = offlineArea(dataSource[index]);
if (offlineAreas.data?.length) { if (offlineAreas.data?.length) {
option.markArea = null; option.markArea = null;
item.markArea = offlineAreas; item.markArea = offlineAreas;
} }
if (needMarkLine && selected[item.name]) { if (needMarkLine && selected[item.name]) {
item.markLine = alarmMarkLine( item.markLine = alarmMarkLine(
dataSource[index], dataSource[index],
index, index,
[dataSource[index]], [dataSource[index]],
deviceAlarmSchemes, deviceAlarmSchemes,
); );
item.markPoint = minMaxMarkPoint(dataSource[index], index, [dataSource[index]]); item.markPoint = minMaxMarkPoint(dataSource[index], index, [dataSource[index]]);
} else { } else {
item.markLine = {}; item.markLine = {};
item.markPoint = {}; item.markPoint = {};
}
});
chart.setOption(option, true);
} }
});
chart.setOption(option, true);
}
if (!chart) return;
chart.on('legendselectchanged', hander);
return () => {
chart.off('legendselectchanged', hander);
};
}, [dataSource, deviceAlarmSchemes]);
// 网格开关,不更新整个图表 if (!chart) return;
useEffect(() => { chart.on('legendselectchanged', hander);
const chart = chartRef.current?.getEchartsInstance?.(); return () => {
if (!chart) return; chart.off('legendselectchanged', hander);
const option = chart.getOption(); };
// 交互指针 }, [dataSource, deviceAlarmSchemes]);
const tooltip = {
trigger: 'axis', // 网格开关,不更新整个图表
axisPointer: { useEffect(() => {
type: showGridLine ? 'cross' : 'line', const chart = chartRef.current?.getEchartsInstance?.();
}, if (!chart) return;
}; const option = chart.getOption();
// 网格线 // 交互指针
const axisConfig = { const tooltip = {
minorTick: { trigger: 'axis',
show: showGridLine, axisPointer: {
splitNumber: 2, type: showGridLine ? 'cross' : 'line',
}, },
minorSplitLine: { };
show: showGridLine, // 网格线
lineStyle: { const axisConfig = {
type: 'dashed', minorTick: {
}, show: showGridLine,
}, splitNumber: 2,
splitLine: { },
show: showGridLine, minorSplitLine: {
}, show: showGridLine,
}; lineStyle: {
let yAxis = axisConfig; type: 'dashed',
if (isArray(option.yAxis)) { },
yAxis = option.yAxis.map((item) => ({ ...axisConfig })); },
} splitLine: {
let xAxis = axisConfig; show: showGridLine,
chart.setOption({ },
xAxis, };
yAxis, let yAxis = axisConfig;
tooltip, if (isArray(option.yAxis)) {
}); yAxis = option.yAxis.map((item) => ({...axisConfig}));
}, [showGridLine]); }
let xAxis = axisConfig;
chart.setOption({
xAxis,
yAxis,
tooltip,
});
}, [showGridLine]);
// 数据都为空显示缺省页 // 数据都为空显示缺省页
const isEmpty = useMemo( const isEmpty = useMemo(
() => () =>
!dataSource || !dataSource ||
!dataSource.length || !dataSource.length ||
!dataSource.find((e) => e.dataModel && e.dataModel.length > 0), !dataSource.find((e) => e.dataModel && e.dataModel.length > 0),
[dataSource], [dataSource],
); );
return isEmpty ? ( return isEmpty ? (
<PandaEmpty /> <PandaEmpty/>
) : ( ) : (
<BasicChart ref={chartRef} option={option} notMerge style={{ width: '100%', height: '100%' }} /> <BasicChart ref={chartRef} option={option} notMerge style={{width: '100%', height: '100%'}}/>
); );
}); });
export default SimgleChart; export default SimgleChart;
...@@ -2,7 +2,7 @@ import React from 'react'; ...@@ -2,7 +2,7 @@ import React from 'react';
import HistoryView from '../index'; import HistoryView from '../index';
const deviceParams = [ const deviceParams = [
{ /* {
deviceCode: 'EGBF00000146', deviceCode: 'EGBF00000146',
sensors: '进水压力,出水瞬时流量,出水累计流量', sensors: '进水压力,出水瞬时流量,出水累计流量',
deviceType: '二供泵房', deviceType: '二供泵房',
...@@ -13,7 +13,7 @@ const deviceParams = [ ...@@ -13,7 +13,7 @@ const deviceParams = [
sensors: '进水压力,出水瞬时流量,出水累计流量', sensors: '进水压力,出水瞬时流量,出水累计流量',
deviceType: '二供泵房', deviceType: '二供泵房',
pointAddressID: 4, pointAddressID: 4,
}, },*/
{ {
deviceCode: 'EGBF00000002', deviceCode: 'EGBF00000002',
sensors: '进水压力,出水瞬时流量,出水累计流量', sensors: '进水压力,出水瞬时流量,出水累计流量',
......
...@@ -3,17 +3,20 @@ import HistoryView from '../index'; ...@@ -3,17 +3,20 @@ import HistoryView from '../index';
const deviceParams = [ const deviceParams = [
{ {
deviceCode: 'EGBF00000146', deviceCode: 'EGBF00000082',
sensors: '进水压力,出水瞬时流量,出水累计流量', sensors: '进水压力',
// sensors: '出水瞬时流量',
// sensors: '出水累计流量',
// sensors: '进水压力,出水瞬时流量,出水累计流量',
deviceType: '二供泵房', deviceType: '二供泵房',
pointAddressID: 4, pointAddressID: 4,
}, },
{ /* {
deviceCode: 'EGJZ00001113', deviceCode: 'EGBF00000083',
sensors: '出水瞬时流量,出水压力,泵1状态', sensors: '出水瞬时流量,出水压力,泵1状态',
deviceType: '二供机组', deviceType: '二供机组',
pointAddressID: 4, pointAddressID: 4,
}, },*/
// { // {
// deviceCode: 'EGJZ00001113', // deviceCode: 'EGJZ00001113',
// sensors: '出水压力', // sensors: '出水压力',
...@@ -24,7 +27,7 @@ const deviceParams = [ ...@@ -24,7 +27,7 @@ const deviceParams = [
const Demo = () => { const Demo = () => {
return ( return (
<div style={{ height: 700 }}> <div style={{ height: 700 }}>
<HistoryView deviceParams={deviceParams} defaultModel="table" /> <HistoryView deviceParams={deviceParams} defaultModel="curve" />
</div> </div>
); );
}; };
......
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