glimmer-libui-cc-graphs_and_charts 0.2.2 → 0.2.3

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
  SHA256:
3
- metadata.gz: 6b1c01b4d2bd5df0119a5da0969ea0f8697880f5e82b951df8fb11e7ff64cef5
4
- data.tar.gz: 277fd2a3c47009ae872f84393c2f59700c099ea5da6ad472307c4d581fac8b2f
3
+ metadata.gz: c3b89df50fd8dd9d1670fd4e54568fdf90538dfb8a1566bbb7431826c8578f2e
4
+ data.tar.gz: 52820e7aaef7a1edbead1748cc33fc50408d7dd8a7763a93db53154cf4232752
5
5
  SHA512:
6
- metadata.gz: 3bc2bb802a8a058bf9ffb4fb65c5fa2afa9a3fc0578a0956c9ea4e1d2ab1ddc47fe1f2f89ba3afa2e16500c6f4c28a7154caa541d7961075c56c5d8976f4e06f
7
- data.tar.gz: bc82a867fa5ee64776a724d46db62c7039c353cbfaaebabb9e822901faea7e3371fe8ca9c8b1324b96decd880c52e46637dc1c871a4a98175c33abe19ee977d3
6
+ metadata.gz: 5d5ab5c841bd63fc6154b326cd8ff7cb175dd727292a6bfbd95082274f42127f850a321de30224099904064c8809228d5a063cf353cb0296eb31e675b4e227e9
7
+ data.tar.gz: b690434592d74c43929567d856771528e4e31792d575682983838a4fe619fd319f0935e594f8413f2ad7904b59b4ac13ff345e665de570edcdbeb9ef354b7248
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
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
+
3
7
  ## 0.2.2
4
8
 
5
9
  - Display `bar_chart` axis labels `x_axis_label` and `y_axis_label`
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # Graphs and Charts 0.2.2 (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.2'
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,
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.2
1
+ 0.2.3
@@ -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.2 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.2".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 = "2024-01-01"
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 = [
@@ -121,8 +121,9 @@ module Glimmer
121
121
  @grid_marker_number_values = nil
122
122
  @grid_marker_numbers = nil
123
123
  @chart_stroke_marker_values = nil
124
- @mod_values = nil
124
+ @y_axis_mod_values = nil
125
125
  @y_value_max = nil
126
+ @bars_data = nil
126
127
  end
127
128
 
128
129
  def calculate_dynamic_options
@@ -183,7 +184,7 @@ module Glimmer
183
184
  @grid_marker_number_values ||= []
184
185
  # @grid_marker_numbers ||= []
185
186
  @chart_stroke_marker_values ||= []
186
- @mod_values ||= []
187
+ @y_axis_mod_values ||= []
187
188
  y_axis_grid_marker_points.each_with_index do |marker_point, index|
188
189
  @grid_marker_number_values[index] ||= begin
189
190
  value = (y_axis_grid_marker_points.size - index).to_i
@@ -199,11 +200,11 @@ module Glimmer
199
200
  color_hash[:thickness] = (index != y_axis_grid_marker_points.size - 1 ? 2 : 1) if color_hash[:thickness].nil?
200
201
  end
201
202
  chart_stroke_marker_value = @chart_stroke_marker_values[index]
202
- @mod_values[index] ||= begin
203
- mod_value_multiplier = ((y_axis_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)
204
205
  [(5 * mod_value_multiplier), 1].max
205
206
  end
206
- mod_value = @mod_values[index]
207
+ mod_value = @y_axis_mod_values[index]
207
208
  comparison_value = (mod_value > 2) ? 0 : 1
208
209
  if mod_value > 2
209
210
  if grid_marker_number_value % mod_value == comparison_value
@@ -284,19 +285,24 @@ module Glimmer
284
285
  }
285
286
  }
286
287
  end
287
- def max_marker_count
288
- [(0.15*height).to_i, 1].max
288
+
289
+ def y_axis_max_marker_count
290
+ [(0.15*height_drawable).to_i, 1].max
289
291
  end
290
292
 
291
293
  def bars
292
- values.each_with_index do |(x_value, y_value), index|
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|
293
303
  x = chart_y_axis_label_padding_width + chart_grid_marker_padding_width + chart_padding_width + (index * bar_width_including_padding) + bar_padding_width
294
304
  bar_height = y_value * y_resolution
295
305
  y = height - chart_grid_marker_padding_height - chart_x_axis_label_padding_height - chart_padding_height - bar_height
296
- rectangle(x, y, bar_width, bar_height) {
297
- fill chart_color_bar
298
- }
299
-
300
306
  x_axis_grid_marker_text = x_value.to_s
301
307
  grid_marker_number_font = marker_font
302
308
  x_axis_grid_marker_text_size = estimate_width_of_text(x_axis_grid_marker_text, grid_marker_number_font)
@@ -304,9 +310,45 @@ module Glimmer
304
310
  x_axis_grid_marker_x = middle_of_bar_x - x_axis_grid_marker_text_size/2.0
305
311
  middle_of_x_axis_grid_marker_padding = height - chart_grid_marker_padding_height/2.0 - chart_x_axis_label_padding_height
306
312
  x_axis_grid_marker_y = middle_of_x_axis_grid_marker_padding - chart_font_marker_text[:size]/2.0 - 7.0
307
- text(x_axis_grid_marker_x, x_axis_grid_marker_y, x_axis_grid_marker_text_size) {
308
- string(x_axis_grid_marker_text) {
309
- font grid_marker_number_font
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
310
352
  color chart_color_marker_text
311
353
  }
312
354
  }
metadata CHANGED
@@ -1,14 +1,14 @@
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.2
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: 2024-01-01 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