feat: 折线图2秒后自动失焦
This commit is contained in:
@@ -105,19 +105,28 @@ export default function FundIntradayChart({ series = [], referenceNav }) {
|
|||||||
},
|
},
|
||||||
onHover: (event, chartElement, chart) => {
|
onHover: (event, chartElement, chart) => {
|
||||||
const target = event?.native?.target;
|
const target = event?.native?.target;
|
||||||
if (target) {
|
|
||||||
target.style.cursor = chartElement[0] ? 'crosshair' : 'default';
|
|
||||||
}
|
|
||||||
|
|
||||||
const currentChart = chart || chartRef.current;
|
const currentChart = chart || chartRef.current;
|
||||||
if (!currentChart) return;
|
if (!currentChart) return;
|
||||||
|
|
||||||
|
const tooltipActive = currentChart.tooltip?._active ?? [];
|
||||||
|
const activeElements = currentChart.getActiveElements
|
||||||
|
? currentChart.getActiveElements()
|
||||||
|
: [];
|
||||||
|
const hasActive =
|
||||||
|
(chartElement && chartElement.length > 0) ||
|
||||||
|
(tooltipActive && tooltipActive.length > 0) ||
|
||||||
|
(activeElements && activeElements.length > 0);
|
||||||
|
|
||||||
|
if (target) {
|
||||||
|
target.style.cursor = hasActive ? 'crosshair' : 'default';
|
||||||
|
}
|
||||||
|
|
||||||
if (hoverTimeoutRef.current) {
|
if (hoverTimeoutRef.current) {
|
||||||
clearTimeout(hoverTimeoutRef.current);
|
clearTimeout(hoverTimeoutRef.current);
|
||||||
hoverTimeoutRef.current = null;
|
hoverTimeoutRef.current = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (chartElement[0]) {
|
if (hasActive) {
|
||||||
hoverTimeoutRef.current = setTimeout(() => {
|
hoverTimeoutRef.current = setTimeout(() => {
|
||||||
const c = chartRef.current || currentChart;
|
const c = chartRef.current || currentChart;
|
||||||
if (!c) return;
|
if (!c) return;
|
||||||
|
|||||||
@@ -220,10 +220,25 @@ export default function FundTrendChart({ code, isExpanded, onToggleExpand, trans
|
|||||||
},
|
},
|
||||||
onHover: (event, chartElement, chart) => {
|
onHover: (event, chartElement, chart) => {
|
||||||
const target = event?.native?.target;
|
const target = event?.native?.target;
|
||||||
|
const currentChart = chart || chartRef.current;
|
||||||
|
if (!currentChart) return;
|
||||||
|
|
||||||
|
const tooltipActive = currentChart.tooltip?._active ?? [];
|
||||||
|
const activeElements = currentChart.getActiveElements
|
||||||
|
? currentChart.getActiveElements()
|
||||||
|
: [];
|
||||||
|
const hasActive =
|
||||||
|
(chartElement && chartElement.length > 0) ||
|
||||||
|
(tooltipActive && tooltipActive.length > 0) ||
|
||||||
|
(activeElements && activeElements.length > 0);
|
||||||
|
|
||||||
if (target) {
|
if (target) {
|
||||||
target.style.cursor = chartElement[0] ? 'crosshair' : 'default';
|
target.style.cursor = hasActive ? 'crosshair' : 'default';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 仅用于桌面端 hover 改变光标,不在这里做 2 秒清除,避免移动端 hover 事件不稳定
|
||||||
|
},
|
||||||
|
onClick: (_event, _elements, chart) => {
|
||||||
const currentChart = chart || chartRef.current;
|
const currentChart = chart || chartRef.current;
|
||||||
if (!currentChart) return;
|
if (!currentChart) return;
|
||||||
|
|
||||||
@@ -232,7 +247,6 @@ export default function FundTrendChart({ code, isExpanded, onToggleExpand, trans
|
|||||||
hoverTimeoutRef.current = null;
|
hoverTimeoutRef.current = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (chartElement[0]) {
|
|
||||||
hoverTimeoutRef.current = setTimeout(() => {
|
hoverTimeoutRef.current = setTimeout(() => {
|
||||||
const c = chartRef.current || currentChart;
|
const c = chartRef.current || currentChart;
|
||||||
if (!c) return;
|
if (!c) return;
|
||||||
@@ -241,12 +255,8 @@ export default function FundTrendChart({ code, isExpanded, onToggleExpand, trans
|
|||||||
c.tooltip.setActiveElements([], { x: 0, y: 0 });
|
c.tooltip.setActiveElements([], { x: 0, y: 0 });
|
||||||
}
|
}
|
||||||
c.update();
|
c.update();
|
||||||
if (target) {
|
|
||||||
target.style.cursor = 'default';
|
|
||||||
}
|
|
||||||
}, 2000);
|
}, 2000);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
};
|
};
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user