What does object binding in D3.js do

I am trying to understand the D3.js code for this example and confused by this code:

 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 dx; }) .attr("cy", function(d) { return dy; }); 

What does the second line of this code do? What data is it associated with?

+4
source share
1 answer

The data specified in the element above is specified by the getLevels(d, t) function, where d is the range number 2-4, and t is the number obtained from the current time.

It only ever returns an array of arrays. Since the array is already of type Object , the calling object () in the array returns the original array. Therefore, from what I see, the author simply uses Object as a kind of identification function, similar to:

 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 dx; }) .attr("cy", function(d) { return dy; }); 
+6
source

Source: https://habr.com/ru/post/1480832/


All Articles