glimmer-libui-cc-graphs_and_charts 0.1.5 → 0.1.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +8 -1
- data/README.md +4 -4
- data/VERSION +1 -1
- data/examples/graphs_and_charts/basic_line_graph.rb +23 -16
- 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 +78 -4
- 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: bad5c6db427c320e3b452ee60e2b3af416604525c96e74c915b59c905d746b07
|
4
|
+
data.tar.gz: 3659c73cd8a91a9da31c5cf2cb896b04130a7e1a4c58d2f2e92f7b841726de58
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9ff88818e482120a5492d7bb2a789afc89d1a40efed3411d355afcc5db7737ef5f5a5e206a3a2737ccdcaf11a8ba01592a398878b1cd005153d1d3ead08d2728
|
7
|
+
data.tar.gz: b487f6b49b979d6b3a72a2c174f8cd55c558037e2baf2997b6ddaf0a2b2e9ffa243d62ce48558966115a07bfaccf69802682a7d94b0af4043dad29da5e33e909
|
data/CHANGELOG.md
CHANGED
@@ -1,10 +1,17 @@
|
|
1
1
|
# Change Log
|
2
2
|
|
3
|
+
## 0.1.6
|
4
|
+
|
5
|
+
- Support passing line `values` as a `Hash` map of x-axis values to y-axis values instead of using the combination of `y_values`, `x_value_start`, and `x_interval_in_seconds`
|
6
|
+
- Rename `examples/graphs_and_charts/basic_line_graph.rb` to `examples/graphs_and_charts/basic_line_graph_relative.rb`
|
7
|
+
- New `examples/graphs_and_charts/basic_line_graph.rb` (replacing older example that got renamed to `basic_line_graph_relative.rb`)
|
8
|
+
- Add graph auto-scaling logic to both `examples/graphs_and_charts/basic_line_graph.rb` & `examples/graphs_and_charts/basic_line_graph_relative.rb`
|
9
|
+
|
3
10
|
## 0.1.5
|
4
11
|
|
5
12
|
- Render circles for every point in addition to the lines connecting all the points
|
6
13
|
- Render a single point if there is only 1 value in `lines` `y_values` instead of rendering nothing until 2 values exist at least
|
7
|
-
- Support `graph_point_radius`, `graph_selected_point_radius`, and `graph_fill_selected_point` options for
|
14
|
+
- Support `graph_point_radius`, `graph_selected_point_radius`, and `graph_fill_selected_point` options for customizing the circle of every rendered point and selected point.
|
8
15
|
- Avoid rendering on top of the grid markers on the left side
|
9
16
|
- Optimize performance of rendering grid markers and showing mouse hover selection stats of a point
|
10
17
|
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Graphs and Charts 0.1.
|
1
|
+
# Graphs and Charts 0.1.6 (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)
|
@@ -12,7 +12,7 @@ Graphs and Charts (Custom Controls) for [Glimmer DSL for LibUI](https://github.c
|
|
12
12
|
Add this line to Bundler `Gemfile`:
|
13
13
|
|
14
14
|
```ruby
|
15
|
-
gem 'glimmer-libui-cc-graphs_and_charts', '~> 0.1.
|
15
|
+
gem 'glimmer-libui-cc-graphs_and_charts', '~> 0.1.6'
|
16
16
|
```
|
17
17
|
|
18
18
|
Run:
|
@@ -47,7 +47,7 @@ line_graph(
|
|
47
47
|
width: 900,
|
48
48
|
height: 300,
|
49
49
|
graph_point_distance: :width_divided_by_point_count,
|
50
|
-
|
50
|
+
series: [
|
51
51
|
{
|
52
52
|
name: 'Feature A',
|
53
53
|
stroke: [163, 40, 39, thickness: 2],
|
@@ -94,7 +94,7 @@ class BasicLineGraph
|
|
94
94
|
width: 900,
|
95
95
|
height: 300,
|
96
96
|
graph_point_distance: :width_divided_by_point_count,
|
97
|
-
|
97
|
+
series: [
|
98
98
|
{
|
99
99
|
name: 'Feature A',
|
100
100
|
stroke: [163, 40, 39, thickness: 2],
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.6
|
@@ -7,36 +7,43 @@ require 'glimmer/view/line_graph'
|
|
7
7
|
class BasicLineGraph
|
8
8
|
include Glimmer::LibUI::Application
|
9
9
|
|
10
|
-
before_body do
|
11
|
-
@start_time = Time.now
|
12
|
-
end
|
13
|
-
|
14
10
|
body {
|
15
|
-
window('Basic Line Graph', 900,
|
16
|
-
line_graph(
|
11
|
+
window('Basic Line Graph', 900, 300) { |main_window|
|
12
|
+
@line_graph = line_graph(
|
17
13
|
width: 900,
|
18
14
|
height: 300,
|
19
|
-
graph_point_distance: :width_divided_by_point_count,
|
20
15
|
lines: [
|
21
16
|
{
|
22
|
-
name: '
|
17
|
+
name: 'Stock 1',
|
23
18
|
stroke: [163, 40, 39, thickness: 2],
|
24
|
-
|
25
|
-
|
19
|
+
values: {
|
20
|
+
Time.new(2030, 12, 1) => 80,
|
21
|
+
Time.new(2030, 12, 2) => 36,
|
22
|
+
Time.new(2030, 12, 4) => 10,
|
23
|
+
Time.new(2030, 12, 5) => 60,
|
24
|
+
Time.new(2030, 12, 6) => 20,
|
25
|
+
},
|
26
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
27
|
},
|
29
28
|
{
|
30
|
-
name: '
|
29
|
+
name: 'Stock 2',
|
31
30
|
stroke: [47, 109, 104, thickness: 2],
|
32
|
-
|
33
|
-
|
31
|
+
values: {
|
32
|
+
Time.new(2030, 12, 1) => 62,
|
33
|
+
Time.new(2030, 12, 2) => 0,
|
34
|
+
Time.new(2030, 12, 3) => 90,
|
35
|
+
Time.new(2030, 12, 5) => 0,
|
36
|
+
Time.new(2030, 12, 7) => 17,
|
37
|
+
},
|
34
38
|
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
39
|
},
|
37
40
|
],
|
38
|
-
display_attributes_on_hover: true,
|
39
41
|
)
|
42
|
+
|
43
|
+
on_content_size_changed do
|
44
|
+
@line_graph.width = main_window.content_size[0]
|
45
|
+
@line_graph.height = main_window.content_size[1]
|
46
|
+
end
|
40
47
|
}
|
41
48
|
}
|
42
49
|
end
|
@@ -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 BasicLineGraph
|
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', 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
|
+
BasicLineGraph.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.1.
|
5
|
+
# stub: glimmer-libui-cc-graphs_and_charts 0.1.6 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.1.
|
9
|
+
s.version = "0.1.6".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-
|
14
|
+
s.date = "2023-12-22"
|
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 = [
|
@@ -25,6 +25,7 @@ Gem::Specification.new do |s|
|
|
25
25
|
"README.md",
|
26
26
|
"VERSION",
|
27
27
|
"examples/graphs_and_charts/basic_line_graph.rb",
|
28
|
+
"examples/graphs_and_charts/basic_line_graph_relative.rb",
|
28
29
|
"glimmer-libui-cc-graphs_and_charts.gemspec",
|
29
30
|
"lib/glimmer-libui-cc-graphs_and_charts.rb",
|
30
31
|
"lib/glimmer/view/line_graph.rb"
|
@@ -131,6 +131,10 @@ module Glimmer
|
|
131
131
|
def clear_drawing_cache
|
132
132
|
@graph_point_distance_per_line = nil
|
133
133
|
@y_value_max_for_all_lines = nil
|
134
|
+
@x_resolution = nil
|
135
|
+
@x_value_range_for_all_lines = nil
|
136
|
+
@x_value_min_for_all_lines = nil
|
137
|
+
@x_value_max_for_all_lines = nil
|
134
138
|
@grid_marker_points = nil
|
135
139
|
@points = nil
|
136
140
|
@grid_marker_number_values = nil
|
@@ -145,15 +149,19 @@ module Glimmer
|
|
145
149
|
end
|
146
150
|
|
147
151
|
def calculate_graph_point_distance_per_line
|
148
|
-
return unless graph_point_distance == :width_divided_by_point_count
|
152
|
+
return unless lines[0]&.[](:y_values) && graph_point_distance == :width_divided_by_point_count
|
149
153
|
|
150
154
|
@graph_point_distance_per_line ||= lines.inject({}) do |hash, line|
|
151
155
|
value = (width - 2.0*graph_padding_width - graph_grid_marker_padding_width) / (line[:y_values].size - 1).to_f
|
152
|
-
value = [value,
|
156
|
+
value = [value, drawable_width].min
|
153
157
|
hash.merge(line => value)
|
154
158
|
end
|
155
159
|
end
|
156
160
|
|
161
|
+
def drawable_width
|
162
|
+
width - 2.0*graph_padding_width - graph_grid_marker_padding_width
|
163
|
+
end
|
164
|
+
|
157
165
|
def graph_point_distance_for_line(line)
|
158
166
|
@graph_point_distance_per_line&.[](line) || graph_point_distance
|
159
167
|
end
|
@@ -244,7 +252,7 @@ module Glimmer
|
|
244
252
|
def single_line_graph(graph_line)
|
245
253
|
last_point = nil
|
246
254
|
points = calculate_points(graph_line)
|
247
|
-
points.each do |point|
|
255
|
+
points.to_a.each do |point|
|
248
256
|
if last_point
|
249
257
|
line(last_point[:x], last_point[:y], point[:x], point[:y]) {
|
250
258
|
stroke graph_line[:stroke]
|
@@ -260,6 +268,14 @@ module Glimmer
|
|
260
268
|
end
|
261
269
|
|
262
270
|
def calculate_points(graph_line)
|
271
|
+
if lines[0]&.[](:y_values)
|
272
|
+
calculate_points_relative(graph_line)
|
273
|
+
else
|
274
|
+
calculate_points_absolute(graph_line)
|
275
|
+
end
|
276
|
+
end
|
277
|
+
|
278
|
+
def calculate_points_relative(graph_line)
|
263
279
|
@points ||= {}
|
264
280
|
if @points[graph_line].nil?
|
265
281
|
y_values = graph_line[:y_values] || []
|
@@ -275,9 +291,67 @@ module Glimmer
|
|
275
291
|
@points[graph_line]
|
276
292
|
end
|
277
293
|
|
294
|
+
def calculate_points_absolute(graph_line)
|
295
|
+
@points ||= {}
|
296
|
+
if @points[graph_line].nil?
|
297
|
+
values = graph_line[:values] || []
|
298
|
+
# all points are visible when :values is supplied because we stretch the graph to show them all
|
299
|
+
graph_y_max = [y_value_max_for_all_lines, 1].max
|
300
|
+
x_value_range_for_all_lines
|
301
|
+
points = values.each_with_index.map do |(x_value, y_value), index|
|
302
|
+
relative_x_value = x_value - x_value_min_for_all_lines
|
303
|
+
stretched_x_value = x_value_range_for_all_lines == 0 ? 0 : relative_x_value.to_f * x_resolution.to_f
|
304
|
+
x = width - graph_padding_width - stretched_x_value
|
305
|
+
y = ((height - graph_padding_height) - y_value * ((height - graph_padding_height * 2) / graph_y_max))
|
306
|
+
{x: x, y: y, index: index, x_value: x_value, y_value: y_value}
|
307
|
+
end
|
308
|
+
# Translation is not supported today
|
309
|
+
# TODO consider supporting in the future
|
310
|
+
# @points[graph_line] = translate_points(graph_line, points)
|
311
|
+
@points[graph_line] = points
|
312
|
+
end
|
313
|
+
@points[graph_line]
|
314
|
+
end
|
315
|
+
|
316
|
+
# this is the multiplier that we must multiply by the relative_x_value
|
317
|
+
def x_resolution
|
318
|
+
@x_resolution ||= drawable_width.to_f / x_value_range_for_all_lines.to_f
|
319
|
+
end
|
320
|
+
|
321
|
+
def x_value_range_for_all_lines
|
322
|
+
@x_value_range_for_all_lines ||= x_value_max_for_all_lines - x_value_min_for_all_lines
|
323
|
+
end
|
324
|
+
|
325
|
+
def x_value_min_for_all_lines
|
326
|
+
if @x_value_min_for_all_lines.nil?
|
327
|
+
line_visible_x_values = lines.map { |line| line[:values].to_h.keys }
|
328
|
+
all_visible_x_values = line_visible_x_values.reduce(:+) || []
|
329
|
+
# Right now, we assume Time objects
|
330
|
+
# TODO support String representations of Time (w/ some auto-detection of format)
|
331
|
+
@x_value_min_for_all_lines = all_visible_x_values.min
|
332
|
+
end
|
333
|
+
@x_value_min_for_all_lines
|
334
|
+
end
|
335
|
+
|
336
|
+
def x_value_max_for_all_lines
|
337
|
+
if @x_value_max_for_all_lines.nil?
|
338
|
+
line_visible_x_values = lines.map { |line| line[:values].to_h.keys }
|
339
|
+
all_visible_x_values = line_visible_x_values.reduce(:+) || []
|
340
|
+
# Right now, we assume Time objects
|
341
|
+
# TODO support String representations of Time (w/ some auto-detection of format)
|
342
|
+
@x_value_max_for_all_lines = all_visible_x_values.max
|
343
|
+
end
|
344
|
+
@x_value_max_for_all_lines
|
345
|
+
end
|
346
|
+
|
278
347
|
def y_value_max_for_all_lines
|
279
348
|
if @y_value_max_for_all_lines.nil?
|
280
|
-
|
349
|
+
if lines[0]&.[](:y_values)
|
350
|
+
line_visible_y_values = lines.map { |line| line[:y_values][0, max_visible_point_count(line)] }
|
351
|
+
else
|
352
|
+
# When using :values , we always stretch the graph so that all points are visible
|
353
|
+
line_visible_y_values = lines.map { |line| line[:values].to_h.values }
|
354
|
+
end
|
281
355
|
all_visible_y_values = line_visible_y_values.reduce(:+) || []
|
282
356
|
@y_value_max_for_all_lines = all_visible_y_values.max.to_f
|
283
357
|
end
|
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.1.
|
4
|
+
version: 0.1.6
|
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-
|
11
|
+
date: 2023-12-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: glimmer-dsl-libui
|
@@ -81,6 +81,7 @@ files:
|
|
81
81
|
- README.md
|
82
82
|
- VERSION
|
83
83
|
- examples/graphs_and_charts/basic_line_graph.rb
|
84
|
+
- examples/graphs_and_charts/basic_line_graph_relative.rb
|
84
85
|
- glimmer-libui-cc-graphs_and_charts.gemspec
|
85
86
|
- lib/glimmer-libui-cc-graphs_and_charts.rb
|
86
87
|
- lib/glimmer/view/line_graph.rb
|