Home.jsx 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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/message';
  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 nextProps.shouldUpdate.has('memory') || nextProps.shouldUpdate.has('traffic');
  38. }
  39. render() {
  40. const {memory, traffic} = this.props;
  41. return (
  42. <ChartGrid spacing={24}>
  43. <AreaChart xs={6} height={300} values={memory}>
  44. <YAxis />
  45. <Area type="monotone" dataKey="value" stroke={this.memoryColor} fill={this.memoryColor} />
  46. </AreaChart>
  47. <LineChart xs={6} height={300} values={traffic}>
  48. <Line type="monotone" dataKey="value" stroke={this.trafficColor} dot={false} />
  49. </LineChart>
  50. <LineChart xs={6} height={300} values={memory}>
  51. <YAxis />
  52. <CartesianGrid stroke="#eee" strokeDasharray="5 5" />
  53. <Line type="monotone" dataKey="value" stroke={this.memoryColor} dot={false} />
  54. </LineChart>
  55. <AreaChart xs={6} height={300} values={traffic}>
  56. <CartesianGrid stroke="#eee" strokeDasharray="5 5" vertical={false} />
  57. <Area type="monotone" dataKey="value" stroke={this.trafficColor} fill={this.trafficColor} />
  58. </AreaChart>
  59. </ChartGrid>
  60. );
  61. }
  62. }
  63. export default withTheme()(Home);