Skip to content

Commit

Permalink
[change] Show node labels only after a suitable zoom level #148
Browse files Browse the repository at this point in the history
closes #148
  • Loading branch information
totallynotvaishnav committed Sep 20, 2022
1 parent c51b518 commit 7e2e925
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 13 deletions.
2 changes: 1 addition & 1 deletion dist/netjsongraph.min.js

Large diffs are not rendered by default.

10 changes: 4 additions & 6 deletions src/js/netjsongraph.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ const NetJSONGraphDefaultConfig = {
switchMode: false,
maxPointsFetched: 10000,
showMetaOnNarrowScreens: false,
showLabelsAtZoomLevel: 7,
echartsOption: {
aria: {
show: true,
Expand Down Expand Up @@ -66,6 +67,9 @@ const NetJSONGraphDefaultConfig = {
color: "#fff",
position: "top",
},
labelLayout: {
hideOverlap: true,
},
force: {
gravity: 0.1,
edgeLength: [20, 60],
Expand Down Expand Up @@ -102,9 +106,6 @@ const NetJSONGraphDefaultConfig = {
series: [
{
zoom: 0.7,
labelLayout: {
hideOverlap: true,
},
},
],
toolbox: {
Expand All @@ -120,9 +121,6 @@ const NetJSONGraphDefaultConfig = {
series: [
{
zoom: 1,
labelLayout: {
hideOverlap: false,
},
},
],
toolbox: {
Expand Down
36 changes: 36 additions & 0 deletions src/js/netjsongraph.render.js
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,42 @@ class NetJSONGraphRender {
);
}

if (self.leaflet.getZoom() < self.config.showLabelsAtZoomLevel) {
self.echarts.setOption({
series: [
{
label: {
show: false,
},
},
],
});
}

self.leaflet.on("zoomend", () => {
if (self.leaflet.getZoom() >= self.config.showLabelsAtZoomLevel) {
self.echarts.setOption({
series: [
{
label: {
show: true,
},
},
],
});
} else {
self.echarts.setOption({
series: [
{
label: {
show: false,
},
},
],
});
}
});

self.event.emit("onLoad");
self.event.emit("onReady");
self.event.emit("renderArray");
Expand Down
9 changes: 3 additions & 6 deletions test/netjsongraph.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ describe("NetJSONGraph Specification", () => {
color: "#fff",
position: "top",
},
labelLayout: {
hideOverlap: true,
},
force: {
gravity: 0.1,
edgeLength: [20, 60],
Expand Down Expand Up @@ -68,9 +71,6 @@ describe("NetJSONGraph Specification", () => {
series: [
{
zoom: 0.7,
labelLayout: {
hideOverlap: true,
},
},
],
toolbox: {
Expand All @@ -86,9 +86,6 @@ describe("NetJSONGraph Specification", () => {
series: [
{
zoom: 1,
labelLayout: {
hideOverlap: false,
},
},
],
toolbox: {
Expand Down

0 comments on commit 7e2e925

Please sign in to comment.