Commit a7f8ce51 authored by 陈龙's avatar 陈龙

feat: 标题被legend覆盖问题的优化;相同数据的轴合并

parent e3b48dbb
...@@ -18,8 +18,6 @@ export const buildDefaultLegend = (option) => { ...@@ -18,8 +18,6 @@ export const buildDefaultLegend = (option) => {
textStyle: { textStyle: {
padding: [0, 0, 0, 4], padding: [0, 0, 0, 4],
color: '#2d2d2d', color: '#2d2d2d',
width: 120,
overflow:'truncate'
}, },
tooltip:{ tooltip:{
show:true show:true
......
import React, { memo, useMemo } from 'react'; import React, {memo, useMemo} from 'react';
import _ from 'lodash'; import _ from 'lodash';
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 from './utils'; import optionGenerator from './utils';
const ChartTitle = ({ prefixCls, title, unit }) => { const ChartTitle = ({prefixCls, title, unit}) => {
const cls = `${prefixCls}-grid-item-title`; const cls = `${prefixCls}-grid-item-title`;
return ( return (
<div className={cls}> <div className={cls}>
...@@ -13,7 +13,6 @@ const ChartTitle = ({ prefixCls, title, unit }) => { ...@@ -13,7 +13,6 @@ const ChartTitle = ({ prefixCls, title, unit }) => {
</div> </div>
); );
}; };
const GridChart = memo((props) => { const GridChart = memo((props) => {
const { const {
dataSource, dataSource,
...@@ -22,11 +21,11 @@ const GridChart = memo((props) => { ...@@ -22,11 +21,11 @@ const GridChart = memo((props) => {
smooth = true, smooth = true,
curveCenter, curveCenter,
} = props; } = props;
const { prefixCls } = props; const {prefixCls} = props;
const gridData = useMemo(() => { const gridData = useMemo(() => {
const grids = dataSource.reduce((pre, item, index) => { const grids = dataSource.reduce((pre, item, index) => {
const { sensorName, deviceType } = item; const {sensorName, deviceType} = item;
const key = `${deviceType}_${sensorName}`; // 同设备类型同指标才在同一组 const key = `${deviceType}_${sensorName}`; // 同设备类型同指标才在同一组
let grid = pre.find((g) => g.key === key); let grid = pre.find((g) => g.key === key);
if (!grid) { if (!grid) {
...@@ -46,21 +45,27 @@ const GridChart = memo((props) => { ...@@ -46,21 +45,27 @@ const GridChart = memo((props) => {
const options = useMemo(() => { const options = useMemo(() => {
let _options = gridData.map((item) => { let _options = gridData.map((item) => {
const { key, list, equipmentName, sensorName, stationCode, unit } = item; const {key, list, equipmentName, sensorName, stationCode, unit} = item;
let max = 300;
// 5:左侧竖条的宽度;10:标题部分的左侧margin;
// sensorName长度*单个宽度16.7;5:单位部分的左侧margin;
// 91:单位部分的宽度(格式固定,宽度相对固定)
let maxTitleLength = 5 + 10 + sensorName.length * 16.7 + 5 + 91;
let finalLength = maxTitleLength > max ? max : maxTitleLength
const cusOption = { const cusOption = {
title: { title: {
show: true, show: true,
// text: `{prefix|}{t|${sensorName}}${unit ? '{suffix|(单位:' + unit + ')}' : ''}`, // text: `{prefix|}{t|${sensorName}}${unit ? '{suffix|(单位:' + unit + ')}' : ''}`,
text: ' ', text: ' ',
textStyle: { textStyle: {
width: 200, width: finalLength,
overflow: 'truncate', overflow: 'truncate',
}, },
}, },
legend: { legend: {
// orient: 'vertical', // orient: 'vertical',
itemGap: 10, itemGap: 10,
padding: [0, 0, 0, 200], padding: [0, 0, 0, finalLength],
textStyle: { textStyle: {
width: 120, width: 120,
overflow: 'truncate', overflow: 'truncate',
...@@ -71,7 +76,10 @@ const GridChart = memo((props) => { ...@@ -71,7 +76,10 @@ const GridChart = memo((props) => {
curveCenter, curveCenter,
nameWithSensor: false, nameWithSensor: false,
showGridLine: true, showGridLine: true,
isMultiple: gridData.length > 1
}); });
// 在多图表里,底部缩放条的高度减小
return { return {
key, key,
option: option, option: option,
...@@ -83,7 +91,7 @@ const GridChart = memo((props) => { ...@@ -83,7 +91,7 @@ const GridChart = memo((props) => {
return ( return (
<div className={`${prefixCls}-grid`}> <div className={`${prefixCls}-grid`}>
{options.map((item, index) => { {options.map((item, index) => {
const { sensorName, unit } = gridData[index]; const {sensorName, unit} = gridData[index];
const isEmpty = const isEmpty =
!item.option.series.length || !item.option.series.length ||
!item.option.series.find((e) => e.data && e.data.length > 0); !item.option.series.find((e) => e.data && e.data.length > 0);
...@@ -97,12 +105,12 @@ const GridChart = memo((props) => { ...@@ -97,12 +105,12 @@ const GridChart = memo((props) => {
}} }}
> >
<div className={`${prefixCls}-grid-item-wrap`}> <div className={`${prefixCls}-grid-item-wrap`}>
<ChartTitle prefixCls={prefixCls} title={sensorName} unit={unit} /> <ChartTitle prefixCls={prefixCls} title={sensorName} unit={unit}/>
{isEmpty ? ( {isEmpty ? (
<PandaEmpty /> <PandaEmpty/>
) : ( ) : (
<BasicChart <BasicChart
style={{ width: '100%', height: '100%' }} style={{width: '100%', height: '100%'}}
option={item.option} option={item.option}
notMerge notMerge
/> />
......
...@@ -4,25 +4,25 @@ import { MobileHistoryChart } from "../mobile"; ...@@ -4,25 +4,25 @@ import { MobileHistoryChart } from "../mobile";
const deviceParams = [ const deviceParams = [
/*10.182*/ /*10.182*/
/* { /* {
deviceCode: 'EGBF00000141', deviceCode: 'EGBF00000141',
// sensors: '进水压力,出水瞬时流量,出水累计流量', // sensors: '进水压力,出水瞬时流量,出水累计流量',
sensors: '进水压力', sensors: '进水压力',
deviceType: '熊猫二供泵房', deviceType: '熊猫二供泵房',
pointAddressID: 208, pointAddressID: 208,
}, */ },*/
/* { /* {
"deviceCode": "SYJ00000008", "deviceCode": "SYJ00000008",
"sensors": "瞬时流量", "sensors": "瞬时流量",
"deviceType": "水源井" "deviceType": "水源井"
}, },*/
{ {
deviceCode: 'EGJZ00000197', deviceCode: 'EGJZ00000197',
sensors: '进水压力,出水压力,出水瞬时流量,出水累计流量', sensors: '进水压力,出水压力,出水瞬时流量,出水累计流量',
// sensors: '1#变频器运行频率', // sensors: '1#变频器运行频率',
deviceType: '二供机组', deviceType: '二供机组',
// pointAddressID: 208, // pointAddressID: 208,
}, */ },
/* { /* {
deviceCode: 'EGJZ00000198', deviceCode: 'EGJZ00000198',
sensors: '进水压力,出水压力,出水瞬时流量,出水累计流量', sensors: '进水压力,出水压力,出水瞬时流量,出水累计流量',
...@@ -63,7 +63,7 @@ const deviceParams = [ ...@@ -63,7 +63,7 @@ const deviceParams = [
"sensors": "瞬时流量", "sensors": "瞬时流量",
"deviceType": "水厂" "deviceType": "水厂"
}, */ }, */
{ /* {
"deviceCode": "JFJ00000001", "deviceCode": "JFJ00000001",
"sensors": "沉淀池投矾量瞬时,", "sensors": "沉淀池投矾量瞬时,",
"deviceType": "加矾间" "deviceType": "加矾间"
...@@ -92,7 +92,7 @@ const deviceParams = [ ...@@ -92,7 +92,7 @@ const deviceParams = [
deviceCode: 'EGJZ00000027', deviceCode: 'EGJZ00000027',
sensors: '2#变频器运行频率', sensors: '2#变频器运行频率',
deviceType: '二供机组', deviceType: '二供机组',
}, },*/
/*确山*/ /*确山*/
/*泵3状态*/ /*泵3状态*/
/* { /* {
......
import moment from 'moment'; import moment from 'moment';
import _, { isArray } from 'lodash'; import _, {isArray} from 'lodash';
import maxIcon from './assets/最大实心.svg'; import maxIcon from './assets/最大实心.svg';
import minIcon from './assets/最小实心.svg'; import minIcon from './assets/最小实心.svg';
import minIconDownArrow from './assets/最小实心箭头朝下.svg'; import minIconDownArrow from './assets/最小实心箭头朝下.svg';
import lineChart from '@wisdom-components/basicchart/es/LineChart'; import lineChart from '@wisdom-components/basicchart/es/LineChart';
import { offset } from 'highcharts';
/** 轴宽度, 用于计算多轴显示时, 轴线偏移和绘图区域尺寸 */ /** 轴宽度, 用于计算多轴显示时, 轴线偏移和绘图区域尺寸 */
const AXIS_WIDTH = 40; const AXIS_WIDTH = 40;
...@@ -68,7 +67,7 @@ const currentOption = isMobile() ? MOBILE_OPTION : PC_OPTION; ...@@ -68,7 +67,7 @@ const currentOption = isMobile() ? MOBILE_OPTION : PC_OPTION;
* @returns * @returns
*/ */
const nameFormatter = (data, contrast, contrastOption, nameWithSensor) => { const nameFormatter = (data, contrast, contrastOption, nameWithSensor) => {
const { equipmentName, sensorName, unit, dataModel, dateFrom, dateTo } = data; const {equipmentName, sensorName, unit, dataModel, dateFrom, dateTo} = data;
let name = nameWithSensor ? `${equipmentName}-${sensorName}` : equipmentName; let name = nameWithSensor ? `${equipmentName}-${sensorName}` : equipmentName;
if (contrast) { if (contrast) {
const time = dateFrom.slice(0, contrastOption === 'day' ? 10 : 7).replace(/-/g, ''); const time = dateFrom.slice(0, contrastOption === 'day' ? 10 : 7).replace(/-/g, '');
...@@ -103,7 +102,7 @@ const dataAccessor = (data, contrast, contrastOption) => { ...@@ -103,7 +102,7 @@ const dataAccessor = (data, contrast, contrastOption) => {
* @returns Null/areaStyle, 为null显示曲线图, 为areaStyle对象显示为面积图. * @returns Null/areaStyle, 为null显示曲线图, 为areaStyle对象显示为面积图.
*/ */
const areaStyleFormatter = (data) => { const areaStyleFormatter = (data) => {
const { sensorName } = data; const {sensorName} = data;
return sensorName && sensorName.indexOf('流量') > -1 ? {} : null; return sensorName && sensorName.indexOf('流量') > -1 ? {} : null;
}; };
...@@ -114,7 +113,7 @@ const areaStyleFormatter = (data) => { ...@@ -114,7 +113,7 @@ const areaStyleFormatter = (data) => {
* @returns * @returns
*/ */
const minMax = (data) => { const minMax = (data) => {
const { dataModel } = data; const {dataModel} = data;
let min = Number.MAX_SAFE_INTEGER; let min = Number.MAX_SAFE_INTEGER;
let max = Number.MIN_SAFE_INTEGER; let max = Number.MIN_SAFE_INTEGER;
dataModel.forEach((item) => { dataModel.forEach((item) => {
...@@ -145,7 +144,7 @@ const markLineItem = (name, value, color) => { ...@@ -145,7 +144,7 @@ const markLineItem = (name, value, color) => {
export const alarmMarkLine = (dataItem, index, dataSource, schemes) => { export const alarmMarkLine = (dataItem, index, dataSource, schemes) => {
// 只有一个数据曲线时显示markline // 只有一个数据曲线时显示markline
if (!dataItem || !schemes || dataSource.length !== 1) return {}; if (!dataItem || !schemes || dataSource.length !== 1) return {};
const { deviceType, stationCode, sensorName, decimalPoint } = dataItem; const {deviceType, stationCode, sensorName, decimalPoint} = dataItem;
const curSchemes = schemes.filter( const curSchemes = schemes.filter(
(item) => (item) =>
item.deviceCode === stationCode && item.deviceCode === stationCode &&
...@@ -154,7 +153,7 @@ export const alarmMarkLine = (dataItem, index, dataSource, schemes) => { ...@@ -154,7 +153,7 @@ export const alarmMarkLine = (dataItem, index, dataSource, schemes) => {
); );
const data = []; const data = [];
curSchemes.forEach((scheme) => { curSchemes.forEach((scheme) => {
const { hLimit, hhLimit, lLimit, llLimit } = scheme; const {hLimit, hhLimit, lLimit, llLimit} = scheme;
lLimit !== null && lLimit !== void 0 && data.push(markLineItem('低限', lLimit, '#fa8c16')); lLimit !== null && lLimit !== void 0 && data.push(markLineItem('低限', lLimit, '#fa8c16'));
hLimit !== null && hLimit !== void 0 && data.push(markLineItem('高限', hLimit, '#fa8c16')); hLimit !== null && hLimit !== void 0 && data.push(markLineItem('高限', hLimit, '#fa8c16'));
llLimit !== null && llLimit !== void 0 && data.push(markLineItem('低低限', llLimit, '#FF0000')); llLimit !== null && llLimit !== void 0 && data.push(markLineItem('低低限', llLimit, '#FF0000'));
...@@ -246,7 +245,7 @@ export const decorateAxisGridLine = (axis, showGrid) => { ...@@ -246,7 +245,7 @@ export const decorateAxisGridLine = (axis, showGrid) => {
*/ */
export const offlineArea = (dataItem) => { export const offlineArea = (dataItem) => {
if (!dataItem) return {}; if (!dataItem) return {};
const { dataModel } = dataItem; const {dataModel} = dataItem;
let datas = new Array(); let datas = new Array();
let offlineData = []; let offlineData = [];
let hasOffline = false; let hasOffline = false;
...@@ -256,7 +255,7 @@ export const offlineArea = (dataItem) => { ...@@ -256,7 +255,7 @@ export const offlineArea = (dataItem) => {
{ {
name: '离线', name: '离线',
xAxis: new Date(item.pt), xAxis: new Date(item.pt),
label: { show: !datas?.length }, label: {show: !datas?.length},
}, },
]; ];
hasOffline = true; hasOffline = true;
...@@ -277,32 +276,10 @@ export const offlineArea = (dataItem) => { ...@@ -277,32 +276,10 @@ export const offlineArea = (dataItem) => {
data: datas, data: datas,
}; };
}; };
// 生成默认legend配置
export const buildDefaultLegend = (option) => {
const { title } = option;
let paddingRight = 0;
if (title && title.show) paddingRight = 80; // 给标题留够空间
return {
show: true,
right: 20,
top: 20,
icon: 'rect',
itemWidth: 14,
itemHeight: 8,
itemGap: 20,
padding: [0, 0, 0, paddingRight],
textStyle: {
padding: [0, 0, 0, 4],
color: '#2d2d2d',
},
};
};
// tooltip 模板 // tooltip 模板
const headTemplate = (param, opt) => { const headTemplate = (param, opt) => {
if (!param) return ''; if (!param) return '';
const { name, axisValueLabel, axisType, axisValue } = param; const {name, axisValueLabel, axisType, axisValue} = param;
const timeFormat = const timeFormat =
opt && opt.contrast opt && opt.contrast
? opt.contrastOption === 'day' ? opt.contrastOption === 'day'
...@@ -318,7 +295,7 @@ const headTemplate = (param, opt) => { ...@@ -318,7 +295,7 @@ const headTemplate = (param, opt) => {
}; };
const seriesTemplate = (param, unit) => { const seriesTemplate = (param, unit) => {
if (!param || param.seriesName === '自定义') return ''; if (!param || param.seriesName === '自定义') return '';
const { value, encode } = param; const {value, encode} = param;
// const val = value[encode.y[0]]; // const val = value[encode.y[0]];
const _unit = unit || ''; const _unit = unit || '';
const color = '#008CFF'; const color = '#008CFF';
...@@ -467,7 +444,7 @@ const handleSpecial1 = (special, dataSource) => { ...@@ -467,7 +444,7 @@ const handleSpecial1 = (special, dataSource) => {
}, },
}, },
name: item.text, name: item.text,
label: { show: true }, label: {show: true},
}, },
{ {
xAxis: item.lte, xAxis: item.lte,
...@@ -512,17 +489,18 @@ const returnXAxis = ({ ...@@ -512,17 +489,18 @@ const returnXAxis = ({
restOption, restOption,
smooth, smooth,
special, special,
}) => { yAxis
}) => {
// 根据"指标名称"分类yAxis // 根据"指标名称"分类yAxis
const yAxisInterator = (() => { const yAxisInterator = (() => {
const map = new Map(); const map = new Map();
let current = -1; let current = -1;
const get = (name) => (map.has(name) ? map.get(name) : map.set(name, ++current).get(name)); const get = (name) => (map.has(name) ? map.get(name) : map.set(name, ++current).get(name));
return { get }; return {get};
})(); })();
let _offlineData = []; let _offlineData = [];
// 生成visualMap、markArea // 生成visualMap、markArea
let { visualMap, markArea } = handleSpecial1(special, dataSource); let {visualMap, markArea} = handleSpecial1(special, dataSource);
let _filterArr = ['是否在线']; let _filterArr = ['是否在线'];
if (special?.special1?.name) { if (special?.special1?.name) {
_filterArr.push(special.special1.name); _filterArr.push(special.special1.name);
...@@ -536,12 +514,14 @@ const returnXAxis = ({ ...@@ -536,12 +514,14 @@ const returnXAxis = ({
return !_filterArr.includes(item.sensorName); return !_filterArr.includes(item.sensorName);
}) })
.map((item, index) => { .map((item, index) => {
const { sensorName, unit } = item; const {sensorName, unit} = item;
const name = nameFormatter(item, contrast, contrastOption, nameWithSensor); const name = nameFormatter(item, contrast, contrastOption, nameWithSensor);
const data = dataAccessor(item, contrast, contrastOption); const data = dataAccessor(item, contrast, contrastOption);
const type = 'line'; const type = 'line';
const areaStyle = areaStyleFormatter(item); const areaStyle = areaStyleFormatter(item);
const yAxisIndex = yAxisInterator.get(sensorName); const _index = yAxis.findIndex(item => item.name === unit);
const yAxisIndex = _index > -1 ? _index : 0;
// console.log('yAxisIndex: ',yAxisInterator);
const markLine = showMarkLine const markLine = showMarkLine
? alarmMarkLine(item, index, dataSource, deviceAlarmSchemes) ? alarmMarkLine(item, index, dataSource, deviceAlarmSchemes)
: {}; : {};
...@@ -638,32 +618,70 @@ const handleMaxValue = (value) => { ...@@ -638,32 +618,70 @@ const handleMaxValue = (value) => {
if (value >= 100000) return `${(value / 1000).toFixed(2)}k`; if (value >= 100000) return `${(value / 1000).toFixed(2)}k`;
return value.toFixed(2); return value.toFixed(2);
} }
const handleYAxis = ({ dataSource, needUnit, curveCenter, showGridLine }) => { const reduceYAxis = (arr, dataSource) => {
// 一种指标一个y轴
const yAxisMap = new Map();
// 1. 找出最大值; 2. 计算出y轴最大宽度动态计算偏移距离;
let _maxValueArray = [];
let _offsetValue = []; let _offsetValue = [];
dataSource.forEach((item, index) => { // 1. 合并相同单位的坐标轴
let _maxValue = item.dataModel.reduce((final, cur) => { let _arr = arr.reduce((final, cur) => {
let _key = cur.name === null ? 'null' : cur.name
if (!final[_key]) {
final[_key] = cur
}
return final;
}, {});
console.log('datasource: ', dataSource);
// 2. 合并相同单位的数据,找出最大值
let _maxValueArr = Object.values(dataSource.reduce((final, cur) => {
let _key = cur.name === null ? 'null' : cur.name;
let _maxValue = cur.dataModel.reduce((final, cur) => {
if (cur.pv > final) final = cur.pv; if (cur.pv > final) final = cur.pv;
return final return final
}, 0); }, 0);
_maxValueArray.push(handleMaxValue(_maxValue)); if (final[_key] === undefined) {
const { sensorName, unit } = item; final[_key] = _maxValue
} else {
final[_key] = Math.max([final[_key], _maxValue]);
}
return final
}, {}));
// 3. 合并,生成Y轴配置
return Object.values(_arr).map((item, index) => {
let _key = item.name === null ? 'null' : item.name;
let _offset = _maxValueArr[index - 2];
let _baseOffset = _offsetValue[index - 2] ?? 0;
let _finalOffset = (_offset !== undefined ? (_offset === 0 ? 2 : _offset.toString().replaceAll('.', '').length) * 12 : 0) + _baseOffset;
_offsetValue.push(_finalOffset);
return ({
...item,
offset: _finalOffset,
position: index % 2 === 0 ? 'left' : 'right',
nameTextStyle: {
align: index % 2 === 0 ? 'right' : 'left',
},
})
});
};
const handleYAxis = ({dataSource, needUnit, curveCenter, showGridLine}) => {
// 1. 新需求:合并相同的坐标轴
// 一种指标一个y轴 -------- 需求变更:相同类型的指标放到同一指标轴(单位相同) 2023年9月28日
const yAxisMap = new Map();
// 1. 找出最大值; 2. 计算出y轴最大宽度动态计算偏移距离;
dataSource.forEach((item, index) => {
const {sensorName, unit} = item;
const key = sensorName; const key = sensorName;
if (!yAxisMap.has(key)) { if (!yAxisMap.has(key)) {
const i = yAxisMap.size; /* const i = yAxisMap.size;
let _offset = _maxValueArray[i - 2]; let _offset = _maxValueArray[i - 2];
let _baseOffset = _offsetValue[i - 2] ?? 0; let _baseOffset = _offsetValue[i - 2] ?? 0;
let _finalOffset = (_offset !== undefined ? (_offset === 0 ? 2 : _offset.toString().replaceAll('.','').length) * 10 : 0) + _baseOffset; let _finalOffset = (_offset !== undefined ? (_offset === 0 ? 2 : _offset.toString().replaceAll('.','').length) * 10 : 0) + _baseOffset;
_offsetValue.push(_finalOffset); _offsetValue.push(_finalOffset);*/
const axis = { const axis = {
type: 'value', type: 'value',
name: needUnit ? unit : null, name: needUnit ? unit : null,
position: i % 2 === 0 ? 'left' : 'right', // position: i % 2 === 0 ? 'left' : 'right',
// offset: _offset !== undefined ? (_offset === 0? 2:_offset.toString().length) * 10 : 0, // offset: _offset !== undefined ? (_offset === 0? 2:_offset.toString().length) * 10 : 0,
offset: _finalOffset, // offset: _finalOffset,
axisLabel: { axisLabel: {
formatter: (value) => { formatter: (value) => {
return handleMaxValue(value); return handleMaxValue(value);
...@@ -672,9 +690,6 @@ const handleYAxis = ({ dataSource, needUnit, curveCenter, showGridLine }) => { ...@@ -672,9 +690,6 @@ const handleYAxis = ({ dataSource, needUnit, curveCenter, showGridLine }) => {
axisLine: { axisLine: {
show: true, show: true,
}, },
nameTextStyle: {
align: i % 2 === 0 ? 'right' : 'left',
},
minorTick: { minorTick: {
lineStyle: { lineStyle: {
color: '#e2e2e2', color: '#e2e2e2',
...@@ -702,31 +717,29 @@ const handleYAxis = ({ dataSource, needUnit, curveCenter, showGridLine }) => { ...@@ -702,31 +717,29 @@ const handleYAxis = ({ dataSource, needUnit, curveCenter, showGridLine }) => {
const axis = yAxisMap.get(key); const axis = yAxisMap.get(key);
decorateAxisGridLine(axis, showGridLine); decorateAxisGridLine(axis, showGridLine);
}); });
const yAxis = yAxisMap.size > 0 ? [...yAxisMap.values()] : { type: 'value' }; const yAxis = yAxisMap.size > 0 ? reduceYAxis([...yAxisMap.values()], dataSource) : {type: 'value'};
// 根据y轴个数调整边距
const leftNum = Math.ceil(yAxisMap.size / 2); const leftNum = Math.ceil(yAxisMap.size / 2);
const rightNum = Math.floor(yAxisMap.size / 2); const rightNum = Math.floor(yAxisMap.size / 2);
return { leftNum, rightNum, yAxis }; return {leftNum, rightNum, yAxis};
}; };
const assignOptions = (restOption, xAxis, legendData, chartType, contrast, contrastOption) => { const assignOptions = (restOption, xAxis, legendData, chartType, contrast, contrastOption, config) => {
restOption.dataZoom = [ restOption.dataZoom = [
{ {
show: true, show: true,
bottom: 10, bottom: 20,
start: 0, start: 0,
end: 100, end: 100,
height: currentOption['dataZoomHeight'], height: config.isMultiple ? 20 : 28,
type: 'inside', type: 'inside',
zoomOnMouseWheel: true, zoomOnMouseWheel: true,
filterMode: chartType === 'lineChart' ? 'none' : 'weakFilter', filterMode: chartType === 'lineChart' ? 'none' : 'weakFilter',
}, },
{ {
show: true, show: true,
bottom: 10, bottom: 20,
start: 0, start: 0,
end: 100, end: 100,
height: currentOption['dataZoomHeight'], height: config.isMultiple ? 20 : 28,
type: 'slider', type: 'slider',
zoomOnMouseWheel: true, zoomOnMouseWheel: true,
labelFormatter: function (e) { labelFormatter: function (e) {
...@@ -741,7 +754,7 @@ const assignOptions = (restOption, xAxis, legendData, chartType, contrast, contr ...@@ -741,7 +754,7 @@ const assignOptions = (restOption, xAxis, legendData, chartType, contrast, contr
]; ];
xAxis.minInterval = 3600 * (1 * 1000); xAxis.minInterval = 3600 * (1 * 1000);
if (legendData) { if (legendData) {
restOption.legend = { ...buildDefaultLegend({}), ...{ data: legendData } }; restOption.legend = {...restOption.legend, ...{data: legendData}};
} }
}; };
...@@ -790,7 +803,7 @@ const handleGrid = (dataSource, needUnit, leftNum, rightNum, chartType) => { ...@@ -790,7 +803,7 @@ const handleGrid = (dataSource, needUnit, leftNum, rightNum, chartType) => {
top: _base + _topForUnit, top: _base + _topForUnit,
// left: leftNum === 1 ? 10 : leftNum * AXIS_WIDTH, // left: leftNum === 1 ? 10 : leftNum * AXIS_WIDTH,
left: 20, left: 20,
right:10, right: 10,
// right: rightNum === 0 ? 20 : rightNum * AXIS_WIDTH, // right: rightNum === 0 ? 20 : rightNum * AXIS_WIDTH,
bottom: 60, bottom: 60,
containLabel: true, containLabel: true,
...@@ -899,14 +912,17 @@ const optionGenerator = ( ...@@ -899,14 +912,17 @@ const optionGenerator = (
restOption, restOption,
special, special,
} = handleDefault(config, cusOption); } = handleDefault(config, cusOption);
const { leftNum, rightNum, yAxis } = handleYAxis({ const {leftNum, rightNum, yAxis} = handleYAxis({
dataSource, dataSource,
needUnit, needUnit,
curveCenter, curveCenter,
showGridLine, showGridLine,
}); });
console.log(yAxis);
const grid = handleGrid(dataSource, needUnit, leftNum, rightNum, chartType); const grid = handleGrid(dataSource, needUnit, leftNum, rightNum, chartType);
let { xAxis, series, visualMap } = returnXAxis({ let {xAxis, series, visualMap} = returnXAxis({
dataSource, dataSource,
contrast, contrast,
contrastOption, contrastOption,
...@@ -917,6 +933,7 @@ const optionGenerator = ( ...@@ -917,6 +933,7 @@ const optionGenerator = (
smooth, smooth,
restOption, restOption,
special, special,
yAxis
}); });
decorateAxisGridLine(xAxis, showGridLine); decorateAxisGridLine(xAxis, showGridLine);
const tooltipTimeFormat = !contrast const tooltipTimeFormat = !contrast
...@@ -930,16 +947,16 @@ const optionGenerator = ( ...@@ -930,16 +947,16 @@ const optionGenerator = (
if (chartType === 'boxChart' && lineDataType === '特征曲线') { if (chartType === 'boxChart' && lineDataType === '特征曲线') {
const otherData = const otherData =
dataSource?.[0]?.dataModel.map((item) => { dataSource?.[0]?.dataModel.map((item) => {
const { firstPV, lastPV, maxPV, minPV, pt } = item; const {firstPV, lastPV, maxPV, minPV, pt} = item;
return [moment(pt).valueOf(), firstPV, lastPV, minPV, maxPV]; return [moment(pt).valueOf(), firstPV, lastPV, minPV, maxPV];
}) || []; //当存在othersData的时候,只是单曲线 }) || []; //当存在othersData的时候,只是单曲线
xAxis = { type: 'time' }; xAxis = {type: 'time'};
decorateAxisGridLine(xAxis, showGridLine); decorateAxisGridLine(xAxis, showGridLine);
let unit = []; let unit = [];
series = series.map((item) => { series = series.map((item) => {
if (item.unit) unit.push(item.unit); if (item.unit) unit.push(item.unit);
item.areaStyle = null; item.areaStyle = null;
return { ...item, showSymbol: false }; return {...item, showSymbol: false};
}); });
series.push({ series.push({
type: 'candlestick', type: 'candlestick',
...@@ -970,7 +987,7 @@ const optionGenerator = ( ...@@ -970,7 +987,7 @@ const optionGenerator = (
* 2. 当最大值小于零时(此时,最小值一定小于零); * 2. 当最大值小于零时(此时,最小值一定小于零);
*/ */
dataSource?.[0]?.dataModel.forEach((item) => { dataSource?.[0]?.dataModel.forEach((item) => {
const { firstPV, lastPV, maxPV, minPV, pt } = item; const {firstPV, lastPV, maxPV, minPV, pt} = item;
_maxValues.push(maxPV); _maxValues.push(maxPV);
let time = contrast ? moment(pt).format(formatStr) : pt; let time = contrast ? moment(pt).format(formatStr) : pt;
_maxData.push([ _maxData.push([
...@@ -980,13 +997,13 @@ const optionGenerator = ( ...@@ -980,13 +997,13 @@ const optionGenerator = (
_minData.push([moment(time).valueOf(), maxPV > 0 ? minPV : maxPV]); _minData.push([moment(time).valueOf(), maxPV > 0 ? minPV : maxPV]);
}); //当存在othersData的时候,只是单曲线 }); //当存在othersData的时候,只是单曲线
// xAxis = {type: 'category', data: series[0].data.map(item => moment(item[0]).format('YYYY-MM-DD HH:mm:ss'))}; // xAxis = {type: 'category', data: series[0].data.map(item => moment(item[0]).format('YYYY-MM-DD HH:mm:ss'))};
xAxis = { type: 'time' }; xAxis = {type: 'time'};
decorateAxisGridLine(xAxis, showGridLine); decorateAxisGridLine(xAxis, showGridLine);
let _unit = ''; let _unit = '';
series = series.map((item) => { series = series.map((item) => {
_unit = item.unit ?? ''; _unit = item.unit ?? '';
item.areaStyle = null; item.areaStyle = null;
return { ...item, showSymbol: false }; return {...item, showSymbol: false};
}); });
[[..._minData], [..._maxData]].forEach((item, index) => { [[..._minData], [..._maxData]].forEach((item, index) => {
series.push({ series.push({
...@@ -1059,14 +1076,14 @@ const optionGenerator = ( ...@@ -1059,14 +1076,14 @@ const optionGenerator = (
} else { } else {
tooltip = tooltipAccessor( tooltip = tooltipAccessor(
series.map((item) => item.unit), series.map((item) => item.unit),
{ contrastOption, contrast }, {contrastOption, contrast},
); );
} }
tooltip.timeFormat = tooltipTimeFormat; tooltip.timeFormat = tooltipTimeFormat;
let _legendData = series let _legendData = series
.filter((item) => !['周期最大值', '周期最小值', '自定义'].includes(item.name)) .filter((item) => !['周期最大值', '周期最小值', '自定义'].includes(item.name)) // legend中,过滤掉辅助业务的legend
.map((item) => item.name); .map((item) => item.name);
assignOptions(restOption, xAxis, _legendData, chartType, contrast, contrastOption); assignOptions(restOption, xAxis, _legendData, chartType, contrast, contrastOption, config);
let _options = { let _options = {
yAxis, yAxis,
grid, grid,
...@@ -1076,6 +1093,7 @@ const optionGenerator = ( ...@@ -1076,6 +1093,7 @@ const optionGenerator = (
visualMap, visualMap,
...restOption, ...restOption,
}; };
console.log('_options: ', _options)
return _options; return _options;
}; };
......
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