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