UNPKG

recharts

Version:
178 lines (156 loc) 6.51 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.adaptEventsOfChild = exports.adaptEventHandlers = exports.FilteredElementKeyMap = void 0; var _react = require("react"); var _excludeEventProps = require("./excludeEventProps"); /** * Determines how values are stacked: * * - `none` is the default, it adds values on top of each other. No smarts. Negative values will overlap. * - `expand` make it so that the values always add up to 1 - so the chart will look like a rectangle. * - `wiggle` and `silhouette` tries to keep the chart centered. * - `sign` stacks positive values above zero and negative values below zero. Similar to `none` but handles negatives. * - `positive` ignores all negative values, and then behaves like \`none\`. * * Also see https://d3js.org/d3-shape/stack#stack-offsets * (note that the `diverging` offset in d3 is named `sign` in recharts) */ /** * @deprecated use either `CartesianLayout` or `PolarLayout` instead. * Mixing both charts families leads to ambiguity in the type system. * These two layouts share very few properties, so it is best to keep them separate. */ /** * @deprecated do not use: too many properties, mixing too many concepts, cartesian and polar together, everything optional. */ // // Event Handler Types -- Copied from @types/react/index.d.ts and adapted for Props. // var SVGContainerPropKeys = ['viewBox', 'children']; var PolyElementKeys = ['points', 'pathLength']; /** svg element types that have specific attribute filtration requirements */ /** map of svg element types to unique svg attributes that belong to that element */ var FilteredElementKeyMap = exports.FilteredElementKeyMap = { svg: SVGContainerPropKeys, polygon: PolyElementKeys, polyline: PolyElementKeys }; /** The type of easing function to use for animations */ /** Specifies the duration of animation, the unit of this option is ms. */ /** * This object defines the offset of the chart area and width and height and brush and ... it's a bit too much information all in one. * We use it internally but let's not expose it to the outside world. * If you are looking for this information, instead import `ChartOffset` or `PlotArea` from `recharts`. */ /** * The domain of axis. * This is the definition * * Numeric domain is always defined by an array of exactly two values, for the min and the max of the axis. * Categorical domain is defined as array of all possible values. * * Can be specified in many ways: * - array of numbers * - with special strings like 'dataMin' and 'dataMax' * - with special string math like 'dataMin - 100' * - with keyword 'auto' * - or a function * - array of functions * - or a combination of the above */ /** * NumberDomain is an evaluated {@link AxisDomain}. * Unlike {@link AxisDomain}, it has no variety - it's a tuple of two number. * This is after all the keywords and functions were evaluated and what is left is [min, max]. * * Know that the min, max values are not guaranteed to be nice numbers - values like -Infinity or NaN are possible. * * There are also `category` axes that have different things than numbers in their domain. */ /** The props definition of base axis */ /** Defines how ticks are placed and whether / how tick collisions are handled. * 'preserveStart' keeps the left tick on collision and ensures that the first tick is always shown. * 'preserveEnd' keeps the right tick on collision and ensures that the last tick is always shown. * 'preserveStartEnd' keeps the left tick on collision and ensures that the first and last ticks always show. * 'equidistantPreserveStart' selects a number N such that every nTh tick will be shown without collision. */ /** * Ticks can be any type when the axis is the type of category. * * Ticks must be numbers when the axis is the type of number. */ var adaptEventHandlers = (props, newHandler) => { if (!props || typeof props === 'function' || typeof props === 'boolean') { return null; } var inputProps = props; if (/*#__PURE__*/(0, _react.isValidElement)(props)) { inputProps = props.props; } if (typeof inputProps !== 'object' && typeof inputProps !== 'function') { return null; } var out = {}; Object.keys(inputProps).forEach(key => { if ((0, _excludeEventProps.isEventKey)(key)) { out[key] = newHandler || (e => inputProps[key](inputProps, e)); } }); return out; }; exports.adaptEventHandlers = adaptEventHandlers; var getEventHandlerOfChild = (originalHandler, data, index) => e => { originalHandler(data, index, e); return null; }; var adaptEventsOfChild = (props, data, index) => { if (props === null || typeof props !== 'object' && typeof props !== 'function') { return null; } var out = null; Object.keys(props).forEach(key => { var item = props[key]; if ((0, _excludeEventProps.isEventKey)(key) && typeof item === 'function') { if (!out) out = {}; out[key] = getEventHandlerOfChild(item, data, index); } }); return out; }; /** * 'axis' means that all graphical items belonging to this axis tick will be highlighted, * and all will be present in the tooltip. * Tooltip with 'axis' will display when hovering on the chart background. * * 'item' means only the one graphical item being hovered will show in the tooltip. * Tooltip with 'item' will display when hovering over individual graphical items. * * This is calculated internally; * charts have a `defaultTooltipEventType` and `validateTooltipEventTypes` options. * * Users then use <Tooltip shared={true} /> or <Tooltip shared={false} /> to control their preference, * and charts will then see what is allowed and what is not. */ /** * These are the props we are going to pass to an `activeDot` if it is a function or a custom Component */ /** * This is the type of `activeDot` prop on: * - Area * - Line * - Radar */ // TODO we need two different range objects, one for polar and another for cartesian layouts /** * Simplified version of the MouseEvent so that we don't have to mock the whole thing in tests. * * This is meant to represent the React.MouseEvent * which is a wrapper on top of https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent */ /** * Coordinates relative to the top-left corner of the chart. * Also include scale which means that a chart that's scaled will return the same coordinates as a chart that's not scaled. */ exports.adaptEventsOfChild = adaptEventsOfChild;