epoch-charting
Version:
A general purpose real-time charting library for building beautiful, smooth, and high performance visualizations.
81 lines (67 loc) • 2.35 kB
text/coffeescript
# Real-time stacked area chart implementation.
class Epoch.Time.Area extends Epoch.Time.Stack
constructor: (={}) ->
.type ?= 'time.area'
super()
# Sets the appropriate styles to the graphics context given a particular layer.
# [Object] layer Layer for which to set the styles.
setStyles: (layer) ->
if layer? && layer.className?
styles = "g.#{layer.className.replace(/\s/g,'.')} path.area"
else
styles = "g path.area"
.fillStyle = styles.fill
if styles.stroke?
.strokeStyle = styles.stroke
if styles['stroke-width']?
.lineWidth = styles['stroke-width'].replace('px', '')
# Draws areas for the chart
_drawAreas: (delta=0) ->
[y, w, layers] = [, , ]
for i in [layers.length-1..0]
continue unless (layer = layers[i])
layer
.beginPath()
[j, k, trans] = [.windowSize, layer.values.length, ]
firstX = null
while (--j >= -2) and (--k >= 0)
entry = layer.values[k]
args = [(j+1)*w+delta, y(entry.y + entry.y0)]
args[0] += w if trans
if i == .windowSize - 1
.moveTo.apply , args
else
.lineTo.apply , args
if trans
borderX = (j+3)*w+delta
else
borderX = (j+2)*w+delta
.lineTo(borderX, )
.lineTo(*+w+delta, )
.closePath()
.fill()
# Draws strokes for the chart
_drawStrokes: (delta=0) ->
[y, w, layers] = [, , ]
for i in [layers.length-1..0]
continue unless (layer = layers[i])
layer
.beginPath()
[i, k, trans] = [.windowSize, layer.values.length, ]
firstX = null
while (--i >= -2) and (--k >= 0)
entry = layer.values[k]
args = [(i+1)*w+delta, y(entry.y + entry.y0)]
args[0] += w if trans
if i == .windowSize - 1
.moveTo.apply , args
else
.lineTo.apply , args
.stroke()
# Draws the area chart.
draw: (delta=0) ->
super()