glimmer-libui-cc-graphs_and_charts 0.4.0 → 0.4.2
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 +4 -4
- data/CHANGELOG.md +10 -0
- data/README.md +36 -4
- data/VERSION +1 -1
- data/examples/graphs_and_charts/basic_line_graph_relative.rb +49 -0
- data/glimmer-libui-cc-graphs_and_charts.gemspec +4 -3
- data/lib/glimmer/view/line_graph.rb +23 -5
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d2c272045c6c7fce0af891fe8cb87940a5c2c4e51c8f80fd9cb29ae20d19f429
|
4
|
+
data.tar.gz: 302c1b38be9fe0b96501e3eae432f7ba06ba73da64eb83f8d63834d2d12381e2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f9c18491aa8a799e13172ddbc63a44f9c44aced1d69de0b35f55539b28387437e84c370872216b77a2dcd2ffa470dab37ae6962d998fed98b07f2b4f9ca9a13e
|
7
|
+
data.tar.gz: bbee30db1ed485df4b84eed78d91e128df3d0bd79815f0e9b9e568b54bcdc756e629cc381349f4f6933455ef9d273696ca7ebe885830191230c39ca6514b66dc
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,15 @@
|
|
1
1
|
# Change Log
|
2
2
|
|
3
|
+
## 0.4.2
|
4
|
+
|
5
|
+
- Line Graph relative mode with `reverse_x` as `false` adds x_interval_in_seconds time positively.
|
6
|
+
- examples/graphs_and_charts/basic_line_graph_relative.rb demonstrates Line Graph in relative mode with `reverse_x` as `false`
|
7
|
+
|
8
|
+
## 0.4.1
|
9
|
+
|
10
|
+
- Support `reverse_x` as `false` when rendering a line graph in relative mode (without `display_attributes_on_hover: true` for now).
|
11
|
+
- Add new `examples/graphs_and_charts/basic_line_graph_relative.rb` example that renders line graphs naturally from left to right (with reverse_x not specified, meaning having value `false`).
|
12
|
+
|
3
13
|
## 0.4.0
|
4
14
|
|
5
15
|
- Support `reverse_x` option; when `false`, line graphs are drawn naturally from left to right, and when `true`, line graphs are drawn like before from right to left.
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Graphs and Charts 0.4.
|
1
|
+
# Graphs and Charts 0.4.2 (Alpha)
|
2
2
|
## [Glimmer DSL for LibUI](https://github.com/AndyObtiva/glimmer-dsl-libui) Custom Controls
|
3
3
|
[](http://badge.fury.io/rb/glimmer-libui-cc-graphs_and_charts)
|
4
4
|
[](https://gitter.im/AndyObtiva/glimmer?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
|
@@ -16,7 +16,7 @@ Graphs and Charts (Custom Controls for [Glimmer DSL for LibUI](https://github.co
|
|
16
16
|
Add this line to Bundler `Gemfile`:
|
17
17
|
|
18
18
|
```ruby
|
19
|
-
gem 'glimmer-libui-cc-graphs_and_charts', '~> 0.4.
|
19
|
+
gem 'glimmer-libui-cc-graphs_and_charts', '~> 0.4.2'
|
20
20
|
```
|
21
21
|
|
22
22
|
Run:
|
@@ -137,6 +137,8 @@ Note that you can use in absolute mode or relative mode for determining x-axis v
|
|
137
137
|
- Absolute Mode: pass `values` which maps x-axis values to y-axis values
|
138
138
|
- Relative Mode: pass `y_values`, `x_value_start`, and `x_interval_in_seconds` (x-axis values are calculated automatically in a uniform way from `x_value_start` deducting `x_interval_in_seconds`)
|
139
139
|
|
140
|
+
Look into [lib/glimmer/view/line_graph.rb](/lib/glimmer/view/line_graph.rb) to learn about all supported options.
|
141
|
+
|
140
142
|
**Absolute Mode:**
|
141
143
|
|
142
144
|
It supports any `Numeric` y-axis values in addition to `Time` x-axis values.
|
@@ -216,6 +218,38 @@ line_graph(
|
|
216
218
|
|
217
219
|

|
218
220
|
|
221
|
+
**Relative Mode:**
|
222
|
+
|
223
|
+
Currently, it only supports `Integer` y-axis values in addition to `Time` x-axis values.
|
224
|
+
|
225
|
+
```ruby
|
226
|
+
line_graph(
|
227
|
+
width: 900,
|
228
|
+
height: 300,
|
229
|
+
graph_point_distance: :width_divided_by_point_count,
|
230
|
+
lines: [
|
231
|
+
{
|
232
|
+
name: 'Feature A',
|
233
|
+
stroke: [163, 40, 39, thickness: 2],
|
234
|
+
x_value_start: @start_time,
|
235
|
+
x_interval_in_seconds: 8,
|
236
|
+
x_value_format: -> (time) {time.strftime("%a %d %b %Y %T GMT")},
|
237
|
+
y_values: [80, 36, 10, 60, 20, 110, 16, 5, 36, 1, 77, 15, 3, 34, 8, 63, 12, 17, 90, 28, 70]
|
238
|
+
},
|
239
|
+
{
|
240
|
+
name: 'Feature B',
|
241
|
+
stroke: [47, 109, 104, thickness: 2],
|
242
|
+
x_value_start: @start_time,
|
243
|
+
x_interval_in_seconds: 8,
|
244
|
+
x_value_format: -> (time) {time.strftime("%a %d %b %Y %T GMT")},
|
245
|
+
y_values: [62, 0, 90, 0, 0, 27, 0, 56, 0, 0, 24, 0, 60, 0, 30, 0, 47, 0, 38, 90, 0]
|
246
|
+
},
|
247
|
+
],
|
248
|
+
)
|
249
|
+
```
|
250
|
+
|
251
|
+

|
252
|
+
|
219
253
|
**Relative Mode (reverse x):**
|
220
254
|
|
221
255
|
Currently, it only supports `Integer` y-axis values in addition to `Time` x-axis values.
|
@@ -250,8 +284,6 @@ line_graph(
|
|
250
284
|
|
251
285
|

|
252
286
|
|
253
|
-
Look into [lib/glimmer/view/line_graph.rb](/lib/glimmer/view/line_graph.rb) to learn about all supported options.
|
254
|
-
|
255
287
|
**Basic Line Graph Example:**
|
256
288
|
|
257
289
|
[examples/graphs_and_charts/basic_line_graph.rb](/examples/graphs_and_charts/basic_line_graph.rb)
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.4.
|
1
|
+
0.4.2
|
@@ -0,0 +1,49 @@
|
|
1
|
+
# This line is only needed when running the example from inside the project directory
|
2
|
+
$LOAD_PATH.prepend(File.expand_path(File.join(__dir__, '..', '..', 'lib'))) if File.exist?(File.join(__dir__, '..', '..', 'lib'))
|
3
|
+
|
4
|
+
require 'glimmer-dsl-libui'
|
5
|
+
require 'glimmer/view/line_graph'
|
6
|
+
|
7
|
+
class BasicLineGraphRelative
|
8
|
+
include Glimmer::LibUI::Application
|
9
|
+
|
10
|
+
before_body do
|
11
|
+
@start_time = Time.now
|
12
|
+
end
|
13
|
+
|
14
|
+
body {
|
15
|
+
window('Basic Line Graph Relative', 900, 330) { |main_window|
|
16
|
+
@line_graph = line_graph(
|
17
|
+
width: 900,
|
18
|
+
height: 300,
|
19
|
+
graph_point_distance: :width_divided_by_point_count,
|
20
|
+
lines: [
|
21
|
+
{
|
22
|
+
name: 'Feature A',
|
23
|
+
stroke: [163, 40, 39, thickness: 2],
|
24
|
+
x_value_start: @start_time,
|
25
|
+
x_interval_in_seconds: 8,
|
26
|
+
x_value_format: -> (time) {time.strftime("%a %d %b %Y %T GMT")},
|
27
|
+
y_values: [80, 36, 10, 60, 20, 110, 16, 5, 36, 1, 77, 15, 3, 34, 8, 63, 12, 17, 90, 28, 70]
|
28
|
+
},
|
29
|
+
{
|
30
|
+
name: 'Feature B',
|
31
|
+
stroke: [47, 109, 104, thickness: 2],
|
32
|
+
x_value_start: @start_time,
|
33
|
+
x_interval_in_seconds: 8,
|
34
|
+
x_value_format: -> (time) {time.strftime("%a %d %b %Y %T GMT")},
|
35
|
+
y_values: [62, 0, 90, 0, 0, 27, 0, 56, 0, 0, 24, 0, 60, 0, 30, 0, 47, 0, 38, 90, 0]
|
36
|
+
},
|
37
|
+
],
|
38
|
+
display_attributes_on_hover: true,
|
39
|
+
)
|
40
|
+
|
41
|
+
on_content_size_changed do
|
42
|
+
@line_graph.width = main_window.content_size[0]
|
43
|
+
@line_graph.height = main_window.content_size[1] - 30
|
44
|
+
end
|
45
|
+
}
|
46
|
+
}
|
47
|
+
end
|
48
|
+
|
49
|
+
BasicLineGraphRelative.launch
|
@@ -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.4.
|
5
|
+
# stub: glimmer-libui-cc-graphs_and_charts 0.4.2 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.4.
|
9
|
+
s.version = "0.4.2".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 = "2025-
|
14
|
+
s.date = "2025-02-23"
|
15
15
|
s.description = "Graphs and Charts (Glimmer DSL for LibUI Custom Controls), like Line Graph, Bar Chart, and Bubble Chart.".freeze
|
16
16
|
s.email = "andy.am@gmail.com".freeze
|
17
17
|
s.extra_rdoc_files = [
|
@@ -27,6 +27,7 @@ Gem::Specification.new do |s|
|
|
27
27
|
"examples/graphs_and_charts/basic_bar_chart.rb",
|
28
28
|
"examples/graphs_and_charts/basic_bubble_chart.rb",
|
29
29
|
"examples/graphs_and_charts/basic_line_graph.rb",
|
30
|
+
"examples/graphs_and_charts/basic_line_graph_relative.rb",
|
30
31
|
"examples/graphs_and_charts/basic_line_graph_relative_reverse_x.rb",
|
31
32
|
"examples/graphs_and_charts/basic_line_graph_reverse_x.rb",
|
32
33
|
"glimmer-libui-cc-graphs_and_charts.gemspec",
|
@@ -352,14 +352,16 @@ module Glimmer
|
|
352
352
|
end
|
353
353
|
|
354
354
|
def reverse_x_in_points(points)
|
355
|
+
# TODO consider caching results based on points
|
355
356
|
# TODO look into optimizing operations below by not iterating 3 times (perhaps one iteration could do everything)
|
356
357
|
points = points.map do |point|
|
357
358
|
point.merge(x: width_drawable.to_f - point[:x])
|
358
359
|
end
|
359
360
|
min_point = points.min_by {|point| point[:x]}
|
360
|
-
|
361
|
+
min_point_x = min_point[:x]
|
362
|
+
if min_point_x < 0
|
361
363
|
points.each do |point|
|
362
|
-
point[:x] = point[:x] -
|
364
|
+
point[:x] = point[:x] - min_point_x
|
363
365
|
end
|
364
366
|
end
|
365
367
|
points.each do |point|
|
@@ -507,7 +509,15 @@ module Glimmer
|
|
507
509
|
closest_point = point_distances_from_hover_point.min_by(&:last).first
|
508
510
|
end
|
509
511
|
else
|
510
|
-
closest_points = lines.map { |line|
|
512
|
+
closest_points = lines.map { |line|
|
513
|
+
line_points = @points[line]
|
514
|
+
if !reverse_x
|
515
|
+
line_points = reverse_x_in_points(line_points)
|
516
|
+
line_points[line_points.size - @closest_point_index]
|
517
|
+
else
|
518
|
+
line_points[@closest_point_index]
|
519
|
+
end
|
520
|
+
}
|
511
521
|
end
|
512
522
|
closest_x = closest_points[0]&.[](:x)
|
513
523
|
line(closest_x, graph_padding_height, closest_x, height - graph_padding_height) {
|
@@ -524,7 +534,11 @@ module Glimmer
|
|
524
534
|
stroke stroke_value
|
525
535
|
}
|
526
536
|
end
|
527
|
-
|
537
|
+
if !reverse_x
|
538
|
+
text_label = formatted_x_value(@closest_point_index, closest_points)
|
539
|
+
else
|
540
|
+
text_label = formatted_x_value(@closest_point_index, closest_points)
|
541
|
+
end
|
528
542
|
text_label_width = estimate_width_of_text(text_label, DEFAULT_GRAPH_FONT_MARKER_TEXT)
|
529
543
|
lines_with_closest_points = lines.each_with_index.map do |line, index|
|
530
544
|
next if closest_points[index].nil?
|
@@ -536,7 +550,11 @@ module Glimmer
|
|
536
550
|
line_point = closest_points[index]
|
537
551
|
"#{line[:name]}: #{line_point[:y_value]}"
|
538
552
|
else
|
539
|
-
|
553
|
+
if !reverse_x
|
554
|
+
"#{line[:name]}: #{line[:y_values][closest_points.size - 2 - @closest_point_index]}"
|
555
|
+
else
|
556
|
+
"#{line[:name]}: #{line[:y_values][@closest_point_index]}"
|
557
|
+
end
|
540
558
|
end
|
541
559
|
end
|
542
560
|
closest_point_text_widths = closest_point_texts.map do |text|
|
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.4.
|
4
|
+
version: 0.4.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andy Maleh
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2025-
|
11
|
+
date: 2025-02-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: glimmer-dsl-libui
|
@@ -89,6 +89,7 @@ files:
|
|
89
89
|
- examples/graphs_and_charts/basic_bar_chart.rb
|
90
90
|
- examples/graphs_and_charts/basic_bubble_chart.rb
|
91
91
|
- examples/graphs_and_charts/basic_line_graph.rb
|
92
|
+
- examples/graphs_and_charts/basic_line_graph_relative.rb
|
92
93
|
- examples/graphs_and_charts/basic_line_graph_relative_reverse_x.rb
|
93
94
|
- examples/graphs_and_charts/basic_line_graph_reverse_x.rb
|
94
95
|
- glimmer-libui-cc-graphs_and_charts.gemspec
|