recharts#Brush JavaScript Examples

The following examples show how to use recharts#Brush. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RtcMetricsView.jsx    From amazon-connect-snippets with MIT No Attribution 3 votes vote down vote up
render() {
        const {
            classes, className: classNameProp,
            type, timeRange, indexRange: [startIndex, endIndex],
        } = this.props;
        const {
            data, originalData,
            brushHovering, refAreaLeft, refAreaRight,
        } = this.state;

        return (
            <div className={clsx(classes.root, classNameProp)}>
                <Container
                    title={`WebRTC Metrics - ${type}`}
                    gutters={false}
                    actionGroup={(
                        <Button
                            className={classes.zoomResetButton}
                            onClick={this.handleZoomReset}
                        >
                            Zoom Reset
                        </Button>
                    )}
                >

                    <div className={classes.content}>

                        {/* Audio Level */}
                        <ResponsiveContainer width="100%" height={200}>
                            <LineChart
                                data={data}
                                margin={{
                                    top: 5, right: 20, bottom: 5, left: 20,
                                }}
                                onMouseDown={this.handleMouseDown}
                                onMouseMove={this.handleMouseMove}
                                onMouseUp={this.handleZoom}
                            >
                                <YAxis allowDataOverflow type="number">
                                    <Label angle={270} position="left" style={{ textAnchor: 'middle' }}>
                                        Audio Level
                                    </Label>
                                </YAxis>
                                <XAxis allowDataOverflow dataKey={TIMESTAMP_KEY} tick={this.renderCustomAxisTick} type="number" domain={timeRange} />
                                <CartesianGrid />
                                <Line
                                    type="linear"
                                    dataKey="audioLevel"
                                    stroke={colorMap.audioLevel}
                                    strokeWidth={2}
                                    dot={false}
                                    activeDot
                                    connectNulls={false}
                                    isAnimationActive={false}
                                />
                                <Tooltip content={this.renderCustomTooltip(['audioLevel'])} />
                                <Legend verticalAlign="bottom" />
                                { (refAreaLeft && refAreaRight) && (
                                    <ReferenceArea
                                        x1={refAreaLeft}
                                        x2={refAreaRight}
                                        strokeOpacity={0.3}
                                    />
                                )}
                            </LineChart>
                        </ResponsiveContainer>

                        {/* Packets */}
                        <ResponsiveContainer width="100%" height={200}>
                            <ComposedChart
                                data={data}
                                margin={{
                                    top: 5, right: 20, bottom: 5, left: 20,
                                }}
                                onMouseDown={this.handleMouseDown}
                                onMouseMove={this.handleMouseMove}
                                onMouseUp={this.handleZoom}
                            >
                                <YAxis allowDataOverflow type="number">
                                    <Label angle={270} position="left" style={{ textAnchor: 'middle' }}>
                                        Packets
                                    </Label>
                                </YAxis>
                                <XAxis allowDataOverflow dataKey={TIMESTAMP_KEY} tick={this.renderCustomAxisTick} type="number" domain={timeRange} />
                                <CartesianGrid />
                                <Line
                                    type="linear"
                                    dataKey="packetsLost"
                                    stroke={colorMap.packetsLost}
                                    strokeWidth={2}
                                    dot={false}
                                    activeDot
                                    connectNulls={false}
                                    isAnimationActive={false}
                                />
                                <Line
                                    type="linear"
                                    dataKey="packetsCount"
                                    stroke={colorMap.packetsCount}
                                    strokeWidth={2}
                                    dot={false}
                                    activeDot
                                    connectNulls={false}
                                    isAnimationActive={false}
                                />
                                <Tooltip content={this.renderCustomTooltip(['packetsLost', 'packetsCount'])} />
                                <Legend verticalAlign="bottom" />
                                { (refAreaLeft && refAreaRight) && (
                                    <ReferenceArea
                                        x1={refAreaLeft}
                                        x2={refAreaRight}
                                        strokeOpacity={0.3}
                                    />
                                )}
                            </ComposedChart>
                        </ResponsiveContainer>

                        {/* Jitter Buffer and RTT */}
                        <ResponsiveContainer width="100%" height={200}>
                            <ComposedChart
                                data={data}
                                margin={{
                                    top: 5, right: 20, bottom: 5, left: 20,
                                }}
                                onMouseDown={this.handleMouseDown}
                                onMouseMove={this.handleMouseMove}
                                onMouseUp={this.handleZoom}
                            >
                                <YAxis allowDataOverflow type="number">
                                    { type === 'audio_input' && (
                                        <Label angle={270} position="left" style={{ textAnchor: 'middle' }}>
                                            Jitter Buffer (ms)
                                        </Label>
                                    )}
                                    { type === 'audio_output' && (
                                        <Label angle={270} position="left" style={{ textAnchor: 'middle' }}>
                                            Jitter Buffer &amp; RTT (ms)
                                        </Label>
                                    )}
                                </YAxis>
                                <XAxis allowDataOverflow dataKey={TIMESTAMP_KEY} tick={this.renderCustomAxisTick} type="number" domain={timeRange} />
                                <CartesianGrid />
                                <Line
                                    type="linear"
                                    dataKey="jitterBufferMillis"
                                    stroke={colorMap.jitterBufferMillis}
                                    strokeWidth={2}
                                    dot={false}
                                    activeDot
                                    connectNulls={false}
                                    isAnimationActive={false}
                                />
                                { type === 'audio_output' && (
                                    <Line
                                        type="linear"
                                        dataKey="roundTripTimeMillis"
                                        stroke={colorMap.roundTripTimeMillis}
                                        strokeWidth={2}
                                        dot={false}
                                        activeDot
                                        connectNulls={false}
                                        isAnimationActive={false}
                                    />
                                )}
                                <Tooltip
                                    content={
                                        type === 'audio_output'
                                            ? this.renderCustomTooltip(['jitterBufferMillis', 'roundTripTimeMillis'])
                                            : this.renderCustomTooltip(['jitterBufferMillis'])
                                    }
                                />
                                <Legend verticalAlign="bottom" />
                                { (refAreaLeft && refAreaRight) && (
                                    <ReferenceArea
                                        x1={refAreaLeft}
                                        x2={refAreaRight}
                                        strokeOpacity={0.3}
                                    />
                                )}
                            </ComposedChart>
                        </ResponsiveContainer>

                        {/* Brush */}
                        <ResponsiveContainer width="100%" height={60}>
                            <ComposedChart
                                // update data to force re-rendering
                                data={brushHovering ? originalData : [...originalData]}
                                margin={{
                                    top: 5, right: 20, bottom: 5, left: 20,
                                }}
                                onMouseEnter={() => this.setState({ brushHovering: true })}
                                onMouseLeave={() => this.setState({ brushHovering: false })}
                            >
                                <Brush
                                    className="TimeLineChart-brush"
                                    dataKey={TIMESTAMP_KEY}
                                    stroke="#666666"
                                    startIndex={startIndex || 0}
                                    endIndex={endIndex || originalData.length - 1}
                                    onChange={this.handleChangeBrush}
                                    tickFormatter={this.formatBrushTick}
                                />
                            </ComposedChart>
                        </ResponsiveContainer>

                    </div>
                </Container>
            </div>
        );
    }
Example #2
Source File: BarChart.jsx    From cosmoscan-front with Apache License 2.0 3 votes vote down vote up
BarChart = ({
  isLoading,
  data,
  yAxisWidth,
  yAxisTickCount,
  yAxisLabelsFormatter,
  xAxisTickFormatter,
  xAxisTickCount,
  xAxisTickInterval,
  yAxisDomain,
  tooltipFormatter,
  tooltipLabelFormatter,
  barName,
  barColor,
  noLegend,
  customTooltip,
  isBrush,
}) => {
  const theme = useContext(ThemeContext);

  return (
    <div style={{ width: '100%', height: '400px' }}>
      {/* eslint-disable-next-line no-nested-ternary */}
      {isLoading ? (
        <div className="d-flex justify-content-center align-items-center h-100">
          <Spinner />
        </div>
      ) : data && data.length ? (
        <ResponsiveContainer>
          <BarChartStyled data={data}>
            <CartesianGrid
              strokeDasharray="3 3"
              stroke="#e2e2e9"
              vertical={false}
            />
            <XAxis
              dataKey="name"
              tickLine={false}
              tick={{ fill: theme.gray }}
              tickCount={xAxisTickCount}
              axisLine={false}
              tickFormatter={xAxisTickFormatter}
              interval={xAxisTickInterval}
              minTickGap={0}
            />
            <YAxis
              axisLine={false}
              tickLine={false}
              tick={{ fill: theme.gray }}
              width={yAxisWidth}
              tickCount={yAxisTickCount}
              tickFormatter={yAxisLabelsFormatter}
              type="number"
              domain={yAxisDomain}
            />
            <Tooltip
              formatter={tooltipFormatter}
              labelFormatter={tooltipLabelFormatter}
              content={customTooltip || null}
            />
            {!noLegend && (
              <Legend
                align="left"
                iconType="circle"
                verticalAlign="top"
                height={50}
                wrapperStyle={{
                  fontWeight: 700,
                  textTransform: 'uppercase',
                }}
              />
            )}
            {isBrush && (
              <Brush
                dataKey="name"
                height={15}
                stroke={barColor}
                gap={10}
                startIndex={data.length - 20}
                travellerWidth={8}
                className="mt-5"
              />
            )}
            <Bar
              dataKey="dataPiece"
              fill={barColor}
              name={barName}
              minPointSize={1}
            />
          </BarChartStyled>
        </ResponsiveContainer>
      ) : (
        <div className="d-flex justify-content-center align-items-center h-100">
          No data
        </div>
      )}
    </div>
  );
}