
Product
Introducing Webhook Events for Pull Request Scans
Add real-time Socket webhook events to your workflows to automatically receive pull request scan results and security alerts in real time.
react-vega-lite
Advanced tools
Convert Vega Lite spec into React class conveniently, inspired by this tutorial by @pbeshai
react-vega-lite: 1.x.x
was update with breaking changes to support Vega-Lite 2.0, which is still in beta.
If you are looking to use React with Vega Lite 1.x, please use react-vega-lite: 0.0.1
.
npm install vega vega-lite react-vega react-vega-lite --save
There are two approaches to use this libary.
import React, { PropTypes } from 'react';
import {createClassFromLiteSpec} from 'react-vega-lite';
export default createClassFromLiteSpec('BarChart', {
"description": "A simple bar chart with embedded data.",
"mark": "bar",
"encoding": {
"x": {"field": "a", "type": "ordinal"},
"y": {"field": "b", "type": "quantitative"}
}
});
import React from 'react';
import ReactDOM from 'react-dom';
import BarChart from './BarChart.js';
const barData = {
"values": [
{"a": "A","b": 20}, {"a": "B","b": 34}, {"a": "C","b": 55},
{"a": "D","b": 19}, {"a": "E","b": 40}, {"a": "F","b": 34},
{"a": "G","b": 91}, {"a": "H","b": 78}, {"a": "I","b": 25}
]
};
ReactDOM.render(
<BarChart data={barData} />,
document.getElementById('bar-container')
);
<VegaLite>
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 VegaLite from 'react-vega-lite';
const spec = {
"description": "A simple bar chart with embedded data.",
"mark": "bar",
"encoding": {
"x": {"field": "a", "type": "ordinal"},
"y": {"field": "b", "type": "quantitative"}
}
};
const barData = {
"values": [
{"a": "A","b": 20}, {"a": "B","b": 34}, {"a": "C","b": 55},
{"a": "D","b": 19}, {"a": "E","b": 40}, {"a": "F","b": 34},
{"a": "G","b": 91}, {"a": "H","b": 78}, {"a": "I","b": 25}
]
};
ReactDOM.render(
<VegaLite spec={spec} data={barData} />,
document.getElementById('bar-container')
);
React class VegaLite
and any output class from createClassFromLiteSpec
have these properties:
className:String
style:Object
width:Number
height:Number
padding:Object
renderer:String
logLevel:Number
background:String
enableHover:Boolean
data:Object
onSignalXXX
onNewView
onParseError
which are the same with react-vega
. Please refer to react-vega documentation.
Any class created from createClassFromLiteSpec
will have this function.
spec
You can pass the vega-tooltip
handler instance to the tooltip
property.
import { Handler } from 'vega-tooltip';
<VegaLite spec={spec} data={barData} tooltip={new Handler().call} />
FAQs
Convert Vega-lite spec into React class conveniently
We found that react-vega-lite demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 3 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.
Product
Add real-time Socket webhook events to your workflows to automatically receive pull request scan results and security alerts in real time.
Research
The Socket Threat Research Team uncovered malicious NuGet packages typosquatting the popular Nethereum project to steal wallet keys.
Product
A single platform for static analysis, secrets detection, container scanning, and CVE checks—built on trusted open source tools, ready to run out of the box.