UNPKG

recharts

Version:
115 lines (114 loc) • 6.45 kB
/** * @fileOverview * Users can style graphical items with explicit props (`<Bar fill="red" />`), * and graphical items that render one shape per data point (Bar, Pie, Scatter, ...) * also let users style individual shapes by putting presentation properties * directly in the data array. * * The theme colors are designed as a pair: the `fill` and `stroke` are chosen to look good together. * If we mixed a user-provided `fill` with a theme-provided `stroke`, the result would be a shape with two * unrelated colors. So as soon as a graphical item or a data entry defines its own * `fill` or `stroke`, it drops the theme `fill` and `stroke` together, * and takes its colors only from its own styles and the explicit props of the graphical item. * * Other style properties (opacities, `strokeWidth`, `strokeDasharray`) do not * bring a color of their own, so they merge with the theme field by field. * The `label` styles of the theme keep applying too, and so do the `active` styles without their colors, * see `activeStyles.ts`. */ import { ColorGraphicalItemStyle, ColorStyles2D } from './themeFill'; /** * Explicit `fill` and `stroke` props of a graphical item, both keys present (possibly as `undefined`). * Spreading this object over themed props removes the theme colors * while keeping the colors the user set on the graphical item. */ export type UnthemedColors = { fill: string | undefined; stroke: string | undefined; }; /** * Returns true if the graphical item props or the data entry define their own `fill` or `stroke`. * Such items and entries drop the theme `fill` and `stroke`, and keep the rest of the theme. * A fill object counts by its `color` only, so a fill object without a color keeps the theme colors. * @param entry props of graphical item, data entry, or anything else */ export declare function hasOwnColors(entry: unknown): boolean; type StyleWithoutColors = Omit<ColorGraphicalItemStyle, 'fill' | 'stroke'>; /** * Returns a copy of the style without its `fill` and `stroke`. * Every other key, `active` and `label` included, stays. * The result is cached, so the same style always returns the same object. That keeps theme selectors stable. * @param style theme style, for example an entry of `graphicalItems` */ export declare function withoutColors(style: ColorGraphicalItemStyle): StyleWithoutColors; export declare function withoutColors(style: ColorGraphicalItemStyle | undefined): StyleWithoutColors | undefined; /** * Picks the themeable style properties that the data entry defines, and leaves out the undefined ones. * @param entry data entry */ export declare function getOwnStyles(entry: ColorStyles2D | null | undefined): ColorStyles2D; /** * Picks the `fill` and `stroke` from explicit props, including the undefined ones. * @param explicitProps props as provided by the user, before merging with theme or defaults */ export declare function getUnthemedColors(explicitProps: ColorStyles2D): UnthemedColors; /** * Returns referentially stable {@link getUnthemedColors} if a theme is active, or undefined without a theme. * Without a theme, graphical items keep their legacy behaviour and there is nothing to override. * @param explicitProps props as provided by the user, before merging with theme or defaults */ export declare function useUnthemedColors(explicitProps: ColorStyles2D): UnthemedColors | undefined; /** * Returns the color overrides for a single data entry. * If the entry has its own colors, returns the unthemed colors which remove the theme colors from this entry. * Otherwise returns undefined, and the entry keeps the theme colors. * Either way, the entry keeps the other theme styles. * * @param entry data entry * @param unthemedColors result of {@link getUnthemedColors}, or undefined if there is no active theme */ export declare function getEntryStyleOverrides(entry: unknown, unthemedColors: UnthemedColors | undefined): UnthemedColors | undefined; /** * Picks the valid SVG properties of a data entry, without `id` so that rendered elements do not get duplicate DOM ids, * and without the React `ref` and `key`. * The raw entry, `id` included, stays available as `payload`. * Graphical items spread these after their own props, so the data entry wins. * * @param entry data entry */ export declare function getEntrySvgProps(entry: unknown): Record<string, unknown>; /** * The fill and stroke a graphical item renders a data entry with. * An inline `style.fill` or `style.stroke` of the entry wins over its `fill` or `stroke`, the same as in the browser. * Follows the order in which graphical items spread the styles: the entry colors win over the graphical item colors, * and with a theme, an entry with its own colors drops the theme colors. * * @param entry data entry, with the props of its `Cell` if there is one * @param fill fill of the graphical item, theme included * @param stroke stroke of the graphical item, theme included * @param unthemedColors result of {@link useUnthemedColors}, or undefined without a theme */ export declare function getEntryShapeColors(entry: unknown, fill: string | undefined, stroke: string | undefined, unthemedColors: UnthemedColors | undefined): { fill: string | undefined; stroke: string | undefined; }; /** * The color a graphical item renders a data entry with: its fill, or its stroke when it has no fill. * Tooltip and Legend use this so that they show the same color as the shape. * * @param entry data entry, with the props of its `Cell` if there is one * @param fill fill of the graphical item, theme included * @param stroke stroke of the graphical item, theme included * @param unthemedColors result of {@link useUnthemedColors}, or undefined without a theme * @see getEntryShapeColors */ export declare function getEntryColor(entry: unknown, fill: string | undefined, stroke: string | undefined, unthemedColors: UnthemedColors | undefined): string | undefined; /** * Removes the SVG properties of a data entry (`stroke`, `opacity`, `style`, `data-*`, `id`, ...), and keeps `name`. * Backgrounds are not the graphical item, so they do not take the styles of the data entry. * Custom background shapes still receive the other keys of the entry, and the entry itself as `payload`. * * @param entry data entry, or the item computed from it */ export declare function omitEntrySvgProps(entry: object): Record<string, unknown>; export {};