vega 0.2.1 → 0.2.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 +5 -0
- data/README.md +42 -2
- data/lib/vega/base_chart.rb +10 -0
- data/lib/vega/chart.rb +12 -0
- data/lib/vega/engine.rb +0 -1
- data/lib/vega/lite_chart.rb +12 -0
- data/lib/vega/version.rb +1 -1
- metadata +2 -3
- 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: 455e0c4c1814906c620cc31ddd7ded69330f51b8722abfe23f895ab0bd0e47b0
|
4
|
+
data.tar.gz: 2264a6053aa5588decd30420935452f9c7426d707f5564ff05644e473a463296
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f08e7e57fc295a1f43c5ea0766c69582e6a4ece29dec97beefce16ace22665a3b09d26b9c0c1166628a0454d67f2f0e4f12a0e64d8edf2963c7980f9cb10dc09
|
7
|
+
data.tar.gz: 9e0f2da88f1fe97adb15d8135fd66b3b55782e2c103c7f26cd0290fddc0383ff3b7b4911240da7ce6dbd72da2ad06d6e544c4d512444bccd25f3edb1121b3009
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -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"
|
@@ -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
@@ -50,5 +50,15 @@ module Vega
|
|
50
50
|
value
|
51
51
|
end
|
52
52
|
end
|
53
|
+
|
54
|
+
def export(cmd)
|
55
|
+
require "open3"
|
56
|
+
|
57
|
+
pkg = cmd.start_with?("vg") ? "vega-cli" : "vega-lite"
|
58
|
+
# use --no to prevent automatic installs
|
59
|
+
stdout, stderr, status = Open3.capture3("npm", "exec", "--no", "--package=#{pkg}", "--", cmd, stdin_data: to_json, binmode: true)
|
60
|
+
raise "Command failed: #{stderr}" unless status.success? && stdout.bytesize > 0
|
61
|
+
stdout
|
62
|
+
end
|
53
63
|
end
|
54
64
|
end
|
data/lib/vega/chart.rb
CHANGED
data/lib/vega/engine.rb
CHANGED
@@ -5,7 +5,6 @@ module Vega
|
|
5
5
|
# for importmap
|
6
6
|
if defined?(Importmap)
|
7
7
|
initializer "vega.importmap", after: "importmap" do |app|
|
8
|
-
app.importmap.draw(Engine.root.join("config/importmap.rb"))
|
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/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vega
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Kane
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-11-06 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description:
|
14
14
|
email: andrew@ankane.org
|
@@ -19,7 +19,6 @@ files:
|
|
19
19
|
- CHANGELOG.md
|
20
20
|
- LICENSE.txt
|
21
21
|
- README.md
|
22
|
-
- config/importmap.rb
|
23
22
|
- lib/vega.rb
|
24
23
|
- lib/vega/base_chart.rb
|
25
24
|
- lib/vega/chart.rb
|
data/config/importmap.rb
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
pin_all_from File.expand_path("../vendor/assets/javascripts", __dir__)
|