vega 0.2.0 → 0.2.4

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 81ef88e1766446a7d367331b58abcc2113a05cc3a914891dc81f5f82a026070f
4
- data.tar.gz: 31f67095fcebf1cafa5bf8e50b81bf8a6830082d43bb383a7b6c299034907d24
3
+ metadata.gz: a585bb036b731a2eb4408f72112bba1d64d574e8cc11e12dd22b5df392340f25
4
+ data.tar.gz: 6d703da07e6ae89275f2999e46285df66825703fecccc352ee9747d3e167dad0
5
5
  SHA512:
6
- metadata.gz: fbd22ed80b972dbbc1ab134755a4903b255b328963a8533e7e7cae29403cd1ac81aca3f84f8a0b0f42e93515a18d85a5ec582193a3a1d020f79527a66b8fd1aa
7
- data.tar.gz: 19fad72d73ceddfaf669e3a0c0a970bdaeac5996018522e3acffca488533723e4e79a9609741399aefc1480a74891ac8f2b4db1a62540f107694fcc3e25e0a8d
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
- 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"
@@ -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/v4.json",
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 `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
@@ -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?noext',
36
- 'vega-util': 'https://cdn.jsdelivr.net/npm/vega-util@1.17.0?noext',
37
- 'vega-lite': 'https://cdn.jsdelivr.net/npm/vega-lite@5.1.1?noext',
38
- 'vega-embed': 'https://cdn.jsdelivr.net/npm/vega-embed@6.19.1?noext'
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
@@ -1,3 +1,3 @@
1
1
  module Vega
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.4"
3
3
  end