vg_helper 0.1.0 → 0.1.1
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/README.md +660 -15
- data/lib/vg_helper/version.rb +1 -1
- data/lib/vg_helper.rb +33 -41
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 2142e0527c36a9586942961a2dd42efc1d48090b9ccf3990595a970aa38fbf9c
|
|
4
|
+
data.tar.gz: 771c7a1c68f1a3e7ed30932e243b1062c1d46defe35d42a91eeb8b25eff40981
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 73e911c62c69a0710b6d0ca0d938e7b6b3883bdafea0709a94f031c858c17b49d8c4a7494e4521cc71779bb9978fed8d7df1f67677c031d220fe2b06de0658a8
|
|
7
|
+
data.tar.gz: ac1eb5d9cd9c3f47c3b08f34f61fa8f09ca6f67e8b686404daf9308af5a4333409cf9d8e32046d9227a37b59f3f781dbcfb59e9a887ad5ee9a1bc57b7820e565
|
data/README.md
CHANGED
|
@@ -1,34 +1,674 @@
|
|
|
1
|
-
#
|
|
1
|
+
# VGHelper
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
VGHelper is a small Ruby helper library for creating interactive
|
|
4
|
+
[Vega-Lite](https://vega.github.io/vega-lite/) charts from
|
|
5
|
+
`Rover::DataFrame`.
|
|
4
6
|
|
|
5
|
-
|
|
7
|
+
It provides convenient helpers for time-series and nominal x-axis charts,
|
|
8
|
+
with support for multiple categories, secondary y-axes, reference lines,
|
|
9
|
+
interactive range controls, brush statistics, and offline HTML output.
|
|
10
|
+
|
|
11
|
+
One of the main goals of VGHelper is to make Vega-Lite charts usable
|
|
12
|
+
even in **offline or proxy-restricted environments**.
|
|
13
|
+
|
|
14
|
+
VGHelper bundles the JavaScript runtimes required by Vega, Vega-Lite,
|
|
15
|
+
and Vega-Embed, so HTML generated by VGHelper does not need to load
|
|
16
|
+
these libraries from an external CDN.
|
|
17
|
+
|
|
18
|
+
## Features
|
|
19
|
+
|
|
20
|
+
- Time-series charts (`draw_xdate`)
|
|
21
|
+
- Nominal / categorical x-axis charts (`draw_xnominal`)
|
|
22
|
+
- Multiple series and multiple category columns
|
|
23
|
+
- Line charts with optional point markers
|
|
24
|
+
- Secondary y-axis with bar charts
|
|
25
|
+
- Stacked bars using a secondary category
|
|
26
|
+
- Horizontal reference lines
|
|
27
|
+
- Vertical reference lines
|
|
28
|
+
- Configurable colors for reference lines
|
|
29
|
+
- Interactive x-axis range controls
|
|
30
|
+
- Interactive y-axis range controls
|
|
31
|
+
- Category visibility checkboxes
|
|
32
|
+
- Brush selection
|
|
33
|
+
- Statistics for the selected / displayed range
|
|
34
|
+
- count
|
|
35
|
+
- mean
|
|
36
|
+
- standard deviation
|
|
37
|
+
- maximum
|
|
38
|
+
- minimum
|
|
39
|
+
- Statistics based on total stacked-bar height for the secondary axis
|
|
40
|
+
- Daily and exact-time modes for temporal data
|
|
41
|
+
- Reversible left/right y-axis orientation
|
|
42
|
+
- Self-contained offline HTML output
|
|
43
|
+
- No CDN access required for generated HTML
|
|
44
|
+
|
|
45
|
+
---
|
|
6
46
|
|
|
7
47
|
## Installation
|
|
8
48
|
|
|
9
|
-
|
|
49
|
+
Add this line to your application's Gemfile:
|
|
50
|
+
|
|
51
|
+
```ruby
|
|
52
|
+
gem "vg_helper"
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
and run:
|
|
56
|
+
|
|
57
|
+
```sh
|
|
58
|
+
bundle install
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
Or install it directly:
|
|
62
|
+
|
|
63
|
+
```sh
|
|
64
|
+
gem install vg_helper
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
Then:
|
|
68
|
+
|
|
69
|
+
```ruby
|
|
70
|
+
require "vg_helper"
|
|
71
|
+
require "rover"
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
---
|
|
75
|
+
|
|
76
|
+
## Quick Start
|
|
77
|
+
|
|
78
|
+
```ruby
|
|
79
|
+
require "vg_helper"
|
|
80
|
+
require "rover"
|
|
81
|
+
|
|
82
|
+
df = Rover::DataFrame.new(
|
|
83
|
+
{
|
|
84
|
+
"datetime" => [
|
|
85
|
+
"2026-01-01 10:00:00",
|
|
86
|
+
"2026-01-02 10:00:00",
|
|
87
|
+
"2026-01-03 10:00:00",
|
|
88
|
+
"2026-01-04 10:00:00"
|
|
89
|
+
],
|
|
90
|
+
"category" => [
|
|
91
|
+
"A", "A", "A", "A"
|
|
92
|
+
],
|
|
93
|
+
"value" => [
|
|
94
|
+
10, 15, 12, 18
|
|
95
|
+
]
|
|
96
|
+
}
|
|
97
|
+
)
|
|
98
|
+
|
|
99
|
+
chart = VGHelper.draw_xdate(
|
|
100
|
+
df,
|
|
101
|
+
"datetime",
|
|
102
|
+
"value",
|
|
103
|
+
"category"
|
|
104
|
+
)
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
### Jupyter Notebook / IRuby
|
|
108
|
+
|
|
109
|
+
In Jupyter Notebook with IRuby, place the chart object at the end of
|
|
110
|
+
the cell to display it directly:
|
|
111
|
+
|
|
112
|
+
```ruby
|
|
113
|
+
chart
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
A complete cell can simply end with:
|
|
117
|
+
|
|
118
|
+
```ruby
|
|
119
|
+
chart = VGHelper.draw_xdate(
|
|
120
|
+
df,
|
|
121
|
+
"datetime",
|
|
122
|
+
"value",
|
|
123
|
+
"category"
|
|
124
|
+
)
|
|
125
|
+
|
|
126
|
+
chart
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
The same applies to charts created with `draw_xnominal`.
|
|
130
|
+
|
|
131
|
+
### Offline HTML output
|
|
132
|
+
|
|
133
|
+
To write the chart to an HTML file instead, use `write_htmls`:
|
|
134
|
+
|
|
135
|
+
```ruby
|
|
136
|
+
VGHelper.write_htmls(chart, "chart.html")
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
`write_htmls` uses the bundled `vega.min.js`, `vega-lite.min.js`, and
|
|
140
|
+
`vega-embed.min.js` files. The generated HTML does not load these
|
|
141
|
+
libraries from a CDN and can be viewed without a network connection.
|
|
142
|
+
|
|
143
|
+
Open `chart.html` in a browser to view the interactive chart.
|
|
144
|
+
|
|
145
|
+
---
|
|
146
|
+
|
|
147
|
+
# `draw_xdate`
|
|
148
|
+
|
|
149
|
+
`draw_xdate` creates a chart with a temporal x-axis.
|
|
150
|
+
|
|
151
|
+
```ruby
|
|
152
|
+
VGHelper.draw_xdate(
|
|
153
|
+
df,
|
|
154
|
+
x_col,
|
|
155
|
+
y_col,
|
|
156
|
+
category_col,
|
|
157
|
+
...
|
|
158
|
+
)
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
Basic example:
|
|
162
|
+
|
|
163
|
+
```ruby
|
|
164
|
+
chart = VGHelper.draw_xdate(
|
|
165
|
+
df,
|
|
166
|
+
"datetime",
|
|
167
|
+
"temperature",
|
|
168
|
+
"station"
|
|
169
|
+
)
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
The fourth argument specifies the column used to separate the data
|
|
173
|
+
into series.
|
|
174
|
+
|
|
175
|
+
---
|
|
176
|
+
|
|
177
|
+
## Multiple category columns
|
|
178
|
+
|
|
179
|
+
An array of columns can be supplied as `category_col`.
|
|
180
|
+
|
|
181
|
+
```ruby
|
|
182
|
+
chart = VGHelper.draw_xdate(
|
|
183
|
+
df,
|
|
184
|
+
"datetime",
|
|
185
|
+
"temperature",
|
|
186
|
+
["pref", "city"]
|
|
187
|
+
)
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
VGHelper combines the values internally and treats each combination
|
|
191
|
+
as an independent series.
|
|
192
|
+
|
|
193
|
+
---
|
|
194
|
+
|
|
195
|
+
## Time modes
|
|
196
|
+
|
|
197
|
+
`draw_xdate` supports two time modes.
|
|
198
|
+
|
|
199
|
+
### Daily mode
|
|
200
|
+
|
|
201
|
+
```ruby
|
|
202
|
+
time_mode: :day
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
Dates are normalized to the beginning of each calendar day.
|
|
206
|
+
|
|
207
|
+
This is useful when the time of day is irrelevant and the x-axis
|
|
208
|
+
should represent daily observations.
|
|
209
|
+
|
|
210
|
+
```ruby
|
|
211
|
+
chart = VGHelper.draw_xdate(
|
|
212
|
+
df,
|
|
213
|
+
"datetime",
|
|
214
|
+
"value",
|
|
215
|
+
"category",
|
|
216
|
+
time_mode: :day
|
|
217
|
+
)
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
### Exact-time mode
|
|
221
|
+
|
|
222
|
+
```ruby
|
|
223
|
+
time_mode: :exact
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
The time of day is preserved.
|
|
227
|
+
|
|
228
|
+
```ruby
|
|
229
|
+
chart = VGHelper.draw_xdate(
|
|
230
|
+
df,
|
|
231
|
+
"datetime",
|
|
232
|
+
"value",
|
|
233
|
+
"category",
|
|
234
|
+
time_mode: :exact
|
|
235
|
+
)
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
Use this for hourly, minute-level, or other intraday data.
|
|
239
|
+
|
|
240
|
+
---
|
|
241
|
+
|
|
242
|
+
# `draw_xnominal`
|
|
243
|
+
|
|
244
|
+
`draw_xnominal` creates a chart whose x-axis consists of discrete
|
|
245
|
+
ordered values.
|
|
246
|
+
|
|
247
|
+
For example:
|
|
248
|
+
|
|
249
|
+
```ruby
|
|
250
|
+
df = Rover::DataFrame.new(
|
|
251
|
+
{
|
|
252
|
+
"step" => [
|
|
253
|
+
"STEP_001",
|
|
254
|
+
"STEP_002",
|
|
255
|
+
"STEP_003",
|
|
256
|
+
"STEP_004"
|
|
257
|
+
],
|
|
258
|
+
"value" => [
|
|
259
|
+
10, 13, 18, 16
|
|
260
|
+
],
|
|
261
|
+
"category" => [
|
|
262
|
+
"A", "A", "A", "A"
|
|
263
|
+
]
|
|
264
|
+
}
|
|
265
|
+
)
|
|
266
|
+
|
|
267
|
+
chart = VGHelper.draw_xnominal(
|
|
268
|
+
df,
|
|
269
|
+
"step",
|
|
270
|
+
"value",
|
|
271
|
+
"category"
|
|
272
|
+
)
|
|
273
|
+
```
|
|
274
|
+
|
|
275
|
+
The original order of x values is preserved.
|
|
276
|
+
|
|
277
|
+
This makes `draw_xnominal` useful for data such as:
|
|
278
|
+
|
|
279
|
+
```text
|
|
280
|
+
STEP_001
|
|
281
|
+
STEP_002
|
|
282
|
+
STEP_003
|
|
283
|
+
...
|
|
284
|
+
```
|
|
285
|
+
|
|
286
|
+
where the x values are categories but their sequence is meaningful.
|
|
287
|
+
|
|
288
|
+
---
|
|
289
|
+
|
|
290
|
+
## Limiting the initial x range
|
|
291
|
+
|
|
292
|
+
For large nominal datasets:
|
|
293
|
+
|
|
294
|
+
```ruby
|
|
295
|
+
initialxpoints: 100
|
|
296
|
+
```
|
|
297
|
+
|
|
298
|
+
controls the number of x positions initially displayed.
|
|
299
|
+
|
|
300
|
+
For example:
|
|
301
|
+
|
|
302
|
+
```ruby
|
|
303
|
+
chart = VGHelper.draw_xnominal(
|
|
304
|
+
df,
|
|
305
|
+
"step",
|
|
306
|
+
"value",
|
|
307
|
+
"category",
|
|
308
|
+
initialxpoints: 100
|
|
309
|
+
)
|
|
310
|
+
```
|
|
311
|
+
|
|
312
|
+
---
|
|
313
|
+
|
|
314
|
+
# Interactive controls
|
|
315
|
+
|
|
316
|
+
## X-axis controls
|
|
317
|
+
|
|
318
|
+
The x-axis range controls can be enabled or disabled.
|
|
319
|
+
|
|
320
|
+
```ruby
|
|
321
|
+
xslide: true
|
|
322
|
+
```
|
|
323
|
+
|
|
324
|
+
or:
|
|
325
|
+
|
|
326
|
+
```ruby
|
|
327
|
+
xslide: false
|
|
328
|
+
```
|
|
329
|
+
|
|
330
|
+
For `draw_xdate`, the controls modify the temporal range.
|
|
331
|
+
|
|
332
|
+
For `draw_xnominal`, they modify the range of displayed x positions.
|
|
333
|
+
|
|
334
|
+
---
|
|
335
|
+
|
|
336
|
+
## Y-axis controls
|
|
337
|
+
|
|
338
|
+
Y-axis controls can be enabled with:
|
|
339
|
+
|
|
340
|
+
```ruby
|
|
341
|
+
yslide: true
|
|
342
|
+
```
|
|
343
|
+
|
|
344
|
+
and disabled with:
|
|
345
|
+
|
|
346
|
+
```ruby
|
|
347
|
+
yslide: false
|
|
348
|
+
```
|
|
349
|
+
|
|
350
|
+
The control type can also be selected:
|
|
351
|
+
|
|
352
|
+
```ruby
|
|
353
|
+
yrangechanger: "number"
|
|
354
|
+
```
|
|
355
|
+
|
|
356
|
+
or:
|
|
10
357
|
|
|
11
|
-
|
|
358
|
+
```ruby
|
|
359
|
+
yrangechanger: "range"
|
|
360
|
+
```
|
|
361
|
+
|
|
362
|
+
Explicit y ranges can be supplied where appropriate:
|
|
363
|
+
|
|
364
|
+
```ruby
|
|
365
|
+
miny: 0,
|
|
366
|
+
maxy: 100
|
|
367
|
+
```
|
|
368
|
+
|
|
369
|
+
---
|
|
370
|
+
|
|
371
|
+
## Category checkboxes
|
|
372
|
+
|
|
373
|
+
Series visibility can be controlled interactively.
|
|
374
|
+
|
|
375
|
+
```ruby
|
|
376
|
+
category_check: true
|
|
377
|
+
```
|
|
378
|
+
|
|
379
|
+
This adds a checkbox for each category.
|
|
380
|
+
|
|
381
|
+
To hide these controls:
|
|
382
|
+
|
|
383
|
+
```ruby
|
|
384
|
+
category_check: false
|
|
385
|
+
```
|
|
386
|
+
|
|
387
|
+
---
|
|
388
|
+
|
|
389
|
+
# Brush selection and statistics
|
|
390
|
+
|
|
391
|
+
Both chart helpers support interactive x-axis brush selection.
|
|
392
|
+
|
|
393
|
+
Drag across part of the chart to select a range.
|
|
394
|
+
|
|
395
|
+
VGHelper displays statistics for the selected data:
|
|
396
|
+
|
|
397
|
+
```text
|
|
398
|
+
n
|
|
399
|
+
avg
|
|
400
|
+
std
|
|
401
|
+
max
|
|
402
|
+
min
|
|
403
|
+
```
|
|
404
|
+
|
|
405
|
+
For example:
|
|
406
|
+
|
|
407
|
+
```text
|
|
408
|
+
temperature n: 32 avg: 21.45 std: 2.18 max: 25.60 min: 17.90
|
|
409
|
+
```
|
|
410
|
+
|
|
411
|
+
When no smaller brush range is selected, the statistics correspond
|
|
412
|
+
to the currently displayed range.
|
|
413
|
+
|
|
414
|
+
Category visibility settings are also reflected in the statistics.
|
|
415
|
+
|
|
416
|
+
---
|
|
417
|
+
|
|
418
|
+
# Secondary y-axis
|
|
419
|
+
|
|
420
|
+
A second `Rover::DataFrame` can be displayed as bars using a
|
|
421
|
+
secondary y-axis.
|
|
422
|
+
|
|
423
|
+
```ruby
|
|
424
|
+
chart = VGHelper.draw_xdate(
|
|
425
|
+
df,
|
|
426
|
+
"datetime",
|
|
427
|
+
"temperature",
|
|
428
|
+
"station",
|
|
429
|
+
|
|
430
|
+
df2: volume_df,
|
|
431
|
+
x2_col: "datetime",
|
|
432
|
+
y2_col: "volume"
|
|
433
|
+
)
|
|
434
|
+
```
|
|
435
|
+
|
|
436
|
+
This produces a main chart together with bars using an independent
|
|
437
|
+
y scale.
|
|
438
|
+
|
|
439
|
+
---
|
|
440
|
+
|
|
441
|
+
## Stacked secondary-axis bars
|
|
442
|
+
|
|
443
|
+
A category can also be assigned to the secondary data.
|
|
444
|
+
|
|
445
|
+
```ruby
|
|
446
|
+
chart = VGHelper.draw_xdate(
|
|
447
|
+
df,
|
|
448
|
+
"datetime",
|
|
449
|
+
"temperature",
|
|
450
|
+
"station",
|
|
451
|
+
|
|
452
|
+
df2: volume_df,
|
|
453
|
+
x2_col: "datetime",
|
|
454
|
+
y2_col: "volume",
|
|
455
|
+
y2_category_col: "product"
|
|
456
|
+
)
|
|
457
|
+
```
|
|
458
|
+
|
|
459
|
+
Rows sharing the same x position are displayed as stacked bars.
|
|
460
|
+
|
|
461
|
+
For statistical calculations, VGHelper first calculates the total
|
|
462
|
+
height of each stacked bar.
|
|
463
|
+
|
|
464
|
+
For example, if one x position contains:
|
|
465
|
+
|
|
466
|
+
```text
|
|
467
|
+
Product A : 10
|
|
468
|
+
Product B : 15
|
|
469
|
+
Product C : 5
|
|
470
|
+
```
|
|
471
|
+
|
|
472
|
+
it is treated as one observation:
|
|
473
|
+
|
|
474
|
+
```text
|
|
475
|
+
30
|
|
476
|
+
```
|
|
477
|
+
|
|
478
|
+
The mean, standard deviation, maximum, minimum, and count displayed
|
|
479
|
+
for the secondary axis are then calculated from these stacked totals,
|
|
480
|
+
rather than from the individual bar segments.
|
|
481
|
+
|
|
482
|
+
---
|
|
483
|
+
|
|
484
|
+
# Axis orientation
|
|
485
|
+
|
|
486
|
+
By default, the main y-axis is displayed on the left and the
|
|
487
|
+
secondary y-axis on the right.
|
|
488
|
+
|
|
489
|
+
The orientation can be reversed:
|
|
490
|
+
|
|
491
|
+
```ruby
|
|
492
|
+
reverse_orient: true
|
|
493
|
+
```
|
|
494
|
+
|
|
495
|
+
This places the main axis on the right and the secondary axis
|
|
496
|
+
on the left.
|
|
497
|
+
|
|
498
|
+
---
|
|
499
|
+
|
|
500
|
+
# Horizontal reference lines
|
|
501
|
+
|
|
502
|
+
Horizontal reference lines can be added with `horizontallines`.
|
|
12
503
|
|
|
13
|
-
```
|
|
14
|
-
|
|
504
|
+
```ruby
|
|
505
|
+
horizontallines: [
|
|
506
|
+
[20, "Target"],
|
|
507
|
+
[30, "Upper Limit"]
|
|
508
|
+
]
|
|
15
509
|
```
|
|
16
510
|
|
|
17
|
-
|
|
511
|
+
Colors can be specified separately:
|
|
18
512
|
|
|
19
|
-
```
|
|
20
|
-
|
|
513
|
+
```ruby
|
|
514
|
+
horizontalcolors: [
|
|
515
|
+
"#0000ff",
|
|
516
|
+
"#ff0000"
|
|
517
|
+
]
|
|
21
518
|
```
|
|
22
519
|
|
|
23
|
-
|
|
520
|
+
Reference lines are useful for targets, limits, thresholds,
|
|
521
|
+
specifications, and other fixed values.
|
|
24
522
|
|
|
25
|
-
|
|
523
|
+
---
|
|
26
524
|
|
|
27
|
-
|
|
525
|
+
# Vertical reference lines
|
|
28
526
|
|
|
29
|
-
|
|
527
|
+
Vertical reference lines can also be added.
|
|
30
528
|
|
|
31
|
-
|
|
529
|
+
For a date chart:
|
|
530
|
+
|
|
531
|
+
```ruby
|
|
532
|
+
verticallines: [
|
|
533
|
+
["2026-01-10", "Close"],
|
|
534
|
+
["2026-01-20", "Restart"]
|
|
535
|
+
]
|
|
536
|
+
```
|
|
537
|
+
|
|
538
|
+
For a nominal chart:
|
|
539
|
+
|
|
540
|
+
```ruby
|
|
541
|
+
verticallines: [
|
|
542
|
+
["STEP_020", "Event A"],
|
|
543
|
+
["STEP_050", "Event B"]
|
|
544
|
+
]
|
|
545
|
+
```
|
|
546
|
+
|
|
547
|
+
Colors can be specified with:
|
|
548
|
+
|
|
549
|
+
```ruby
|
|
550
|
+
verticalcolors: [
|
|
551
|
+
"#0000ff",
|
|
552
|
+
"#ff0000"
|
|
553
|
+
]
|
|
554
|
+
```
|
|
555
|
+
|
|
556
|
+
Vertical lines can be used to indicate important x positions.
|
|
557
|
+
|
|
558
|
+
---
|
|
559
|
+
|
|
560
|
+
# Custom marks
|
|
561
|
+
|
|
562
|
+
The Vega-Lite mark definition can be customized with `markkind`.
|
|
563
|
+
|
|
564
|
+
For example:
|
|
565
|
+
|
|
566
|
+
```ruby
|
|
567
|
+
markkind: {
|
|
568
|
+
type: "line",
|
|
569
|
+
point: {
|
|
570
|
+
filled: true,
|
|
571
|
+
size: 40
|
|
572
|
+
},
|
|
573
|
+
tooltip: true
|
|
574
|
+
}
|
|
575
|
+
```
|
|
576
|
+
|
|
577
|
+
This allows VGHelper to expose Vega-Lite's mark configuration while
|
|
578
|
+
providing convenient defaults.
|
|
579
|
+
|
|
580
|
+
---
|
|
581
|
+
|
|
582
|
+
# Offline HTML output
|
|
583
|
+
|
|
584
|
+
VGHelper is designed to work without access to external CDNs.
|
|
585
|
+
|
|
586
|
+
The gem bundles local copies of:
|
|
587
|
+
|
|
588
|
+
```text
|
|
589
|
+
vega.min.js
|
|
590
|
+
vega-lite.min.js
|
|
591
|
+
vega-embed.min.js
|
|
592
|
+
```
|
|
593
|
+
|
|
594
|
+
`write_htmls` embeds these JavaScript files directly into the output
|
|
595
|
+
HTML.
|
|
596
|
+
|
|
597
|
+
```ruby
|
|
598
|
+
VGHelper.write_htmls(
|
|
599
|
+
chart,
|
|
600
|
+
"chart.html"
|
|
601
|
+
)
|
|
602
|
+
```
|
|
603
|
+
|
|
604
|
+
The resulting file can therefore be opened without accessing
|
|
605
|
+
jsDelivr, unpkg, or another CDN.
|
|
606
|
+
|
|
607
|
+
This can be particularly useful in:
|
|
608
|
+
|
|
609
|
+
- corporate proxy environments
|
|
610
|
+
- restricted networks
|
|
611
|
+
- isolated analysis environments
|
|
612
|
+
- offline machines
|
|
613
|
+
|
|
614
|
+
Multiple charts can also be written to the same HTML file:
|
|
615
|
+
|
|
616
|
+
```ruby
|
|
617
|
+
VGHelper.write_htmls(
|
|
618
|
+
[chart1, chart2, chart3],
|
|
619
|
+
"charts.html"
|
|
620
|
+
)
|
|
621
|
+
```
|
|
622
|
+
|
|
623
|
+
---
|
|
624
|
+
|
|
625
|
+
|
|
626
|
+
# TODO
|
|
627
|
+
|
|
628
|
+
VGHelper is still under development.
|
|
629
|
+
|
|
630
|
+
Planned features include:
|
|
631
|
+
|
|
632
|
+
- [ ] Export charts as images
|
|
633
|
+
- [ ] Improve customization of Vega-Lite parameters
|
|
634
|
+
- [ ] Improve documentation and examples
|
|
635
|
+
|
|
636
|
+
---
|
|
637
|
+
|
|
638
|
+
# Dependencies
|
|
639
|
+
|
|
640
|
+
VGHelper currently uses:
|
|
641
|
+
|
|
642
|
+
- Ruby
|
|
643
|
+
- `vega`
|
|
644
|
+
- `rover`
|
|
645
|
+
|
|
646
|
+
Vega, Vega-Lite, and Vega-Embed JavaScript runtimes are bundled
|
|
647
|
+
for offline HTML output.
|
|
648
|
+
|
|
649
|
+
---
|
|
650
|
+
|
|
651
|
+
# Development
|
|
652
|
+
|
|
653
|
+
After checking out the repository:
|
|
654
|
+
|
|
655
|
+
```sh
|
|
656
|
+
bundle install
|
|
657
|
+
```
|
|
658
|
+
|
|
659
|
+
Run the test suite with:
|
|
660
|
+
|
|
661
|
+
```sh
|
|
662
|
+
bundle exec rspec
|
|
663
|
+
```
|
|
664
|
+
|
|
665
|
+
To build the gem locally:
|
|
666
|
+
|
|
667
|
+
```sh
|
|
668
|
+
gem build vg_helper.gemspec
|
|
669
|
+
```
|
|
670
|
+
|
|
671
|
+
---
|
|
32
672
|
|
|
33
673
|
## Contributing
|
|
34
674
|
|
|
@@ -37,3 +677,8 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERN
|
|
|
37
677
|
## License
|
|
38
678
|
|
|
39
679
|
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
|
680
|
+
|
|
681
|
+
The bundled Vega, Vega-Lite, and Vega-Embed JavaScript files remain
|
|
682
|
+
subject to their respective licenses.
|
|
683
|
+
|
|
684
|
+
Please see the relevant license files for details.
|
data/lib/vg_helper/version.rb
CHANGED
data/lib/vg_helper.rb
CHANGED
|
@@ -102,9 +102,9 @@ module VGHelper
|
|
|
102
102
|
"#8c564b", "#e377c2", "#7f7f7f", "#bcbd22", "#17becf",
|
|
103
103
|
"#393b79", "#637939", "#8c6d31", "#843c39", "#7b4173"] * 10)[0...(categories.length)]
|
|
104
104
|
horizontalcolors ||= (["#0000ff", "#ff0000"] * 6)[0...(horizontallines.length)]
|
|
105
|
-
colorset += horizontalcolors
|
|
105
|
+
# colorset += horizontalcolors
|
|
106
106
|
verticalcolors ||= (["#0000ff", "#ff0000"] * 6)[0...(verticallines.length)]
|
|
107
|
-
colorset += verticalcolors
|
|
107
|
+
# colorset += verticalcolors
|
|
108
108
|
|
|
109
109
|
x1_msec = values1[x_col].to_a.map { |v| udate(v) }
|
|
110
110
|
|
|
@@ -264,8 +264,8 @@ module VGHelper
|
|
|
264
264
|
y: {
|
|
265
265
|
field: y_col,
|
|
266
266
|
type: "quantitative",
|
|
267
|
-
scale: { domain: [{expr: "min_y"}, {expr: "max_y"}] }
|
|
268
|
-
axis: nil
|
|
267
|
+
scale: { domain: [{expr: "min_y"}, {expr: "max_y"}] }
|
|
268
|
+
#axis: nil
|
|
269
269
|
},
|
|
270
270
|
color: {
|
|
271
271
|
field: category_col,
|
|
@@ -655,12 +655,17 @@ module VGHelper
|
|
|
655
655
|
.width(width)
|
|
656
656
|
.height(height)
|
|
657
657
|
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
658
|
+
resolve_scale = {
|
|
659
|
+
color: "independent",
|
|
660
|
+
x: "shared"
|
|
661
|
+
}
|
|
662
|
+
|
|
663
|
+
resolve_scale[:y] = "independent" unless v2_array.empty?
|
|
664
|
+
|
|
665
|
+
builder = builder.resolve(
|
|
666
|
+
scale: resolve_scale,
|
|
667
|
+
axis: { x: "shared" }
|
|
662
668
|
)
|
|
663
|
-
end
|
|
664
669
|
|
|
665
670
|
builder
|
|
666
671
|
|
|
@@ -1176,21 +1181,11 @@ module VGHelper
|
|
|
1176
1181
|
|
|
1177
1182
|
encoding: {
|
|
1178
1183
|
y: {
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
"quantitative",
|
|
1184
|
-
|
|
1185
|
-
scale: {
|
|
1186
|
-
domain:
|
|
1187
|
-
ydomain
|
|
1188
|
-
},
|
|
1189
|
-
|
|
1190
|
-
axis:
|
|
1191
|
-
nil
|
|
1184
|
+
field: y_col_str,
|
|
1185
|
+
type: "quantitative",
|
|
1186
|
+
scale: { domain: ydomain }
|
|
1187
|
+
#axis: nil
|
|
1192
1188
|
},
|
|
1193
|
-
|
|
1194
1189
|
color: {
|
|
1195
1190
|
field:
|
|
1196
1191
|
category_col_str,
|
|
@@ -1539,29 +1534,26 @@ module VGHelper
|
|
|
1539
1534
|
############################
|
|
1540
1535
|
# Build
|
|
1541
1536
|
############################
|
|
1542
|
-
|
|
1537
|
+
|
|
1543
1538
|
builder =
|
|
1544
1539
|
Vega.lite
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1540
|
+
.data(values: all_data)
|
|
1541
|
+
.params(params)
|
|
1542
|
+
.encoding(x: x_encoding)
|
|
1543
|
+
.layer(layers)
|
|
1544
|
+
.width(width)
|
|
1545
|
+
.height(height)
|
|
1546
|
+
.title(title)
|
|
1547
|
+
|
|
1548
|
+
resolve_scale = {
|
|
1549
|
+
color: "independent"
|
|
1550
|
+
}
|
|
1552
1551
|
|
|
1553
|
-
|
|
1554
|
-
builder =
|
|
1555
|
-
builder.resolve(
|
|
1556
|
-
scale: {
|
|
1557
|
-
y:
|
|
1558
|
-
"independent",
|
|
1552
|
+
resolve_scale[:y] = "independent" unless v2_array.empty?
|
|
1559
1553
|
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
}
|
|
1554
|
+
builder = builder.resolve(
|
|
1555
|
+
scale: resolve_scale
|
|
1563
1556
|
)
|
|
1564
|
-
end
|
|
1565
1557
|
|
|
1566
1558
|
builder
|
|
1567
1559
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: vg_helper
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- showata
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-08-
|
|
11
|
+
date: 2026-08-30 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: rover-df
|