netjsongraph.js
netjsongraph.js copied to clipboard
[feature] Update URL with node click of map interactions #238
Checklist
- [x] I have read the OpenWISP Contributing Guidelines.
- [x] I have manually tested the changes proposed in this pull request.
- [ ] I have written new test cases for new code and/or updated existing tests for changes to existing code.
- [ ] I have updated the documentation.
Reference to Existing Issue
Closes #238 .
Description of Changes
- Update URL query params on map interactions (zoom, move, bounds change)
- Add mode in URL to differentiate indoor map and geo-map
- Open floorplan overlay when in indoor map mode
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, this is a bad idea. What if the user updates the HTML element? Then, the old URLs will no longer work.
Updates
- ~~Added a new object in the netjsongraph instance
this.nodeIndex, which contains the key asnode.idorsourceNodeId-targetNodeIdin case of a link, so that it can be looked afterwards bythis.data.nodes[index] or this.data.links[index].~~ - Updated the tests with these new changes and added new unit and browser tests for case of links.
- Did not add browser tests for adding nodes to url on click on the node or link, as we currently don't have resilient logic to trigger the click event of the node or link in selenium tests. Moving the mouse programmatically and triggering a click will cause unexpected failure on different window sizes.
- Adding the value for nodeIndex as index of the array present
this.data.nodesorthis.data.nodeswas a bad idea, as it cannot be sure the array will be in the same sequence every time. On monitoring found that the index is getting changed on readering a url in a new tab. - So in
netjsongraph.core.jswe are already traversing the nodes and links to set thethis.data, so I created a shallow copy of it in this.nodeLinkIndex as key of node id orsource~targetfor further looks without need for a traversal. - Used
~as a separator in case of setting link key in dict assource~target, uuid can have-and give unexpected results
Feel free to update the Readme if you want some additional details to mention or want to remove something.