This repository has been archived by the owner on May 3, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
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
9 changed files
with
364 additions
and
95 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
.Vega { | ||
|
||
} | ||
.vega-actions { | ||
display: none; | ||
} |
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 |
---|---|---|
@@ -1,14 +1,54 @@ | ||
import React from 'react'; | ||
import vegaEmbed from 'vega-embed'; | ||
import './index.css'; | ||
|
||
export default class VegaComponent extends React.Component { | ||
const DEFAULT_WIDTH = 500; | ||
const DEFAULT_HEIGHT = DEFAULT_WIDTH / 1.5; | ||
|
||
render() { | ||
return ( | ||
<div className="Vega"> | ||
{JSON.stringify(this.props.data)} | ||
</div> | ||
); | ||
export default class Vega extends React.Component { | ||
|
||
static defaultProps = { | ||
renderedCallback: () => ({}), | ||
embedMode: 'vega-lite' | ||
}; | ||
|
||
componentDidMount() { | ||
this.embed( | ||
this.el, | ||
this.props.data, | ||
this.props.embedMode, | ||
this.props.renderedCallback | ||
); | ||
} | ||
|
||
shouldComponentUpdate(nextProps) { | ||
return this.props.data !== nextProps.data; | ||
} | ||
|
||
componentDidUpdate() { | ||
this.embed( | ||
this.el, | ||
this.props.data, | ||
this.props.embedMode, | ||
this.props.renderedCallback | ||
); | ||
} | ||
|
||
render() { | ||
return <div ref={el => this.el = el} />; | ||
} | ||
|
||
embed = (el, spec, mode, cb) => { | ||
const embedSpec = { mode, spec }; | ||
const width = DEFAULT_WIDTH; | ||
const height = DEFAULT_HEIGHT; | ||
if (mode === 'vega-lite') { | ||
embedSpec.spec.config = { | ||
...embedSpec.spec.config, | ||
cell: { width, height } | ||
}; | ||
} | ||
vegaEmbed(el, embedSpec, cb); | ||
} | ||
|
||
} |
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 |
---|---|---|
|
@@ -13,6 +13,10 @@ | |
"author": "Grant Nestor <[email protected]>", | ||
"license": "ISC", | ||
"dependencies": { | ||
"react": "^15.3.2" | ||
"d3": "3.5.17", | ||
"react": "^15.3.2", | ||
"vega": "^2.6.1", | ||
"vega-embed": "^2.2.0", | ||
"vega-lite": "^1.1.3" | ||
} | ||
} |
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
Oops, something went wrong.