Skip to content

Commit 84ba376

Browse files
committed
[fix] Update name of config to bookmarkableActions and some corner cases
1 parent 0c1311a commit 84ba376

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
@@ -88,8 +88,8 @@
8888
},
8989
},
9090
],
91-
urlFragments: {
92-
show: true,
91+
bookmarkableActions: {
92+
enabled: true,
9393
id: "basicUsage",
9494
},
9595
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
@@ -285,8 +285,8 @@ const NetJSONGraphDefaultConfig = {
285285
},
286286
],
287287
linkCategories: [],
288-
urlFragments: {
289-
show: false,
288+
bookmarkableActions: {
289+
enabled: false,
290290
id: null,
291291
},
292292

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
@@ -1214,9 +1214,9 @@ class NetJSONGraphUtil {
12141214
}
12151215

12161216
setUrlFragments(self, params) {
1217-
if (!self.config.urlFragments.show) return;
1217+
if (!self.config.bookmarkableActions.enabled) return;
12181218
const fragments = this.parseUrlFragments();
1219-
const id = self.config.urlFragments.id;
1219+
const id = self.config.bookmarkableActions.id;
12201220
let nodeId, zoom;
12211221
if (params.componentSubType === "graph") {
12221222
nodeId = params.data.id;
@@ -1225,49 +1225,45 @@ class NetJSONGraphUtil {
12251225
nodeId = params.data.node.id;
12261226
}
12271227
zoom = self?.leaflet?.getZoom();
1228-
if (!fragments[id]) {
1228+
if (!fragments[id] || !(fragments[id] instanceof URLSearchParams)) {
12291229
fragments[id] = new URLSearchParams();
12301230
fragments[id].set("id", id);
12311231
}
12321232
fragments[id].set("nodeId", nodeId);
1233-
if (zoom != undefined) {
1233+
if (zoom != null) {
12341234
fragments[id].set("zoom", zoom);
12351235
}
12361236
window.location.hash = this.generateUrlFragments(fragments);
12371237
}
12381238

1239-
removeUrlFragment(self) {
1240-
if (!self.config.urlFragments.show) return;
1239+
removeUrlFragment(self, id) {
1240+
if (!self.config.bookmarkableActions.enabled) return;
12411241

12421242
const fragments = this.parseUrlFragments();
1243-
const id = self.config.urlFragments.id;
12441243
if (fragments[id]) {
12451244
delete fragments[id];
12461245
}
12471246
window.location.hash = this.generateUrlFragments(fragments);
12481247
}
12491248

12501249
setSelectedNodeFromUrlFragments(self, fragments, node) {
1251-
if (!self.config.urlFragments.show || !Object.keys(fragments).length) return;
1252-
const id = self.config.urlFragments.id;
1250+
if (!self.config.bookmarkableActions.enabled || !Object.keys(fragments).length) return;
1251+
const id = self.config.bookmarkableActions.id;
12531252
const nodeId = fragments[id]?.get("nodeId");
12541253
const zoom = fragments[id]?.get("zoom");
12551254
if (nodeId === node.id) {
12561255
self.selectedNode = node;
1257-
if (zoom != undefined) self.selectedNode.zoom = Number(zoom);
1256+
if (zoom != null) self.selectedNode.zoom = Number(zoom);
12581257
}
12591258
}
12601259

12611260
applyUrlFragmentState(self) {
1262-
if (!self.config.urlFragments.show) return;
1261+
if (!self.config.bookmarkableActions.enabled) return;
12631262
const node = self.selectedNode;
12641263
if (!node) return;
12651264
const nodeType =
12661265
self.config.graphConfig.series.type || self.config.mapOptions.nodeConfig.type;
1267-
const {
1268-
properties: {location},
1269-
zoom,
1270-
} = node;
1266+
const { location, zoom } = node;
12711267
if (["scatter", "effectScatter"].includes(nodeType) && zoom != null) {
12721268
self.leaflet.setView([location.lat, location.lng], zoom);
12731269
}

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)