vega 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/README.md +65 -23
- data/lib/vega/base_chart.rb +5 -2
- data/lib/vega/chart.rb +2 -0
- data/lib/vega/lite_chart.rb +12 -3
- data/lib/vega/method_helpers.rb +2 -1
- data/lib/vega/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 854e0601118f529798b5850bc36babaff268a6df96932da17c3e3f9f96330234
|
4
|
+
data.tar.gz: 50359706b33864f64a18e0db734eb4c3209b6f225aabaab3553cf6bfd583219f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 388eab29e442fcf3a33788b0a59522be829ef43dd5a56a7fd06a0f803c929be6bae6b72421ad2dc11cecb8ba3382d7e445ba4f2d822577a6f2622328911e70c7
|
7
|
+
data.tar.gz: 683e03f32841bf0605c310cd31fd545ca2110f8c85b46a10391e90204676ac08e8b7b753061d14f9f27758b208daa06f0039b5786367b27e4a2b95651f0cb6ea
|
data/CHANGELOG.md
CHANGED
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: "
|
97
|
-
y: {field: "
|
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
|
-
|
111
|
+
Data can be an array
|
120
112
|
|
121
113
|
```ruby
|
122
|
-
data(
|
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(
|
120
|
+
data("https://www.example.com/data.json")
|
129
121
|
```
|
130
122
|
|
131
|
-
|
123
|
+
Or a Rover data frame
|
132
124
|
|
133
125
|
```ruby
|
134
|
-
data(
|
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
|
-
###
|
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
|
|
data/lib/vega/base_chart.rb
CHANGED
@@ -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}
|
data/lib/vega/chart.rb
CHANGED
data/lib/vega/lite_chart.rb
CHANGED
@@ -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
|
data/lib/vega/method_helpers.rb
CHANGED
@@ -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
|
-
|
28
|
+
value = [value] unless value.is_a?(Array)
|
29
|
+
(@spec[method] ||= []).push(*value)
|
29
30
|
self
|
30
31
|
end
|
31
32
|
immutable_method(method)
|
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.1.
|
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-
|
11
|
+
date: 2020-09-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|