Commit a808e0e6 authored by Kjetil Thuen's avatar Kjetil Thuen

Fixed remove event, made animation smooth

parent 25942971
......@@ -12,13 +12,16 @@ next = ->
value: v = ~~Math.max(10, Math.min(90, v + 10 * (Math.random() - .5)))
chartWidth = ->
500
900
chartHeight = ->
280
500
numBars = ->
20
100
speed = ->
500
barWidth = ->
chartWidth() / numBars()
......@@ -36,29 +39,31 @@ redraw = ->
.attr("y", (d) -> chartHeight() - y d.value - .5)
.attr("width", barWidth())
.attr("height", (d) -> y d.value)
.transition().duration(1000).attr "x", (d, i) ->
.transition()
.ease("linear")
.duration(speed()).attr "x", (d, i) ->
x(i) - .5
rect.transition()
.duration(1000)
.ease("linear")
.duration(speed())
.attr "x", (d, i) ->
x(i) - .5
rect.exit()
.transition()
.duration(1000)
.attr("x", (d, i) ->
x(i - 1) - .5)
.duration(speed() / 2)
.style("opacity", 0)
.remove()
setupChart = (containerId) ->
data = d3.range(33).map(next)
data = d3.range(100).map(next)
setInterval (->
data.shift()
data.push next()
redraw()
), 1500
), speed()
chart = d3.select(containerId)
.append("svg")
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment