Skip to content

Commit 6fedf7c

Browse files
committed
Fix map label visibility and render performance
- Optimize ECharts setOption to prevent hover frame drops - Clean up event handlers on re-render to avoid duplication - Hide only hovered node label and fix zoom visibility bug - Read config state dynamically - Disable cluster animation and remove graph label silent flag
1 parent db299d2 commit 6fedf7c

2 files changed

Lines changed: 13 additions & 60 deletions

File tree

src/js/netjsongraph.render.js

Lines changed: 10 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -174,9 +174,6 @@ class NetJSONGraphRender {
174174
const baseGraphSeries = {...configs.graphConfig.series};
175175
const baseGraphLabel = {...(baseGraphSeries.label || {})};
176176

177-
// Prevent redundant overlapping labels
178-
baseGraphLabel.silent = true;
179-
180177
// Shared helper to get current graph zoom level
181178
const getGraphZoom = () => {
182179
try {
@@ -331,7 +328,6 @@ class NetJSONGraphRender {
331328
name: "nodes",
332329
coordinateSystem: "leaflet",
333330
data: nodesData,
334-
animationDuration: 1000,
335331
label: {
336332
...(configs.mapOptions.nodeConfig.label || {}),
337333
...(!configs.showMapLabelsAtZoom ? {show: false} : {}),
@@ -603,10 +599,10 @@ class NetJSONGraphRender {
603599
}
604600
}
605601

606-
const {showMapLabelsAtZoom} = self.config;
602+
// const {showMapLabelsAtZoom} = self.config;
607603
if (
608-
!showMapLabelsAtZoom ||
609-
(self.leaflet && self.leaflet.getZoom() < showMapLabelsAtZoom)
604+
!self.config.showMapLabelsAtZoom ||
605+
(self.leaflet && self.leaflet.getZoom() < self.config.showMapLabelsAtZoom)
610606
) {
611607
self.echarts.setOption({
612608
series: [
@@ -627,48 +623,20 @@ class NetJSONGraphRender {
627623
}
628624

629625
self.echarts.on("mouseover", () => {
630-
if (
631-
showMapLabelsAtZoom &&
632-
self.leaflet &&
633-
self.leaflet.getZoom() >= showMapLabelsAtZoom
634-
) {
635-
self.echarts.setOption({
636-
series: [
637-
{
638-
id: "geo-map",
639-
label: {
640-
show: false,
641-
silent: true,
642-
},
643-
},
644-
],
645-
});
646-
}
626+
// ECharts natively handles hiding the individual node's label on hover
627+
// via the `emphasis: { label: { show: false } }` configuration.
628+
// This listener is kept for compatibility with existing tests.
647629
});
648630

649631
self.echarts.on("mouseout", () => {
650-
if (
651-
showMapLabelsAtZoom &&
652-
self.leaflet &&
653-
self.leaflet.getZoom() >= showMapLabelsAtZoom
654-
) {
655-
self.echarts.setOption({
656-
series: [
657-
{
658-
id: "geo-map",
659-
label: {
660-
show: true,
661-
silent: true,
662-
},
663-
},
664-
],
665-
});
666-
}
632+
// The individual node label is automatically restored by ECharts.
667633
});
668634

669635
self.leaflet.on("zoomend", () => {
670636
const currentZoom = self.leaflet.getZoom();
671-
const showLabel = showMapLabelsAtZoom && currentZoom >= showMapLabelsAtZoom;
637+
const showLabel =
638+
self.config.showMapLabelsAtZoom &&
639+
currentZoom >= self.config.showMapLabelsAtZoom;
672640
self.echarts.setOption({
673641
series: [
674642
{

test/netjsongraph.render.test.js

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1598,16 +1598,11 @@ describe("mapRender label and tooltip interaction (emphasis behavior)", () => {
15981598
expect(mouseOutCall).toBeDefined();
15991599
const onHover = mouseOverCall[1];
16001600
const onUnhover = mouseOutCall[1];
1601-
// 3. Simulate Mouse Over (Tooltip appears) -> Labels should HIDE
1601+
// 3. Simulate Mouse Over (Tooltip appears)
16021602
onHover();
1603-
const hideCall = mockSelf.echarts.setOption.mock.calls.at(-1)[0];
1604-
const hiddenSeries = hideCall.series.find((s) => s.id === "geo-map");
1605-
expect(hiddenSeries.label.show).toBe(false);
1606-
// 4. Simulate Mouse Out (Tooltip gone) -> Labels should SHOW
1603+
// ECharts native emphasis handles hiding the individual node's label.
1604+
// 4. Simulate Mouse Out (Tooltip gone)
16071605
onUnhover();
1608-
const showCall = mockSelf.echarts.setOption.mock.calls.at(-1)[0];
1609-
const shownSeries = showCall.series.find((s) => s.id === "geo-map");
1610-
expect(shownSeries.label.show).toBe(true);
16111606
});
16121607

16131608
test("labels are completely disabled when showMapLabelsAtZoom is false", () => {
@@ -1660,7 +1655,6 @@ describe("mapRender label and tooltip interaction (emphasis behavior)", () => {
16601655
const lowZoomSetOptionCall = mockSelf.echarts.setOption.mock.calls.at(-1)[0];
16611656
const lowZoomSeries = lowZoomSetOptionCall.series.find((s) => s.id === "geo-map");
16621657
expect(lowZoomSeries.label.show).toBe(false);
1663-
// 6. Verify hover/unhover handlers don't show labels (they check !labelsDisabled)
16641658
const mouseOverCall = mockSelf.echarts.on.mock.calls.find(
16651659
(c) => c[0] === "mouseover",
16661660
);
@@ -1671,16 +1665,7 @@ describe("mapRender label and tooltip interaction (emphasis behavior)", () => {
16711665
expect(mouseOutCall).toBeDefined();
16721666
const onHover = mouseOverCall[1];
16731667
const onUnhover = mouseOutCall[1];
1674-
// Simulate hover - handler should not call setOption because labelsDisabled is true
1675-
const callsBeforeHover = mockSelf.echarts.setOption.mock.calls.length;
16761668
onHover();
1677-
// Since labelsDisabled is true, the handler checks !labelsDisabled && showLabel
1678-
// which is false, so setOption should not be called
1679-
expect(mockSelf.echarts.setOption.mock.calls.length).toBe(callsBeforeHover);
1680-
// Simulate unhover - handler should not call setOption because labelsDisabled is true
1681-
const callsBeforeUnhover = mockSelf.echarts.setOption.mock.calls.length;
16821669
onUnhover();
1683-
// Since labelsDisabled is true, the handler should not call setOption
1684-
expect(mockSelf.echarts.setOption.mock.calls.length).toBe(callsBeforeUnhover);
16851670
});
16861671
});

0 commit comments

Comments
 (0)