vega 0.1.1 → 0.2.1

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: 854e0601118f529798b5850bc36babaff268a6df96932da17c3e3f9f96330234
4
- data.tar.gz: 50359706b33864f64a18e0db734eb4c3209b6f225aabaab3553cf6bfd583219f
3
+ metadata.gz: 30bfea4df021c4f5b65530adbc1c83f5a07f5bf323faf0b25e817f9b8e2d56b7
4
+ data.tar.gz: 06ab9a178a4edfea2a0360a95dd33eca2e3197bbdd196bb764c52114028ea511
5
5
  SHA512:
6
- metadata.gz: 388eab29e442fcf3a33788b0a59522be829ef43dd5a56a7fd06a0f803c929be6bae6b72421ad2dc11cecb8ba3382d7e445ba4f2d822577a6f2622328911e70c7
7
- data.tar.gz: 683e03f32841bf0605c310cd31fd545ca2110f8c85b46a10391e90204676ac08e8b7b753061d14f9f27758b208daa06f0039b5786367b27e4a2b95651f0cb6ea
6
+ metadata.gz: f6e7098cdb5660031ab98e3838c9bb68d25bf338614fd41e0fe2b31588aef2c4953cce0059a61c0338075533de5a17076a050cf75ff95e52a2a0d46611dd6954
7
+ data.tar.gz: 9d79099d412b36555e9cacb5594d5022706760ea05a880606920b326b77a09f2d373433dc1f82dde49d451c3a76f035f8b6d7de1c197a1361c8735faee90919f
data/CHANGELOG.md CHANGED
@@ -1,3 +1,21 @@
1
+ ## 0.2.1 (2021-10-24)
2
+
3
+ - Added support for `nil` height
4
+ - Fixed source map warnings
5
+
6
+ ## 0.2.0 (2021-10-23)
7
+
8
+ - Added experimental support for `importmap-rails`
9
+ - Updated Vega to 5.21.0, Vega-Lite to 5.1.1, and Vega-Embed to 6.19.1
10
+
11
+ ## 0.1.3 (2021-03-14)
12
+
13
+ - Added Vega-Interpreter
14
+
15
+ ## 0.1.2 (2021-02-09)
16
+
17
+ - Updated Vega to 5.19.1, Vega-Lite to 4.17.0, and Vega-Embed to 6.15.1
18
+
1
19
  ## 0.1.1 (2020-09-27)
2
20
 
3
21
  - Added `repeat`, `resolve`, `spec` and `selection` methods
data/LICENSE.txt CHANGED
@@ -1,6 +1,6 @@
1
1
  BSD 3-Clause License
2
2
 
3
- Copyright (c) 2020, Andrew Kane.
3
+ Copyright (c) 2020-2021, Andrew Kane.
4
4
  All rights reserved.
5
5
 
6
6
  Redistribution and use in source and binary forms, with or without
data/README.md CHANGED
@@ -2,11 +2,11 @@
2
2
 
3
3
  Interactive charts for Ruby, powered by [Vega](https://vega.github.io/vega/) and [Vega-Lite](https://vega.github.io/vega-lite/)
4
4
 
5
- [See what’s possible](https://vega.github.io/vega-lite/examples/)
5
+ [See it in action](https://vega.dokkuapp.com)
6
6
 
7
7
  Works with Rails, iRuby, and other frameworks
8
8
 
9
- [![Build Status](https://travis-ci.org/ankane/vega.svg?branch=master)](https://travis-ci.org/ankane/vega)
9
+ [![Build Status](https://github.com/ankane/vega-ruby/workflows/build/badge.svg?branch=master)](https://github.com/ankane/vega-ruby/actions)
10
10
 
11
11
  ## Installation
12
12
 
@@ -18,11 +18,24 @@ 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 `app/javascript/application.js`:
30
+
31
+ ```js
32
+ import "vega"
33
+ import "vega-lite"
34
+ import "vega-embed"
35
+
36
+ window.dispatchEvent(new Event("vega:load"));
37
+ ```
38
+
26
39
  ### Rails 6 / Webpacker
27
40
 
28
41
  Run:
@@ -56,9 +69,9 @@ No additional set up is needed.
56
69
  For Sinatra and other web frameworks, include the Vega JavaScript files on pages with charts:
57
70
 
58
71
  ```html
59
- <script src="https://cdn.jsdelivr.net/npm/vega@5.16.1"></script>
60
- <script src="https://cdn.jsdelivr.net/npm/vega-lite@4.16.2"></script>
61
- <script src="https://cdn.jsdelivr.net/npm/vega-embed@6.12.2"></script>
72
+ <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>
62
75
  ```
63
76
 
64
77
  ## Getting Started
@@ -85,7 +98,7 @@ Vega.lite
85
98
  .data([{city: "A", sales: 28}, {city: "B", sales: 55}, {city: "C", sales: 43}])
86
99
  .mark(type: "bar", tooltip: true)
87
100
  .encoding(
88
- x: {field: "city", type: "ordinal"},
101
+ x: {field: "city", type: "nominal"},
89
102
  y: {field: "sales", type: "quantitative"}
90
103
  )
91
104
  ```
@@ -294,7 +307,7 @@ You can also create a specification by hand
294
307
 
295
308
  ```ruby
296
309
  spec = {
297
- "$schema" => "https://vega.github.io/schema/vega-lite/v4.json",
310
+ "$schema" => "https://vega.github.io/schema/vega-lite/v5.json",
298
311
  "data" => {"url" => "https://www.example.com"},
299
312
  # ...
300
313
  }
@@ -318,24 +331,52 @@ Get the spec for a chart
318
331
  chart.spec
319
332
  ```
320
333
 
334
+ ## Content Security Policy (CSP)
335
+
336
+ By default, the Vega parser uses the Function constructor, which [can cause issues with CSP](https://vega.github.io/vega/usage/interpreter/).
337
+
338
+ For Rails 7 / Importmap, add to `app/javascript/application.js`:
339
+
340
+ ```js
341
+ import "vega-interpreter"
342
+ ```
343
+
344
+ For Rails 6 / Webpacker, run:
345
+
346
+ ```sh
347
+ yarn add vega-interpreter
348
+ ```
349
+
350
+ For Rails 5 / Sprockets, add to `app/assets/javascripts/application.js`:
351
+
352
+ ```js
353
+ //= require vega-interpreter
354
+ ```
355
+
356
+ And set embed options for your charts
357
+
358
+ ```ruby
359
+ embed_options(ast: true)
360
+ ```
361
+
321
362
  ## History
322
363
 
323
- View the [changelog](https://github.com/ankane/vega/blob/master/CHANGELOG.md)
364
+ View the [changelog](https://github.com/ankane/vega-ruby/blob/master/CHANGELOG.md)
324
365
 
325
366
  ## Contributing
326
367
 
327
368
  Everyone is encouraged to help improve this project. Here are a few ways you can help:
328
369
 
329
- - [Report bugs](https://github.com/ankane/vega/issues)
330
- - Fix bugs and [submit pull requests](https://github.com/ankane/vega/pulls)
370
+ - [Report bugs](https://github.com/ankane/vega-ruby/issues)
371
+ - Fix bugs and [submit pull requests](https://github.com/ankane/vega-ruby/pulls)
331
372
  - Write, clarify, or fix documentation
332
373
  - Suggest or add new features
333
374
 
334
375
  To get started with development:
335
376
 
336
377
  ```sh
337
- git clone https://github.com/ankane/vega.git
338
- cd vega
378
+ git clone https://github.com/ankane/vega-ruby.git
379
+ cd vega-ruby
339
380
  bundle install
340
381
  bundle exec rake test
341
382
  ```
@@ -0,0 +1 @@
1
+ pin_all_from File.expand_path("../vendor/assets/javascripts", __dir__)
data/lib/vega/engine.rb CHANGED
@@ -1,5 +1,16 @@
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.importmap.draw(Engine.root.join("config/importmap.rb"))
9
+ app.config.assets.precompile << "vega-embed.js"
10
+ app.config.assets.precompile << "vega-interpreter.js"
11
+ app.config.assets.precompile << "vega-lite.js"
12
+ app.config.assets.precompile << "vega.js"
13
+ end
14
+ end
4
15
  end
5
16
  end
@@ -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/v4.json"
14
+ @schema = "https://vega.github.io/schema/vega-lite/v5.json"
15
15
  super()
16
16
  end
17
17
 
data/lib/vega/spec.rb CHANGED
@@ -11,7 +11,14 @@ module Vega
11
11
  output = <<~EOS
12
12
  #{html}
13
13
  <script>
14
- #{js}
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.16.1?noext',
29
- 'vega-lite': 'https://cdn.jsdelivr.net/npm/vega-lite@4.16.2?noext',
30
- 'vega-embed': 'https://cdn.jsdelivr.net/npm/vega-embed@6.12.2?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.19.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
@@ -1,3 +1,3 @@
1
1
  module Vega
2
- VERSION = "0.1.1"
2
+ VERSION = "0.2.1"
3
3
  end
@@ -0,0 +1,27 @@
1
+ Copyright (c) 2015-2018, University of Washington Interactive Data Lab
2
+ All rights reserved.
3
+
4
+ Redistribution and use in source and binary forms, with or without
5
+ modification, are permitted provided that the following conditions are met:
6
+
7
+ 1. Redistributions of source code must retain the above copyright notice, this
8
+ list of conditions and the following disclaimer.
9
+
10
+ 2. Redistributions in binary form must reproduce the above copyright notice,
11
+ this list of conditions and the following disclaimer in the documentation
12
+ and/or other materials provided with the distribution.
13
+
14
+ 3. Neither the name of the copyright holder nor the names of its contributors
15
+ may be used to endorse or promote products derived from this software
16
+ without specific prior written permission.
17
+
18
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
22
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
25
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
@@ -1,4 +1,4 @@
1
- Copyright (c) 2015-2018, University of Washington Interactive Data Lab
1
+ Copyright (c) 2015-2021, University of Washington Interactive Data Lab
2
2
  All rights reserved.
3
3
 
4
4
  Redistribution and use in source and binary forms, with or without