blob: de567805fbabb193ce51e1d57aae79408e5d1359 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
# Static line chart implementation (using d3).
class Epoch.Chart.Line extends Epoch.Chart.Plot
constructor: (@options={}) ->
@options.type ?= 'line'
super(@options)
@draw()
# @return [Function] The line generator used to construct the plot.
line: (layer) ->
[x, y] = [@x(), @y(layer.range)]
d3.svg.line()
.x((d) -> x(d.x))
.y((d) -> y(d.y))
# Draws the line chart.
draw: ->
[x, y, layers] = [@x(), @y(), @getVisibleLayers()]
# Zero visible layers, just drop all and get out
if layers.length == 0
return @g.selectAll('.layer').remove()
# 1) Join
layer = @g.selectAll('.layer')
.data(layers, (d) -> d.category)
# 2) Update (only existing)
layer.select('.line').transition().duration(500)
.attr('d', (l) => @line(l)(l.values))
# 3) Enter (Create)
layer.enter().append('g')
.attr('class', (l) -> l.className)
.append('path')
.attr('class', 'line')
.attr('d', (l) => @line(l)(l.values))
# 4) Update (existing & new)
# Nuuupp
# 5) Exit (Remove)
layer.exit().transition().duration(750)
.style('opacity', '0')
.remove()
super()
|