-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Limit zoom bounds when zoomOutRestrict(true)
#1026
Conversation
Updated (solution) fiddle after last commit: |
Fixed references in before-fiddle: https://jsfiddle.net/muxhu0Lh/1/ |
Thanks for the contribution, @indrimuska! This has a whole lot of mapping between domain and range coordinates, and to be honest I've been intimidated to look at it. But I think it can be much, much simpler. It really just needs to keep the same width (if possible), and clamp to the left and right sides. So I'm going to change the interface a little bit and implement it like this: function constrainExtent (extent, constraint) {
var size = extent[1] - extent[0];
if (extent[0] < constraint[0]) {
return [constraint[0], Math.min(constraint[1], constraint[0] + size)];
} else if (extent[1] > constraint[1]) {
return [Math.max(constraint[0], constraint[1] - size), constraint[1]];
} else {
return null;
}
} Both your implementation and mine have the same flaw that they are not updating the zoom behavior. So you can continue panning off the edge, and internally the zoom behavior will continue to change the Still, I think this is better than the old behavior, and d3v4 natively includes the feature, so I think this is good enough for now. |
I've also taken the liberty of turning your fiddle into an interactive test - I can't imagine how to test this stuff automatically, yet we still do need tests. My fix and your test will be in dc.js 2.0. |
thanks to @indrimuska for the fiddle this was based on automated tests would be very difficult for this kind of stuff, so we need tests we can interact with for #1026
Hi @gordonwoodhull, You can reproduce it by trying to zoom in one of the bound, let's say on the left side. If you drag the chart on the left nothing happens. But when you try to drag again on the other side (right) it does not change the domain immediately, it does after a while. This is because the "translated domain" has been moved outside the limits and after a while of right-dragging you put it in the right bounds. I've just pushed a commit in my |
Problem
Zoom range goes out of bound when I pan the chart over the limits (FIDDLE).

Understanding the problem
That issue occurs because how it's made
constrainRange()
private function ofcoordinateGridMixin
:As you see it doesn't take care if
constrainedRange[1]
(upper zoom limit) <constrainedRange[0]
(lower zoom limit).Solution
Based on @mhsmith PR for
d3.js
(d3/d3#1299), I replicated the behavior of the proposedzoom.xExtent
method and replaced the functionconstrainRange()
with a new one calledrestrictZoom()
.This is FIDDLE showing the solution using the compiled version of my
zoom-limit
branch.