vega 0.2.0 → 0.2.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +20 -0
- data/README.md +45 -5
- data/lib/vega/base_chart.rb +15 -0
- data/lib/vega/chart.rb +12 -0
- data/lib/vega/engine.rb +2 -3
- data/lib/vega/lite_chart.rb +12 -0
- data/lib/vega/spec.rb +5 -4
- data/lib/vega/version.rb +1 -1
- data/vendor/assets/javascripts/vega-embed.js +4315 -5203
- data/vendor/assets/javascripts/vega-lite.js +0 -1
- metadata +3 -4
- data/config/importmap.rb +0 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a585bb036b731a2eb4408f72112bba1d64d574e8cc11e12dd22b5df392340f25
|
4
|
+
data.tar.gz: 6d703da07e6ae89275f2999e46285df66825703fecccc352ee9747d3e167dad0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2d5a50065d7b9cc715046d7f61cc406be7847e2ad91b0578b0de555e7659665f311034b1adfcfa31bd9f96e15fff240f6df6b6b4bb502d240fdf373711244e65
|
7
|
+
data.tar.gz: 297c9d86387858617ee12afb5fd44ae46929ea63c74f601240b8c53a79e50e0b6876496014caaa724f57b98eb20137309312657c7eb5f89250b0c1c70f6c73e3
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,23 @@
|
|
1
|
+
## 0.2.4 (2022-01-15)
|
2
|
+
|
3
|
+
- Support for `importmap-rails` is no longer experimental
|
4
|
+
- Fixed asset precompilation error with `importmap-rails`
|
5
|
+
|
6
|
+
## 0.2.3 (2021-11-15)
|
7
|
+
|
8
|
+
- Updated Vega-Embed to 6.20.1 to fix spec version warnings
|
9
|
+
- Fixed error with iRuby
|
10
|
+
|
11
|
+
## 0.2.2 (2021-11-06)
|
12
|
+
|
13
|
+
- Added experimental support for exporting charts
|
14
|
+
- Removed automatic pinning for `importmap-rails` (still experimental)
|
15
|
+
|
16
|
+
## 0.2.1 (2021-10-24)
|
17
|
+
|
18
|
+
- Added support for `nil` height
|
19
|
+
- Fixed source map warnings
|
20
|
+
|
1
21
|
## 0.2.0 (2021-10-23)
|
2
22
|
|
3
23
|
- Added experimental support for `importmap-rails`
|
data/README.md
CHANGED
@@ -16,9 +16,9 @@ Add this line to your application’s Gemfile:
|
|
16
16
|
gem 'vega'
|
17
17
|
```
|
18
18
|
|
19
|
-
|
19
|
+
Then follow the instructions for how you plan to use it:
|
20
20
|
|
21
|
-
- [Rails 7 / Importmap](#rails-7--importmap)
|
21
|
+
- [Rails 7 / Importmap](#rails-7--importmap)
|
22
22
|
- [Rails 6 / Webpacker](#rails-6--webpacker)
|
23
23
|
- [Rails 5 / Sprockets](#rails-5--sprockets)
|
24
24
|
- [iRuby](#iruby)
|
@@ -26,7 +26,15 @@ The follow the instructions for how you plan to use it:
|
|
26
26
|
|
27
27
|
### Rails 7 / Importmap
|
28
28
|
|
29
|
-
Add to `
|
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`:
|
30
38
|
|
31
39
|
```js
|
32
40
|
import "vega"
|
@@ -307,7 +315,7 @@ You can also create a specification by hand
|
|
307
315
|
|
308
316
|
```ruby
|
309
317
|
spec = {
|
310
|
-
"$schema" => "https://vega.github.io/schema/vega-lite/
|
318
|
+
"$schema" => "https://vega.github.io/schema/vega-lite/v5.json",
|
311
319
|
"data" => {"url" => "https://www.example.com"},
|
312
320
|
# ...
|
313
321
|
}
|
@@ -331,11 +339,43 @@ Get the spec for a chart
|
|
331
339
|
chart.spec
|
332
340
|
```
|
333
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
|
+
|
334
368
|
## Content Security Policy (CSP)
|
335
369
|
|
336
370
|
By default, the Vega parser uses the Function constructor, which [can cause issues with CSP](https://vega.github.io/vega/usage/interpreter/).
|
337
371
|
|
338
|
-
For Rails 7 / Importmap, add to `
|
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`:
|
339
379
|
|
340
380
|
```js
|
341
381
|
import "vega-interpreter"
|
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, {}]
|
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
@@ -3,9 +3,8 @@ module Vega
|
|
3
3
|
# for assets
|
4
4
|
|
5
5
|
# for importmap
|
6
|
-
|
7
|
-
|
8
|
-
app.importmap.draw(Engine.root.join("config/importmap.rb"))
|
6
|
+
initializer "vega.importmap" do |app|
|
7
|
+
if defined?(Importmap)
|
9
8
|
app.config.assets.precompile << "vega-embed.js"
|
10
9
|
app.config.assets.precompile << "vega-interpreter.js"
|
11
10
|
app.config.assets.precompile << "vega-lite.js"
|
data/lib/vega/lite_chart.rb
CHANGED
data/lib/vega/spec.rb
CHANGED
@@ -32,10 +32,10 @@ module Vega
|
|
32
32
|
<script>
|
33
33
|
require.config({
|
34
34
|
paths: {
|
35
|
-
'vega': 'https://cdn.jsdelivr.net/npm/vega@5.21.0
|
36
|
-
'vega-util': 'https://cdn.jsdelivr.net/npm/vega-util@1.17.0
|
37
|
-
'vega-lite': 'https://cdn.jsdelivr.net/npm/vega-lite@5.1.1
|
38
|
-
'vega-embed': 'https://cdn.jsdelivr.net/npm/vega-embed@6.
|
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'
|
39
39
|
}
|
40
40
|
});
|
41
41
|
require(['vega', 'vega-util', 'vega-lite', 'vega-embed'], function(vega, vegaUtil, vegaLite, vegaEmbed) {
|
@@ -52,6 +52,7 @@ module Vega
|
|
52
52
|
id = "chart-#{SecureRandom.hex(16)}" # 2**128 values
|
53
53
|
width = @spec["width"].is_a?(Integer) ? "#{@spec["width"]}px" : "100%"
|
54
54
|
height = @spec["height"].is_a?(Integer) ? "#{@spec["height"]}px" : "300px"
|
55
|
+
height = "auto" if @spec["height"].nil?
|
55
56
|
|
56
57
|
# user can override with usermeta: {embedOptions: ...}
|
57
58
|
embed_options = {actions: false}
|
data/lib/vega/version.rb
CHANGED