glimmer-libui-cc-graphs_and_charts 0.2.1 → 0.2.3

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
  SHA256:
3
- metadata.gz: 263ed1c13a5130568949ac82714104e494a4e8ffd1ded95fec7d14110d5fc364
4
- data.tar.gz: 2eea70d52135a1381d2ae30c2fb03dac37f5a07c0f74ba94875ea8a5fb82b867
3
+ metadata.gz: c3b89df50fd8dd9d1670fd4e54568fdf90538dfb8a1566bbb7431826c8578f2e
4
+ data.tar.gz: 52820e7aaef7a1edbead1748cc33fc50408d7dd8a7763a93db53154cf4232752
5
5
  SHA512:
6
- metadata.gz: 8cf72862f552c4d9de06163653465ea4cf4779f371080b8fb4a345fa1bce9315ad190e12c8cdffaf71ae546d43510804d1574e12a7080e30a35901e3e842d947
7
- data.tar.gz: cff63fd75943908ee9084e821c7a6a32d517c729796cbdc705f4928431f27540d904c0ea1080c9248a0542a43cbc660e652d07b0cb69e8e641153956d1354e47
6
+ metadata.gz: 5d5ab5c841bd63fc6154b326cd8ff7cb175dd727292a6bfbd95082274f42127f850a321de30224099904064c8809228d5a063cf353cb0296eb31e675b4e227e9
7
+ data.tar.gz: b690434592d74c43929567d856771528e4e31792d575682983838a4fe619fd319f0935e594f8413f2ad7904b59b4ac13ff345e665de570edcdbeb9ef354b7248
data/CHANGELOG.md CHANGED
@@ -1,5 +1,15 @@
1
1
  # Change Log
2
2
 
3
+ ## 0.2.3
4
+
5
+ - Automatically scale number of `bar_chart` horizontal grid markers so that if the chart width gets small enough for them to run into each other, less of them are displayed
6
+
7
+ ## 0.2.2
8
+
9
+ - Display `bar_chart` axis labels `x_axis_label` and `y_axis_label`
10
+ - Display `bar_chart` x-axis values below the chart
11
+ - Fix issue with `bar_chart` vertical scaling of grid markers when numbers are larger than 1000 and have `K` in them by disabling `K` formatting for now (the issue was seeing the same marker number twice because two consecutive markers were calculated with similar shortened values; e.g. both 10K when one is 10100 and the other is 10750).
12
+
3
13
  ## 0.2.1
4
14
 
5
15
  - Fix clipped text of grid markers when they include 1000 displayed as 1K
data/LICENSE.txt CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2023 Andy Maleh
1
+ Copyright (c) 2023-2024 Andy Maleh
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # Graphs and Charts 0.2.1 (Alpha)
1
+ # Graphs and Charts 0.2.3 (Alpha)
2
2
  ## [Glimmer DSL for LibUI](https://github.com/AndyObtiva/glimmer-dsl-libui) Custom Controls
3
3
  [![Gem Version](https://badge.fury.io/rb/glimmer-libui-cc-graphs_and_charts.svg)](http://badge.fury.io/rb/glimmer-libui-cc-graphs_and_charts)
4
4
  [![Join the chat at https://gitter.im/AndyObtiva/glimmer](https://badges.gitter.im/AndyObtiva/glimmer.svg)](https://gitter.im/AndyObtiva/glimmer?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
@@ -14,7 +14,7 @@ Graphs and Charts (Custom Controls) for [Glimmer DSL for LibUI](https://github.c
14
14
  Add this line to Bundler `Gemfile`:
15
15
 
16
16
  ```ruby
17
- gem 'glimmer-libui-cc-graphs_and_charts', '~> 0.2.1'
17
+ gem 'glimmer-libui-cc-graphs_and_charts', '~> 0.2.3'
18
18
  ```
19
19
 
20
20
  Run:
@@ -50,6 +50,8 @@ You can then nest `bar_chart` under `window` or some container like `vertical_bo
50
50
  bar_chart(
51
51
  width: 900,
52
52
  height: 300,
53
+ x_axis_label: 'Month',
54
+ y_axis_label: 'New Customer Accounts',
53
55
  values: {
54
56
  'Jan' => 30,
55
57
  'Feb' => 49,
@@ -87,6 +89,8 @@ class BasicBarChart
87
89
  @bar_chart = bar_chart(
88
90
  width: 900,
89
91
  height: 300,
92
+ x_axis_label: 'Month',
93
+ y_axis_label: 'New Customer Accounts',
90
94
  values: {
91
95
  'Jan' => 30,
92
96
  'Feb' => 49,
@@ -332,5 +336,5 @@ Copyright
332
336
 
333
337
  [MIT](LICENSE.txt)
334
338
 
335
- Copyright (c) 2023 Andy Maleh. See
339
+ Copyright (c) 2023-2024 Andy Maleh. See
336
340
  [LICENSE.txt](LICENSE.txt) for further details.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.1
1
+ 0.2.3
@@ -12,6 +12,8 @@ class BasicBarChart
12
12
  @bar_chart = bar_chart(
13
13
  width: 900,
14
14
  height: 300,
15
+ x_axis_label: 'Month',
16
+ y_axis_label: 'New Customer Accounts',
15
17
  values: {
16
18
  'Jan' => 30,
17
19
  'Feb' => 49,
@@ -25,7 +27,7 @@ class BasicBarChart
25
27
  'Oct' => 68,
26
28
  'Nov' => 52,
27
29
  'Dec' => 36,
28
- }
30
+ },
29
31
  )
30
32
 
31
33
  on_content_size_changed do
@@ -2,16 +2,16 @@
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
3
  # Instead, edit Juwelier::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
- # stub: glimmer-libui-cc-graphs_and_charts 0.2.1 ruby lib
5
+ # stub: glimmer-libui-cc-graphs_and_charts 0.2.3 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "glimmer-libui-cc-graphs_and_charts".freeze
9
- s.version = "0.2.1".freeze
9
+ s.version = "0.2.3".freeze
10
10
 
11
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
12
12
  s.require_paths = ["lib".freeze]
13
13
  s.authors = ["Andy Maleh".freeze]
14
- s.date = "2023-12-29"
14
+ s.date = "2024-01-03"
15
15
  s.description = "Graphs and Charts (Custom Controls) for Glimmer DSL for LibUI, like Line Graph.".freeze
16
16
  s.email = "andy.am@gmail.com".freeze
17
17
  s.extra_rdoc_files = [
@@ -39,7 +39,7 @@ Gem::Specification.new do |s|
39
39
 
40
40
  s.specification_version = 4
41
41
 
42
- s.add_runtime_dependency(%q<glimmer-dsl-libui>.freeze, ["~> 0.11".freeze])
42
+ s.add_runtime_dependency(%q<glimmer-dsl-libui>.freeze, [">= 0.11.8".freeze, "< 2.0.0".freeze])
43
43
  s.add_development_dependency(%q<rspec>.freeze, ["~> 3.5.0".freeze])
44
44
  s.add_development_dependency(%q<juwelier>.freeze, ["= 2.4.9".freeze])
45
45
  s.add_development_dependency(%q<simplecov>.freeze, [">= 0".freeze])
@@ -16,9 +16,19 @@ module Glimmer
16
16
 
17
17
  DEFAULT_CHART_PADDING_WIDTH = 5.0
18
18
  DEFAULT_CHART_PADDING_HEIGHT = 5.0
19
- DEFAULT_CHART_GRID_MARKER_PADDING_WIDTH = 37.0
20
19
  DEFAULT_CHART_BAR_PADDING_WIDTH_PERCENTAGE = 30.0
21
20
 
21
+ # This is y-axis grid marker padding that is to the left of the bar chart
22
+ DEFAULT_CHART_GRID_MARKER_PADDING_WIDTH = 37.0
23
+ # This is x-axis grid marker padding that is below the bar chart
24
+ DEFAULT_CHART_GRID_MARKER_PADDING_HEIGHT = 30.0
25
+
26
+ # This is y-axis label padding that is to the left of the bar chart
27
+ DEFAULT_CHART_Y_AXIS_LABEL_PADDING_WIDTH = 25.0
28
+
29
+ # This is x-axis label padding that is below the bar chart
30
+ DEFAULT_CHART_X_AXIS_LABEL_PADDING_HEIGHT = 25.0
31
+
22
32
  DEFAULT_CHART_STROKE_GRID = [185, 184, 185]
23
33
  DEFAULT_CHART_STROKE_MARKER = [185, 184, 185]
24
34
  DEFAULT_CHART_STROKE_MARKER_LINE = [217, 217, 217, thickness: 1, dashes: [1, 1]]
@@ -33,9 +43,20 @@ module Glimmer
33
43
 
34
44
  option :chart_padding_width, default: DEFAULT_CHART_PADDING_WIDTH
35
45
  option :chart_padding_height, default: DEFAULT_CHART_PADDING_HEIGHT
36
- option :chart_grid_marker_padding_width, default: DEFAULT_CHART_GRID_MARKER_PADDING_WIDTH
37
46
  option :chart_bar_padding_width_percentage, default: DEFAULT_CHART_BAR_PADDING_WIDTH_PERCENTAGE
38
47
 
48
+ # This is y-axis grid marker padding that is to the left of the bar chart
49
+ option :chart_grid_marker_padding_width, default: DEFAULT_CHART_GRID_MARKER_PADDING_WIDTH
50
+
51
+ # This is x-axis grid marker padding that is below the bar chart
52
+ option :chart_grid_marker_padding_height, default: DEFAULT_CHART_GRID_MARKER_PADDING_HEIGHT
53
+
54
+ # This is y-axis label padding that is to the left of the bar chart
55
+ option :chart_y_axis_label_padding_width, default: DEFAULT_CHART_Y_AXIS_LABEL_PADDING_WIDTH
56
+
57
+ # This is x-axis label padding that is below the bar chart
58
+ option :chart_x_axis_label_padding_height, default: DEFAULT_CHART_X_AXIS_LABEL_PADDING_HEIGHT
59
+
39
60
  option :chart_stroke_grid, default: DEFAULT_CHART_STROKE_GRID
40
61
  option :chart_stroke_marker, default: DEFAULT_CHART_STROKE_MARKER
41
62
  option :chart_stroke_marker_line, default: DEFAULT_CHART_STROKE_MARKER_LINE
@@ -57,9 +78,16 @@ module Glimmer
57
78
  # '7' => 03,
58
79
  # }
59
80
  option :values, default: {}
81
+ option :x_axis_label, default: nil
82
+ option :y_axis_label, default: nil
60
83
 
61
84
  attr_reader :bar_width_including_padding
62
85
 
86
+ before_body do
87
+ self.chart_y_axis_label_padding_width = 0 if y_axis_label.to_s.empty?
88
+ self.chart_x_axis_label_padding_height = 0 if x_axis_label.to_s.empty?
89
+ end
90
+
63
91
  after_body do
64
92
  observe(self, :values) do
65
93
  clear_drawing_cache
@@ -89,11 +117,13 @@ module Glimmer
89
117
  def clear_drawing_cache
90
118
  @y_resolution = nil
91
119
  @bar_width_including_padding = nil
92
- @grid_marker_points = nil
120
+ @y_axis_grid_marker_points = nil
93
121
  @grid_marker_number_values = nil
94
122
  @grid_marker_numbers = nil
95
123
  @chart_stroke_marker_values = nil
96
- @mod_values = nil
124
+ @y_axis_mod_values = nil
125
+ @y_value_max = nil
126
+ @bars_data = nil
97
127
  end
98
128
 
99
129
  def calculate_dynamic_options
@@ -118,11 +148,11 @@ module Glimmer
118
148
  end
119
149
 
120
150
  def width_drawable
121
- width - 2.0*chart_padding_width - chart_grid_marker_padding_width
151
+ width - 2.0*chart_padding_width - chart_grid_marker_padding_width - chart_y_axis_label_padding_width
122
152
  end
123
153
 
124
154
  def height_drawable
125
- height - 2.0*chart_padding_height
155
+ height - 2.0*chart_padding_height - chart_grid_marker_padding_height - chart_x_axis_label_padding_height
126
156
  end
127
157
 
128
158
  def chart_background
@@ -130,37 +160,51 @@ module Glimmer
130
160
  fill 255, 255, 255
131
161
  }
132
162
  end
133
-
163
+
134
164
  def grid_lines
135
- line(chart_padding_width, chart_padding_height, chart_padding_width, height - chart_padding_height) {
165
+ x_axis_grid_lines
166
+ y_axis_grid_lines
167
+ x_axis_label_text
168
+ y_axis_label_text
169
+ end
170
+
171
+ def x_axis_grid_lines
172
+ line_y = height - chart_padding_height - chart_grid_marker_padding_height - chart_x_axis_label_padding_height
173
+ line(chart_x_axis_label_padding_height + chart_padding_width, line_y, width - chart_padding_width, line_y) {
136
174
  stroke chart_stroke_grid
137
175
  }
138
- line(chart_padding_width, height - chart_padding_height, width - chart_padding_width, height - chart_padding_height) {
176
+ end
177
+
178
+ def y_axis_grid_lines
179
+ line_x = chart_y_axis_label_padding_width + chart_padding_width
180
+ line(line_x, chart_padding_height, line_x, height - chart_padding_height - chart_grid_marker_padding_height - chart_x_axis_label_padding_height) {
139
181
  stroke chart_stroke_grid
140
182
  }
141
- grid_marker_number_font = chart_font_marker_text.merge(size: 11)
183
+ grid_marker_number_font = marker_font
142
184
  @grid_marker_number_values ||= []
143
- @grid_marker_numbers ||= []
185
+ # @grid_marker_numbers ||= []
144
186
  @chart_stroke_marker_values ||= []
145
- @mod_values ||= []
146
- grid_marker_points.each_with_index do |marker_point, index|
187
+ @y_axis_mod_values ||= []
188
+ y_axis_grid_marker_points.each_with_index do |marker_point, index|
147
189
  @grid_marker_number_values[index] ||= begin
148
- value = (grid_marker_points.size - index).to_i
190
+ value = (y_axis_grid_marker_points.size - index).to_i
149
191
  value = y_value_max if !y_value_max.nil? && y_value_max.to_i != y_value_max && index == 0
150
192
  value
151
193
  end
152
194
  grid_marker_number_value = @grid_marker_number_values[index]
153
- @grid_marker_numbers[index] ||= (grid_marker_number_value >= 1000) ? "#{grid_marker_number_value / 1000}K" : grid_marker_number_value.to_s
154
- grid_marker_number = @grid_marker_numbers[index]
195
+ # figuring out how to setup 1K numbers without repeating a number twice is more complicated than just enabling this code
196
+ # disabling for now
197
+ # @grid_marker_numbers[index] ||= (grid_marker_number_value >= 1000) ? "#{grid_marker_number_value / 1000}K" : grid_marker_number_value.to_s
198
+ grid_marker_number = grid_marker_number_value.to_s
155
199
  @chart_stroke_marker_values[index] ||= BarChart.interpret_color(chart_stroke_marker).tap do |color_hash|
156
- color_hash[:thickness] = (index != grid_marker_points.size - 1 ? 2 : 1) if color_hash[:thickness].nil?
200
+ color_hash[:thickness] = (index != y_axis_grid_marker_points.size - 1 ? 2 : 1) if color_hash[:thickness].nil?
157
201
  end
158
202
  chart_stroke_marker_value = @chart_stroke_marker_values[index]
159
- @mod_values[index] ||= begin
160
- mod_value_multiplier = ((grid_marker_points.size / max_marker_count) + 1)
203
+ @y_axis_mod_values[index] ||= begin
204
+ mod_value_multiplier = ((y_axis_grid_marker_points.size / y_axis_max_marker_count) + 1)
161
205
  [(5 * mod_value_multiplier), 1].max
162
206
  end
163
- mod_value = @mod_values[index]
207
+ mod_value = @y_axis_mod_values[index]
164
208
  comparison_value = (mod_value > 2) ? 0 : 1
165
209
  if mod_value > 2
166
210
  if grid_marker_number_value % mod_value == comparison_value
@@ -173,7 +217,7 @@ module Glimmer
173
217
  stroke chart_stroke_marker_value
174
218
  }
175
219
  end
176
- if grid_marker_number_value % mod_value == comparison_value && grid_marker_number_value != grid_marker_points.size
220
+ if grid_marker_number_value % mod_value == comparison_value && grid_marker_number_value != y_axis_grid_marker_points.size
177
221
  line(marker_point[:x], marker_point[:y], marker_point[:x] + width - chart_padding_width, marker_point[:y]) {
178
222
  stroke chart_stroke_marker_line
179
223
  }
@@ -190,40 +234,131 @@ module Glimmer
190
234
  end
191
235
  end
192
236
 
193
- def grid_marker_points
194
- if @grid_marker_points.nil?
237
+ def y_axis_grid_marker_points
238
+ if @y_axis_grid_marker_points.nil?
195
239
  if values.any?
196
240
  chart_y_max = [y_value_max, 1].max
197
- current_chart_height = (height - chart_padding_height * 2)
241
+ current_chart_height = (height - chart_padding_height * 2 - chart_grid_marker_padding_height - chart_x_axis_label_padding_height)
198
242
  y_value_count = chart_y_max.ceil
199
- @grid_marker_points = chart_y_max.to_i.times.map do |marker_index|
200
- x = chart_padding_width
243
+ @y_axis_grid_marker_points = chart_y_max.to_i.times.map do |marker_index|
244
+ x = chart_y_axis_label_padding_width + chart_padding_width
201
245
  y_value = y_value_count - marker_index
202
246
  scaled_y_value = y_value.to_f * y_resolution.to_f
203
- y = height - chart_padding_height - scaled_y_value
247
+ y = height - chart_padding_height - chart_grid_marker_padding_height - chart_x_axis_label_padding_height - scaled_y_value
204
248
  {x: x, y: y}
205
249
  end
206
250
  end
207
251
  end
208
252
 
209
- @grid_marker_points
253
+ @y_axis_grid_marker_points
254
+ end
255
+
256
+ def x_axis_label_text
257
+ x_axis_label_font = marker_font
258
+ x_axis_label_width = estimate_width_of_text(x_axis_label, x_axis_label_font)
259
+ middle_of_x_axis_label_padding_x = chart_y_axis_label_padding_width + (width - chart_y_axis_label_padding_width)/2.0
260
+ x_axis_label_x = middle_of_x_axis_label_padding_x - x_axis_label_width/2.0
261
+ middle_of_x_axis_label_padding_y = height - (chart_x_axis_label_padding_height/2.0)
262
+ x_axis_label_y = middle_of_x_axis_label_padding_y - x_axis_label_font[:size]/2.0 - 7.0
263
+ text(x_axis_label_x, x_axis_label_y, x_axis_label_width) {
264
+ string(x_axis_label) {
265
+ font x_axis_label_font
266
+ color chart_color_marker_text
267
+ }
268
+ }
269
+ end
270
+
271
+ def y_axis_label_text
272
+ y_axis_label_font = marker_font
273
+ y_axis_label_width = estimate_width_of_text(y_axis_label, y_axis_label_font)
274
+ middle_of_y_axis_label_padding_x = chart_y_axis_label_padding_width/2.0
275
+ y_axis_label_x = middle_of_y_axis_label_padding_x - y_axis_label_width/2.0
276
+ middle_of_y_axis_label_padding_y = (height - chart_x_axis_label_padding_height)/2.0
277
+ y_axis_label_y = middle_of_y_axis_label_padding_y - y_axis_label_font[:size]/2.0
278
+ text(y_axis_label_x, y_axis_label_y, y_axis_label_width) {
279
+ string(y_axis_label) {
280
+ font y_axis_label_font
281
+ color chart_color_marker_text
282
+ }
283
+ transform {
284
+ rotate(middle_of_y_axis_label_padding_x, middle_of_y_axis_label_padding_y, -90)
285
+ }
286
+ }
210
287
  end
211
288
 
212
- def max_marker_count
213
- [(0.15*height).to_i, 1].max
289
+ def y_axis_max_marker_count
290
+ [(0.15*height_drawable).to_i, 1].max
214
291
  end
215
292
 
216
293
  def bars
217
- values.each_with_index do |(x_value, y_value), index|
218
- x = chart_grid_marker_padding_width + chart_padding_width + (index * bar_width_including_padding) + bar_padding_width
294
+ @bars_data = calculate_bars_data
295
+ @bars_data.each do |bar_data|
296
+ bar(bar_data)
297
+ end
298
+ x_axis_grid_markers(@bars_data)
299
+ end
300
+
301
+ def calculate_bars_data
302
+ values.each_with_index.map do |(x_value, y_value), index|
303
+ x = chart_y_axis_label_padding_width + chart_grid_marker_padding_width + chart_padding_width + (index * bar_width_including_padding) + bar_padding_width
219
304
  bar_height = y_value * y_resolution
220
- y = height - chart_padding_height - bar_height
221
- rectangle(x, y, bar_width, bar_height) {
222
- fill chart_color_bar
305
+ y = height - chart_grid_marker_padding_height - chart_x_axis_label_padding_height - chart_padding_height - bar_height
306
+ x_axis_grid_marker_text = x_value.to_s
307
+ grid_marker_number_font = marker_font
308
+ x_axis_grid_marker_text_size = estimate_width_of_text(x_axis_grid_marker_text, grid_marker_number_font)
309
+ middle_of_bar_x = x + bar_width/2.0
310
+ x_axis_grid_marker_x = middle_of_bar_x - x_axis_grid_marker_text_size/2.0
311
+ middle_of_x_axis_grid_marker_padding = height - chart_grid_marker_padding_height/2.0 - chart_x_axis_label_padding_height
312
+ x_axis_grid_marker_y = middle_of_x_axis_grid_marker_padding - chart_font_marker_text[:size]/2.0 - 7.0
313
+ {
314
+ index: index,
315
+ x: x,
316
+ y: y,
317
+ bar_width: bar_width,
318
+ bar_height: bar_height,
319
+ x_axis_grid_marker_x: x_axis_grid_marker_x,
320
+ x_axis_grid_marker_y: x_axis_grid_marker_y,
321
+ x_axis_grid_marker_text: x_axis_grid_marker_text,
322
+ x_axis_grid_marker_text_size: x_axis_grid_marker_text_size,
323
+ }
324
+ end
325
+ end
326
+
327
+ def bar(bar_data)
328
+ rectangle(bar_data[:x], bar_data[:y], bar_data[:bar_width], bar_data[:bar_height]) {
329
+ fill chart_color_bar
330
+ }
331
+ end
332
+
333
+ def x_axis_grid_markers(bars_data)
334
+ skip_count = 0
335
+ collision_detected = true
336
+ while collision_detected
337
+ collision_detected = bars_data.each_with_index.any? do |bar_data, index|
338
+ next if index == 0
339
+ last_bar_text_data = bars_data[index - 1]
340
+ bar_data[:x_axis_grid_marker_x] < (last_bar_text_data[:x_axis_grid_marker_x] + last_bar_text_data[:x_axis_grid_marker_text_size] + 5)
341
+ end
342
+ if collision_detected
343
+ skip_count += 1
344
+ bars_data = bars_data.each_with_index.select {|bar_data, index| index % (skip_count+1) == 0 }.map(&:first)
345
+ end
346
+ end
347
+ x_axis_grid_marker_font = marker_font
348
+ bars_data.each do |bar_data|
349
+ text(bar_data[:x_axis_grid_marker_x], bar_data[:x_axis_grid_marker_y], bar_data[:x_axis_grid_marker_text_size]) {
350
+ string(bar_data[:x_axis_grid_marker_text]) {
351
+ font x_axis_grid_marker_font
352
+ color chart_color_marker_text
353
+ }
223
354
  }
224
355
  end
225
356
  end
226
357
 
358
+ def marker_font
359
+ chart_font_marker_text.merge(size: 11)
360
+ end
361
+
227
362
  # this is the multiplier that we must multiply by the relative y value
228
363
  def y_resolution
229
364
  # TODO in the future, we will use the y range, but today, we assume it starts at 0
@@ -238,9 +373,10 @@ module Glimmer
238
373
  end
239
374
 
240
375
  def estimate_width_of_text(text_string, font_properties)
376
+ return 0 if text_string.to_s.empty?
241
377
  # TODO refactor move this method to somewhere common like Glimmer module
242
378
  font_size = font_properties[:size] || 16
243
- estimated_font_width = 0.62 * font_size
379
+ estimated_font_width = 0.63 * font_size
244
380
  text_string.chars.size * estimated_font_width
245
381
  end
246
382
 
@@ -195,6 +195,7 @@ module Glimmer
195
195
  value
196
196
  end
197
197
  grid_marker_number_value = @grid_marker_number_values[index]
198
+ # TODO consider not caching the following line as that might save memory and run faster without caching
198
199
  @grid_marker_numbers[index] ||= (grid_marker_number_value >= 1000) ? "#{grid_marker_number_value / 1000}K" : grid_marker_number_value.to_s
199
200
  grid_marker_number = @grid_marker_numbers[index]
200
201
  @graph_stroke_marker_values[index] ||= LineGraph.interpret_color(graph_stroke_marker).tap do |color_hash|
@@ -552,8 +553,9 @@ module Glimmer
552
553
  end
553
554
 
554
555
  def estimate_width_of_text(text_string, font_properties)
556
+ return 0 if text_string.to_s.empty?
555
557
  font_size = font_properties[:size] || 16
556
- estimated_font_width = 0.62 * font_size
558
+ estimated_font_width = 0.63 * font_size
557
559
  text_string.chars.size * estimated_font_width
558
560
  end
559
561
 
metadata CHANGED
@@ -1,29 +1,35 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: glimmer-libui-cc-graphs_and_charts
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andy Maleh
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-12-29 00:00:00.000000000 Z
11
+ date: 2024-01-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: glimmer-dsl-libui
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 0.11.8
20
+ - - "<"
18
21
  - !ruby/object:Gem::Version
19
- version: '0.11'
22
+ version: 2.0.0
20
23
  type: :runtime
21
24
  prerelease: false
22
25
  version_requirements: !ruby/object:Gem::Requirement
23
26
  requirements:
24
- - - "~>"
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: 0.11.8
30
+ - - "<"
25
31
  - !ruby/object:Gem::Version
26
- version: '0.11'
32
+ version: 2.0.0
27
33
  - !ruby/object:Gem::Dependency
28
34
  name: rspec
29
35
  requirement: !ruby/object:Gem::Requirement