UNPKG

recharts

Version:
184 lines (183 loc) • 8.48 kB
import * as React from 'react'; import { ComponentType, ReactNode } from 'react'; import { RechartsFill, RechartsFillDefinitionProps, RechartsLinearGradient, RechartsPattern } from './RechartsFill'; /** * Returns the `fill` attribute that references a fill definition. * @param id the id given to the definition */ export declare function getFillUrl(id: string): string; /** * Turns a {@link RechartsPattern} into a fill definition: a repeating texture over the base color. * The texture defaults to the `pageBackground` color from the theme, or white when no theme is set. * * Call it outside of components, so that the definition stays the same between renders. * * @example * const stripes = pattern(patterns.diagonal); * <Bar dataKey="uv" fill={{ definition: stripes }} /> * * @param value the pattern to draw * @returns a component to use as the `definition` of a {@link RechartsFill} * @since 3.11 * @public */ export declare function pattern(value: RechartsPattern): ComponentType<RechartsFillDefinitionProps>; /** * Turns a {@link RechartsLinearGradient} into a fill definition. Stops without a color use the base color. * * Call it outside of components, so that the definition stays the same between renders. * * @example * const fade = linearGradient(gradients.fadeDown); * <Bar dataKey="uv" fill={{ definition: fade }} /> * * @param gradient the gradient to draw * @returns a component to use as the `definition` of a {@link RechartsFill} * @since 3.11 * @public */ export declare function linearGradient(gradient: RechartsLinearGradient): ComponentType<RechartsFillDefinitionProps>; /** * Splits the `fill` prop of a graphical item into the base color, and the fill object if there is one. * A fill object without `color` gives no color of its own, so the item keeps the theme colors. * @param fill the `fill` prop */ export declare function splitFill(fill: string | RechartsFill | undefined): { color: string | undefined; fillObject: RechartsFill | undefined; }; /** * DOM id of the fill definition of a graphical item. * @param id id of the graphical item */ export declare function getSeriesFillId(id: string): string; /** * Renders the definition of a fill object. Render it inside `<defs>`. */ export declare function FillObjectDefinition({ id, fillObject, color, bounds, }: { id: string; fillObject: RechartsFill; color: string | undefined; /** * The size of the area the definition paints, if it paints one area of known size. */ bounds?: RechartsFillDefinitionProps['bounds']; }): React.JSX.Element; /** * Reads the `fill` of a data entry, which can be a color string or a fill object. * Data entries have no types, so this checks that an object has a `definition` before treating it as a fill object. * Anything else counts as no fill. * @param entry the data entry, possibly merged with the props of its Cell */ export declare function readEntryFill(entry: unknown): { color: string | undefined; fillObject: RechartsFill | undefined; }; /** * DOM id of the fill definition of one data entry of a graphical item. * @param id id of the graphical item * @param index index of the data entry */ export declare function getEntryFillId(id: string, index: number): string; /** * Returns the item without the fill object that its data entry may have spread into it. * The item keeps the color of the fill object, or no `fill` at all, so that it takes the fill of the graphical item. * Shapes never get a fill object, only colors and `url(#…)` references. * @param item the item computed from the data entry, with the entry spread into it * @param entry the data entry, possibly merged with the props of its Cell */ export declare function withEntryFillColor<T extends object>(item: T, entry: unknown): T; /** * Renders the definitions of the data entries that have their own fill object. Render it inside `<defs>`. */ export declare function EntryFillDefinitions({ id, entries, }: { /** * id of the graphical item */ id: string; entries: ReadonlyArray<{ index: number; payload: unknown; color: string | undefined; }>; }): React.JSX.Element; /** * Returns true if any of the data entries has its own fill object. * @param payloads the data entries */ export declare function hasEntryFillObjects(payloads: ReadonlyArray<unknown>): boolean; /** * Returns the fill object a data entry paints with: its own, or none if it has its own color, * or else the fill object of its graphical item. * @param payload the data entry, possibly merged with the props of its Cell * @param seriesFillObject the fill object of the graphical item */ export declare function getEntryFillObject(payload: unknown, seriesFillObject: RechartsFill | undefined): RechartsFill | undefined; /** * Returns the fill object of a data entry in a graphical item that takes one theme entry per data entry, * like Pie and Funnel: the entry's own fill object, else the item's fill object, else the theme definition. * An entry with its own color, or an item with its own colors, doesn't take the theme definition. * * @param payload the data entry, possibly merged with the props of its Cell * @param index index of the data entry * @param seriesFillObject the fill object of the graphical item * @param themeFillObjects the fill object of each theme entry, from {@link useThemeFillObjects} * @param seriesHasOwnColors true if the graphical item sets its own colors */ export declare function getIndexedEntryFillObject(payload: unknown, index: number, seriesFillObject: RechartsFill | undefined, themeFillObjects: ReadonlyArray<RechartsFill | undefined>, seriesHasOwnColors: boolean): RechartsFill | undefined; /** * Returns the fill object of each theme entry, or undefined for an entry that fills with a color. * The result is the same array as long as the theme stays the same. */ export declare function useThemeFillObjects(): ReadonlyArray<RechartsFill | undefined>; /** * The paint of one fill in a component that isn't a graphical item, like a ReferenceArea or a grid. * Makes a unique id for the definition. * * @param fill the `fill` prop: a color, or a fill object * @param fallbackColor the color to use when the fill has no color of its own, for example from the theme * @param idPrefix prefix of the unique id * @param bounds the size of the painted area, if it is known when calling the hook * @returns `paint` for the `fill` attribute, `color` for everything that needs a plain color, * `definition` to render inside `<defs>`, and `renderDefinition` for when the size of the painted area * is known only later */ export declare function useFillPaint(fill: string | RechartsFill | undefined, fallbackColor: string | undefined, idPrefix: string, bounds?: RechartsFillDefinitionProps['bounds']): { paint: string | undefined; color: string | undefined; definition: ReactNode; renderDefinition: (paintedBounds: RechartsFillDefinitionProps['bounds']) => ReactNode; }; /** * The paints of a list of fills, like the stripes of a grid. Each fill object gets its own definition. * * @param fills the fills: colors or fill objects * @param idPrefix prefix of the unique ids * @returns `paints` for the `fill` attributes, by index, and `definitions` to render inside `<defs>`. * Without fill objects, `definitions` is null. */ export declare function useFillPaints(fills: ReadonlyArray<string | RechartsFill> | undefined, idPrefix: string): { paints: Array<string>; definitions: ReactNode; }; /** * Returns bounds of the given size, or undefined if a side is not a positive number. * @param width width of the painted area * @param height height of the painted area */ export declare function getShapeBounds(width: unknown, height: unknown): RechartsFillDefinitionProps['bounds']; /** * Renders the definition of a fill object with a unique id, and the shape that paints with it. * Shape components use it only when their `fill` is a fill object, so that plain colors render without any hook. */ export declare function FillObjectPaint({ fill, bounds, children, }: { fill: RechartsFill; /** * The size of the shape, if the shape knows it. */ bounds?: RechartsFillDefinitionProps['bounds']; /** * Renders the shape with the `url(#…)` of the definition as its `fill`. */ children: (paint: string) => ReactNode; }): React.JSX.Element;