ChartGrid.jsx 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. // @flow
  2. // Copyright 2017 The go-ethereum Authors
  3. // This file is part of the go-ethereum library.
  4. //
  5. // The go-ethereum library is free software: you can redistribute it and/or modify
  6. // it under the terms of the GNU Lesser General Public License as published by
  7. // the Free Software Foundation, either version 3 of the License, or
  8. // (at your option) any later version.
  9. //
  10. // The go-ethereum library is distributed in the hope that it will be useful,
  11. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. // GNU Lesser General Public License for more details.
  14. //
  15. // You should have received a copy of the GNU Lesser General Public License
  16. // along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
  17. import React, {Component} from 'react';
  18. import type {Node} from 'react';
  19. import Grid from 'material-ui/Grid';
  20. import {ResponsiveContainer} from 'recharts';
  21. export type Props = {
  22. spacing: number,
  23. children: Node,
  24. };
  25. // ChartGrid renders a grid container for responsive charts.
  26. // The children are Recharts components extended with the Material-UI's xs property.
  27. class ChartGrid extends Component<Props> {
  28. render() {
  29. return (
  30. <Grid container spacing={this.props.spacing}>
  31. {
  32. React.Children.map(this.props.children, child => (
  33. <Grid item xs={child.props.xs}>
  34. <ResponsiveContainer width="100%" height={child.props.height}>
  35. {React.cloneElement(child, {data: child.props.values.map(value => ({value}))})}
  36. </ResponsiveContainer>
  37. </Grid>
  38. ))
  39. }
  40. </Grid>
  41. );
  42. }
  43. }
  44. export default ChartGrid;