Made constrain about viewport center (experiment!) #118
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Not really a serious PR but more of food for thought (please feel free to close it).
My fork here is the result of an experiment of my project where users can do remote collaborative work with visualizations in real-time.
In this project it is possible to share views but because the viewports of users can differ a lot I decided to make everything about the view center, e.g. the coordinates shared are the values of the SVG transform in the current view center (subtracting half of map width/height). Also when resizing the viewport the centered content stays centered.
This fork here is then about making the constrains also all about the center, so that e.g.
.translateExtent()
only restricts panning insofar as to make sure that the center of the view is restricted making it independent of the viewport (otherwise users with different viewports would have different restriction for which coordinate positions [representing the viewport center] they can reach). I guess I could have alternatively set.translateExtent
dynamically but I doubt that this would have been a nicer solution.Now I have no idea whether this would be worth allowing in d3.zoom and if yes then how; maybe
constrain()
could be made replaceable altough this would mean four additional parameters. So this is why this here is not a serious PR (and again please feel free to close it) and I would just like to have some input.(On a side node, in my project I tried using separate transforms for d3.zoom and the centering stuff, see https://stackoverflow.com/q/46533546/2261442, but in the end I wasn't able to come up with a useful solution, my own answer which I accepted also has severe drawbacks)