Skip to content

Commit

Permalink
[fix] Fixed issue of resizing graph on zoom
Browse files Browse the repository at this point in the history
  • Loading branch information
pandafy committed Apr 27, 2023
1 parent f217864 commit e55223b
Showing 1 changed file with 33 additions and 30 deletions.
63 changes: 33 additions & 30 deletions src/js/netjsongraph.render.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
});
}
});
Expand Down

0 comments on commit e55223b

Please sign in to comment.