Class: Spree::PromotionalCostReport::UsageCountChart

Inherits:
Object
  • Object
show all
Defined in:
app/reports/spree/promotional_cost_report/usage_count_chart.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(result) ⇒ UsageCountChart

Returns a new instance of UsageCountChart.



5
6
7
8
9
10
11
12
13
# File 'app/reports/spree/promotional_cost_report/usage_count_chart.rb', line 5

def initialize(result)
  @grouped_by_promotion = result.observations.group_by(&:promotion_name)
  @time_dimension = result.time_dimension
  self.time = []
  if @grouped_by_promotion.values.first.present?
    self.time   = @grouped_by_promotion.values.first.collect { |observation_value| observation_value.send(@time_dimension) }
  end
  self.series = @grouped_by_promotion.collect { |promotion, values| { type: 'column', name: promotion, data: values.collect(&:usage_count) }  }
end

Instance Attribute Details

#seriesObject

Returns the value of attribute series.



3
4
5
# File 'app/reports/spree/promotional_cost_report/usage_count_chart.rb', line 3

def series
  @series
end

#timeObject

Returns the value of attribute time.



3
4
5
# File 'app/reports/spree/promotional_cost_report/usage_count_chart.rb', line 3

def time
  @time
end

Instance Method Details

#to_hObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'app/reports/spree/promotional_cost_report/usage_count_chart.rb', line 16

def to_h
  {
    id: 'promotion-usage-count',
    json: {
      chart: { type: 'spline' },
      title: {
        useHTML: true,
        text: "<span class='chart-title'>Promotion Usage Count</span><span class='fa fa-question-circle' data-toggle='tooltip' title='Compare the usage of individual promotions'></span>"
      },
      xAxis: { categories: time },
      yAxis: {
        title: { text: 'Count' }
      },
      tooltip: { valuePrefix: '#' },
      legend: {
        layout: 'vertical',
        align: 'right',
        verticalAlign: 'middle',
        borderWidth: 0
      },
      series: series
    }
  }
end