Tiramitsu
Tiramitsu

Reputation: 71

d3.js with coffeescript - use the timer make strange behavior

I'm starting with d3.js and I don't understand a strange call function. I'm using coffeescript and here is my code :

it doesn't work :

handleTick = () ->
    t += 0.01   
    d3.select('.ball').attr({cx: (width / 2) + 100 * Math.cos(w * t), cy: (height / 2) + 100 * Math.sin(w * t)})    
d3.timer handleTick

it work :

handleTick = () ->
    t += 0.01   
    console.log d3.select('.ball').attr({cx: (width / 2) + 100 * Math.cos(w * t), cy: (height / 2) + 100 * Math.sin(w * t)})    
d3.timer handleTick

Thanks !

Upvotes: 0

Views: 121

Answers (1)

Jed Schneider
Jed Schneider

Reputation: 14671

try

handleTick = () ->
  t += 0.01   
  d3.select('.ball').attr({cx: (width / 2) + 100 * Math.cos(w * t), cy: (height / 2) + 100 * Math.sin(w * t)})
  return 0

as mentioned in the comments, coffeescript always returns the last expression, since console.log statements return void, it would make sense that the d3.select statement is probably returning something the api isn't expecting.

Upvotes: 1

Related Questions