D3缩放可重置通过笔刷选择的比例. [英] D3 Zoom resets scales selected via brushing.

查看:157
本文介绍了D3缩放可重置通过笔刷选择的比例.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使缩放和画笔一起工作了.唯一的问题是,当我通过笔刷在X轴上设置了特定时间段,然后尝试使用缩放(在鼠标拖动或鼠标滚轮上)时,它将重置先前选择的比例,因此缩放不存储以前通过刷牙之前设置.

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)?

推荐答案

通过在画笔上添加以下几行来解决该问题:

Solved the problem by adding the following lines on brush:

zoom.x(xScale)
zoom.translate()  

工作示例是此处.

这篇关于D3缩放可重置通过笔刷选择的比例.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆