Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
117
rated 0 times [  121] [ 4]  / answers: 1 / hits: 65369  / 12 Years ago, tue, october 9, 2012, 12:00:00

I am not able to understand how d3.call() works and when and where to use that. Here is the tutorial link that I'm trying to complete.



Can someone please explain specifically what this piece is doing



var xAxis = d3.svg.axis()
.scale(xScale)
.orient(bottom);

svg.append(g).call(xAxis);

More From » d3.js

 Answers
3

I think the trick here is to understand that xAxis is a function that generates a bunch of SVG elements. In fact it is the function returned by d3.svg.axis(). The scale and orient functions are just part of the chaining syntax (read more of that here: http://alignedleft.com/tutorials/d3/chaining-methods/).



So svg.append(g) appends an SVG group element to the svg and returns a reference to itself in the form of a selection (same chain syntax at work here). When you use call on a selection you are calling the function named xAxis on the elements of the selection g. In this case you are running the axis function, xAxis, on the newly created and appended group, g.



If that still doesn't make sense, the syntax above is equivalent to:



xAxis(svg.append(g));


or:



d3.svg.axis()
.scale(xScale)
.orient(bottom)(svg.append(g));

[#82657] Monday, October 8, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
bruno

Total Points: 602
Total Questions: 100
Total Answers: 111

Location: Tajikistan
Member since Sun, Aug 29, 2021
3 Years ago
;