Class: MotionPlot::PercentBarDelegate

Inherits:
BaseDelegate show all
Defined in:
lib/motion-plot/chart/delegates/percent_bar_delegate.rb

Instance Method Summary collapse

Methods inherited from BaseDelegate

#numberOfRecordsForPlot

Constructor Details

#initialize(source) ⇒ PercentBarDelegate

Returns a new instance of PercentBarDelegate.



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

def initialize(source)
  super
  @number_of_plots = @delegated_to.series.keys.size
end

Instance Method Details

#barPlot(plot, barWasSelectedAtRecordIndex: index) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/motion-plot/chart/delegates/percent_bar_delegate.rb', line 23

def barPlot(plot, barWasSelectedAtRecordIndex:index)
  if(@delegated_to.data_label and @delegated_to.data_label.annotation)
    @delegated_to.graph.plotAreaFrame.plotArea.removeAnnotation(@delegated_to.data_label.annotation)
    @delegated_to.data_label.annotation = nil
  end

  y_value     = (@delegated_to.series[plot.identifier].data[index].round(2) / total_sum_at_index(index)) * 100
  plot_index  = @delegated_to.series[plot.identifier].index
  y_pos       = (0..plot_index).inject(0) {|base, i| base + (@delegated_to.data_hash[i][index] / total_sum_at_index(index)) * 100 }
  
  @delegated_to.graph.plotAreaFrame.plotArea.addAnnotation(@delegated_to.data_label.annotation_for("#{y_value} %", atCoordinate: [index+CPTDecimalFloatValue(plot.barOffset), y_pos], plotSpace: @delegated_to.graph.defaultPlotSpace))
end

#numberForPlot(plot, field: field_enum, recordIndex: index) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/motion-plot/chart/delegates/percent_bar_delegate.rb', line 9

def numberForPlot(plot, field:field_enum, recordIndex:index)
  case field_enum
  when CPTBarPlotFieldBarLocation
    index
  when CPTBarPlotFieldBarTip
    plot_index = @delegated_to.series[plot.identifier].index
    record_data = @delegated_to.series[plot.identifier].data[index]
    bar_tip_value(plot_index, recordIndex:index, startValue:record_data)
  when CPTBarPlotFieldBarBase
    plot_index = @delegated_to.series[plot.identifier].index
    bar_base_value(plot_index, recordIndex:index)
  end
end