UNPKG

recharts

Version:
197 lines (188 loc) • 4.76 kB
import { symbolCircle, symbolCross, symbolDiamond, symbolSquare, symbolStar, symbolTriangle, symbolWye } from 'victory-vendor/d3-shape'; import { getSymbolPath } from './symbolPath'; /** * A stop of a {@link RechartsLinearGradient}. * * @since 3.11 * @public */ /** * A linear gradient, drawn in the bounding box of each shape. Turn it into a fill definition with {@link linearGradient}. * * The coordinates go from 0 to 1 across the bounding box of the shape, the same as in SVG `objectBoundingBox` units. * Because of that, an angled gradient looks skewed on narrow shapes. * * @since 3.11 * @public */ /** * Props of a {@link RechartsFill} `definition` component. * * @since 3.11 * @public */ /** * A repeating texture, drawn over the base color of the fill. * It is a plain value, so it can be stored as JSON. * * Use one of the built-in {@link patterns}, adjust one by spreading it (`{ ...patterns.dots, width: 6 }`), * or write your own `path`. Turn it into a fill definition with {@link pattern}. * For a texture that SVG paths can't draw, write your own `definition` component. * * @since 3.11 * @public */ /** * A fill of a graphical item that paints its shapes with an SVG paint server, such as a gradient or a pattern. * * Recharts renders the `definition` in `<defs>` with a unique id, and paints the shapes with `url(#id)`. * Tooltip and labels use the solid `color`. * * Use {@link linearGradient} or {@link pattern} to make a definition from the built-in * {@link gradients} and {@link patterns}, or write your own component. * * @example <Bar dataKey="uv" fill={{ definition: pattern(patterns.diagonal) }} /> * @example <Bar dataKey="uv" fill={{ color: 'blue', definition: linearGradient(gradients.fadeDown) }} /> * * @since 3.11 * @public */ var SYMBOL_TILE_SIZE = 12; /** * Area of each symbol, in square pixels. The same as in `Symbols`: equal areas make the shapes look equally heavy. */ var SYMBOL_AREA = 24; /** * A pattern of one of the `Symbols` shapes, filled, in staggered rows: * two symbols per tile, the second one moved by half a tile in both directions. * @param symbolType the d3 symbol type */ function symbolPattern(symbolType) { var quarter = SYMBOL_TILE_SIZE / 4; return { width: SYMBOL_TILE_SIZE, height: SYMBOL_TILE_SIZE, path: [getSymbolPath(symbolType, SYMBOL_AREA, quarter, quarter), getSymbolPath(symbolType, SYMBOL_AREA, 3 * quarter, 3 * quarter)] }; } var circle = symbolPattern(symbolCircle); /** * Built-in patterns. Each of them is a plain {@link RechartsPattern} value. * Use them with {@link pattern}: `fill={{ definition: pattern(patterns.diagonal) }}`. * * `circle`, `cross`, `diamond`, `square`, `star`, `triangle`, and `wye` draw the same shapes as {@link Symbols}, * in staggered rows. `dots` is the same pattern as `circle`. * * @since 3.11 * @public */ export var patterns = { diagonal: { width: 8, height: 8, rotation: 45, path: 'M0 4H8', strokeWidth: 3 }, crosshatch: { width: 8, height: 8, rotation: 45, path: ['M0 4H8', 'M4 0V8'], strokeWidth: 1.5 }, horizontal: { width: 8, height: 8, path: 'M0 4H8', strokeWidth: 3 }, vertical: { width: 8, height: 8, path: 'M4 0V8', strokeWidth: 3 }, grid: { width: 8, height: 8, path: ['M0 4H8', 'M4 0V8'], strokeWidth: 1.5 }, dots: circle, zigzag: { width: 8, height: 8, path: 'M0 5L2 3L4 5L6 3L8 5', strokeWidth: 1.5 }, circle, cross: symbolPattern(symbolCross), diamond: symbolPattern(symbolDiamond), square: symbolPattern(symbolSquare), star: symbolPattern(symbolStar), triangle: symbolPattern(symbolTriangle), wye: symbolPattern(symbolWye) }; /** * Built-in linear gradients. Each of them fades the base color of the fill, so they work with any color. * Each of them is a plain {@link RechartsLinearGradient} value. * Use them with {@link linearGradient}: `fill={{ definition: linearGradient(gradients.fadeDown) }}`. * * @since 3.11 * @public */ export var gradients = { fadeDown: { x1: 0, y1: 0, x2: 0, y2: 1, stops: [{ offset: 0, opacity: 1 }, { offset: 1, opacity: 0.2 }] }, fadeUp: { x1: 0, y1: 1, x2: 0, y2: 0, stops: [{ offset: 0, opacity: 1 }, { offset: 1, opacity: 0.2 }] }, fadeRight: { x1: 0, y1: 0, x2: 1, y2: 0, stops: [{ offset: 0, opacity: 1 }, { offset: 1, opacity: 0.2 }] }, fadeLeft: { x1: 1, y1: 0, x2: 0, y2: 0, stops: [{ offset: 0, opacity: 1 }, { offset: 1, opacity: 0.2 }] } };