Commit 5605c080 authored by 陈龙's avatar 陈龙

fix: 修复切换功能无法生成tip的问题

parent ae5c513b
...@@ -25,6 +25,7 @@ const ChartWidthRef = (props) => { ...@@ -25,6 +25,7 @@ const ChartWidthRef = (props) => {
const timerRef = useRef(null); const timerRef = useRef(null);
const minMaxMarkPoint = (dataSource, chart, isInit) => { const minMaxMarkPoint = (dataSource, chart, isInit) => {
// 只有一个数据曲线时显示markline // 只有一个数据曲线时显示markline
let isMultiple = props.isMultiple
if (dataSource.length !== 1) return {}; if (dataSource.length !== 1) return {};
// 1. 找出最大、最小的值 // 1. 找出最大、最小的值
let pointArr = dataSource[0].dataModel; let pointArr = dataSource[0].dataModel;
...@@ -82,29 +83,31 @@ const ChartWidthRef = (props) => { ...@@ -82,29 +83,31 @@ const ChartWidthRef = (props) => {
// 6. 确定使用的图形 // 6. 确定使用的图形
// 默认图形,居中 // 默认图形,居中
let maxIconPath = `path://M1233.329493 195.75466633h-1112.064c-34.128213 0-61.781333 27.661653-61.781333 61.781334v473.658026c0 34.117973 27.65312 61.781333 61.781333 61.781334h472.80128l83.23072 144.155306 83.23072-144.155306h472.80128c34.128213 0 61.781333-27.66336 61.781334-61.781334V257.53600033c0-34.117973-27.65312-61.781333-61.781334-61.781334z`; let maxIconPath = `path://M1233.329493 195.75466633h-1112.064c-34.128213 0-61.781333 27.661653-61.781333 61.781334v473.658026c0 34.117973 27.65312 61.781333 61.781333 61.781334h472.80128l83.23072 144.155306 83.23072-144.155306h472.80128c34.128213 0 61.781333-27.66336 61.781334-61.781334V257.53600033c0-34.117973-27.65312-61.781333-61.781334-61.781334z`;
let maxSymbolOffset = [0, -14]; let maxSymbolOffset = isMultiple ? [0, -14] : [0, -20];
let _maxOffset = isMultiple ? -14 : -20;
if (maxOutEdge) { if (maxOutEdge) {
if (maxOutSide === 'left') { if (maxOutSide === 'left') {
// 左边界超出,使用朝右的图表 // 左边界超出,使用朝右的图表
maxSymbolOffset = ['50%', -14]; maxSymbolOffset = ['50%', _maxOffset];
maxIconPath = 'path://M48.677,6.151v10c0,1.7-1.3,3-3,3h-35.5l-6.7,4c0,0,0.2-5.3,0.2-7v-10c0-1.7,1.3-3,3-3h39C47.277,3.151,48.677,4.551,48.677,6.151z'; maxIconPath = 'path://M48.677,6.151v10c0,1.7-1.3,3-3,3h-35.5l-6.7,4c0,0,0.2-5.3,0.2-7v-10c0-1.7,1.3-3,3-3h39C47.277,3.151,48.677,4.551,48.677,6.151z';
} else if (maxOutSide === 'right') { } else if (maxOutSide === 'right') {
// 右边界超出,使用朝左的图表 // 右边界超出,使用朝左的图表
maxSymbolOffset = ['-50%', -14]; maxSymbolOffset = ['-50%', _maxOffset];
maxIconPath = 'path://M6.477,3.151h39c1.7,0,3,1.3,3,3v10c0,1.7,0.2,7,0.2,7l-6.7-4h-35.5c-1.7,0-3-1.3-3-3v-10C3.477,4.551,4.877,3.151,6.477,3.151z' maxIconPath = 'path://M6.477,3.151h39c1.7,0,3,1.3,3,3v10c0,1.7,0.2,7,0.2,7l-6.7-4h-35.5c-1.7,0-3-1.3-3-3v-10C3.477,4.551,4.877,3.151,6.477,3.151z'
} }
} }
// 默认图形 // 默认图形
let minIconPath = 'path://M131.999 849.579h1112.064c34.128 0 61.781-27.662 61.781-61.781v-473.658c0-34.118-27.653-61.781-61.781-61.781h-472.801l-83.231-144.155-83.231 144.155h-472.801c-34.128 0-61.781 27.663-61.781 61.781v473.658c0 34.118 27.653 61.781 61.781 61.781z'; let minIconPath = 'path://M131.999 849.579h1112.064c34.128 0 61.781-27.662 61.781-61.781v-473.658c0-34.118-27.653-61.781-61.781-61.781h-472.801l-83.231-144.155-83.231 144.155h-472.801c-34.128 0-61.781 27.663-61.781 61.781v473.658c0 34.118 27.653 61.781 61.781 61.781z';
let minSymbolOffset = [0, 14]; let minSymbolOffset = isMultiple ? [0, 14] : [0, 20];
let _minOffset = isMultiple ? 14 : 20;
if (minOutEdge) { if (minOutEdge) {
if (minOutSide === 'left') { if (minOutSide === 'left') {
// 左边界超出,使用朝右的图表 // 左边界超出,使用朝右的图表
minSymbolOffset = ['50%', 14]; minSymbolOffset = ['50%', _minOffset];
minIconPath = 'path://M45.677,23.151h-39c-1.7,0-3-1.3-3-3v-10c0-1.7-0.2-7-0.2-7l6.7,4h35.5c1.7,0,3,1.3,3,3v10C48.677,21.751,47.277,23.151,45.677,23.151z'; minIconPath = 'path://M45.677,23.151h-39c-1.7,0-3-1.3-3-3v-10c0-1.7-0.2-7-0.2-7l6.7,4h35.5c1.7,0,3,1.3,3,3v10C48.677,21.751,47.277,23.151,45.677,23.151z';
} else if (minOutSide === 'right') { } else if (minOutSide === 'right') {
// 右边界超出,使用朝左的图表 // 右边界超出,使用朝左的图表
minSymbolOffset = ['-50%', 14]; minSymbolOffset = ['-50%', _minOffset];
minIconPath = 'path://M3.477,20.151v-10c0-1.7,1.3-3,3-3h35.5l6.7-4c0,0-0.2,5.3-0.2,7v10c0,1.7-1.3,3-3,3h-39C4.877,23.151,3.477,21.751,3.477,20.151z' minIconPath = 'path://M3.477,20.151v-10c0-1.7,1.3-3,3-3h35.5l6.7-4c0,0-0.2,5.3-0.2,7v10c0,1.7-1.3,3-3,3h-39C4.877,23.151,3.477,21.751,3.477,20.151z'
} }
} }
...@@ -118,15 +121,15 @@ const ChartWidthRef = (props) => { ...@@ -118,15 +121,15 @@ const ChartWidthRef = (props) => {
symbol: minIconPath, symbol: minIconPath,
symbolSize: (e) => { symbolSize: (e) => {
let str = ![undefined, null].includes(e) ? String(e) : ''; let str = ![undefined, null].includes(e) ? String(e) : '';
let length = 40 + str.length * 6 let length = (isMultiple ? 40 : 60) + str.length * 6
return [length, 20] return [length, isMultiple ? 20 : 32]
}, },
label: { label: {
show: true, show: true,
color: '#fff', color: '#fff',
formatter: '最小: {c}', formatter: '最小: {c}',
fontSize: 12, fontSize: isMultiple ? 12 : 14,
fontWeight: 'normal', fontWeight: isMultiple ? 'normal' : 'bold',
verticalAlign: 'top', verticalAlign: 'top',
offset: [0, -2] offset: [0, -2]
}, },
...@@ -142,20 +145,20 @@ const ChartWidthRef = (props) => { ...@@ -142,20 +145,20 @@ const ChartWidthRef = (props) => {
symbolOffset: maxSymbolOffset, symbolOffset: maxSymbolOffset,
symbolSize: (e) => { symbolSize: (e) => {
let str = ![undefined, null].includes(e) ? String(e) : ''; let str = ![undefined, null].includes(e) ? String(e) : '';
let length = 40 + str.length * 6 let length = (isMultiple ? 40 : 60) + str.length * 6
return [length, 20] return [length, isMultiple ? 20 : 32]
}, },
itemStyle: { itemStyle: {
// color: "#1980ff", // color: "#1980ff",
}, },
label: { label: {
color: '#fff',
fontSize: 12,
fontWeight: 'normal',
show: true, show: true,
color: '#fff',
formatter: '最大: {c}', formatter: '最大: {c}',
offset: [0, -1] fontSize: isMultiple ? 12 : 14,
} fontWeight: isMultiple ? 'normal' : 'bold',
offset: [0, -2]
},
}, },
{ {
name: '', name: '',
...@@ -195,18 +198,43 @@ const ChartWidthRef = (props) => { ...@@ -195,18 +198,43 @@ const ChartWidthRef = (props) => {
}; };
// 将opt修改一下 // 将opt修改一下
const cur_opt = useMemo(() => { const cur_opt = useMemo(() => {
let _option = cloneDeep(props.option);
const chart = ref.current?.getEchartsInstance?.();
if (_option?.series?.[0] && chart) {
_option.series[0].markPoint = minMaxMarkPoint(props.data.list, chart, true);
_option.series[0].markLine = {
silent: false,
symbol: 'none',
data: [{
name: '平均线',
type: 'average',
lineStyle: {
color: '#00b8b1',
type: 'solid',
},
label: {
position: 'insideEndTop',
color: '#00b8b1',
formatter: function (param) {
return `平均值:${param.value}`;
},
},
}]
}
}
return { return {
...props.option, grid: { ..._option, grid: {
...props.option, ...props.option.grid,
top: 45, top: 45,
bottom: 65, bottom: 65,
} }
} }
}, [props.option]); }, [props.option, ref, props.data.list]);
useEffect(() => { useEffect(() => {
console.log('props.opt: ', props.option); ref.current?.resize?.();
if (props.data.list?.length !== 1) return; if (props.data.list?.length !== 1) return;
const chart = ref.current?.getEchartsInstance?.(); const chart = ref.current?.getEchartsInstance?.();
chart.setOption({ chart.setOption({
series: { series: {
...@@ -242,11 +270,7 @@ const ChartWidthRef = (props) => { ...@@ -242,11 +270,7 @@ const ChartWidthRef = (props) => {
chart.off('legendselectchanged', renderMarkPoint); chart.off('legendselectchanged', renderMarkPoint);
chart.off('datazoom', dataZoomFn); chart.off('datazoom', dataZoomFn);
} }
}, [cur_opt]); }, [JSON.stringify(cur_opt)]);
useEffect(() => {
if (props.data.list?.length !== 1) return;
renderMarkPoint(false)
}, [props.data.list]);
return <BasicChart return <BasicChart
ref={ref} ref={ref}
{...props} {...props}
...@@ -530,6 +554,7 @@ const GridChart = memo((props) => { ...@@ -530,6 +554,7 @@ const GridChart = memo((props) => {
isInit ? '' : <PandaEmpty/> isInit ? '' : <PandaEmpty/>
) : ( ) : (
<ChartWidthRef <ChartWidthRef
isMultiple={gridData.length > 1}
data={gridData[index]} data={gridData[index]}
style={{width: '100%', height: '100%'}} style={{width: '100%', height: '100%'}}
option={item.option} option={item.option}
......
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