Skip to content

Commit f849e2f

Browse files
committed
[fix] Add new config for disabling zoom
1 parent ba4f267 commit f849e2f

File tree

7 files changed

+33
-10
lines changed

7 files changed

+33
-10
lines changed

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,10 @@ NetJSON format used internally is based on [networkgraph](http://netjson.org/rfc
473473
bookmarkableActions: {
474474
enabled: boolean,
475475
id: string,
476-
zoomLevel: number
476+
zoom: {
477+
enabled: boolean,
478+
zoomLevel: integer
479+
}
477480
}
478481
```
479482

@@ -482,7 +485,6 @@ NetJSON format used internally is based on [networkgraph](http://netjson.org/rfc
482485
You can enable or disable adding url fragments by setting enabled to true or false. When enabled, the following parameters are added to the URL:
483486
1. id – A prefix used to uniquely identify the map.
484487
2. nodeId – The id of the selected node.
485-
3. zoomLevel – The zoom level applied when restoring the state from the URL fragments.
486488

487489
This feature allows you to create shareable and restorable map or graph states using URL fragments. When this feature is enabled, the URL updates automatically whenever you click a node or a link in your NetJSONGraph visualization. This makes it easy to share a specific view, restore it later, or navigate between different states using the browser’s back and forward buttons.
488490

public/example_templates/netjsonmap-indoormap-overlay.html

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,10 @@
9999
bookmarkableActions: {
100100
enabled: true,
101101
id: "geoMap",
102-
zoomLevel: 10,
102+
zoom: {
103+
enabled: true,
104+
zoomLevel: 10
105+
}
103106
},
104107
prepareData: (data) => {
105108
data.nodes.forEach((n) => {
@@ -173,6 +176,9 @@
173176
bookmarkableActions: {
174177
enabled: true,
175178
id: "indoorMap",
179+
zoom: {
180+
enabled: false,
181+
}
176182
},
177183
prepareData: (data) => {
178184
data.nodes.forEach((n) => {

public/example_templates/netjsonmap-indoormap.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@
6464
bookmarkableActions: {
6565
enabled: true,
6666
id: "indoorMap",
67+
zoom: {
68+
enabled: false,
69+
}
6770
},
6871
// Convert to internal json format
6972
prepareData: function (data) {

public/example_templates/netjsonmap.html

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,10 @@
9898
bookmarkableActions: {
9999
enabled: true,
100100
id: "geographicMap",
101-
zoomLevel: 10,
101+
zoom: {
102+
enabled: true,
103+
zoomLevel: 10,
104+
},
102105
},
103106

104107
prepareData: (data) => {

src/js/netjsongraph.config.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,10 @@ const NetJSONGraphDefaultConfig = {
288288
bookmarkableActions: {
289289
enabled: false,
290290
id: null,
291-
zoomLevel: null,
291+
zoom: {
292+
enabled: false,
293+
zoomLevel: null,
294+
},
292295
},
293296

294297
/**

src/js/netjsongraph.util.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1296,7 +1296,7 @@ class NetJSONGraphUtil {
12961296
const fragmentParams = fragments[id] && fragments[id].get ? fragments[id] : null;
12971297
const nodeId =
12981298
fragmentParams && fragmentParams.get ? fragmentParams.get("nodeId") : undefined;
1299-
if (!nodeId || !self.nodeLinkIndex || !self.nodeLinkIndex[nodeId] == null) {
1299+
if (!nodeId || !self.nodeLinkIndex || self.nodeLinkIndex[nodeId] == null) {
13001300
return;
13011301
}
13021302
const [source, target] = nodeId.split("~");
@@ -1311,11 +1311,13 @@ class NetJSONGraphUtil {
13111311
const zoom =
13121312
cluster != null
13131313
? self.config.disableClusteringAtLevel
1314-
: self.config.bookmarkableActions.zoomLevel ||
1314+
: self.config.bookmarkableActions.zoom.zoomLevel ||
13151315
self.config.showLabelsAtZoomLevel;
13161316
// Currently, there’s no way to center the view on a link element within the graph or map.
13171317
// The view is only centered when using a Leaflet map and the selected element is a node.
1318-
self.leaflet?.setView(center, zoom);
1318+
if (self.config.bookmarkableActions.zoom.enabled) {
1319+
self.leaflet?.setView(center, zoom);
1320+
}
13191321
}
13201322
self.config.onClickElement.call(self, source && target ? "link" : "node", node);
13211323
}

test/netjsongraph.util.test.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ describe("Test URL fragment utilities", () => {
264264
const self = {
265265
config: {
266266
render: "graph",
267-
bookmarkableActions: {enabled: true, id: "geo"},
267+
bookmarkableActions: {enabled: true, id: "geo", zoom: {enabled: true}},
268268
},
269269
utils: {...utils, graphRender: "graph", mapRender: "map"},
270270
nodeLinkIndex: {node1: node1, node2: node2},
@@ -305,7 +305,11 @@ describe("Test URL fragment utilities", () => {
305305
const self = {
306306
config: {
307307
render: "map",
308-
bookmarkableActions: {enabled: true, id: "geo", zoomLevel: 6},
308+
bookmarkableActions: {
309+
enabled: true,
310+
id: "geo",
311+
zoom: {enabled: true, zoomLevel: 6},
312+
},
309313
graphConfig: {series: {type: null}},
310314
mapOptions: {nodeConfig: {type: "scatter"}, center: [0, 0]},
311315
onClickElement: mockOnClick,

0 commit comments

Comments
 (0)