Class: Spree::TrendingSearchReport::FrequencyDistributionPieChart
- Inherits:
-
Object
- Object
- Spree::TrendingSearchReport::FrequencyDistributionPieChart
- Defined in:
- app/reports/spree/trending_search_report/frequency_distribution_pie_chart.rb
Instance Attribute Summary collapse
-
#chart_data ⇒ Object
Returns the value of attribute chart_data.
Instance Method Summary collapse
-
#initialize(result) ⇒ FrequencyDistributionPieChart
constructor
A new instance of FrequencyDistributionPieChart.
- #to_h ⇒ Object
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_data ⇒ Object
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_h ⇒ Object
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 |