From e55223bbd8b46a9b16a3b322504e92c39148e23f Mon Sep 17 00:00:00 2001 From: Gagan Deep Date: Thu, 27 Apr 2023 13:09:26 +0530 Subject: [PATCH] [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 817c87e..80d1608 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, + }, }); } });