summaryrefslogtreecommitdiffstats
path: root/debian/missing-sources/epoch/src/time/line.coffee
blob: 8a4271b2680e0d087af16a881b07e23216af1e22 (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
# Real-time line chart implementation
class Epoch.Time.Line extends Epoch.Time.Plot
  constructor: (@options={}) ->
    @options.type ?= 'time.line'
    super(@options)
    @draw()

  # Sets the graphics context styles based ont he given layer class name.
  # @param [String] className The class name of the layer for which to set the styles.
  setStyles: (className) ->
    styles = @getStyles "g.#{className.replace(/\s/g,'.')} path.line"
    @ctx.fillStyle = styles.fill
    @ctx.strokeStyle = styles.stroke
    @ctx.lineWidth = @pixelRatio * styles['stroke-width'].replace('px', '')

  # Draws the line chart.
  draw: (delta=0) ->
    @clear()
    w = @w()
    for layer in @getVisibleLayers()
      continue unless Epoch.isNonEmptyArray(layer.values)
      @setStyles(layer.className)
      @ctx.beginPath()
      y = @y(layer.range)
      [i, k, trans] = [@options.windowSize, layer.values.length, @inTransition()]

      while (--i >= -2) and (--k >= 0)
        entry = layer.values[k]
        args = [(i+1)*w+delta, y(entry.y)]
        args[0] += w if trans
        if i == @options.windowSize - 1
          @ctx.moveTo.apply @ctx, args
        else
          @ctx.lineTo.apply @ctx, args

      @ctx.stroke()

    super()