analytics_charts 1.2.1 → 1.3.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 075b6d3446dcec242da5a7bcdb943ab0e9790437
4
- data.tar.gz: 109f747a6f9a006224a6df4d217ae2c6e9942869
3
+ metadata.gz: 3f29114a8beff4861cb697eac809bbb8f624266c
4
+ data.tar.gz: a2417f08e626a1c566ac7e63f8f9fcf09bb1ca2e
5
5
  SHA512:
6
- metadata.gz: 5b053d7f2a3655837d05306e90543f1fd18e128f65b11c53fad37c182820faa2f56a39aa735fa5a30d5ff62e3867c0c24a83636029bfe51a7bea1eeaab32589e
7
- data.tar.gz: 5c87eb71c29aa833b09b44e06ea61d592a917ba7feb6c77a1522fdaf9bcabedfe0007159eb1047e8febfbb1875ff72efd746bcf45c8c339be934a3643d22ab7b
6
+ metadata.gz: 4ca8393d4cc654891666703b2455357ea385421956343ab93046079bd55d6169d9c37b4972f720de641db69afb154a2251ec04971c8eb57c18f6626c5391dd37
7
+ data.tar.gz: abd3bbb6f944fb54ebd42a9863d6a8402494e3a158099bb51528f3ce4157752829467a17858b71e911d733240057666f60c5ddbd11d0e467fd1cff76bcf93f4c
@@ -17,6 +17,7 @@ class AnalyticsCharts::CustomPie
17
17
  @d = Draw.new
18
18
  @data = Hash.new # Value is array with two items
19
19
  @aggregate = Array([0,0,0,0]) # Cluster brands into categories
20
+ @thresholds = Array(["","","",""]) # Will populate with integer thresholds
20
21
  @label_hash = Hash.new
21
22
  @pie_label_hash = Hash.new
22
23
  @label_hash = label_hash if label_hash
@@ -40,11 +41,25 @@ class AnalyticsCharts::CustomPie
40
41
  @colors = list
41
42
  end
42
43
 
44
+ def choose_color(rating)
45
+ return @colors[0]
46
+ end
47
+
48
+ def highest_score(index, score)
49
+ @thresholds[index] = score
50
+ end
43
51
  def insert_pie_data(name, amount, quality)
44
52
  #convert all '' instances to an apostrophe
45
53
  name = name.gsub(/'/, "\'")
46
- @data[name] = [amount, quality]
47
- @aggregate[quality] += amount
54
+ # Figure out whether to give name a 0,1,2, or 3
55
+ [0,1,2,3].each do |rank|
56
+ next if @thresholds[rank].is_a?(String)
57
+ if quality < @thresholds[rank]
58
+ @data[name] = [amount, rank]
59
+ @aggregate[rank] += amount
60
+ break
61
+ end
62
+ end
48
63
  end
49
64
  def insert_text_with_arrow(x_offset, y_offset, text, features = {})
50
65
  features.each { |feature, attribute|
@@ -62,8 +62,21 @@ class AnalyticsCharts::PieAndLabels < AnalyticsCharts::CustomPie
62
62
 
63
63
  end
64
64
 
65
- def insert_legend(label, quality)
66
- @legend_data[quality] = label
65
+ def insert_legend(label, quality, color)
66
+ case color
67
+ when "green"
68
+ @legend_data[3] = label
69
+ highest_score(3, quality)
70
+ when "yellow"
71
+ @legend_data[2] = label
72
+ highest_score(2, quality)
73
+ when "orange"
74
+ @legend_data[1] = label
75
+ highest_score(1, quality)
76
+ when "red"
77
+ @legend_data[0] = label
78
+ highest_score(0, quality)
79
+ end
67
80
  end
68
81
 
69
82
  def draw_legend
@@ -74,29 +87,31 @@ class AnalyticsCharts::PieAndLabels < AnalyticsCharts::CustomPie
74
87
  x_pos = 230
75
88
  side_length = 15
76
89
  @legend_data.each_with_index do |data, index|
77
- case index
78
- when 3
79
- insert_text(x_pos + 20, y_offset + 12, data,
80
- @label_hash.merge({'fill' => '#FFFFFF', 'pointsize'=> 10 }))
81
- @d.fill('#1E753B')
82
- @d.rectangle(x_pos,y_offset,x_pos + side_length, y_offset + side_length)
83
- when 2
84
- insert_text(x_pos + 20, y_offset + 12, data,
85
- @label_hash.merge({'fill' => '#FFFFFF', 'pointsize'=> 10 }))
86
- @d.fill('#C1B630')
87
- @d.rectangle(x_pos,y_offset,x_pos + side_length, y_offset + side_length)
88
- when 1
89
- insert_text(x_pos + 20, y_offset + 12, data,
90
- @label_hash.merge({'fill' => '#FFFFFF', 'pointsize'=> 10 }))
91
- @d.fill('#BE6428')
92
- @d.rectangle(x_pos,y_offset,x_pos + side_length, y_offset + side_length)
93
- when 0
94
- insert_text(x_pos + 20, y_offset + 12, data,
95
- @label_hash.merge({'fill' => '#FFFFFF', 'pointsize'=> 10 }))
96
- @d.fill('#AD1F25')
97
- @d.rectangle(x_pos,y_offset,x_pos + side_length, y_offset + side_length)
90
+ unless data.empty? # Allows us to use only three legends or less
91
+ case index
92
+ when 3
93
+ insert_text(x_pos + 20, y_offset + 12, data,
94
+ @label_hash.merge({'fill' => '#FFFFFF', 'pointsize'=> 10 }))
95
+ @d.fill('#1E753B')
96
+ @d.rectangle(x_pos,y_offset,x_pos + side_length, y_offset + side_length)
97
+ when 2
98
+ insert_text(x_pos + 20, y_offset + 12, data,
99
+ @label_hash.merge({'fill' => '#FFFFFF', 'pointsize'=> 10 }))
100
+ @d.fill('#C1B630')
101
+ @d.rectangle(x_pos,y_offset,x_pos + side_length, y_offset + side_length)
102
+ when 1
103
+ insert_text(x_pos + 20, y_offset + 12, data,
104
+ @label_hash.merge({'fill' => '#FFFFFF', 'pointsize'=> 10 }))
105
+ @d.fill('#BE6428')
106
+ @d.rectangle(x_pos,y_offset,x_pos + side_length, y_offset + side_length)
107
+ when 0
108
+ insert_text(x_pos + 20, y_offset + 12, data,
109
+ @label_hash.merge({'fill' => '#FFFFFF', 'pointsize'=> 10 }))
110
+ @d.fill('#AD1F25')
111
+ @d.rectangle(x_pos,y_offset,x_pos + side_length, y_offset + side_length)
112
+ end
113
+ y_offset -= side_length
98
114
  end
99
- y_offset -= side_length
100
115
  end
101
116
  end
102
117
  def draw_line
@@ -1,3 +1,3 @@
1
1
  module AnalyticsCharts
2
- VERSION = "1.2.1"
2
+ VERSION = "1.3.1"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: analytics_charts
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.1
4
+ version: 1.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - STEPHEN YU
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-06-23 00:00:00.000000000 Z
11
+ date: 2015-07-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler