Skip to content
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

Not Compatible with Brushing #40

Closed
jasonbodily opened this issue Jul 4, 2016 · 2 comments
Closed

Not Compatible with Brushing #40

jasonbodily opened this issue Jul 4, 2016 · 2 comments

Comments

@jasonbodily
Copy link

Creating a brush and zoom chart like this one http://bl.ocks.org/nnattawat/9689303 in version 4 becomes extremely difficult. An infinite loop occurs:

  • A zoom event is only able to move the brush using "brush.move". This triggers a brush event.
  • The brush event must update the zoom scale and translate which it cannot do except by calling "zoom.transform".
  • This triggers a zoom event...

The zoom could be calculated and set to the node manually but the documentation says this is bad practice. Is there be a way to update the zoom without triggering an event? Previously in V3 you could reset the scale, I believe.

@mbostock
Copy link
Member

mbostock commented Jul 4, 2016

Use d3.event.sourceEvent to break the infinite loop.

function brushed() {
  if (d3.event.sourceEvent && d3.event.sourceEvent.type === "zoom") return; // ignore brush-by-zoom
  
}

function zoomed() {
  if (d3.event.sourceEvent && d3.event.sourceEvent.type === "brush") return; // ignore zoom-by-brush
  
}

http://bl.ocks.org/mbostock/34f08d5e11952a80609169b7917d4172

@mbostock mbostock closed this as completed Jul 4, 2016
@jasonbodily
Copy link
Author

A million thanks for recreating that example! I'd been looking for it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants