Footer.jsx 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  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 withStyles from 'material-ui/styles/withStyles';
  19. import Typography from 'material-ui/Typography';
  20. import Grid from 'material-ui/Grid';
  21. import {ResponsiveContainer, AreaChart, Area, Tooltip} from 'recharts';
  22. import ChartRow from './ChartRow';
  23. import CustomTooltip, {bytePlotter, bytePerSecPlotter, percentPlotter, multiplier} from './CustomTooltip';
  24. import {styles as commonStyles} from '../common';
  25. import type {General, System} from '../types/content';
  26. const FOOTER_SYNC_ID = 'footerSyncId';
  27. const CPU = 'cpu';
  28. const MEMORY = 'memory';
  29. const DISK = 'disk';
  30. const TRAFFIC = 'traffic';
  31. const TOP = 'Top';
  32. const BOTTOM = 'Bottom';
  33. // styles contains the constant styles of the component.
  34. const styles = {
  35. footer: {
  36. maxWidth: '100%',
  37. flexWrap: 'nowrap',
  38. margin: 0,
  39. },
  40. chartRowWrapper: {
  41. height: '100%',
  42. padding: 0,
  43. },
  44. doubleChartWrapper: {
  45. height: '100%',
  46. width: '99%',
  47. },
  48. };
  49. // themeStyles returns the styles generated from the theme for the component.
  50. const themeStyles: Object = (theme: Object) => ({
  51. footer: {
  52. backgroundColor: theme.palette.grey[900],
  53. color: theme.palette.getContrastText(theme.palette.grey[900]),
  54. zIndex: theme.zIndex.appBar,
  55. height: theme.spacing.unit * 10,
  56. },
  57. });
  58. export type Props = {
  59. classes: Object, // injected by withStyles()
  60. theme: Object,
  61. general: General,
  62. system: System,
  63. shouldUpdate: Object,
  64. };
  65. // Footer renders the footer of the dashboard.
  66. class Footer extends Component<Props> {
  67. shouldComponentUpdate(nextProps) {
  68. return typeof nextProps.shouldUpdate.general !== 'undefined' || typeof nextProps.shouldUpdate.system !== 'undefined';
  69. }
  70. // halfHeightChart renders an area chart with half of the height of its parent.
  71. halfHeightChart = (chartProps, tooltip, areaProps) => (
  72. <ResponsiveContainer width='100%' height='50%'>
  73. <AreaChart {...chartProps} >
  74. {!tooltip || (<Tooltip cursor={false} content={<CustomTooltip tooltip={tooltip} />} />)}
  75. <Area isAnimationActive={false} type='monotone' {...areaProps} />
  76. </AreaChart>
  77. </ResponsiveContainer>
  78. );
  79. // doubleChart renders a pair of charts separated by the baseline.
  80. doubleChart = (syncId, chartKey, topChart, bottomChart) => {
  81. if (!Array.isArray(topChart.data) || !Array.isArray(bottomChart.data)) {
  82. return null;
  83. }
  84. const topDefault = topChart.default || 0;
  85. const bottomDefault = bottomChart.default || 0;
  86. const topKey = `${chartKey}${TOP}`;
  87. const bottomKey = `${chartKey}${BOTTOM}`;
  88. const topColor = '#8884d8';
  89. const bottomColor = '#82ca9d';
  90. return (
  91. <div style={styles.doubleChartWrapper}>
  92. {this.halfHeightChart(
  93. {
  94. syncId,
  95. data: topChart.data.map(({value}) => ({[topKey]: value || topDefault})),
  96. margin: {top: 5, right: 5, bottom: 0, left: 5},
  97. },
  98. topChart.tooltip,
  99. {dataKey: topKey, stroke: topColor, fill: topColor},
  100. )}
  101. {this.halfHeightChart(
  102. {
  103. syncId,
  104. data: bottomChart.data.map(({value}) => ({[bottomKey]: -value || -bottomDefault})),
  105. margin: {top: 0, right: 5, bottom: 5, left: 5},
  106. },
  107. bottomChart.tooltip,
  108. {dataKey: bottomKey, stroke: bottomColor, fill: bottomColor},
  109. )}
  110. </div>
  111. );
  112. };
  113. render() {
  114. const {general, system} = this.props;
  115. return (
  116. <Grid container className={this.props.classes.footer} direction='row' alignItems='center' style={styles.footer}>
  117. <Grid item xs style={styles.chartRowWrapper}>
  118. <ChartRow>
  119. {this.doubleChart(
  120. FOOTER_SYNC_ID,
  121. CPU,
  122. {data: system.processCPU, tooltip: percentPlotter('Process load')},
  123. {data: system.systemCPU, tooltip: percentPlotter('System load', multiplier(-1))},
  124. )}
  125. {this.doubleChart(
  126. FOOTER_SYNC_ID,
  127. MEMORY,
  128. {data: system.activeMemory, tooltip: bytePlotter('Active memory')},
  129. {data: system.virtualMemory, tooltip: bytePlotter('Virtual memory', multiplier(-1))},
  130. )}
  131. {this.doubleChart(
  132. FOOTER_SYNC_ID,
  133. DISK,
  134. {data: system.diskRead, tooltip: bytePerSecPlotter('Disk read')},
  135. {data: system.diskWrite, tooltip: bytePerSecPlotter('Disk write', multiplier(-1))},
  136. )}
  137. {this.doubleChart(
  138. FOOTER_SYNC_ID,
  139. TRAFFIC,
  140. {data: system.networkIngress, tooltip: bytePerSecPlotter('Download')},
  141. {data: system.networkEgress, tooltip: bytePerSecPlotter('Upload', multiplier(-1))},
  142. )}
  143. </ChartRow>
  144. </Grid>
  145. <Grid item >
  146. <Typography type='caption' color='inherit'>
  147. <span style={commonStyles.light}>Geth</span> {general.version}
  148. </Typography>
  149. {general.commit && (
  150. <Typography type='caption' color='inherit'>
  151. <span style={commonStyles.light}>{'Commit '}</span>
  152. <a href={`https://github.com/ethereum/go-ethereum/commit/${general.commit}`} target='_blank' style={{color: 'inherit', textDecoration: 'none'}} >
  153. {general.commit.substring(0, 8)}
  154. </a>
  155. </Typography>
  156. )}
  157. </Grid>
  158. </Grid>
  159. );
  160. }
  161. }
  162. export default withStyles(themeStyles)(Footer);