
Security News
vlt Launches "reproduce": A New Tool Challenging the Limits of Package Provenance
vlt's new "reproduce" tool verifies npm packages against their source code, outperforming traditional provenance adoption in the JavaScript ecosystem.
react-vega
Advanced tools
Convert Vega spec into React class conveniently, inspired by this tutorial by @pbeshai
react-vega: 4.x.x
has same interface with 3.x.x
except it uses the lightweight vega-lib
instead of vega
.
react-vega: 3.x.x
was update with breaking changes to support Vega 3.0.
If you are looking to use React with Vega 2.x, please use react-vega: 2.3.1
.
npm install react vega-lib react-vega --save
There are two approaches to use this libary.
See the rest of the spec in spec1.js.
import React, { PropTypes } from 'react';
import {createClassFromSpec} from 'react-vega';
export default createClassFromSpec('BarChart', {
"width": 400,
"height": 200,
"data": [{ "name": "table" }],
"signals": [
{
"name": "tooltip",
"value": {},
"on": [
{"events": "rect:mouseover", "update": "datum"},
{"events": "rect:mouseout", "update": "{}"}
]
}
],
... // See the rest in demo/src/vega/spec1.js
});
import React from 'react';
import ReactDOM from 'react-dom';
import BarChart from './BarChart.js';
const barData = {
table: [...]
};
function handleHover(...args){
console.log(args);
}
ReactDOM.render(
<BarChart data={barData} onSignalHover={handleHover}/>,
document.getElementById('bar-container')
);
<Vega>
generic class and pass in spec
for dynamic component.Provides a bit more flexibility, but at the cost of extra checks for spec changes.
import React from 'react';
import ReactDOM from 'react-dom';
import Vega from 'react-vega';
const spec = {
"width": 400,
"height": 200,
"data": [{ "name": "table" }],
"signals": [
{
"name": "tooltip",
"value": {},
"on": [
{"events": "rect:mouseover", "update": "datum"},
{"events": "rect:mouseout", "update": "{}"}
]
}
],
... // See the rest in demo/src/vega/spec1.js
}
const barData = {
table: [...]
};
function handleHover(...args){
console.log(args);
}
ReactDOM.render(
<Vega spec={spec} data={barData} onSignalHover={handleHover}/>,
document.getElementById('bar-container')
);
React class Vega
and any output class from createClassFromSpec
have these properties:
view.hover()
For data
, this property takes an Object with keys being dataset names defined in the spec's data field, such as:
var barData = {
table: [{"x": 1, "y": 28}, {"x": 2, "y": 55}, ...]
};
Each value can be an array or function(dataset){...}
. If the value is a function, Vega's vis.data(dataName)
will be passed as the argument dataset
.
var barData = {
table: function(dataset){...}
};
In the example above, vis.data('table')
will be passed as dataset
.
All signals defined in the spec can be listened to via these properties.
For example, to listen to signal hover, attach a listener to onSignal+capitalize('hover')
<Vega spec={spec} data={barData} onSignalHover={handleHover}/>
Any class created from createClassFromSpec
will have this method.
spec
© 2016-2017 Krist Wongsuphasawat (@kristw) Apache-2.0 License
FAQs
Convert Vega spec into React class conveniently
The npm package react-vega receives a total of 31,990 weekly downloads. As such, react-vega popularity was classified as popular.
We found that react-vega demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 4 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
vlt's new "reproduce" tool verifies npm packages against their source code, outperforming traditional provenance adoption in the JavaScript ecosystem.
Research
Security News
Socket researchers uncovered a malicious PyPI package exploiting Deezer’s API to enable coordinated music piracy through API abuse and C2 server control.
Research
The Socket Research Team discovered a malicious npm package, '@ton-wallet/create', stealing cryptocurrency wallet keys from developers and users in the TON ecosystem.