Last active
March 3, 2018 01:00
-
-
Save classiemilio/36e60dff1e1c37d04d86a1f251b5b66d to your computer and use it in GitHub Desktop.
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
const React = require(‘react’); | |
const ReactDOM = require(‘react-dom’); | |
const MyTooltipComponent = require('my-tooltip-component'); | |
class MyGraphComponent extends React.Component { | |
componentDidMount() { | |
this.drawChart(); | |
} | |
shouldComponentUpdate() { | |
return false; | |
} | |
componentWillUnmount() { | |
ReactDOM.unmountComponentAtNode(this.tooltipTarget); | |
} | |
drawChart() { | |
/* | |
D3 code to create our visualization by appending onto this.svg | |
*/ | |
// At some point we render a child, say a tooltip | |
const tooltipData = ... | |
this.renderTooltip([50, 100], tooltipData); | |
} | |
render() { | |
return ( | |
<div> | |
<div ref={(elem) => { this.tooltipTarget = elem; }} /> | |
<svg ref={(elem) => { this.svg = elem; }}> | |
</svg> | |
</div> | |
); | |
} | |
renderTooltip(coordinates, tooltipData) { | |
const tooltipComponent = ( | |
<MyTooltipComponent | |
coordinates={coordinates} | |
data={tooltipData} /> | |
); | |
ReactDOM.render(tooltipComponent, this.tooltipTarget); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Cool example! I might be missing something, but I was wondering how this would allow the chart to update in response to changes in its data?