Home.jsx 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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 withTheme from 'material-ui/styles/withTheme';
  19. import {LineChart, AreaChart, Area, YAxis, CartesianGrid, Line} from 'recharts';
  20. import ChartGrid from './ChartGrid';
  21. import type {ChartEntry} from '../types/content';
  22. export type Props = {
  23. theme: Object,
  24. memory: Array<ChartEntry>,
  25. traffic: Array<ChartEntry>,
  26. shouldUpdate: Object,
  27. };
  28. // Home renders the home content.
  29. class Home extends Component<Props> {
  30. constructor(props: Props) {
  31. super(props);
  32. const {theme} = props; // The theme property is injected by withTheme().
  33. this.memoryColor = theme.palette.primary[300];
  34. this.trafficColor = theme.palette.secondary[300];
  35. }
  36. shouldComponentUpdate(nextProps) {
  37. return typeof nextProps.shouldUpdate.home !== 'undefined';
  38. }
  39. memoryColor: Object;
  40. trafficColor: Object;
  41. render() {
  42. let {memory, traffic} = this.props;
  43. memory = memory.map(({value}) => (value || 0));
  44. traffic = traffic.map(({value}) => (value || 0));
  45. return (
  46. <ChartGrid spacing={24}>
  47. <AreaChart xs={6} height={300} values={memory}>
  48. <YAxis />
  49. <Area type="monotone" dataKey="value" stroke={this.memoryColor} fill={this.memoryColor} />
  50. </AreaChart>
  51. <LineChart xs={6} height={300} values={traffic}>
  52. <Line type="monotone" dataKey="value" stroke={this.trafficColor} dot={false} />
  53. </LineChart>
  54. <LineChart xs={6} height={300} values={memory}>
  55. <YAxis />
  56. <CartesianGrid stroke="#eee" strokeDasharray="5 5" />
  57. <Line type="monotone" dataKey="value" stroke={this.memoryColor} dot={false} />
  58. </LineChart>
  59. <AreaChart xs={6} height={300} values={traffic}>
  60. <CartesianGrid stroke="#eee" strokeDasharray="5 5" vertical={false} />
  61. <Area type="monotone" dataKey="value" stroke={this.trafficColor} fill={this.trafficColor} />
  62. </AreaChart>
  63. </ChartGrid>
  64. );
  65. }
  66. }
  67. export default withTheme()(Home);