-
-
Notifications
You must be signed in to change notification settings - Fork 96
[feature] Update URL with node click of map interactions #238 #417
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As discussed in our weekly meeting, the result doesn't seem to match the specs described in #238.
Please read again the specs and ask any question if not clear.
6fa8c24
to
591ed33
Compare
4c6fdfb
to
751d759
Compare
Screencast.from.2025-09-12.02-47-39.webm |
0b32122
to
5bfbddc
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good work @Deepanshu! This is going to be a very user feature in the library. 💪🏼
I found a corner case while going back through the history of the browser using the back button. I expected the map to update when the URL fragment updates, but that is not the case here.
I also explored about enabling this feature by default. If ID is not provided in the config, we can generate a hash based on the HTML element. This can have side-effects, so let's think before going ahead in this direction.
Maybe, auto-generating ID is a bad idea. If the hash will change if the user changed the HTML element. This will render old URLs useless.
diff --git a/src/js/netjsongraph.config.js b/src/js/netjsongraph.config.js
index b4fcc67..444d813 100644
--- a/src/js/netjsongraph.config.js
+++ b/src/js/netjsongraph.config.js
@@ -285,7 +285,7 @@ const NetJSONGraphDefaultConfig = {
],
linkCategories: [],
urlFragments: {
- show: false,
+ show: true,
id: null,
},
diff --git a/src/js/netjsongraph.core.js b/src/js/netjsongraph.core.js
index 1d448d1..1758e0b 100644
--- a/src/js/netjsongraph.core.js
+++ b/src/js/netjsongraph.core.js
@@ -57,6 +57,19 @@ class NetJSONGraph {
console.error("Can't change el again!");
}
+ if (!this.config.urlFragments.id) {
+ // The config does not specify a an ID, we assign one by creating
+ // a hash of the HTML element using FNV-1a algorithm
+ let str = this.el.outerHTML
+ let hash = 0x811c9dc5; // FNV offset basis
+ for (let i = 0; i < str.length; i++) {
+ hash ^= str.charCodeAt(i);
+ hash = (hash * 0x01000193) >>> 0; // FNV prime
+
+ }
+ this.config.urlFragments.id = hash.toString();
+ }
+
return this.config;
}
Maybe, this is a bad idea. What if the user updates the HTML element? Then, the old URLs will no longer work. |
32eb321
to
0883e25
Compare
19c0860
to
a628752
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good work @dee077! 👏🏼 👏🏼 👏🏼
It works as expected.
We need to add a lot of comments in the code to explain our design decision. Otherwise, we will forget about why we chose to implement the feature this way and then search for the details in issues.
const zoom = | ||
cluster != null ? self.config.disableClusteringAtLevel : self.leaflet.getZoom(); | ||
self.leaflet.setView([location.lat, location.lng], zoom); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Didn't we discuss in the last meeting to use a constant zoom on the leaflet map?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is better as the leaflet sets a zoom so that all the nodes are visible on the map initially. Using the initial default zoom set by Leaflet will show the popup along with other locations with this view user can check other locations as well. If we set a custom zoom, the user has to additionally move around on the map.
expect(mockOnClick).toHaveBeenCalledWith("node", node); | ||
}); | ||
|
||
test("Test applyUrlFragmentState runs only after onReady completes", async () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand this test. What are we testing here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We checking the applyUrlFragmentState is called after onRender
Implemented query param updates on node click, zoom and interaction with map. Visiting a URL with query params of map bounds to auto-focuses the node. Fixes #238
cc0fb55
to
9c1380f
Compare
702fba7
to
c076184
Compare
c076184
to
d65b3ac
Compare
Checklist
Reference to Existing Issue
Closes #238 .
Description of Changes