From f2178644f60ce3b8ac1050bfe2c408ac5cb840a5 Mon Sep 17 00:00:00 2001 From: Gagan Deep Date: Wed, 12 Apr 2023 20:43:59 +0530 Subject: [PATCH 1/2] [change] Graph mode respects showLabelsAtZoomLevel setting #148 Closes #148 --- src/js/netjsongraph.render.js | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/src/js/netjsongraph.render.js b/src/js/netjsongraph.render.js index c712b9e6..817c87e4 100644 --- a/src/js/netjsongraph.render.js +++ b/src/js/netjsongraph.render.js @@ -296,6 +296,38 @@ class NetJSONGraphRender { self.echarts.resize(); }; + if ( + self.echarts.getOption().series[0].zoom < + self.config.showLabelsAtZoomLevel + ) { + self.echarts.setOption({ + series: [ + { + label: { + show: false, + }, + }, + ], + }); + } + + self.echarts.on("graphRoam", (e) => { + if ( + self.echarts.getOption().series[0].zoom >= + self.config.showLabelsAtZoomLevel + ) { + self.echarts.setOption({ + series: [ + { + label: { + show: true, + }, + }, + ], + }); + } + }); + self.event.emit("onLoad"); self.event.emit("onReady"); self.event.emit("renderArray"); @@ -421,7 +453,6 @@ class NetJSONGraphRender { self.leaflet.geoJSON.addTo(self.leaflet); } } - if (self.leaflet.getZoom() < self.config.showLabelsAtZoomLevel) { self.echarts.setOption({ series: [ From b06f46093266154cb0c558f7e162b1910e997a95 Mon Sep 17 00:00:00 2001 From: Gagan Deep Date: Thu, 27 Apr 2023 13:09:26 +0530 Subject: [PATCH 2/2] [fix] Fixed issue of resizing graph on zoom --- src/js/netjsongraph.render.js | 63 ++++++++++++++++++----------------- 1 file changed, 33 insertions(+), 30 deletions(-) diff --git a/src/js/netjsongraph.render.js b/src/js/netjsongraph.render.js index 817c87e4..524ec8e6 100644 --- a/src/js/netjsongraph.render.js +++ b/src/js/netjsongraph.render.js @@ -287,43 +287,46 @@ class NetJSONGraphRender { * */ graphRender(JSONData, self) { - self.utils.echartsSetOption( - self.utils.generateGraphOption(JSONData, self), - self, - ); + const echartOptions = self.utils.generateGraphOption(JSONData, self); + if (echartOptions.series[0].label === undefined) { + echartOptions.series[0].label = {}; + } + if ( + !echartOptions.series[0].zoom || + echartOptions.series[0].zoom < self.config.showLabelsAtZoomLevel + ) { + echartOptions.series[0].label.show = false; + } else { + echartOptions.series[0].label.show = true; + } + self.utils.echartsSetOption(echartOptions, self); window.onresize = () => { self.echarts.resize(); }; - if ( - self.echarts.getOption().series[0].zoom < - self.config.showLabelsAtZoomLevel - ) { - self.echarts.setOption({ - series: [ - { - label: { - show: false, - }, - }, - ], - }); - } - - self.echarts.on("graphRoam", (e) => { + self.echarts.on("graphRoam", () => { + const customOptions = self.echarts.getOption(); if ( - self.echarts.getOption().series[0].zoom >= - self.config.showLabelsAtZoomLevel + customOptions.series[0].zoom >= self.config.showLabelsAtZoomLevel && + !customOptions.series[0].label.show ) { - self.echarts.setOption({ - series: [ - { - label: { - show: true, - }, - }, - ], + customOptions.series[0].label.show = true; + self.echarts.setOption(customOptions, { + notMerge: { + silent: true, + }, + lazyUpdate: true, + }); + } else if ( + customOptions.series[0].zoom < self.config.showLabelsAtZoomLevel && + customOptions.series[0].label.show + ) { + customOptions.series[0].label.show = false; + self.echarts.setOption(customOptions, { + notMerge: { + silent: true, + }, }); } });