Class: MotionPlot::StackBarDelegate

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

Instance Method Summary collapse

Constructor Details

#initialize(source) ⇒ StackBarDelegate

consign :series, :to => :delegated_to



6
7
8
# File 'lib/motion-plot/chart/delegates/stack_bar_delegate.rb', line 6

def initialize(source)
  @delegated_to = source
end

Instance Method Details

#barPlot(plot, barWasSelectedAtRecordIndex: index) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/motion-plot/chart/delegates/stack_bar_delegate.rb', line 28

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)
  plot_index  = @delegated_to.series[plot.identifier].index
  y_pos       = (0..plot_index).inject(0) {|base, i| base + @delegated_to.data_hash[i][index]}
  
  @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



14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/motion-plot/chart/delegates/stack_bar_delegate.rb', line 14

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

#numberOfRecordsForPlot(plot) ⇒ Object



10
11
12
# File 'lib/motion-plot/chart/delegates/stack_bar_delegate.rb', line 10

def numberOfRecordsForPlot(plot)
  @delegated_to.series[plot.identifier].data.size
end