Class: Spree::PaymentMethodTransactionsConversionRateReport::PaymentMethodStateDistributionChart

Inherits:
Object
  • Object
show all
Defined in:
app/reports/spree/payment_method_transactions_conversion_rate_report/payment_method_state_distribution_chart.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(result) ⇒ PaymentMethodStateDistributionChart

Returns a new instance of PaymentMethodStateDistributionChart.



4
5
6
7
8
9
# File 'app/reports/spree/payment_method_transactions_conversion_rate_report/payment_method_state_distribution_chart.rb', line 4

def initialize(result)
  @time_dimension = result.time_dimension
  @grouped_by_payment_method = result.observations.group_by(&:payment_method_name)
  @time_series = []
  @time_series = @grouped_by_payment_method.values.first.collect { |observation| observation.send(@time_dimension) } if @grouped_by_payment_method.first.present?
end

Instance Attribute Details

#chart_dataObject

Returns the value of attribute chart_data.



2
3
4
# File 'app/reports/spree/payment_method_transactions_conversion_rate_report/payment_method_state_distribution_chart.rb', line 2

def chart_data
  @chart_data
end

Instance Method Details

#to_hObject



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
# File 'app/reports/spree/payment_method_transactions_conversion_rate_report/payment_method_state_distribution_chart.rb', line 11

def to_h
  @grouped_by_payment_method.collect do |method_name, observations|
    {
      id: 'payment-state-' + method_name,
      json: {
        chart: { type: 'column' },
        title: {
          useHTML: true,
          text: %Q(<span class='chart-title'>#{ method_name } Conversion Status</span>
                   <span class='fa fa-question-circle' data-toggle='tooltip' title=' Tracks the status of Payments made from different payment methods such as CC, Check etc.'></span>)
        },

        xAxis: { categories: @time_series },
        yAxis: {
          title: { text: 'Count' }
        },
        tooltip: { valuePrefix: '#' },
        legend: {
          layout: 'vertical',
          align: 'right',
          verticalAlign: 'middle',
          borderWidth: 0
        },
        series: observations.group_by(&:payment_state).map { |key, value| { name: key, data: value.map(&:count) } }
      }
    }
  end
end