recharts
Version:
React charts
175 lines (174 loc) • 5.79 kB
TypeScript
import * as React from 'react';
import { ReactElement, SVGAttributes, SVGProps } from 'react';
import { DataConsumer, Padding } from '../util/types';
import { OnBrushUpdate } from '../context/brushUpdateContext';
import { RechartsFill } from '../fill/RechartsFill';
/**
* @public
*/
export type BrushTravellerType = ReactElement<SVGElement> | ((props: TravellerProps) => ReactElement<SVGElement>);
type BrushTickFormatter = (value: any, index: number) => number | string;
/**
* The type is exported only so that TypeScript can name it in the declaration files of projects
* that wrap Recharts components. It is not part of the public API and may change in any release.
*
* @internal
*/
export interface BrushProps<DataPointType = any, DataValueType = any> extends DataConsumer<DataPointType, DataValueType> {
/**
* The fill of the brush background: a color, or a {@link RechartsFill} object with an SVG definition,
* such as a pattern or a gradient. The travellers use the plain color.
*
* @example <Brush fill={{ color: '#fff', definition: pattern(patterns.diagonal) }} />
*/
fill?: string | RechartsFill;
/**
* The x-coordinate of brush.
* If left undefined, it will be computed from the chart's offset and margins.
*/
x?: number;
/**
* The y-coordinate of brush.
* If left undefined, it will be computed from the chart's offset and margins.
*/
y?: number;
/**
* Vertical offset added to the brush's computed y-coordinate.
*/
dy?: number;
/**
* Width of the brush in pixels.
* If undefined, defaults to the chart width.
*/
width?: number;
/**
* The SVG element's class name.
*/
className?: string;
/**
* Custom accessible label applied to the brush's traveller handles. If
* not provided, one is generated automatically from the data at the
* current start and end index.
*/
ariaLabel?: string;
/**
* Height of the brush in pixels.
*
* @defaultValue 40
*/
height?: number;
/**
* The width of each traveller.
*
* @defaultValue 5
*/
travellerWidth?: number;
/**
* Custom element or render function used to render each draggable handle
* (the "traveller") at the start and end of the selection. Defaults to a
* small rectangle with two vertical lines.
*/
traveller?: BrushTravellerType;
/**
* Number of data points to skip between chart refreshes.
*
* @defaultValue 1
*/
gap?: number;
/**
* Padding applied only to the small overview chart rendered inside the
* brush (via `children`) has no effect on the brush's own position or
* size.
*
* @defaultValue {"top":1,"right":1,"bottom":1,"left":1}
*/
padding?: Padding;
/**
* The default start index of brush.
* If the option is not set, the start index will be 0.
*/
startIndex?: number;
/**
* The default end index of brush.
* If the option is not set, the end index will be calculated by the length of data.
*/
endIndex?: number;
/**
* The formatter function of ticks.
*/
tickFormatter?: BrushTickFormatter;
/**
* A single chart element (e.g. an AreaChart) rendered as a small preview
* inside the brush, showing an overview of the full dataset. If zero or
* more than one child is passed, nothing is rendered.
*/
children?: ReactElement;
/**
* The handler of changing the active scope of brush.
*/
onChange?: OnBrushUpdate;
/**
* The handler called when the user finishes dragging a traveller or the
* brush slide, receiving the final startIndex and endIndex.
*/
onDragEnd?: OnBrushUpdate;
/**
* Delay, in milliseconds, after the mouse leaves the brush, before an
* in-progress drag interaction is ended.
*
* @defaultValue 1000
*/
leaveTimeOut?: number;
/**
* When true, the start and end index labels are always visible. By
* default, they only appear while the user is interacting with the brush
* (dragging, hovering, or focused via keyboard).
*
* @defaultValue false
*/
alwaysShowText?: boolean;
}
/**
* @public
*/
export type Props = Omit<SVGProps<SVGElement>, 'onChange' | 'onDragEnd' | 'ref' | 'fill'> & BrushProps;
type TravellerProps = {
x: number;
y: number;
width: number;
height: number;
fill?: SVGAttributes<SVGElement>['fill'];
stroke?: SVGAttributes<SVGElement>['stroke'];
};
export declare const defaultBrushProps: {
readonly height: 40;
readonly travellerWidth: 5;
readonly gap: 1;
readonly padding: {
readonly top: 1;
readonly right: 1;
readonly bottom: 1;
readonly left: 1;
};
readonly leaveTimeOut: 1000;
readonly alwaysShowText: false;
};
/**
* Renders a scrollbar that allows the user to zoom and pan in the chart along its XAxis.
* It also allows you to render a small overview of the chart inside the brush that is always visible
* and shows the full data set so that the user can see where they are zoomed in.
*
* If a chart is synchronized with other charts using the `syncId` prop on the chart,
* the brush will also synchronize the zooming and panning between all synchronized charts.
*
* @see {@link https://recharts.github.io/en-US/examples/BrushBarChart/ BarChart with Brush}
* @see {@link https://recharts.github.io/en-US/examples/SynchronizedLineChart/ Synchronized Brush}
*
* @consumes CartesianChartContext
* @public
*/
export declare function Brush(propsWithFillObject: Props): React.JSX.Element;
export declare namespace Brush {
var displayName: string;
}
export {};