Class: MotionPlot::Bar

Inherits:
Base
  • Object
show all
Defined in:
lib/motion-plot/chart/bar_plot.rb

Constant Summary collapse

CPDBarInitialX =
0.0

Instance Attribute Summary collapse

Attributes inherited from Base

#axes, #data_label, #graph, #layer_hosting_view, #legend, #major_grid_line_style, #plot_options, #plot_space, #plots, #series, #theme, #title, #xaxis, #yaxis

Instance Method Summary collapse

Methods inherited from Base

#add_axis_title, #add_chart_title, #add_legend, #add_plot_space, #add_plot_symbol, #add_xy_range, #bootstrap, #default_padding, #initWithOptions

Instance Attribute Details

#data_hashObject (readonly)

Returns the value of attribute data_hash.



4
5
6
# File 'lib/motion-plot/chart/bar_plot.rb', line 4

def data_hash
  @data_hash
end

Instance Method Details

#add_seriesObject



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
49
# File 'lib/motion-plot/chart/bar_plot.rb', line 8

def add_series
  @stacking           = @plot_options ? @plot_options.bar[:stacking] : nil

  bar_x               = CPDBarInitialX
  @data_hash          = {}
  horizontal_bar      = (@plot_options and @plot_options.bar[:orientation] == "vertical") ? true : false
  @delegate_object    = case @stacking
  when "normal"
    StackBarDelegate.new(self)
  when "percent"
    PercentBarDelegate.new(self)
  when "waterfall"
    WaterfallDelegate.new(self)
  else
    BarDelegate.new(self)
  end

  @series.keys.each_with_index do |name, index|
    bar               = CPTBarPlot.tubularBarPlotWithColor(@series[name].color, horizontalBars: horizontal_bar)
    bar.barWidth      = CPTDecimalFromDouble(@series[name].width)
    bar.barOffset     = CPTDecimalFromDouble(bar_x) unless(@stacking)

    bar.identifier    = name

    _style            = CPTMutableLineStyle.alloc.init
    _style.lineWidth  = 0.5
    _style.lineColor  = CPTColor.lightGrayColor

    bar.lineStyle     = _style
    bar.dataSource    = @delegate_object
    bar.delegate      = @delegate_object
    bar.barBasesVary  = @stacking ? true : false

    @graph.addPlot(bar)
    @plots << bar

    animate(bar)

    bar_x += @series[name].width
    @data_hash[index] = @series[name].data
  end
end

#animate(bar) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/motion-plot/chart/bar_plot.rb', line 51

def animate(bar)
  bar.anchorPoint             = [0.0, 0.0]
  scale_direction             = (@plot_options and @plot_options.bar[:orientation] == "vertical") ? "transform.scale.x" : "transform.scale.y"
  scaling                     = CABasicAnimation.animationWithKeyPath(scale_direction)
  scaling.fromValue           = 0.0
  scaling.toValue             = 1.0
  scaling.duration            = 1.0
  scaling.removedOnCompletion = false
  scaling.fillMode            = KCAFillModeBackwards

  bar.addAnimation(scaling, forKey:"scaling")
end