-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
205 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
{ | ||
"name": "react-vega-lite", | ||
"version": "3.0.0", | ||
"description": "Convert Vega-lite spec into React class conveniently", | ||
"author": "Krist Wongsuphasawat <krist.wongz@gmail.com> (http://kristw.yellowpigz.com)", | ||
"keywords": [], | ||
"repository": "git@github.com:vega/react-vega.git", | ||
"bugs": { | ||
"url": "https://github.com/vega/react-vega/issues" | ||
}, | ||
"sideEffects": false, | ||
"main": "lib/index.js", | ||
"module": "esm/index.js", | ||
"files": [ | ||
"src", | ||
"esm", | ||
"lib", | ||
"types" | ||
], | ||
"dependencies": { | ||
"react-vega": "^6.0.0" | ||
}, | ||
"peerDependencies": { | ||
"react": "^16.0.0", | ||
"vega-lite": "^3.1.0" | ||
}, | ||
"license": "Apache-2.0", | ||
"publishConfig": { | ||
"access": "public" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
{ | ||
"name": "react-vega", | ||
"version": "6.0.0", | ||
"description": "Convert Vega spec into React class conveniently", | ||
"author": "Krist Wongsuphasawat <krist.wongz@gmail.com> (http://kristw.yellowpigz.com)", | ||
"keywords": [], | ||
"repository": "git@github.com:vega/react-vega.git", | ||
"bugs": { | ||
"url": "https://github.com/vega/react-vega/issues" | ||
}, | ||
"sideEffects": false, | ||
"main": "lib/index.js", | ||
"module": "esm/index.js", | ||
"files": [ | ||
"src", | ||
"esm", | ||
"lib", | ||
"types" | ||
], | ||
"dependencies": { | ||
"prop-types": "^15.7.2" | ||
}, | ||
"peerDependencies": { | ||
"react": "^16.0.0", | ||
"vega": "^5.3.4" | ||
}, | ||
"license": "Apache-2.0", | ||
"publishConfig": { | ||
"access": "public" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
import React from 'react'; | ||
import VegaLite, { createClassFromLiteSpec } from '../packages/react-vega-lite'; | ||
|
||
const data1 = { | ||
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 }, | ||
], | ||
}; | ||
|
||
const data2 = { | ||
values: [ | ||
{ a: 'A', b: 28 }, | ||
{ a: 'B', b: 55 }, | ||
{ a: 'C', b: 43 }, | ||
{ a: 'D', b: 91 }, | ||
{ a: 'E', b: 81 }, | ||
{ a: 'F', b: 53 }, | ||
{ a: 'G', b: 19 }, | ||
{ a: 'H', b: 87 }, | ||
{ a: 'I', b: 52 }, | ||
], | ||
}; | ||
|
||
const spec1 = { | ||
description: 'A simple bar chart with embedded data.', | ||
encoding: { | ||
x: { field: 'a', type: 'ordinal' }, | ||
y: { field: 'b', type: 'quantitative' }, | ||
}, | ||
mark: 'bar', | ||
}; | ||
|
||
const spec2 = { | ||
description: 'A simple bar chart with embedded data.', | ||
encoding: { | ||
x: { field: 'b', type: 'quantitative' }, | ||
y: { field: 'a', type: 'ordinal' }, | ||
}, | ||
mark: 'bar', | ||
}; | ||
|
||
const BarChart = createClassFromLiteSpec(spec1); | ||
|
||
const code1 = `<VegaLite data={this.state.data} spec={this.state.spec} />`; | ||
|
||
const code2 = `const BarChart = ReactVegaLite.createClassFromLiteSpec(spec1); | ||
<BarChart data={this.state.data} />`; | ||
|
||
export default class Demo extends React.Component { | ||
constructor(props) { | ||
super(props); | ||
this.state = { | ||
data: data1, | ||
info: '', | ||
spec: spec1, | ||
}; | ||
|
||
this.handleHover = this.handleHover.bind(this); | ||
this.handleToggleSpec = this.handleToggleSpec.bind(this); | ||
this.handleUpdateData = this.handleUpdateData.bind(this); | ||
} | ||
|
||
handleHover(...args) { | ||
this.setState({ | ||
info: JSON.stringify(args), | ||
}); | ||
} | ||
|
||
handleToggleSpec() { | ||
const { spec } = this.state; | ||
if (spec === spec1) { | ||
this.setState({ spec: spec2 }); | ||
} else { | ||
this.setState({ spec: spec1 }); | ||
} | ||
} | ||
|
||
handleUpdateData() { | ||
const { data } = this.state; | ||
if (data === data1) { | ||
this.setState({ data: data2 }); | ||
} else if (data === data2) { | ||
this.setState({ data: data1 }); | ||
} | ||
} | ||
|
||
render() { | ||
const { data, spec, info } = this.state; | ||
|
||
return ( | ||
<div> | ||
<div style={{ float: 'right' }}> | ||
<iframe | ||
title="star" | ||
src="https://ghbtns.com/github-btn.html?user=vega&repo=react-vega&type=star&count=true" | ||
frameBorder="0" | ||
scrolling="0" | ||
width="100px" | ||
height="20px" | ||
/> | ||
</div> | ||
<button type="button" onClick={this.handleToggleSpec}> | ||
Toggle Spec | ||
</button> | ||
<button type="button" onClick={this.handleUpdateData}> | ||
Update data | ||
</button> | ||
<h3> | ||
<code><VegaLite></code> React Component | ||
</h3> | ||
Will recompile when spec changes and update when data changes. | ||
<pre>{code1}</pre> | ||
<VegaLite data={data} spec={spec} onSignalHover={this.handleHover} /> | ||
<h3> | ||
<code>ReactVegaLite.createClassFromLiteSpec()</code> | ||
</h3> | ||
Use the given spec to create a reusable component. | ||
<pre>{code2}</pre> | ||
<BarChart data={data} onSignalHover={this.handleHover} /> | ||
{info} | ||
</div> | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters