UNPKG

recharts

Version:
186 lines (185 loc) • 6.86 kB
import * as React from 'react'; import { CSSProperties } from 'react'; import { Props as TextProps } from '../component/Text'; import { ImplicitLabelListType } from '../component/LabelList'; import { TooltipIndex, TooltipPayloadSearcher } from '../state/tooltipSlice'; import { DataKey, EventThrottlingProps, Percent } from '../util/types'; import { RechartsFill } from '../fill/RechartsFill'; /** * @public */ export interface SunburstData { [key: string]: any; name: string; value?: number; /** * A color, or a {@link RechartsFill} object with an SVG definition, such as a pattern or a gradient. */ fill?: string | RechartsFill; tooltipIndex?: TooltipIndex; children?: SunburstData[]; } /** * @public */ export interface SunburstChartProps extends EventThrottlingProps { className?: string; /** * The source data. Each element should be an object. * The properties of each object represent the values of different data dimensions. * * Use the `dataKey` prop to specify which properties to use. * * @example data={[{ name: 'a', value: 12, fill: '#8884d8' }, { name: 'b', value: 5, fill: '#83a6ed' }]} */ data: SunburstData; /** * The width of chart container. * Can be a number or a percent string like "100%". * * @see {@link https://recharts.github.io/en-US/guide/sizes/ Chart sizing guide} */ width?: number | Percent; /** * The height of chart container. * Can be a number or a percent string like "100%". * * @see {@link https://recharts.github.io/en-US/guide/sizes/ Chart sizing guide} */ height?: number | Percent; /** * If true, then it will listen to container size changes and adapt the SVG chart accordingly. * If false, then it renders the chart at the specified width and height and will stay that way * even if the container size changes. * * This is similar to ResponsiveContainer but without the need for an extra wrapper component. * The `responsive` prop also uses standard CSS sizing rules, instead of custom resolution logic (like ResponsiveContainer does). * @default false */ responsive?: boolean; /** * Distance between sectors. * * @defaultValue 2 */ padding?: number; /** * Decides how to extract value from the data. * * @defaultValue value */ dataKey?: string; /** * Name represents each sector in the tooltip. * This allows you to extract the name from the data: * * - `string`: the name of the field in the data object; * - `number`: the index of the field in the data; * - `function`: a function that receives the data object and returns the name. * * @defaultValue name */ nameKey?: DataKey<any>; /** * Padding between each hierarchical level. */ ringPadding?: number; /** * The radius of the inner circle at the center of the chart. * * @defaultValue 50 */ innerRadius?: number; /** * Outermost edge of the chart. * Defaults to the max possible radius for a circle inscribed in the chart container */ outerRadius?: number; /** * The x-coordinate of center in pixels. * If undefined, it will be set to half of the chart width. */ cx?: number; /** * The y-coordinate of center in pixels. * If undefined, it will be set to half of the chart height. */ cy?: number; /** Angle in degrees from which the chart should start. */ startAngle?: number; /** Angle, in degrees, at which the chart should end. */ endAngle?: number; children?: React.ReactNode; /** * The fill of the sectors: a color, or a {@link RechartsFill} object with an SVG definition, * such as a pattern or a gradient. A node in the data can set its own `fill` the same way. * If the fill object has no `color`, the definition gets the color the sector would have without it. * * @example <SunburstChart data={data} fill={{ color: '#8884d8', definition: pattern(patterns.dots) }} /> */ fill?: string | RechartsFill; stroke?: string; /** * An object with text options to control the appearance of the default chart labels. * Shared SVG styles also apply to the `label` prop; explicit label props win. * * @deprecated Prefer `label` for new code. Text-specific options remain supported for default labels. */ textOptions?: TextProps; /** * Renders one label for each sector. 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. * * Explicit LabelList children render independently of this prop. * * @defaultValue true * @since 3.11 * @example <SunburstChart data={data} label={{ dataKey: 'name', background: true }} /> */ label?: ImplicitLabelListType; onMouseEnter?: (node: SunburstData, e: React.MouseEvent) => void; onMouseLeave?: (node: SunburstData, e: React.MouseEvent) => void; onClick?: (node: SunburstData) => void; style?: CSSProperties; id?: string; } export declare const payloadSearcher: TooltipPayloadSearcher; export declare const defaultSunburstChartProps: { readonly throttleDelay: number | "raf"; readonly throttledEvents: ReadonlyArray<keyof GlobalEventHandlersEventMap> | "all"; readonly padding: 2; readonly dataKey: "value"; readonly nameKey: "name"; readonly ringPadding: 2; readonly innerRadius: 50; readonly fill: "#333"; readonly stroke: "#FFF"; readonly textOptions: { fontWeight: string; paintOrder: string; fontSize: string; stroke: string; fill: string; pointerEvents: string; }; readonly label: true; readonly startAngle: 0; readonly endAngle: 360; readonly responsive: false; }; /** * The sunburst is a hierarchical chart, similar to a {@link Treemap}, plotted in polar coordinates. * Sunburst charts effectively convey the hierarchical relationships and proportions within each level. * It is easy to see all the middle layers in the hierarchy, which might get lost in other visualizations. * For some datasets, the radial layout may be more visually appealing and intuitive than a traditional {@link Treemap}. * * @consumes ResponsiveContainerContext * @provides TooltipEntrySettings * @public */ export declare const SunburstChart: (outsideProps: SunburstChartProps) => React.JSX.Element;