Sha256: f99d8d8d7a2d941814b0ad3517680ea84d9c07b0a51a934902051d58d69d3c09

Contents?: true

Size: 1.23 KB

Versions: 3

Compression:

Stored size: 1.23 KB

Contents

class Spree::PromotionalCostReport::UsageCountChart

  attr_accessor :time, :series

  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


  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

end

Version data entries

3 entries across 3 versions & 2 rubygems

Version Path
spree_admin_insights-3.2.0 app/reports/spree/promotional_cost_report/usage_count_chart.rb
solidus_admin_insights-2.1.1 app/reports/spree/promotional_cost_report/usage_count_chart.rb
solidus_admin_insights-2.1.0 app/reports/spree/promotional_cost_report/usage_count_chart.rb