1

我一直在d3.boxd3.bullet中闲逛。在这两种情况下,当前比例都是使用类似下面的东西来检索的......

var x0 = this.__chart__ || d3.scale.linear()
  .domain([0, Infinity])
  .range(x1.range());

...x1当前比例对象在哪里。我意识到这个成语是用来更新箱线图或子弹图的,但有人能解释一下吗?this.__chart__指的是什么?规模物体?为什么是有条件的?( ||) 当当前尺度不可能有这么大的范围时,为什么x0的域会覆盖 0 到无穷大的范围?

抱歉,如果我的问题没有明确说明。任何帮助将不胜感激。

4

1 回答 1

1

上下文是包含图表的thisDOM 元素:即g元素。将一些变量绑定到 DOM 元素,例如this.myvar = state,提供了一种处理图表特定状态的方法。对一个特定图表 g 元素的多次更新调用,将都可以访问同一个变量。

Mike 和 Jason__chart__在各种图表以及d3 轴组件中使用了属性名称,以跟踪图表的特定状态。

没错,在这种情况下,它是存储在 g 元素__chart__属性中的比例。请参阅 bullet.js 的摘录:

  // Compute the new x-scale.
  var x1 = d3.scale.linear()
      .domain([0, Math.max(rangez[0], markerz[0], measurez[0])])
      .range(reverse ? [width, 0] : [0, width]);

  // Retrieve the old x-scale, if this is an update.
  var x0 = this.__chart__ || d3.scale.linear()
      .domain([0, Infinity])
      .range(x1.range());

  // Stash the new scale.
  this.__chart__ = x1;

x1因此,根据当前数据确定比例。它将存储在 中__chart__,以供将来使用新数据更新此图表时使用。

The previous scale is taken from this.__chart__ and kept in x0. The this.__chart__ will return undefined when the chart is just being constructed (i.e. the enter phase). In that case x0 will instead become d3.scale.linear().domain([0, Infinity]).range(x1.range()). See short circuit eval.

The old scale is needed for smooth transition. When new data points are entered, we first want to plot them on the chart using the old scale. After that we will transition all points (new and updated) according to the new scale.

Regarding the [0, Infinity] domain. So, a scale with this domain will only be used when the chart is just constructed. That means it provides a way to setup the initial transition when introducing the chart. A infinite domain with a finite range means that all points are scaled to 0. So, when the chart is set up, all points will be plotted at 0 and transition to the proper values according the x1 scale.

于 2012-12-15T06:27:41.467 回答