Class: Spree::TrendingSearchReport::FrequencyDistributionPieChart

Inherits:
Object
  • Object
show all
Defined in:
app/reports/spree/trending_search_report/frequency_distribution_pie_chart.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(result) ⇒ FrequencyDistributionPieChart

Returns a new instance of FrequencyDistributionPieChart.



4
5
6
7
# File 'app/reports/spree/trending_search_report/frequency_distribution_pie_chart.rb', line 4

def initialize(result)
  total_occurrences = result.observations.sum(&:occurrences).to_f
  self.chart_data = result.observations.collect { |x| { name: x.searched_term, y: x.occurrences/total_occurrences } }
end

Instance Attribute Details

#chart_dataObject

Returns the value of attribute chart_data.



2
3
4
# File 'app/reports/spree/trending_search_report/frequency_distribution_pie_chart.rb', line 2

def chart_data
  @chart_data
end

Instance Method Details

#to_hObject



9
10
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
39
40
# File 'app/reports/spree/trending_search_report/frequency_distribution_pie_chart.rb', line 9

def to_h
  {

    name: 'trending-search',
    json: {
      chart: { type: 'pie' },
      title: {
        useHTML: true,
        text: "<span class='chart-title'>Trending Search Keywords(Top 20)</span><span class='fa fa-question-circle' data-toggle='tooltip' title='Track the most trending keywords searched by users'></span>"
      },
      tooltip: {
        pointFormat: 'Search %: <b>{point.percentage:.1f}%</b>'
      },
      plotOptions: {
        pie: {
          allowPointSelect: true,
          cursor: 'pointer',
          dataLabels: {
            enabled: false
          },
          showInLegend: true
        }
      },
      series: [
        {
          name: 'Hits',
          data: chart_data
        }
      ]
    }
  }
end