Skip to content

Instantly share code, notes, and snippets.

@petebrowne
Last active June 11, 2016 17:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save petebrowne/c32b1c7f44b159b41a8fd7318ef84180 to your computer and use it in GitHub Desktop.
Save petebrowne/c32b1c7f44b159b41a8fd7318ef84180 to your computer and use it in GitHub Desktop.
class App extends React.Component {
render() {
// For a real world project, use something like
// https://github.com/digidem/react-dimensions
let width = window.innerWidth;
let height = window.innerHeight;
let minViewportSize = Math.min(width, height);
// This sets the radius of the pie chart to fit within
// the current window size, with some additional padding
let radius = (minViewportSize * .9) / 2;
// Centers the pie chart
let x = width / 2;
let y = height / 2;
return (
<svg width="100%" height="100%">
{/* We'll create this component in a minute */}
<Pie x={x} y={y} radius={radius} data={this.props.data} />
</svg>
);
}
}
ReactDOM.render(
// App takes one prop: the pie chart data as an array of values
<App data={[5, 2, 7, 1, 1, 3, 4, 9]} />,
document.getElementById('app')
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment