Sha256: 23d20940ed7c4ba2c181badfd40b9d15aa02c9531dfcb9607f659d601c5d7336

Contents?: true

Size: 1.43 KB

Versions: 3

Compression:

Stored size: 1.43 KB

Contents

class Spree::PaymentMethodTransactionsConversionRateReport::PaymentMethodStateDistributionChart
  attr_accessor :chart_data

  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

  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
end

Version data entries

3 entries across 3 versions & 2 rubygems

Version Path
spree_admin_insights-3.2.0 app/reports/spree/payment_method_transactions_conversion_rate_report/payment_method_state_distribution_chart.rb
solidus_admin_insights-2.1.1 app/reports/spree/payment_method_transactions_conversion_rate_report/payment_method_state_distribution_chart.rb
solidus_admin_insights-2.1.0 app/reports/spree/payment_method_transactions_conversion_rate_report/payment_method_state_distribution_chart.rb