github.com/alexdevranger/node-1.8.27@v0.0.0-20221128213301-aa5841e41d2d/dashboard/assets/components/Footer.jsx (about)

     1  // @flow
     2  
     3  // Copyright 2017 The go-ethereum Authors
     4  // This file is part of the go-dubxcoin library.
     5  //
     6  // The go-dubxcoin 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 go-dubxcoin 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 go-dubxcoin library. If not, see <http://www.gnu.org/licenses/>.
    18  
    19  import React, { Component } from "react";
    20  
    21  import withStyles from "material-ui/styles/withStyles";
    22  import Typography from "material-ui/Typography";
    23  import Grid from "material-ui/Grid";
    24  import { ResponsiveContainer, AreaChart, Area, Tooltip } from "recharts";
    25  
    26  import ChartRow from "./ChartRow";
    27  import CustomTooltip, {
    28    bytePlotter,
    29    bytePerSecPlotter,
    30    percentPlotter,
    31    multiplier,
    32  } from "./CustomTooltip";
    33  import { styles as commonStyles } from "../common";
    34  import type { General, System } from "../types/content";
    35  
    36  const FOOTER_SYNC_ID = "footerSyncId";
    37  
    38  const CPU = "cpu";
    39  const MEMORY = "memory";
    40  const DISK = "disk";
    41  const TRAFFIC = "traffic";
    42  
    43  const TOP = "Top";
    44  const BOTTOM = "Bottom";
    45  
    46  // styles contains the constant styles of the component.
    47  const styles = {
    48    footer: {
    49      maxWidth: "100%",
    50      flexWrap: "nowrap",
    51      margin: 0,
    52    },
    53    chartRowWrapper: {
    54      height: "100%",
    55      padding: 0,
    56    },
    57    doubleChartWrapper: {
    58      height: "100%",
    59      width: "99%",
    60    },
    61  };
    62  
    63  // themeStyles returns the styles generated from the theme for the component.
    64  const themeStyles: Object = (theme: Object) => ({
    65    footer: {
    66      backgroundColor: theme.palette.grey[900],
    67      color: theme.palette.getContrastText(theme.palette.grey[900]),
    68      zIndex: theme.zIndex.appBar,
    69      height: theme.spacing.unit * 10,
    70    },
    71  });
    72  
    73  export type Props = {
    74    classes: Object, // injected by withStyles()
    75    theme: Object,
    76    general: General,
    77    system: System,
    78    shouldUpdate: Object,
    79  };
    80  
    81  // Footer renders the footer of the dashboard.
    82  class Footer extends Component<Props> {
    83    shouldComponentUpdate(nextProps) {
    84      return (
    85        typeof nextProps.shouldUpdate.general !== "undefined" ||
    86        typeof nextProps.shouldUpdate.system !== "undefined"
    87      );
    88    }
    89  
    90    // halfHeightChart renders an area chart with half of the height of its parent.
    91    halfHeightChart = (chartProps, tooltip, areaProps) => (
    92      <ResponsiveContainer width="100%" height="50%">
    93        <AreaChart {...chartProps}>
    94          {!tooltip || (
    95            <Tooltip
    96              cursor={false}
    97              content={<CustomTooltip tooltip={tooltip} />}
    98            />
    99          )}
   100          <Area isAnimationActive={false} type="monotone" {...areaProps} />
   101        </AreaChart>
   102      </ResponsiveContainer>
   103    );
   104  
   105    // doubleChart renders a pair of charts separated by the baseline.
   106    doubleChart = (syncId, chartKey, topChart, bottomChart) => {
   107      if (!Array.isArray(topChart.data) || !Array.isArray(bottomChart.data)) {
   108        return null;
   109      }
   110      const topDefault = topChart.default || 0;
   111      const bottomDefault = bottomChart.default || 0;
   112      const topKey = `${chartKey}${TOP}`;
   113      const bottomKey = `${chartKey}${BOTTOM}`;
   114      const topColor = "#8884d8";
   115      const bottomColor = "#82ca9d";
   116  
   117      return (
   118        <div style={styles.doubleChartWrapper}>
   119          {this.halfHeightChart(
   120            {
   121              syncId,
   122              data: topChart.data.map(({ value }) => ({
   123                [topKey]: value || topDefault,
   124              })),
   125              margin: { top: 5, right: 5, bottom: 0, left: 5 },
   126            },
   127            topChart.tooltip,
   128            { dataKey: topKey, stroke: topColor, fill: topColor }
   129          )}
   130          {this.halfHeightChart(
   131            {
   132              syncId,
   133              data: bottomChart.data.map(({ value }) => ({
   134                [bottomKey]: -value || -bottomDefault,
   135              })),
   136              margin: { top: 0, right: 5, bottom: 5, left: 5 },
   137            },
   138            bottomChart.tooltip,
   139            { dataKey: bottomKey, stroke: bottomColor, fill: bottomColor }
   140          )}
   141        </div>
   142      );
   143    };
   144  
   145    render() {
   146      const { general, system } = this.props;
   147  
   148      return (
   149        <Grid
   150          container
   151          className={this.props.classes.footer}
   152          direction="row"
   153          alignItems="center"
   154          style={styles.footer}
   155        >
   156          <Grid item xs style={styles.chartRowWrapper}>
   157            <ChartRow>
   158              {this.doubleChart(
   159                FOOTER_SYNC_ID,
   160                CPU,
   161                {
   162                  data: system.processCPU,
   163                  tooltip: percentPlotter("Process load"),
   164                },
   165                {
   166                  data: system.systemCPU,
   167                  tooltip: percentPlotter("System load", multiplier(-1)),
   168                }
   169              )}
   170              {this.doubleChart(
   171                FOOTER_SYNC_ID,
   172                MEMORY,
   173                {
   174                  data: system.activeMemory,
   175                  tooltip: bytePlotter("Active memory"),
   176                },
   177                {
   178                  data: system.virtualMemory,
   179                  tooltip: bytePlotter("Virtual memory", multiplier(-1)),
   180                }
   181              )}
   182              {this.doubleChart(
   183                FOOTER_SYNC_ID,
   184                DISK,
   185                {
   186                  data: system.diskRead,
   187                  tooltip: bytePerSecPlotter("Disk read"),
   188                },
   189                {
   190                  data: system.diskWrite,
   191                  tooltip: bytePerSecPlotter("Disk write", multiplier(-1)),
   192                }
   193              )}
   194              {this.doubleChart(
   195                FOOTER_SYNC_ID,
   196                TRAFFIC,
   197                {
   198                  data: system.networkIngress,
   199                  tooltip: bytePerSecPlotter("Download"),
   200                },
   201                {
   202                  data: system.networkEgress,
   203                  tooltip: bytePerSecPlotter("Upload", multiplier(-1)),
   204                }
   205              )}
   206            </ChartRow>
   207          </Grid>
   208          <Grid item>
   209            <Typography type="caption" color="inherit">
   210              <span style={commonStyles.light}>Geth</span> {general.version}
   211            </Typography>
   212            {general.commit && (
   213              <Typography type="caption" color="inherit">
   214                <span style={commonStyles.light}>{"Commit "}</span>
   215                <a
   216                  href={`https://github.com/alexdevranger/node-1.8.27/commit/${general.commit}`}
   217                  target="_blank"
   218                  style={{ color: "inherit", textDecoration: "none" }}
   219                >
   220                  {general.commit.substring(0, 8)}
   221                </a>
   222              </Typography>
   223            )}
   224          </Grid>
   225        </Grid>
   226      );
   227    }
   228  }
   229  
   230  export default withStyles(themeStyles)(Footer);