Class: MotionPlot::WaterfallDelegate

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

Instance Method Summary collapse

Methods inherited from BaseDelegate

#initialize

Constructor Details

This class inherits a constructor from MotionPlot::BaseDelegate

Instance Method Details

#barPlot(plot, barWasSelectedAtRecordIndex: index) ⇒ Object



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

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

  data_index  = (index == @data_size - 1) ? (index - 1) : index
  data        = @delegated_to.series[plot.identifier].data
  y_value     = data[data_index].round(2)
  y_pos       = bar_tip_value(data_index, seriesData: data, startValue: y_value)
  y_value     = y_pos.round(2) if(index == @data_size - 1) # total bar of waterfall chart
  
  @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



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

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

#numberOfRecordsForPlot(plot) ⇒ Object



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

def numberOfRecordsForPlot(plot)
  @data_size = @delegated_to.series[plot.identifier].data.size + 1
end