vega 0.1.3 → 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 +4 -4
- data/CHANGELOG.md +20 -0
- data/README.md +69 -10
- data/lib/vega/base_chart.rb +15 -0
- data/lib/vega/chart.rb +12 -0
- data/lib/vega/engine.rb +10 -0
- data/lib/vega/lite_chart.rb +13 -1
- data/lib/vega/spec.rb +14 -5
- data/lib/vega/version.rb +1 -1
- data/licenses/LICENSE-vega.txt +1 -1
- data/vendor/assets/javascripts/vega-embed.js +4448 -4611
- data/vendor/assets/javascripts/vega-lite.js +5558 -5551
- data/vendor/assets/javascripts/vega.js +3632 -3509
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4e3a67fe76080049bf0aece9305b4b75830595582417ae7f041ffef56accae89
|
4
|
+
data.tar.gz: c8b284392d1d872ab214ee1a25226d0d682f8e39e5099d4c549ee52be803887a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2e9f5e249a6ad941fc37dee172ffdbe9d6d24b20b3376c49557762df5178cdaacdf535cd2d15780aeb0f68865cca23565ae8ecc1c18b47808c4d2c76b78193c1
|
7
|
+
data.tar.gz: dc8fa74465709a9ef563b49747efc27be0d93c04c44668e1d05ff049eb7a686030f4323dfb8c0ec3e10d871777719eb1c2bb52c844b851eaec37d29416712bc8
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,23 @@
|
|
1
|
+
## 0.2.3 (2021-11-15)
|
2
|
+
|
3
|
+
- Updated Vega-Embed to 6.20.1 to fix spec version warnings
|
4
|
+
- Fixed error with iRuby
|
5
|
+
|
6
|
+
## 0.2.2 (2021-11-06)
|
7
|
+
|
8
|
+
- Added experimental support for exporting charts
|
9
|
+
- Removed automatic pinning for `importmap-rails` (still experimental)
|
10
|
+
|
11
|
+
## 0.2.1 (2021-10-24)
|
12
|
+
|
13
|
+
- Added support for `nil` height
|
14
|
+
- Fixed source map warnings
|
15
|
+
|
16
|
+
## 0.2.0 (2021-10-23)
|
17
|
+
|
18
|
+
- Added experimental support for `importmap-rails`
|
19
|
+
- Updated Vega to 5.21.0, Vega-Lite to 5.1.1, and Vega-Embed to 6.19.1
|
20
|
+
|
1
21
|
## 0.1.3 (2021-03-14)
|
2
22
|
|
3
23
|
- Added Vega-Interpreter
|
data/README.md
CHANGED
@@ -6,7 +6,7 @@ Interactive charts for Ruby, powered by [Vega](https://vega.github.io/vega/) and
|
|
6
6
|
|
7
7
|
Works with Rails, iRuby, and other frameworks
|
8
8
|
|
9
|
-
[](https://github.com/ankane/vega/actions)
|
9
|
+
[](https://github.com/ankane/vega-ruby/actions)
|
10
10
|
|
11
11
|
## Installation
|
12
12
|
|
@@ -18,11 +18,32 @@ gem 'vega'
|
|
18
18
|
|
19
19
|
The follow the instructions for how you plan to use it:
|
20
20
|
|
21
|
+
- [Rails 7 / Importmap](#rails-7--importmap) (experimental)
|
21
22
|
- [Rails 6 / Webpacker](#rails-6--webpacker)
|
22
23
|
- [Rails 5 / Sprockets](#rails-5--sprockets)
|
23
24
|
- [iRuby](#iruby)
|
24
25
|
- [Other](#other)
|
25
26
|
|
27
|
+
### Rails 7 / Importmap
|
28
|
+
|
29
|
+
Add to `config/importmap.rb`:
|
30
|
+
|
31
|
+
```ruby
|
32
|
+
pin "vega", to: "vega.js"
|
33
|
+
pin "vega-lite", to: "vega-lite.js"
|
34
|
+
pin "vega-embed", to: "vega-embed.js"
|
35
|
+
```
|
36
|
+
|
37
|
+
And add to `app/javascript/application.js`:
|
38
|
+
|
39
|
+
```js
|
40
|
+
import "vega"
|
41
|
+
import "vega-lite"
|
42
|
+
import "vega-embed"
|
43
|
+
|
44
|
+
window.dispatchEvent(new Event("vega:load"));
|
45
|
+
```
|
46
|
+
|
26
47
|
### Rails 6 / Webpacker
|
27
48
|
|
28
49
|
Run:
|
@@ -56,9 +77,9 @@ No additional set up is needed.
|
|
56
77
|
For Sinatra and other web frameworks, include the Vega JavaScript files on pages with charts:
|
57
78
|
|
58
79
|
```html
|
59
|
-
<script src="https://cdn.jsdelivr.net/npm/vega@5.
|
60
|
-
<script src="https://cdn.jsdelivr.net/npm/vega-lite@
|
61
|
-
<script src="https://cdn.jsdelivr.net/npm/vega-embed@6.
|
80
|
+
<script src="https://cdn.jsdelivr.net/npm/vega@5.21.0"></script>
|
81
|
+
<script src="https://cdn.jsdelivr.net/npm/vega-lite@5.1.1"></script>
|
82
|
+
<script src="https://cdn.jsdelivr.net/npm/vega-embed@6.19.1"></script>
|
62
83
|
```
|
63
84
|
|
64
85
|
## Getting Started
|
@@ -294,7 +315,7 @@ You can also create a specification by hand
|
|
294
315
|
|
295
316
|
```ruby
|
296
317
|
spec = {
|
297
|
-
"$schema" => "https://vega.github.io/schema/vega-lite/
|
318
|
+
"$schema" => "https://vega.github.io/schema/vega-lite/v5.json",
|
298
319
|
"data" => {"url" => "https://www.example.com"},
|
299
320
|
# ...
|
300
321
|
}
|
@@ -318,10 +339,48 @@ Get the spec for a chart
|
|
318
339
|
chart.spec
|
319
340
|
```
|
320
341
|
|
342
|
+
## Exporting Charts (experimental)
|
343
|
+
|
344
|
+
Export charts to PNG, SVG, or PDF. This requires Node.js and npm 7+. Run:
|
345
|
+
|
346
|
+
```sh
|
347
|
+
yarn add vega-cli vega-lite
|
348
|
+
```
|
349
|
+
|
350
|
+
For PNG, use:
|
351
|
+
|
352
|
+
```ruby
|
353
|
+
File.binwrite("chart.png", chart.to_png)
|
354
|
+
```
|
355
|
+
|
356
|
+
For SVG, use:
|
357
|
+
|
358
|
+
```ruby
|
359
|
+
File.binwrite("chart.svg", chart.to_svg)
|
360
|
+
```
|
361
|
+
|
362
|
+
For PDF, use:
|
363
|
+
|
364
|
+
```ruby
|
365
|
+
File.binwrite("chart.pdf", chart.to_pdf)
|
366
|
+
```
|
367
|
+
|
321
368
|
## Content Security Policy (CSP)
|
322
369
|
|
323
370
|
By default, the Vega parser uses the Function constructor, which [can cause issues with CSP](https://vega.github.io/vega/usage/interpreter/).
|
324
371
|
|
372
|
+
For Rails 7 / Importmap, add to `config/importmap.rb`:
|
373
|
+
|
374
|
+
```ruby
|
375
|
+
pin "vega-interpreter", to: "vega-interpreter.js"
|
376
|
+
```
|
377
|
+
|
378
|
+
And add to `app/javascript/application.js`:
|
379
|
+
|
380
|
+
```js
|
381
|
+
import "vega-interpreter"
|
382
|
+
```
|
383
|
+
|
325
384
|
For Rails 6 / Webpacker, run:
|
326
385
|
|
327
386
|
```sh
|
@@ -342,22 +401,22 @@ embed_options(ast: true)
|
|
342
401
|
|
343
402
|
## History
|
344
403
|
|
345
|
-
View the [changelog](https://github.com/ankane/vega/blob/master/CHANGELOG.md)
|
404
|
+
View the [changelog](https://github.com/ankane/vega-ruby/blob/master/CHANGELOG.md)
|
346
405
|
|
347
406
|
## Contributing
|
348
407
|
|
349
408
|
Everyone is encouraged to help improve this project. Here are a few ways you can help:
|
350
409
|
|
351
|
-
- [Report bugs](https://github.com/ankane/vega/issues)
|
352
|
-
- Fix bugs and [submit pull requests](https://github.com/ankane/vega/pulls)
|
410
|
+
- [Report bugs](https://github.com/ankane/vega-ruby/issues)
|
411
|
+
- Fix bugs and [submit pull requests](https://github.com/ankane/vega-ruby/pulls)
|
353
412
|
- Write, clarify, or fix documentation
|
354
413
|
- Suggest or add new features
|
355
414
|
|
356
415
|
To get started with development:
|
357
416
|
|
358
417
|
```sh
|
359
|
-
git clone https://github.com/ankane/vega.git
|
360
|
-
cd vega
|
418
|
+
git clone https://github.com/ankane/vega-ruby.git
|
419
|
+
cd vega-ruby
|
361
420
|
bundle install
|
362
421
|
bundle exec rake test
|
363
422
|
```
|
data/lib/vega/base_chart.rb
CHANGED
@@ -26,6 +26,11 @@ module Vega
|
|
26
26
|
Spec.new(spec).to_iruby
|
27
27
|
end
|
28
28
|
|
29
|
+
# for https://github.com/SciRuby/iruby/issues/314
|
30
|
+
def to_iruby_mimebundle(**)
|
31
|
+
[[to_iruby].to_h, nil]
|
32
|
+
end
|
33
|
+
|
29
34
|
def to_json
|
30
35
|
spec.to_json
|
31
36
|
end
|
@@ -50,5 +55,15 @@ module Vega
|
|
50
55
|
value
|
51
56
|
end
|
52
57
|
end
|
58
|
+
|
59
|
+
def export(cmd)
|
60
|
+
require "open3"
|
61
|
+
|
62
|
+
pkg = cmd.start_with?("vg") ? "vega-cli" : "vega-lite"
|
63
|
+
# use --no to prevent automatic installs
|
64
|
+
stdout, stderr, status = Open3.capture3("npm", "exec", "--no", "--package=#{pkg}", "--", cmd, stdin_data: to_json, binmode: true)
|
65
|
+
raise "Command failed: #{stderr}" unless status.success? && stdout.bytesize > 0
|
66
|
+
stdout
|
67
|
+
end
|
53
68
|
end
|
54
69
|
end
|
data/lib/vega/chart.rb
CHANGED
data/lib/vega/engine.rb
CHANGED
@@ -1,5 +1,15 @@
|
|
1
1
|
module Vega
|
2
2
|
class Engine < ::Rails::Engine
|
3
3
|
# for assets
|
4
|
+
|
5
|
+
# for importmap
|
6
|
+
if defined?(Importmap)
|
7
|
+
initializer "vega.importmap", after: "importmap" do |app|
|
8
|
+
app.config.assets.precompile << "vega-embed.js"
|
9
|
+
app.config.assets.precompile << "vega-interpreter.js"
|
10
|
+
app.config.assets.precompile << "vega-lite.js"
|
11
|
+
app.config.assets.precompile << "vega.js"
|
12
|
+
end
|
13
|
+
end
|
4
14
|
end
|
5
15
|
end
|
data/lib/vega/lite_chart.rb
CHANGED
@@ -11,7 +11,7 @@ module Vega
|
|
11
11
|
:transform, :layer, :hconcat, :vconcat, :concat
|
12
12
|
|
13
13
|
def initialize
|
14
|
-
@schema = "https://vega.github.io/schema/vega-lite/
|
14
|
+
@schema = "https://vega.github.io/schema/vega-lite/v5.json"
|
15
15
|
super()
|
16
16
|
end
|
17
17
|
|
@@ -29,5 +29,17 @@ module Vega
|
|
29
29
|
dup.spec!(*args)
|
30
30
|
end
|
31
31
|
end
|
32
|
+
|
33
|
+
def to_png
|
34
|
+
export("vl2png")
|
35
|
+
end
|
36
|
+
|
37
|
+
def to_svg
|
38
|
+
export("vl2svg")
|
39
|
+
end
|
40
|
+
|
41
|
+
def to_pdf
|
42
|
+
export("vl2pdf")
|
43
|
+
end
|
32
44
|
end
|
33
45
|
end
|
data/lib/vega/spec.rb
CHANGED
@@ -11,7 +11,14 @@ module Vega
|
|
11
11
|
output = <<~EOS
|
12
12
|
#{html}
|
13
13
|
<script>
|
14
|
-
|
14
|
+
(function() {
|
15
|
+
var createChart = function() { #{js} };
|
16
|
+
if ("vegaEmbed" in window) {
|
17
|
+
createChart();
|
18
|
+
} else {
|
19
|
+
window.addEventListener("vega:load", createChart, true);
|
20
|
+
}
|
21
|
+
})();
|
15
22
|
</script>
|
16
23
|
EOS
|
17
24
|
output.respond_to?(:html_safe) ? output.html_safe : output
|
@@ -25,12 +32,13 @@ module Vega
|
|
25
32
|
<script>
|
26
33
|
require.config({
|
27
34
|
paths: {
|
28
|
-
'vega': 'https://cdn.jsdelivr.net/npm/vega@5.
|
29
|
-
'vega-
|
30
|
-
'vega-
|
35
|
+
'vega': 'https://cdn.jsdelivr.net/npm/vega@5.21.0/build/vega.min',
|
36
|
+
'vega-util': 'https://cdn.jsdelivr.net/npm/vega-util@1.17.0/build/vega-util.min',
|
37
|
+
'vega-lite': 'https://cdn.jsdelivr.net/npm/vega-lite@5.1.1/build/vega-lite.min',
|
38
|
+
'vega-embed': 'https://cdn.jsdelivr.net/npm/vega-embed@6.20.1/build/vega-embed.min'
|
31
39
|
}
|
32
40
|
});
|
33
|
-
require(['vega', 'vega-lite', 'vega-embed'], function(vega, vegaLite, vegaEmbed) {
|
41
|
+
require(['vega', 'vega-util', 'vega-lite', 'vega-embed'], function(vega, vegaUtil, vegaLite, vegaEmbed) {
|
34
42
|
#{js}
|
35
43
|
});
|
36
44
|
</script>
|
@@ -44,6 +52,7 @@ module Vega
|
|
44
52
|
id = "chart-#{SecureRandom.hex(16)}" # 2**128 values
|
45
53
|
width = @spec["width"].is_a?(Integer) ? "#{@spec["width"]}px" : "100%"
|
46
54
|
height = @spec["height"].is_a?(Integer) ? "#{@spec["height"]}px" : "300px"
|
55
|
+
height = "auto" if @spec["height"].nil?
|
47
56
|
|
48
57
|
# user can override with usermeta: {embedOptions: ...}
|
49
58
|
embed_options = {actions: false}
|
data/lib/vega/version.rb
CHANGED
data/licenses/LICENSE-vega.txt
CHANGED