D3 Zoom resets scales selected via brushing.

℡╲_俬逩灬. 提交于 2019-12-25 06:32:03

问题


I've made zooming and brushing working together. The only problem is, when I've set the particular period on X axis via brushing and then trying to use zoom (on mouse drag or mouse wheel), it resets previous selected scales, so zoom doesn't store x axis domain that was set via brushing before.

zoomRight = d3.behavior.zoom()
  .x(xScale)
  .y(yRightScale)
  .scaleExtent([1,20])

zoomed = ->
  zoomRight.scale(zoom.scale()).translate(zoom.translate())
  canvas.select("._x._axis").call xAxis
  canvas.select(".axisLeft").call yLeftAxis
  canvas.select(".axisRight").call yRightAxis
  canvas.select(".y.grid").call make_y_axis().tickSize(-width, 0, 0).tickFormat("")
  canvas.select(".line1").attr("d", line1(data))
  canvas.select(".line2").attr("d", line2(data))
  brush.extent(xScale.domain())
  canvas.select(".brush").call(brush)

zoom = d3.behavior.zoom()
  .x(xScale)
  .y(yLeftScale)
  .scaleExtent([1,20]) # 20x times zoom
  .on("zoom", zoomed)

Full code is here fiddle. How can I force zoom to remember the previous brushing selection(position)?


回答1:


Solved the problem by adding the following lines on brush:

zoom.x(xScale)
zoom.translate()  

Working example is here.



来源:https://stackoverflow.com/questions/23784092/d3-zoom-resets-scales-selected-via-brushing

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!