Skip to content

Commit 5f5f055

Browse files
committed
[fix] Update name of config to bookmarkableActions and some corner cases
1 parent 9e5d85c commit 5f5f055

File tree

9 files changed

+32
-40
lines changed

9 files changed

+32
-40
lines changed

public/example_templates/netjsongraph.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,8 @@
8282
},
8383
},
8484
],
85-
urlFragments: {
86-
show: true,
85+
bookmarkableActions: {
86+
enabled: true,
8787
id: "basicUsage",
8888
},
8989
prepareData: (data) => {

public/example_templates/netjsonmap-indoormap-overlay.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,8 @@
8585
},
8686
baseOptions: {media: [{option: {tooltip: {show: true}}}]},
8787
},
88-
urlFragments: {
89-
show: true,
88+
bookmarkableActions: {
89+
enabled: true,
9090
id: "geoMap",
9191
},
9292
prepareData: (data) => {
@@ -156,8 +156,8 @@
156156
},
157157
baseOptions: {media: [{option: {tooltip: {show: true}}}]},
158158
},
159-
urlFragments:{
160-
show: true,
159+
bookmarkableActions:{
160+
enabled: true,
161161
id: "indoorMap",
162162
},
163163
prepareData: (data) => {

public/example_templates/netjsonmap-indoormap.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,8 @@
106106
],
107107
},
108108
},
109-
urlFragments: {
110-
show: true,
109+
bookmarkableActions: {
110+
enabled: true,
111111
id: "indoorMap"
112112
},
113113

public/example_templates/netjsonmap.html

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,8 @@
7171
<script type="text/javascript">
7272
const map = new NetJSONGraph("../assets/data/netjsonmap.json", {
7373
render: "map",
74-
// set map initial state.
75-
urlFragments: {
76-
show: true,
74+
bookmarkableActions: {
75+
enabled: true,
7776
id: "geographicMap"
7877
},
7978
mapOptions: {
@@ -100,7 +99,7 @@
10099
},
101100
},
102101
],
103-
// Convert to internal json format
102+
104103
prepareData: (data) => {
105104
data.nodes.map((node) => {
106105
node.label = node.name;

src/js/netjsongraph.config.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -284,8 +284,8 @@ const NetJSONGraphDefaultConfig = {
284284
},
285285
],
286286
linkCategories: [],
287-
urlFragments: {
288-
show: false,
287+
bookmarkableActions: {
288+
enabled: false,
289289
id: null,
290290
},
291291

src/js/netjsongraph.render.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ class NetJSONGraphRender {
9393
"click",
9494
(params) => {
9595
const clickElement = configs.onClickElement.bind(self);
96+
self.utils.setUrlFragments(self, params);
9697
if (params.componentSubType === "graph") {
9798
return clickElement(
9899
params.dataType === "edge" ? "link" : "node",
@@ -102,7 +103,6 @@ class NetJSONGraphRender {
102103
if (params.componentSubType === "graphGL") {
103104
return clickElement("node", params.data);
104105
}
105-
self.utils.setUrlFragments(self, params);
106106
return params.componentSubType === "lines"
107107
? clickElement("link", params.data.link)
108108
: !params.data.cluster && clickElement("node", params.data.node);

src/js/netjsongraph.util.js

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1200,9 +1200,9 @@ class NetJSONGraphUtil {
12001200
}
12011201

12021202
setUrlFragments(self, params) {
1203-
if (!self.config.urlFragments.show) return;
1203+
if (!self.config.bookmarkableActions.enabled) return;
12041204
const fragments = this.parseUrlFragments();
1205-
const id = self.config.urlFragments.id;
1205+
const id = self.config.bookmarkableActions.id;
12061206
let nodeId, zoom;
12071207
if (params.componentSubType === "graph") {
12081208
nodeId = params.data.id;
@@ -1211,49 +1211,45 @@ class NetJSONGraphUtil {
12111211
nodeId = params.data.node.id;
12121212
}
12131213
zoom = self?.leaflet?.getZoom();
1214-
if (!fragments[id]) {
1214+
if (!fragments[id] || !(fragments[id] instanceof URLSearchParams)) {
12151215
fragments[id] = new URLSearchParams();
12161216
fragments[id].set("id", id);
12171217
}
12181218
fragments[id].set("nodeId", nodeId);
1219-
if (zoom != undefined) {
1219+
if (zoom != null) {
12201220
fragments[id].set("zoom", zoom);
12211221
}
12221222
window.location.hash = this.generateUrlFragments(fragments);
12231223
}
12241224

1225-
removeUrlFragment(self) {
1226-
if (!self.config.urlFragments.show) return;
1225+
removeUrlFragment(self, id) {
1226+
if (!self.config.bookmarkableActions.enabled) return;
12271227

12281228
const fragments = this.parseUrlFragments();
1229-
const id = self.config.urlFragments.id;
12301229
if (fragments[id]) {
12311230
delete fragments[id];
12321231
}
12331232
window.location.hash = this.generateUrlFragments(fragments);
12341233
}
12351234

12361235
setSelectedNodeFromUrlFragments(self, fragments, node) {
1237-
if (!self.config.urlFragments.show || !Object.keys(fragments).length) return;
1238-
const id = self.config.urlFragments.id;
1236+
if (!self.config.bookmarkableActions.enabled || !Object.keys(fragments).length) return;
1237+
const id = self.config.bookmarkableActions.id;
12391238
const nodeId = fragments[id]?.get("nodeId");
12401239
const zoom = fragments[id]?.get("zoom");
12411240
if (nodeId === node.id) {
12421241
self.selectedNode = node;
1243-
if (zoom != undefined) self.selectedNode.zoom = Number(zoom);
1242+
if (zoom != null) self.selectedNode.zoom = Number(zoom);
12441243
}
12451244
}
12461245

12471246
applyUrlFragmentState(self) {
1248-
if (!self.config.urlFragments.show) return;
1247+
if (!self.config.bookmarkableActions.enabled) return;
12491248
const node = self.selectedNode;
12501249
if (!node) return;
12511250
const nodeType =
12521251
self.config.graphConfig.series.type || self.config.mapOptions.nodeConfig.type;
1253-
const {
1254-
properties: {location},
1255-
zoom,
1256-
} = node;
1252+
const { location, zoom } = node;
12571253
if (["scatter", "effectScatter"].includes(nodeType) && zoom != null) {
12581254
self.leaflet.setView([location.lat, location.lng], zoom);
12591255
}

test/netjsongraph.util.test.js

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,6 @@ describe("Test URL fragment utilities", () => {
202202
});
203203

204204
test("Test parseUrlFragments parses multiple fragments and decodes values", () => {
205-
// use ids that match what we will assert on
206205
window.location.hash =
207206
"#id=geoMap&nodeId=abc%3A123&zoom=5;id=indoorMap&nodeId=indoor-node&zoom=5";
208207
const fragments = utils.parseUrlFragments();
@@ -216,7 +215,7 @@ describe("Test URL fragment utilities", () => {
216215
test("Test setUrlFragments adds a new fragment with nodeId and zoom", () => {
217216
const self = {
218217
config: {
219-
urlFragments: {show: true, id: "geoMap"},
218+
bookmarkableActions: {enabled: true, id: "geoMap"},
220219
},
221220
leaflet: {getZoom: () => 7},
222221
};
@@ -238,7 +237,7 @@ describe("Test URL fragment utilities", () => {
238237
window.location.hash = "id=graph&nodeId=node-1";
239238

240239
const self = {
241-
config: {urlFragments: {show: true, id: "geo"}},
240+
config: {bookmarkableActions: {enabled: true, id: "geo"}},
242241
leaflet: {getZoom: () => 9},
243242
};
244243
const params = {
@@ -258,8 +257,8 @@ describe("Test URL fragment utilities", () => {
258257

259258
test("removeUrlFragment deletes the fragment for the given id", () => {
260259
window.location.hash = "id=keep&nodeId=a;id=removeMe&nodeId=b";
261-
const self = {config: {urlFragments: {show: true, id: "removeMe"}}};
262-
utils.removeUrlFragment(self);
260+
const self = {config: {bookmarkableActions: {enabled: true, id: "removeMe"}}};
261+
utils.removeUrlFragment(self, "removeMe");
263262
const fragments = utils.parseUrlFragments();
264263
expect(fragments.keep).toBeDefined();
265264
expect(fragments.removeMe).toBeUndefined();
@@ -268,10 +267,9 @@ describe("Test URL fragment utilities", () => {
268267

269268
test("Test setSelectedNodeFromUrlFragments sets selectedNode and numeric zoom", () => {
270269
window.location.hash = "#id=geo&nodeId=abc&zoom=4";
271-
const self = {config: {urlFragments: {show: true, id: "geo"}}};
270+
const self = {config: {bookmarkableActions: {enabled: true, id: "geo"}}};
272271
const fragments = utils.parseUrlFragments();
273272

274-
// node with matching id
275273
const node = {id: "abc", properties: {}};
276274
utils.setSelectedNodeFromUrlFragments(self, fragments, node);
277275

@@ -291,7 +289,7 @@ describe("Test URL fragment utilities", () => {
291289

292290
const self = {
293291
config: {
294-
urlFragments: {show: true, id: "geo"},
292+
bookmarkableActions: {enabled: true, id: "geo"},
295293
graphConfig: {series: {type: null}},
296294
mapOptions: {nodeConfig: {type: "scatter"}},
297295
onClickElement: mockOnClick,

webpack.config.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@ module.exports = (env, argv) => ({
2929
},
3030
devtool: argv.mode === "development" ? "eval-source-map" : "source-map",
3131
optimization: {
32-
// Todo: Make it false
33-
minimize: false,
32+
minimize: true,
3433
minimizer: argv.mode === "production" ? minimizer : [],
3534
},
3635
module: {

0 commit comments

Comments
 (0)