summaryrefslogtreecommitdiffstats
path: root/debian/missing-sources/epoch/src/time/bar.coffee
blob: 7bcb7be0a694e457c8ab6d6e903fe2f9e8efaab6 (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
47
48
# Real-time Bar Chart implementation.
class Epoch.Time.Bar extends Epoch.Time.Stack
  constructor: (@options={}) ->
    @options.type ?= 'time.bar'
    super(@options)
    @draw()

  # @return [Number] An offset used to align the ticks to the center of the rendered bars.
  _offsetX: ->
   0.5 * @w() / @pixelRatio

  # Sets the styles for the graphics context given a layer class name.
  # @param [String] className The class name to use when deriving the styles.
  setStyles: (className) ->
    styles = @getStyles "rect.bar.#{className.replace(/\s/g,'.')}"
    @ctx.fillStyle = styles.fill

    if !styles.stroke? or styles.stroke == 'none'
      @ctx.strokeStyle = 'transparent'
    else
      @ctx.strokeStyle = styles.stroke

    if styles['stroke-width']?
      @ctx.lineWidth = styles['stroke-width'].replace('px', '')

  # Draws the stacked bar chart.
  draw: (delta=0) ->
    @clear()
    [y, w] = [@y(), @w()]

    for layer in @getVisibleLayers()
      continue unless Epoch.isNonEmptyArray(layer.values)
      @setStyles(layer.className)

      [i, k, trans] = [@options.windowSize, layer.values.length, @inTransition()]
      iBoundry = if trans then -1 else 0

      while (--i >= iBoundry) and (--k >= 0)
        entry = layer.values[k]
        [ex, ey, ey0] = [i*w+delta, entry.y, entry.y0]
        ex += w if trans
        args = [ex+1, y(ey+ey0), w-2, @innerHeight()-y(ey)+0.5*@pixelRatio]

        @ctx.fillRect.apply(@ctx, args)
        @ctx.strokeRect.apply(@ctx, args)

    super()