5

この例D3.jsのコードを理解しようとしていますが、次のコードに混乱しています。

var circle = interpolation.selectAll("circle")
    .data(Object);
circle.enter().append("circle")
    .attr("r", 4)
    .attr("fill","yellow");
circle
    .attr("cx", function y(d) { console.log(d.attr("class")); return d.x; })
    .attr("cy", function(d) { return d.y; });

このコードの 2 行目は実際に何をするのでしょうか? どのデータにバインドしますか?

4

1 に答える 1

8

上記の要素にバインドされたデータは、 function によって与えられますgetLevels(d, t)。ここで、dは 2 ~ 4 の範囲の数値でありt、現在の時刻から派生した数値です。

これは、配列の配列のみを返します。配列は既に Object 型であるため、 Array で Object() を呼び出すと元の配列が返されます。したがって、私が見る限り、作成者は Object を次のような恒等関数の一種として使用しているだけです。

var identity = function(d){
  return d;
}

var circle = interpolation.selectAll("circle")
    .data(identity);
circle.enter().append("circle")
    .attr("r", 4)
    .attr("fill","yellow");
circle
    .attr("cx", function y(d) { console.log(d.attr("class")); return d.x; })
    .attr("cy", function(d) { return d.y; });
于 2013-05-15T02:51:11.670 に答える