vega 0.1.0 → 0.1.1

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: 52225cdedf189b9d6c9b589c52fd7bb10d6c9aa1dc17685b920b60fabee42d66
4
- data.tar.gz: 82dd13b27708aa6ad57e4358d75c4913e232c8f85b4eb2768598dc53d81f82fd
3
+ metadata.gz: 854e0601118f529798b5850bc36babaff268a6df96932da17c3e3f9f96330234
4
+ data.tar.gz: 50359706b33864f64a18e0db734eb4c3209b6f225aabaab3553cf6bfd583219f
5
5
  SHA512:
6
- metadata.gz: c1ed453f8f337c3863dadafe79a8e44a3a22896fc114c6de6e9b3646908deb86b9fb3d76d826a174ee21722a1b2a4ba9905ad13b2594592d074cd3611fa37bbd
7
- data.tar.gz: 58be98b855093e3b6f554fc094a85cf5f79dd3efd10304cb5ba0bd05749277a66fba1e4f1e2c502af401cea6b9ca7269f40bdbb6b8d6e8c37033def50bc5119f
6
+ metadata.gz: 388eab29e442fcf3a33788b0a59522be829ef43dd5a56a7fd06a0f803c929be6bae6b72421ad2dc11cecb8ba3382d7e445ba4f2d822577a6f2622328911e70c7
7
+ data.tar.gz: 683e03f32841bf0605c310cd31fd545ca2110f8c85b46a10391e90204676ac08e8b7b753061d14f9f27758b208daa06f0039b5786367b27e4a2b95651f0cb6ea
@@ -1,3 +1,9 @@
1
+ ## 0.1.1 (2020-09-27)
2
+
3
+ - Added `repeat`, `resolve`, `spec` and `selection` methods
4
+ - Added `hconcat` and `vconcat` methods
5
+ - Added support for Daru data frames
6
+
1
7
  ## 0.1.0 (2020-09-26)
2
8
 
3
9
  - First release
data/README.md CHANGED
@@ -2,8 +2,12 @@
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/)
6
+
5
7
  Works with Rails, iRuby, and other frameworks
6
8
 
9
+ [![Build Status](https://travis-ci.org/ankane/vega.svg?branch=master)](https://travis-ci.org/ankane/vega)
10
+
7
11
  ## Installation
8
12
 
9
13
  Add this line to your application’s Gemfile:
@@ -14,8 +18,8 @@ gem 'vega'
14
18
 
15
19
  The follow the instructions for how you plan to use it:
16
20
 
17
- - [Rails 6 / Webpacker](#rails)
18
- - [Rails 5 / Sprockets](#rails)
21
+ - [Rails 6 / Webpacker](#rails-6--webpacker)
22
+ - [Rails 5 / Sprockets](#rails-5--sprockets)
19
23
  - [iRuby](#iruby)
20
24
  - [Other](#other)
21
25
 
@@ -78,23 +82,11 @@ Create a bar chart
78
82
 
79
83
  ```ruby
80
84
  Vega.lite
81
- .data(
82
- values: [
83
- {a: "A", b: 28},
84
- {a: "B", b: 55},
85
- {a: "C", b: 43},
86
- {a: "D", b: 91},
87
- {a: "E", b: 81},
88
- {a: "F", b: 53},
89
- {a: "G", b: 19},
90
- {a: "H", b: 87},
91
- {a: "I", b: 52}
92
- ]
93
- )
85
+ .data([{city: "A", sales: 28}, {city: "B", sales: 55}, {city: "C", sales: 43}])
94
86
  .mark(type: "bar", tooltip: true)
95
87
  .encoding(
96
- x: {field: "a", type: "ordinal"},
97
- y: {field: "b", type: "quantitative"}
88
+ x: {field: "city", type: "ordinal"},
89
+ y: {field: "sales", type: "quantitative"}
98
90
  )
99
91
  ```
100
92
 
@@ -116,22 +108,28 @@ Vega.lite
116
108
 
117
109
  [Docs](https://vega.github.io/vega-lite/docs/data.html)
118
110
 
119
- The data source can be an array
111
+ Data can be an array
120
112
 
121
113
  ```ruby
122
- data(values: [{x: "A", y: 1}, {x: "B", y: 2}])
114
+ data([{x: "A", y: 1}, {x: "B", y: 2}])
123
115
  ```
124
116
 
125
117
  Or a URL
126
118
 
127
119
  ```ruby
128
- data(url: "https://www.example.com")
120
+ data("https://www.example.com/data.json")
129
121
  ```
130
122
 
131
- You can also specify the data format
123
+ Or a Rover data frame
132
124
 
133
125
  ```ruby
134
- data(url: "https://www.example.com/data.csv", format: {type: "csv"})
126
+ data(df)
127
+ ```
128
+
129
+ Or a data generator
130
+
131
+ ```ruby
132
+ data(sequence: {start: 0, stop: 10, step: 1, as: "x"})
135
133
  ```
136
134
 
137
135
  ### Transforms
@@ -192,7 +190,51 @@ encoding(x: {field: "a", type: "ordinal"})
192
190
  projection(type: "albersUsa")
193
191
  ```
194
192
 
195
- ### Configuration
193
+ ### View Composition
194
+
195
+ [Docs](https://vega.github.io/vega-lite/docs/composition.html)
196
+
197
+ Faceting
198
+
199
+ ```ruby
200
+ facet(row: {field: "x"})
201
+ ```
202
+
203
+ Layering
204
+
205
+ ```ruby
206
+ layer(view)
207
+ ```
208
+
209
+ Concatenation
210
+
211
+ ```ruby
212
+ hconcat(view)
213
+ vconcat(view)
214
+ concat(view)
215
+ ```
216
+
217
+ Repeating
218
+
219
+ ```ruby
220
+ repeat(row: ["a", "b", "c"])
221
+ ```
222
+
223
+ Resolving
224
+
225
+ ```ruby
226
+ resolve(scale: {color: "independent"})
227
+ ```
228
+
229
+ ### Selections
230
+
231
+ [Docs](https://vega.github.io/vega-lite/docs/selection.html)
232
+
233
+ ```ruby
234
+ selection(x: {type: "single"})
235
+ ```
236
+
237
+ ### Config
196
238
 
197
239
  [Docs](https://vega.github.io/vega-lite/docs/config.html)
198
240
 
@@ -2,8 +2,6 @@ module Vega
2
2
  class BaseChart
3
3
  extend MethodHelpers
4
4
 
5
- attr_reader :spec
6
-
7
5
  def initialize
8
6
  @spec = {
9
7
  "$schema": @schema,
@@ -28,6 +26,10 @@ module Vega
28
26
  Spec.new(spec).to_iruby
29
27
  end
30
28
 
29
+ def to_json
30
+ spec.to_json
31
+ end
32
+
31
33
  private
32
34
 
33
35
  def initialize_dup(*)
@@ -38,6 +40,7 @@ module Vega
38
40
 
39
41
  def data_value(value)
40
42
  value = value.to_a if defined?(Rover::DataFrame) && value.is_a?(Rover::DataFrame)
43
+ value = value.to_a[0] if defined?(Daru::DataFrame) && value.is_a?(Daru::DataFrame)
41
44
  case value
42
45
  when Array
43
46
  {values: value}
@@ -11,6 +11,8 @@ module Vega
11
11
  array_methods \
12
12
  :signals, :scales, :projections, :axes, :legends, :marks
13
13
 
14
+ attr_reader :spec
15
+
14
16
  def initialize
15
17
  @schema = "https://vega.github.io/schema/vega/v5.json"
16
18
  super()
@@ -2,13 +2,13 @@ module Vega
2
2
  class LiteChart < BaseChart
3
3
  # https://vega.github.io/vega-lite/docs/spec.html
4
4
  scalar_methods \
5
- :background, :padding, :autosize, :title, :name, :description, :width, :height, :mark
5
+ :background, :padding, :autosize, :title, :name, :description, :width, :height, :mark, :spec, :repeat
6
6
 
7
7
  hash_methods \
8
- :config, :usermeta, :projection, :datasets, :encoding
8
+ :config, :usermeta, :projection, :datasets, :encoding, :facet, :resolve, :selection, :view
9
9
 
10
10
  array_methods \
11
- :transform, :layer
11
+ :transform, :layer, :hconcat, :vconcat, :concat
12
12
 
13
13
  def initialize
14
14
  @schema = "https://vega.github.io/schema/vega-lite/v4.json"
@@ -20,5 +20,14 @@ module Vega
20
20
  self
21
21
  end
22
22
  immutable_method :data
23
+
24
+ undef spec
25
+ def spec(*args)
26
+ if args.empty?
27
+ @spec
28
+ else
29
+ dup.spec!(*args)
30
+ end
31
+ end
23
32
  end
24
33
  end
@@ -25,7 +25,8 @@ module Vega
25
25
  def array_methods(*methods)
26
26
  methods.each do |method|
27
27
  define_method("#{method}!") do |value|
28
- (@spec[method] ||= []) << value
28
+ value = [value] unless value.is_a?(Array)
29
+ (@spec[method] ||= []).push(*value)
29
30
  self
30
31
  end
31
32
  immutable_method(method)
@@ -1,3 +1,3 @@
1
1
  module Vega
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
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.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Kane
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-09-26 00:00:00.000000000 Z
11
+ date: 2020-09-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler