analytics_charts 1.1.5 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 44dcc0bd83faced53baccb85717032d0fe7b04a5
4
- data.tar.gz: c0cd007502249e3c65168d0d7b46a8df17ea8b1a
3
+ metadata.gz: 7f5c41a11cdfea8955c12131c81208ae7f780c88
4
+ data.tar.gz: 12a17c75600e207ec8871c7b35a36e536e86c55a
5
5
  SHA512:
6
- metadata.gz: c69429d6ab98d61888e5fcfc29c4e17da9702199b8e8c1c51fd5f74264853a705039822dcf3a0df7f385d3a95d93795a557c16aa646d78e750efe64cbc0c3e35
7
- data.tar.gz: 4ed3f22956eb7bf83aa28edf7bdcc0bf59a689ebd4ed1522a8380a8b8f80fa911975ac247d7876d33229d6ffafa851b4f2e24a28dc819ba979a0258c9f708a3f
6
+ metadata.gz: a23205b4a8af0244b686008c7068d44efebc170deac03040d432b6bb2131408be330757b0e464b27eb31c1374cb03a912a9106774b03a7399efc7355c48d1091
7
+ data.tar.gz: bfbf38ad217e39e65822a0538d8010f03ed45228d0022cfed3180d5dfdbaccf27820fed38d3f926a22644441d8e23149047116e8f8299e67fffa2880af1a7836
@@ -46,12 +46,24 @@ class AnalyticsCharts::CustomPie
46
46
  @data[name] = [amount, quality]
47
47
  @aggregate[quality] += amount
48
48
  end
49
-
49
+ def insert_text_with_arrow(x_offset, y_offset, text, features = {})
50
+ features.each { |feature, attribute|
51
+ set_feature(feature, attribute)
52
+ }
53
+ @d.annotate(@base_image, 0 ,0, x_offset, y_offset, text)
54
+ height = @d.get_type_metrics(@base_image, text).ascent
55
+ y_offset -= height / 2
56
+ arrow_xpos = x_offset + @d.get_type_metrics(@base_image, text).width + 5
57
+ @d.stroke_width(4)
58
+ @d.stroke features["fill"]
59
+ @d = @d.line(arrow_xpos+1,y_offset,arrow_xpos+12,y_offset+6)
60
+ @d = @d.line(arrow_xpos,y_offset,arrow_xpos+30,y_offset)
61
+ @d = @d.line(arrow_xpos+1,y_offset,arrow_xpos+12,y_offset-6)
62
+ end
50
63
  def insert_text(x_offset, y_offset, text, features = {})
51
64
  features.each { |feature, attribute|
52
65
  set_feature(feature, attribute)
53
66
  }
54
- #puts @d.get_type_metrics(@base_image, text.to_s).width,@d.get_type_metrics(@base_image, text.to_s).height,text
55
67
  @d.annotate(@base_image, 0 ,0, x_offset, y_offset, text)
56
68
  end
57
69
 
@@ -62,7 +74,7 @@ class AnalyticsCharts::CustomPie
62
74
  @d = @d.stroke "#FFFFFF"
63
75
  @d = @d.ellipse(@pie_center_x, @pie_center_y,
64
76
  @pie_radius / 2.0, @pie_radius / 2.0,
65
- 0, 360) # <= +0.5 'fudge factor' gets rid of the ugly gaps
77
+ 0, 360 + 0.5) # <= +0.5 'fudge factor' gets rid of the ugly gaps
66
78
  @d = @d.stroke "#000000"
67
79
  @d.stroke_width(5)
68
80
  @d = @d.line(@pie_center_x-30,@pie_center_y-30,@pie_center_x-14,@pie_center_y-14)
@@ -79,7 +91,6 @@ class AnalyticsCharts::CustomPie
79
91
  end
80
92
  if @data.size > 0
81
93
  @d.stroke_width(@pie_radius)
82
- total_sum = 0.0
83
94
  prev_degrees = 60.0
84
95
  @d.fill_opacity(0) # VERY IMPORTANT, otherwise undesired artifact can result.
85
96
  degrees = Array([0,0,0,0])
@@ -167,14 +178,33 @@ class AnalyticsCharts::CustomPie
167
178
  x_offset = @label_start_x
168
179
  y_offset = @label_start_y
169
180
  for data in sorted_data
181
+ has_data = false
170
182
  if data[1][0] > 0 # Amount > 0
171
183
  font_weight = 900 # Very Bold
172
- text = data[0] + ' <--'
184
+ text = data[0]
185
+ has_data = true
173
186
  else
174
187
  text = data[0]
175
188
  font_weight = 900 # Very Bold
176
189
  end
177
- case data[1][1]
190
+ if has_data
191
+ case data[1][1]
192
+ when 3
193
+ # label_hash gets merged and overrided by fill and font_weight.
194
+ insert_text_with_arrow(x_offset, y_offset, text,
195
+ @label_hash.merge({'fill'=> '#1E753B', 'font_weight'=> font_weight }))
196
+ when 2
197
+ insert_text_with_arrow(x_offset, y_offset, text,
198
+ @label_hash.merge({'fill'=> '#C1B630', 'font_weight'=> font_weight }))
199
+ when 1
200
+ insert_text_with_arrow(x_offset, y_offset, text,
201
+ @label_hash.merge({'fill'=> '#BE6428', 'font_weight'=> font_weight }))
202
+ when 0
203
+ insert_text_with_arrow(x_offset, y_offset, text,
204
+ @label_hash.merge({'fill'=> '#AD1F25', 'font_weight'=> font_weight }))
205
+ end
206
+ else
207
+ case data[1][1]
178
208
  when 3
179
209
  # label_hash gets merged and overrided by fill and font_weight.
180
210
  insert_text(x_offset, y_offset, text,
@@ -188,6 +218,7 @@ class AnalyticsCharts::CustomPie
188
218
  when 0
189
219
  insert_text(x_offset, y_offset, text,
190
220
  @label_hash.merge({'fill'=> '#AD1F25', 'font_weight'=> font_weight }))
221
+ end
191
222
  end
192
223
  y_offset += @label_offset
193
224
  end
@@ -1,3 +1,3 @@
1
1
  module AnalyticsCharts
2
- VERSION = "1.1.5"
2
+ VERSION = "1.2.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: analytics_charts
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.5
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - STEPHEN YU