2013-05-15 3 views
4

에서 할 객체 바인딩을 수행합니다내가이 코드에 의해 <a href="http://www.jasondavies.com/animated-bezier/" rel="nofollow">this example</a>의 <code>D3.js</code> 코드를 이해하려고 노력하고 있고 혼란 스러워요 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; }); 

이 코드의 두 번째 줄은 실제로 무엇을 하는가? 어떤 데이터에 바인딩됩니까?

답변

6

위의 요소에서 바인드 된 데이터는 getLevels(d, t)으로 표시되며 여기서 d은 2 - 4의 수이고 t은 현재 시간에서 파생 된 숫자입니다.

이것은 배열 배열을 반환합니다.

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; }); 
+0

감사합니다 : 배열 ... 따라서, 내가 볼 수있는 것과 already of type Object, 배열에서 개체()를 호출하면 원래의 배열을 반환하기 때문에, 저자는 단순히 유사 식별 기능의 일종으로 개체 사용 , minikomi. 나는'Object'가 정체성 함수로 사용되기 전에 본 적이 없으므로 이것으로 혼란 스러웠습니다. 나는'Object'를'function (d) {return d; }'그것은 잘 작동합니다. 매우 명확한 설명에 감사드립니다. – BruceHill

+0

문제 없습니다. 그것은 나를 위해 약간의 머리 긁는 사람이었다. – minikomi

관련 문제