Javascript库d3调用函数 [英] Javascript library d3 call function

查看:36
本文介绍了Javascript库d3调用函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法理解d3.call()的工作原理以及何时何地使用它.此处是我要完成的教程链接.

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);

推荐答案

我认为这里的诀窍是要理解xAxis是一个生成一堆SVG元素的函数.实际上,它是 d3.svg.axis()返回的函数.scale和Orient函数只是链接语法的一部分(有关更多信息,请参见: http://alignedleft.com/tutorials/d3/chaining-methods/).

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/).

因此, svg.append("g")将SVG组元素附加到svg并以选择形式返回引用其自身(此处使用相同的链语法).在选择上使用 call 时,将在选择 g 的元素上调用名为 xAxis 的函数.在这种情况下,您将在新创建并附加的组 g 上运行轴函数 xAxis .

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"));

或:

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

这篇关于Javascript库d3调用函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆