8000 Made constrain about viewport center (experiment!) by Herst · Pull Request #118 · d3/d3-zoom · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Made constrain about viewport center (experiment!) #118

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

Closed
wants to merge 1 commit into from

Conversation

Herst
Copy link
Contributor
@Herst Herst commented Oct 14, 2017

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)

@Herst
Copy link
Contributor Author
Herst commented Oct 16, 2017

I just came up with an alternative idea in which this could be achieved. Simply make the extent which constrain() uses separate from the one used elsewhere. This way someone could set this new constrainExtent to [[center, center], [center, center]] and achieve the same goal. What do you think?

mbostock added a commit that referenced this pull request Oct 18, 2017
@mbostock mbostock mentioned this pull request Oct 18, 2017
@mbostock
Copy link
Member

My preference would be to add a zoom.constrain method which lets you override the definition of constrain, with the default implementation being today’s implementation. We employ a similar strategy for zoom.filter and zoom.extent.

Please review #119. Thank you!

@mbostock mbostock closed this Oct 18, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
0