recharts
Version:
React charts
302 lines (301 loc) • 12.5 kB
TypeScript
import * as React from 'react';
import { ReactElement } from 'react';
import { Series } from 'victory-vendor/d3-shape';
import { RadialBarSectorProps } from '../util/RadialBarUtils';
import { Props as SectorProps } from '../shape/Sector';
import { ImplicitLabelListType } from '../component/LabelList';
import { BarPositionPosition } from '../util/ChartUtils';
import { ActiveShape, AnimationDuration, EasingInput, ValueAxisDataConsumer, DataKey, LayoutType, LegendType, PolarViewBoxRequired, PresentationAttributesAdaptChildEvent, TickItem, TooltipType, PolarLayout } from '../util/types';
import { TooltipTriggerInfo } from '../context/tooltipContext';
import { Formatter } from '../component/DefaultTooltipContent';
import { BaseAxisWithScale } from '../state/selectors/axisSelectors';
import { ChartData } from '../state/chartDataSlice';
import { AnimationInterpolateFn } from '../animation/AnimatedItems';
import { AnimationMatchByProp } from '../animation/matchBy';
import { AxisId } from '../state/cartesianAxisSlice';
import { ZIndexable } from '../zIndex/ZIndexLayer';
import { RechartsFill } from '../fill/RechartsFill';
/**
* @public
*/
export type RadialBarDataItem = Omit<SectorProps, 'fill'> & PolarViewBoxRequired & TooltipTriggerInfo & {
/**
* The color of the entry. A fill object in the props paints the entry with its definition.
*/
fill?: string;
value?: any;
payload?: any;
background?: Omit<SectorProps, 'fill'> & {
fill?: string;
};
};
type RadialBarBackground = boolean | (ActiveShape<SectorProps> & ZIndexable);
/**
* 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 InternalRadialBarProps<DataPointType = any, DataValueType = any> extends ValueAxisDataConsumer<DataPointType, DataValueType>, ZIndexable {
/**
* The fill of the sectors. Either a color string, or a {@link RechartsFill} object with an SVG definition,
* such as a pattern or a gradient.
*
* Each sector can have its own fill too: set `fill` in its data entry, to a color or to a fill object.
*
* With a fill object, Recharts renders the definition with a unique ID, in the chart and in the Legend icons.
* Tooltip and labels use the solid `color` of the fill object.
* If the fill object has no `color`, the sectors keep the theme colors and the definition gets the theme color.
*
* @example <RadialBar dataKey="uv" fill={{ definition: pattern(patterns.diagonal) }} />
*/
fill?: string | RechartsFill;
activeShape?: ActiveShape<RadialBarSectorProps, SVGPathElement>;
/**
* @defaultValue 0
*/
angleAxisId?: AxisId;
/**
* Specifies when the animation should begin, the unit of this option is ms.
* @defaultValue 0
*/
animationBegin?: number;
/**
* Specifies the duration of animation, the unit of this option is ms.
* @defaultValue 1500
*/
animationDuration?: AnimationDuration;
/**
* The type of easing function.
* @defaultValue ease
*/
animationEasing?: EasingInput;
/**
* Custom animation function for interpolating data items.
* When provided, this replaces the default animation interpolation.
*
* @param prevItems The items from the previous animation frame, or null on first render
* @param nextItems The target items to animate towards
* @param animationElapsedTime A normalized time value (0 = start, 1 = end)
* @returns The interpolated items at time animationElapsedTime
*
* @since 3.9
* @see {@link https://recharts.github.io/en-US/guide/animations/ Animations guide}
*/
animationInterpolateFn?: AnimationInterpolateFn<RadialBarDataItem, PolarLayout>;
/**
* Strategy for matching previous items to next items during animation.
* Determines how Recharts pairs old data points with new data points
* to create smooth transitions.
*
* - `matchAppend` (default): match sequentially by index and treat newly appended items as new
* - `matchByIndex`: match by array position with proportional stretching
* - `matchByDataKey('someKey')`: match by a data key from the payload
* - Custom function `(item, index) => key`: match by the returned key
*
* @defaultValue append
* @see matchByIndex
* @see matchByDataKey
* @see matchAppend
*/
animationMatchBy?: AnimationMatchByProp<RadialBarDataItem>;
/**
* Renders a background for each bar. Options:
* - `false`: no background;
* - `true`: renders default background;
* - `object`: the props of background rectangle;
* - `ReactElement`: a custom background element;
* - `function`: a render function of custom background.
*
* @defaultValue false
*/
background?: RadialBarBackground;
/**
* The width or height of each bar. If the barSize is not specified, the size of the bar will be calculated by the barCategoryGap, barGap and the quantity of bar groups.
*/
barSize?: number;
className?: string;
/**
* @defaultValue false
*/
cornerIsExternal?: boolean;
/**
* @defaultValue 0
*/
cornerRadius?: string | number;
/**
* Calculated radial bar sectors
*/
sectors: ReadonlyArray<RadialBarDataItem>;
/**
* @defaultValue false
*/
forceCornerRadius?: boolean;
/**
* @defaultValue false
*/
hide?: boolean;
/**
* If set false, animation of radial bars will be disabled.
* If set "auto", the animation will be disabled in SSR and will respect the user's prefers-reduced-motion system preference for accessibility.
* @defaultValue auto
*/
isAnimationActive?: boolean | 'auto';
/**
* Renders one label for each data point. Options:
* - `true`: renders default labels;
* - `false`: no labels are rendered;
* - `object`: the props of LabelList component;
* - `ReactElement`: a custom SVG label element, such as `<text>` or `<g>`.
* HTML elements such as `<div>` are not valid inside the chart SVG and may trigger React DOM warnings.
* - `function`: a render function of custom label.
*
* @defaultValue false
*/
label?: ImplicitLabelListType;
/**
* The type of icon in legend. If set to 'none', no legend item will be rendered.
* @defaultValue rect
*/
legendType?: LegendType;
maxBarSize?: number;
/**
* The minimum angle of each non-zero bar.
* @defaultValue 0
*/
minAngle?: number;
/**
* @defaultValue 0
*/
minPointSize?: number;
/**
* The customized event handler of animation end
*/
onAnimationEnd?: () => void;
/**
* The customized event handler of animation start
*/
onAnimationStart?: () => void;
/**
* The customized event handler of click in this chart.
*/
onClick?: (data: RadialBarDataItem, index: number, e: React.MouseEvent<SVGGraphicsElement>) => void;
/**
* The customized event handler of mousedown in this chart.
*/
onMouseDown?: (data: RadialBarDataItem, index: number, e: React.MouseEvent<SVGGraphicsElement>) => void;
/**
* The customized event handler of mouseup in this chart.
*/
onMouseUp?: (data: RadialBarDataItem, index: number, e: React.MouseEvent<SVGGraphicsElement>) => void;
/**
* The customized event handler of mousemove in this chart.
*/
onMouseMove?: (data: RadialBarDataItem, index: number, e: React.MouseEvent<SVGGraphicsElement>) => void;
/**
* The customized event handler of mouseover in this chart.
*/
onMouseOver?: (data: RadialBarDataItem, index: number, e: React.MouseEvent<SVGGraphicsElement>) => void;
/**
* The customized event handler of mouseout in this chart.
*/
onMouseOut?: (data: RadialBarDataItem, index: number, e: React.MouseEvent<SVGGraphicsElement>) => void;
/**
* The customized event handler of mouseenter in this chart.
*/
onMouseEnter?: (data: RadialBarDataItem, index: number, e: React.MouseEvent<SVGGraphicsElement>) => void;
/**
* The customized event handler of mouseleave in this chart.
*/
onMouseLeave?: (data: RadialBarDataItem, index: number, e: React.MouseEvent<SVGGraphicsElement>) => void;
onTouchStart?: (data: RadialBarDataItem, index: number, e: React.TouchEvent<SVGGraphicsElement>) => void;
onTouchMove?: (data: RadialBarDataItem, index: number, e: React.TouchEvent<SVGGraphicsElement>) => void;
onTouchEnd?: (data: RadialBarDataItem, index: number, e: React.TouchEvent<SVGGraphicsElement>) => void;
/**
* @defaultValue 0
*/
radiusAxisId?: AxisId;
/**
* If set a ReactElement, the shape of radial bar sectors can be customized.
* If set a function, the function will be called to render customized shape.
* During animations, the function shape also receives `animationElapsedTime`, `isAnimating`, and `isEntrance`.
* By default, renders a sector.
*/
shape?: ActiveShape<RadialBarSectorProps, SVGPathElement>;
stackId?: string | number;
tooltipType?: TooltipType;
/**
* Formats the value displayed in the tooltip for this RadialBar.
* When set, takes precedence over the `formatter` prop on the Tooltip component.
*/
formatter?: Formatter;
/**
* Z-Index of this component and its children. The higher the value,
* the more on top it will be rendered.
* Components with higher zIndex will appear in front of components with lower zIndex.
* If undefined or 0, the content is rendered in the default layer without portals.
*
* @since 3.4
* @defaultValue 300
* @see {@link https://recharts.github.io/en-US/guide/zIndex/ Z-Index and layers guide}
*/
zIndex?: number;
}
/**
* @public
*/
export type RadialBarProps<DataPointType = any, DataValueType = any> = Omit<PresentationAttributesAdaptChildEvent<RadialBarDataItem, SVGElement>, 'ref' | keyof InternalRadialBarProps<DataPointType, DataValueType>> & Omit<InternalRadialBarProps<DataPointType, DataValueType>, 'sectors'>;
export declare const defaultRadialBarProps: {
readonly angleAxisId: 0;
readonly animationBegin: 0;
readonly animationDuration: 1500;
readonly animationEasing: "ease";
readonly animationMatchBy: "append";
readonly animationInterpolateFn: AnimationInterpolateFn<RadialBarDataItem, PolarLayout>;
readonly background: false;
readonly cornerIsExternal: false;
readonly cornerRadius: 0;
readonly forceCornerRadius: false;
readonly hide: false;
readonly isAnimationActive: "auto";
readonly label: false;
readonly legendType: "rect";
readonly minAngle: 0;
readonly minPointSize: 0;
readonly radiusAxisId: 0;
readonly shape: (props: SectorProps) => React.JSX.Element;
readonly zIndex: 300;
};
export declare function computeRadialBarDataItems({ displayedData, stackedData, dataStartIndex, stackedDomain, dataKey, baseValue, layout, radiusAxis, radiusAxisTicks, bandSize, pos, angleAxis, minAngle, minPointSize, cx, cy, angleAxisTicks, cells, startAngle: rootStartAngle, endAngle: rootEndAngle, }: {
displayedData: ChartData;
stackedData: Series<Record<number, number>, DataKey<any>> | undefined;
dataStartIndex: number;
stackedDomain: ReadonlyArray<unknown> | null;
dataKey: DataKey<any> | undefined;
baseValue: number | unknown;
layout: LayoutType;
radiusAxis: BaseAxisWithScale;
radiusAxisTicks: ReadonlyArray<TickItem> | undefined;
bandSize: number;
pos: BarPositionPosition;
angleAxis: BaseAxisWithScale;
minAngle: number;
minPointSize: number;
cx: number;
cy: number;
angleAxisTicks: ReadonlyArray<TickItem> | undefined;
cells: ReadonlyArray<ReactElement> | undefined;
startAngle: number;
endAngle: number;
}): ReadonlyArray<RadialBarDataItem>;
/**
* @consumes PolarChartContext
* @provides LabelListContext
* @provides CellReader
* @public
*/
export declare function RadialBar<DataPointType = any, DataValueType = any>(propsWithFillObject: RadialBarProps<DataPointType, DataValueType>): React.JSX.Element;
export declare namespace RadialBar {
var displayName: string;
}
export {};