[英]d3.js passing bound function does not appear to execute the function
I am trying to reuse some code that makes x-axis ticks. 我正在尝试重用一些使x轴出现刻度的代码。 Here is the method I've put it in:
这是我放入的方法:
xTicks: (scale, dayTickFormat) ->
d3.svg.axis().scale(scale).orient("bottom")
.ticks(d3.time.days, 1)
.tickSize(10)
.tickFormat(dayTickFormat)
.tickPadding(8)
Please pardon the coffeescript :\\ 请原谅咖啡文字:\\
Anyway, I here is the code that calls that: 无论如何,我这里是调用该代码的代码:
drawTicks: (chart, chartOptions, margin, x, y, num_y_ticks) ->
xTickGroup = chart.append("g").attr("class", "day-ticks")
.call(@xTicks.bind(@, x, dayTickFormat))
.attr("transform", "translate(#{chartOptions.offset.left}, #{chartOptions.height - 10})")
When this code executes, I don't get any ticks. 当执行此代码时,我没有任何打勾。 I'm stumped.
我很沮丧 Any thoughts?
有什么想法吗?
OK, nvm, I got it. 好的,nvm,我明白了。
call() wasn't calling the "d3.svg.axis()" bit, it was calling the method I had wrapped around it. call()并未调用“ d3.svg.axis()”位,而是在调用我包装的方法。 So, if I store my method in a variable like so:
因此,如果我将方法存储在这样的变量中:
xTicks = @xTicks(x, dayTickFormat)
I can call it more simply like this: 我可以这样称呼它:
xTickGroup = chart.append("g").attr("class", "day-ticks")
.call(xTicks)
.attr("transform", "translate(#{chartOptions.offset.left}, #{chartOptions.height - 10})")
Hope this helps someone, someday :\\ 希望有一天能对某人有所帮助:\\
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.