vega 0.2.1 → 0.2.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 30bfea4df021c4f5b65530adbc1c83f5a07f5bf323faf0b25e817f9b8e2d56b7
4
- data.tar.gz: 06ab9a178a4edfea2a0360a95dd33eca2e3197bbdd196bb764c52114028ea511
3
+ metadata.gz: 7c067bc284fb8cb8d590bc3840e1903c6da0ba49f55f9c0cc784d88358d0ff5c
4
+ data.tar.gz: 22268adc67db09659c8b7701f893f6df63cbd34810845b6bdcd8a359364b0df1
5
5
  SHA512:
6
- metadata.gz: f6e7098cdb5660031ab98e3838c9bb68d25bf338614fd41e0fe2b31588aef2c4953cce0059a61c0338075533de5a17076a050cf75ff95e52a2a0d46611dd6954
7
- data.tar.gz: 9d79099d412b36555e9cacb5594d5022706760ea05a880606920b326b77a09f2d373433dc1f82dde49d451c3a76f035f8b6d7de1c197a1361c8735faee90919f
6
+ metadata.gz: 5257af439bd6fdb7530a3c036a75449fedb7b2a28efe0aa426761588f07e150de7327ce52dd8e138aebacb87c3ffdf7a484356d021395b37567c01217d0f4931
7
+ data.tar.gz: b360e400d2adb00623c8ec32b1d169260959e6a7b62f4d6723329aefc5177cfb8d60bb07d2d31c966d1442a126e787007bc0dae75eb0846eaf3cadcbc562ed0b
data/CHANGELOG.md CHANGED
@@ -1,3 +1,22 @@
1
+ ## 0.2.5 (2022-01-22)
2
+
3
+ - Updated Vega-Lite to 5.2.0 and Vega-Embed to 6.20.5
4
+
5
+ ## 0.2.4 (2022-01-15)
6
+
7
+ - Support for `importmap-rails` is no longer experimental
8
+ - Fixed asset precompilation error with `importmap-rails`
9
+
10
+ ## 0.2.3 (2021-11-15)
11
+
12
+ - Updated Vega-Embed to 6.20.1 to fix spec version warnings
13
+ - Fixed error with iRuby
14
+
15
+ ## 0.2.2 (2021-11-06)
16
+
17
+ - Added experimental support for exporting charts
18
+ - Removed automatic pinning for `importmap-rails` (still experimental)
19
+
1
20
  ## 0.2.1 (2021-10-24)
2
21
 
3
22
  - Added support for `nil` height
data/README.md CHANGED
@@ -13,12 +13,12 @@ Works with Rails, iRuby, and other frameworks
13
13
  Add this line to your application’s Gemfile:
14
14
 
15
15
  ```ruby
16
- gem 'vega'
16
+ gem "vega"
17
17
  ```
18
18
 
19
- The follow the instructions for how you plan to use it:
19
+ Then follow the instructions for how you plan to use it:
20
20
 
21
- - [Rails 7 / Importmap](#rails-7--importmap) (experimental)
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 `app/javascript/application.js`:
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"
@@ -70,8 +78,8 @@ For Sinatra and other web frameworks, include the Vega JavaScript files on pages
70
78
 
71
79
  ```html
72
80
  <script src="https://cdn.jsdelivr.net/npm/vega@5.21.0"></script>
73
- <script src="https://cdn.jsdelivr.net/npm/vega-lite@5.1.1"></script>
74
- <script src="https://cdn.jsdelivr.net/npm/vega-embed@6.19.1"></script>
81
+ <script src="https://cdn.jsdelivr.net/npm/vega-lite@5.2.0"></script>
82
+ <script src="https://cdn.jsdelivr.net/npm/vega-embed@6.20.5"></script>
75
83
  ```
76
84
 
77
85
  ## Getting Started
@@ -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 `app/javascript/application.js`:
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"
@@ -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
@@ -23,5 +23,17 @@ module Vega
23
23
  self
24
24
  end
25
25
  immutable_method :data
26
+
27
+ def to_png
28
+ export("vg2png")
29
+ end
30
+
31
+ def to_svg
32
+ export("vg2svg")
33
+ end
34
+
35
+ def to_pdf
36
+ export("vg2pdf")
37
+ end
26
38
  end
27
39
  end
data/lib/vega/engine.rb CHANGED
@@ -3,9 +3,8 @@ module Vega
3
3
  # for assets
4
4
 
5
5
  # for importmap
6
- if defined?(Importmap)
7
- initializer "vega.importmap", after: "importmap" do |app|
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"
@@ -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
@@ -34,8 +34,8 @@ module Vega
34
34
  paths: {
35
35
  'vega': 'https://cdn.jsdelivr.net/npm/vega@5.21.0/build/vega.min',
36
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.19.1/build/vega-embed.min'
37
+ 'vega-lite': 'https://cdn.jsdelivr.net/npm/vega-lite@5.2.0/build/vega-lite.min',
38
+ 'vega-embed': 'https://cdn.jsdelivr.net/npm/vega-embed@6.20.5/build/vega-embed.min'
39
39
  }
40
40
  });
41
41
  require(['vega', 'vega-util', 'vega-lite', 'vega-embed'], function(vega, vegaUtil, vegaLite, vegaEmbed) {
data/lib/vega/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Vega
2
- VERSION = "0.2.1"
2
+ VERSION = "0.2.5"
3
3
  end