ankane / vega-ruby Goto Github PK
View Code? Open in Web Editor NEWInteractive charts for Ruby, powered by Vega and Vega-Lite
License: BSD 3-Clause "New" or "Revised" License
Interactive charts for Ruby, powered by Vega and Vega-Lite
License: BSD 3-Clause "New" or "Revised" License
Ideas
importmap-rails
- importmap
branch (need to handle async loading)x
and y
for names?)Vega.lite.default_options = Vega.lite.config(...).embed_options(...).background(...)
iruby 0.7.4
ruby 3.0.4
vega-ruby 0.2.6
jupyter lab 3.3.2
Vega.lite
.data([{city: "A", sales: 28}, {city: "B", sales: 55}, {city: "C", sales: 43}])
.mark(type: "bar", tooltip: true)
.encoding(
x: {field: "city", type: "nominal"},
y: {field: "sales", type: "quantitative"}
)
This might be an issue of jupyterlab? Daruview with googlecharts renders fine.
The docs describe how to make API calls to set the data and then build up the chart configuration. Separately a whole chart can be configured using a Vega spec, which includes a data location.
Is there a way to configure a chart using a Vega spec, but make an API call to independently set the data?
Thanks!
Maybe related to Turbo, not sure, it happens when navigating to the page with charts from the homepage
= javascript_include_tag "admin", "data-turbo-track": "reload"
h1= t(".attendances")
= raw Stl.plot(Attendance.before_today.group_by_day(:created_at).count, Stl.decompose(Attendance.before_today.group_by_day(:created_at).count, period: 7))
h1(style="margin-top: 280px")= t(".users")
= raw Stl.plot(User.before_today.after_import.group_by_day(:created_at).count, Stl.decompose(User.before_today.after_import.group_by_day(:created_at).count, period: 7))
and in admin.js
//= require vega
//= require vega-lite
//= require vega-embed
Vega.lite
.data([{city: "A", sales: 28}, {city: "B", sales: 55}, {city: "C", sales: 43}])
.mark(type: "bar", tooltip: true)
.encoding(
x: {field: "city", type: "nominal"},
y: {field: "sales", type: "quantitative"}
)
RuntimeError: Command failed: npm ERR! canceled
npm ERR! A complete log of this run can be found in:
npm ERR! ~/.npm/_logs/2021-12-21T01_46_21_620Z-debug.log
~/.rvm/gems/ruby-2.6.6/gems/vega-0.2.3/lib/vega/base_chart.rb:65:in `export'
~/.rvm/gems/ruby-2.6.6/gems/vega-0.2.3/lib/vega/lite_chart.rb:38:in `to_svg'
~/.rvm/gems/ruby-2.6.6/gems/iruby-0.4.0/lib/iruby/display.rb:279:in `block in <module:Registry>'
~/.rvm/gems/ruby-2.6.6/gems/iruby-0.4.0/lib/iruby/display.rb:105:in `render'
~/.rvm/gems/ruby-2.6.6/gems/iruby-0.4.0/lib/iruby/display.rb:61:in `block in render'
~/.rvm/gems/ruby-2.6.6/gems/iruby-0.4.0/lib/iruby/display.rb:60:in `each'
~/.rvm/gems/ruby-2.6.6/gems/iruby-0.4.0/lib/iruby/display.rb:60:in `render'
~/.rvm/gems/ruby-2.6.6/gems/iruby-0.4.0/lib/iruby/display.rb:23:in `display'
~/.rvm/gems/ruby-2.6.6/gems/iruby-0.4.0/lib/iruby/kernel.rb:100:in `execute_request'
~/.rvm/gems/ruby-2.6.6/gems/iruby-0.4.0/lib/iruby/kernel.rb:49:in `dispatch'
~/.rvm/gems/ruby-2.6.6/gems/iruby-0.4.0/lib/iruby/kernel.rb:38:in `run'
~/.rvm/gems/ruby-2.6.6/gems/iruby-0.4.0/lib/iruby/command.rb:110:in `run_kernel'
~/.rvm/gems/ruby-2.6.6/gems/iruby-0.4.0/lib/iruby/command.rb:40:in `run'
~/.rvm/gems/ruby-2.6.6/gems/iruby-0.4.0/bin/iruby:5:in `<top (required)>'
~/.rvm/gems/ruby-2.6.6/bin/iruby:23:in `load'
~/.rvm/gems/ruby-2.6.6/bin/iruby:23:in `<main>'
~/.rvm/gems/ruby-2.6.6/bin/ruby_executable_hooks:24:in `eval'
~/.rvm/gems/ruby-2.6.6/bin/ruby_executable_hooks:24:in `<main>'
0 verbose cli [
0 verbose cli '/usr/local/Cellar/node/17.2.0/bin/node',
0 verbose cli '/usr/local/bin/npm',
0 verbose cli 'exec',
0 verbose cli '--no',
0 verbose cli '--package=vega-lite',
0 verbose cli '--',
0 verbose cli 'vl2svg'
0 verbose cli ]
1 info using [email protected]
2 info using [email protected]
3 timing npm:load:whichnode Completed in 0ms
4 timing config:load:defaults Completed in 1ms
5 timing config:load:file:/usr/local/lib/node_modules/npm/npmrc Completed in 1ms
6 timing config:load:builtin Completed in 1ms
7 timing config:load:cli Completed in 2ms
8 timing config:load:env Completed in 0ms
9 timing config:load:file:~/repos/app/.npmrc Completed in 1ms
10 timing config:load:project Completed in 2ms
11 timing config:load:file:~/.npmrc Completed in 0ms
12 timing config:load:user Completed in 0ms
13 timing config:load:file:/usr/local/etc/npmrc Completed in 0ms
14 timing config:load:global Completed in 0ms
15 timing config:load:validate Completed in 0ms
16 timing config:load:credentials Completed in 1ms
17 timing config:load:setEnvs Completed in 1ms
18 timing config:load Completed in 8ms
19 timing npm:load:configload Completed in 8ms
20 timing npm:load:setTitle Completed in 2ms
21 timing npm:load:setupLog Completed in 1ms
22 timing config:load:flatten Completed in 2ms
23 timing npm:load:cleanupLog Completed in 2ms
24 timing npm:load:configScope Completed in 0ms
25 timing npm:load:projectScope Completed in 0ms
26 timing npm:load Completed in 16ms
27 http fetch GET 200 https://registry.npmjs.org/vega-lite 126ms (cache revalidated)
28 timing arborist:ctor Completed in 1ms
29 timing arborist:ctor Completed in 0ms
30 timing command:exec Completed in 884ms
31 verbose stack Error: canceled
31 verbose stack at exec (/usr/local/lib/node_modules/npm/node_modules/libnpmexec/lib/index.js:154:17)
31 verbose stack at async module.exports (/usr/local/lib/node_modules/npm/lib/cli.js:65:5)
32 verbose cwd ~/repos/app/console
33 verbose Darwin 20.6.0
34 verbose argv "/usr/local/Cellar/node/17.2.0/bin/node" "/usr/local/bin/npm" "exec" "--no" "--package=vega-lite" "--" "vl2svg"
35 verbose node v17.2.0
36 verbose npm v8.1.4
37 error canceled
38 verbose exit 1
The gem works wonderful! Thanks for building it.
I just included it into a (static) Bridgetown-page.
Its worth to include the steps in the description
gem 'vega'
in Gemfilerequire 'vega'
in config/initializers. No plugin needed.frontend/javascript/config.js
Example for the frontmatter-approach
~~~ruby
{
layout: :home,
title: 'Übersicht',
vega: Vega.lite .data([{city: "A", sales: 28}, {city: "B", sales: 55}, {city: "C", sales: 43}])
.mark(type: "bar", tooltip: true)
.encoding( x: {field: "city", type: "nominal"},
y: {field: "sales", type: "quantitative"})
}
~~~
# title
<%= data.vega %>
In my impression, this is the easiest way to setup an example-page.
Hi,
first of all, thanks for the Gem, really clean and useful.
I am trying to use =layer=s and I am a bit lost on what to pass as argument. I tried to look at the code, to no avail.
Consider the following excerpt (from the Vega Light website):
"layer": [{
"mark": "bar"
},
{
"mark": {
"type": "text",
"align": "left",
"baseline": "middle",
"dx": 3
},
"encoding": {
"text": {"field": "b", "type": "quantitative"}
}
}]
}
when representing in Ruby, I thought I could do something like:
.layer([
Vega.lite.mark( { type: "bar" }),
Vega.lite.mark
...
])
but it does not work.
Any help really appreciated it.
Thanks again!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.