@octanejs/recharts 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/package.json +53 -0
- package/src/animation/AnimatedItems.tsrx +82 -0
- package/src/animation/AnimationControllerImpl.js +33 -0
- package/src/animation/AnimationHandle.js +291 -0
- package/src/animation/JavascriptAnimate.tsrx +81 -0
- package/src/animation/easing.js +193 -0
- package/src/animation/matchBy.js +279 -0
- package/src/animation/timeoutController.js +49 -0
- package/src/animation/useAnimationController.ts +22 -0
- package/src/animation/useAnimationStartSnapshot.ts +43 -0
- package/src/animation/util.js +11 -0
- package/src/cartesian/Bar.ts +4 -0
- package/src/cartesian/Bar.tsrx +716 -0
- package/src/cartesian/Bar.tsrx.d.ts +4 -0
- package/src/cartesian/BarStack.tsrx +97 -0
- package/src/cartesian/BarStack.tsrx.d.ts +6 -0
- package/src/cartesian/CartesianAxis.tsrx +413 -0
- package/src/cartesian/CartesianAxis.tsrx.d.ts +3 -0
- package/src/cartesian/GraphicalItemClipPath.tsrx +44 -0
- package/src/cartesian/Line.ts +4 -0
- package/src/cartesian/Line.tsrx +544 -0
- package/src/cartesian/Line.tsrx.d.ts +4 -0
- package/src/cartesian/LineDrawShape.tsrx +106 -0
- package/src/cartesian/LineDrawShape.tsrx.d.ts +2 -0
- package/src/cartesian/XAxis.tsrx +156 -0
- package/src/cartesian/XAxis.tsrx.d.ts +3 -0
- package/src/cartesian/YAxis.tsrx +183 -0
- package/src/cartesian/YAxis.tsrx.d.ts +3 -0
- package/src/cartesian/getCartesianPosition.js +277 -0
- package/src/cartesian/getEquidistantTicks.js +133 -0
- package/src/cartesian/getTicks.js +280 -0
- package/src/cartesian/useAnimatedLineLength.ts +33 -0
- package/src/chart/BarChart.tsrx +22 -0
- package/src/chart/BarChart.tsrx.d.ts +2 -0
- package/src/chart/CartesianChart.tsrx +76 -0
- package/src/chart/CartesianChart.tsrx.d.ts +10 -0
- package/src/chart/CategoricalChart.tsrx +54 -0
- package/src/chart/LineChart.tsrx +22 -0
- package/src/chart/LineChart.tsrx.d.ts +2 -0
- package/src/chart/RechartsWrapper.tsrx +294 -0
- package/src/component/ActivePoints.tsrx +76 -0
- package/src/component/Cell.ts +37 -0
- package/src/component/Dots.tsrx +74 -0
- package/src/component/Label.tsrx +309 -0
- package/src/component/Label.tsrx.d.ts +12 -0
- package/src/component/LabelList.tsrx +83 -0
- package/src/component/LabelList.tsrx.d.ts +8 -0
- package/src/component/ResponsiveContainer.ts +22 -0
- package/src/component/Text.tsrx +281 -0
- package/src/component/Text.tsrx.d.ts +9 -0
- package/src/component/responsiveContainerUtils.js +111 -0
- package/src/container/ClipPathProvider.tsrx +29 -0
- package/src/container/Layer.tsrx +9 -0
- package/src/container/Layer.tsrx.d.ts +6 -0
- package/src/container/RootSurface.tsrx +76 -0
- package/src/container/Surface.tsrx +23 -0
- package/src/container/Surface.tsrx.d.ts +12 -0
- package/src/context/CellsContext.ts +80 -0
- package/src/context/ErrorBarContext.tsrx +53 -0
- package/src/context/PanoramaContext.ts +10 -0
- package/src/context/RegisterGraphicalItemId.tsrx +19 -0
- package/src/context/accessibilityContext.js +10 -0
- package/src/context/chartDataContext.ts +57 -0
- package/src/context/chartLayoutContext.ts +171 -0
- package/src/context/legendPortalContext.ts +5 -0
- package/src/context/tooltipContext.js +55 -0
- package/src/context/tooltipPortalContext.ts +5 -0
- package/src/hooks.js +509 -0
- package/src/index.ts +64 -0
- package/src/internal.ts +37 -0
- package/src/polar/defaultPolarAngleAxisProps.js +27 -0
- package/src/polar/defaultPolarRadiusAxisProps.js +24 -0
- package/src/shape/Cross.tsrx +25 -0
- package/src/shape/Cross.tsrx.d.ts +12 -0
- package/src/shape/Curve.tsrx +132 -0
- package/src/shape/Curve.tsrx.d.ts +42 -0
- package/src/shape/Dot.tsrx +21 -0
- package/src/shape/Dot.tsrx.d.ts +9 -0
- package/src/shape/Polygon.tsrx +95 -0
- package/src/shape/Polygon.tsrx.d.ts +13 -0
- package/src/shape/Rectangle.tsrx +162 -0
- package/src/shape/Rectangle.tsrx.d.ts +31 -0
- package/src/shape/Sector.tsrx +219 -0
- package/src/shape/Sector.tsrx.d.ts +29 -0
- package/src/shape/Symbols.tsrx +95 -0
- package/src/shape/Symbols.tsrx.d.ts +15 -0
- package/src/shape/Trapezoid.tsrx +56 -0
- package/src/shape/Trapezoid.tsrx.d.ts +29 -0
- package/src/state/RechartsReduxContext.ts +7 -0
- package/src/state/RechartsStoreProvider.tsrx +24 -0
- package/src/state/ReportChartProps.ts +13 -0
- package/src/state/ReportEventSettings.ts +15 -0
- package/src/state/ReportMainChartProps.ts +22 -0
- package/src/state/SetGraphicalItem.ts +61 -0
- package/src/state/SetLegendPayload.ts +61 -0
- package/src/state/SetTooltipEntrySettings.ts +40 -0
- package/src/state/brushSlice.js +36 -0
- package/src/state/cartesianAxisSlice.js +256 -0
- package/src/state/chartDataSlice.js +67 -0
- package/src/state/errorBarSlice.js +53 -0
- package/src/state/eventSettingsSlice.js +25 -0
- package/src/state/externalEventsMiddleware.js +127 -0
- package/src/state/graphicalItemsSlice.js +91 -0
- package/src/state/hooks.ts +46 -0
- package/src/state/keyboardEventsMiddleware.js +226 -0
- package/src/state/layoutSlice.js +57 -0
- package/src/state/legendSlice.js +83 -0
- package/src/state/mouseEventsMiddleware.js +130 -0
- package/src/state/optionsSlice.js +45 -0
- package/src/state/polarAxisSlice.js +33 -0
- package/src/state/polarOptionsSlice.js +26 -0
- package/src/state/reduxDevtoolsJsonStringifyReplacer.js +14 -0
- package/src/state/referenceElementsSlice.js +51 -0
- package/src/state/renderedTicksSlice.js +41 -0
- package/src/state/rootPropsSlice.js +48 -0
- package/src/state/selectors/arrayEqualityCheck.js +32 -0
- package/src/state/selectors/axisSelectors.js +2113 -0
- package/src/state/selectors/barSelectors.js +263 -0
- package/src/state/selectors/barStackSelectors.js +65 -0
- package/src/state/selectors/brushSelectors.js +21 -0
- package/src/state/selectors/combiners/combineActiveLabel.js +18 -0
- package/src/state/selectors/combiners/combineActiveTooltipIndex.js +75 -0
- package/src/state/selectors/combiners/combineAllBarPositions.js +169 -0
- package/src/state/selectors/combiners/combineAxisRangeWithReverse.js +11 -0
- package/src/state/selectors/combiners/combineBarPosition.js +17 -0
- package/src/state/selectors/combiners/combineBarSizeList.js +115 -0
- package/src/state/selectors/combiners/combineCheckedDomain.js +44 -0
- package/src/state/selectors/combiners/combineConfiguredScale.js +46 -0
- package/src/state/selectors/combiners/combineCoordinateForDefaultIndex.js +48 -0
- package/src/state/selectors/combiners/combineDisplayedStackedData.js +54 -0
- package/src/state/selectors/combiners/combineInverseScaleFunction.js +12 -0
- package/src/state/selectors/combiners/combineRealScaleType.js +36 -0
- package/src/state/selectors/combiners/combineStackedData.js +22 -0
- package/src/state/selectors/combiners/combineTooltipInteractionState.js +121 -0
- package/src/state/selectors/combiners/combineTooltipPayload.js +248 -0
- package/src/state/selectors/combiners/combineTooltipPayloadConfigurations.js +59 -0
- package/src/state/selectors/containerSelectors.js +6 -0
- package/src/state/selectors/dataSelectors.js +97 -0
- package/src/state/selectors/graphicalItemSelectors.js +25 -0
- package/src/state/selectors/legendSelectors.js +18 -0
- package/src/state/selectors/lineSelectors.js +106 -0
- package/src/state/selectors/numberDomainEqualityCheck.js +11 -0
- package/src/state/selectors/pickAxisId.js +3 -0
- package/src/state/selectors/pickAxisType.js +3 -0
- package/src/state/selectors/polarAxisSelectors.js +237 -0
- package/src/state/selectors/rootPropsSelectors.js +13 -0
- package/src/state/selectors/selectActivePropsFromChartPointer.js +23 -0
- package/src/state/selectors/selectAllAxes.js +15 -0
- package/src/state/selectors/selectChartOffset.js +12 -0
- package/src/state/selectors/selectChartOffsetInternal.js +174 -0
- package/src/state/selectors/selectPlotArea.js +19 -0
- package/src/state/selectors/selectTooltipAxisId.js +3 -0
- package/src/state/selectors/selectTooltipAxisType.js +25 -0
- package/src/state/selectors/selectTooltipEventType.js +27 -0
- package/src/state/selectors/selectTooltipPayloadSearcher.js +3 -0
- package/src/state/selectors/selectTooltipSettings.js +3 -0
- package/src/state/selectors/selectTooltipState.js +3 -0
- package/src/state/selectors/selectors.js +222 -0
- package/src/state/selectors/tooltipSelectors.js +471 -0
- package/src/state/selectors/touchSelectors.js +31 -0
- package/src/state/store.js +101 -0
- package/src/state/tooltipSlice.js +237 -0
- package/src/state/touchEventsMiddleware.js +140 -0
- package/src/state/types/StackedGraphicalItem.js +18 -0
- package/src/state/zIndexSlice.js +167 -0
- package/src/synchronisation/syncSelectors.js +5 -0
- package/src/synchronisation/useChartSynchronisation.tsrx +285 -0
- package/src/util/ActiveShapeUtils.tsrx +62 -0
- package/src/util/BarUtils.tsrx +35 -0
- package/src/util/CartesianUtils.js +66 -0
- package/src/util/ChartUtils.js +630 -0
- package/src/util/Constants.js +42 -0
- package/src/util/DOMUtils.js +180 -0
- package/src/util/DataUtils.js +199 -0
- package/src/util/Events.js +7 -0
- package/src/util/Global.js +13 -0
- package/src/util/LRUCache.js +58 -0
- package/src/util/LogUtils.js +29 -0
- package/src/util/PolarUtils.js +190 -0
- package/src/util/ReactUtils.ts +94 -0
- package/src/util/ReduceCSSCalc.js +260 -0
- package/src/util/TickUtils.js +43 -0
- package/src/util/YAxisUtils.js +43 -0
- package/src/util/axisPropsAreEqual.js +63 -0
- package/src/util/createEventProxy.js +18 -0
- package/src/util/excludeEventProps.js +172 -0
- package/src/util/getActiveCoordinate.js +253 -0
- package/src/util/getAxisTypeBasedOnLayout.js +17 -0
- package/src/util/getClassNameFromUnknown.js +8 -0
- package/src/util/getEveryNth.js +29 -0
- package/src/util/getRadiusAndStrokeWidthFromDot.js +28 -0
- package/src/util/getRelativeCoordinate.js +96 -0
- package/src/util/getSliced.js +11 -0
- package/src/util/isDomainSpecifiedByUser.js +255 -0
- package/src/util/isWellBehavedNumber.js +8 -0
- package/src/util/propsAreEqual.js +96 -0
- package/src/util/resolveDefaultProps.js +131 -0
- package/src/util/round.js +39 -0
- package/src/util/scale/RechartsScale.js +68 -0
- package/src/util/scale/createCategoricalInverse.js +77 -0
- package/src/util/scale/getNiceTickValues.js +354 -0
- package/src/util/scale/index.js +3 -0
- package/src/util/scale/util/arithmetic.js +51 -0
- package/src/util/stacks/getStackSeriesIdentifier.js +10 -0
- package/src/util/svgPropertiesAndEvents.ts +29 -0
- package/src/util/svgPropertiesNoEvents.js +383 -0
- package/src/util/types.ts +59 -0
- package/src/util/useAnimationId.ts +14 -0
- package/src/util/useId.ts +13 -0
- package/src/util/usePrefersReducedMotion.ts +30 -0
- package/src/util/useReportScale.ts +26 -0
- package/src/util/useUniqueId.js +34 -0
- package/src/zIndex/DefaultZIndexes.js +75 -0
- package/src/zIndex/ZIndexLayer.tsrx +80 -0
- package/src/zIndex/ZIndexLayer.tsrx.d.ts +2 -0
- package/src/zIndex/ZIndexPortal.tsrx +43 -0
- package/src/zIndex/getZIndexFromUnknown.js +15 -0
- package/src/zIndex/zIndexSelectors.js +45 -0
|
@@ -0,0 +1,716 @@
|
|
|
1
|
+
// Port of cartesian/Bar.tsx — the bar graphical item: redux registration
|
|
2
|
+
// (graphical item, legend, tooltip settings), store-computed rectangles,
|
|
3
|
+
// background bars, active-bar highlight, stack clipping, labels, animation.
|
|
4
|
+
// ONE structural divergence: Cells are collected by REGISTRATION (see
|
|
5
|
+
// context/CellsContext) instead of children introspection — octane's compiled
|
|
6
|
+
// children are opaque. `computeBarRectangles` stays here (vendored
|
|
7
|
+
// barSelectors imports it through cartesian/Bar.ts).
|
|
8
|
+
import { memo, useCallback, useEffect, useRef, useState } from 'octane';
|
|
9
|
+
import { clsx } from 'clsx';
|
|
10
|
+
import { Layer } from '../container/Layer.tsrx';
|
|
11
|
+
import {
|
|
12
|
+
CartesianLabelListContextProvider,
|
|
13
|
+
LabelListFromLabelProp,
|
|
14
|
+
} from '../component/LabelList.tsrx';
|
|
15
|
+
import { interpolate, isNan, mathSign, noop } from '../util/DataUtils';
|
|
16
|
+
import {
|
|
17
|
+
getBaseValueOfBar,
|
|
18
|
+
getCateCoordinateOfBar,
|
|
19
|
+
getTooltipNameProp,
|
|
20
|
+
getValueByDataKey,
|
|
21
|
+
truncateByDomain,
|
|
22
|
+
} from '../util/ChartUtils';
|
|
23
|
+
import { adaptEventsOfChild } from '../util/types.ts';
|
|
24
|
+
import { BarRectangle, defaultBarShape, minPointSizeCallback } from '../util/BarUtils.tsrx';
|
|
25
|
+
import {
|
|
26
|
+
useMouseClickItemDispatch,
|
|
27
|
+
useMouseEnterItemDispatch,
|
|
28
|
+
useMouseLeaveItemDispatch,
|
|
29
|
+
} from '../context/tooltipContext';
|
|
30
|
+
import { SetTooltipEntrySettings } from '../state/SetTooltipEntrySettings';
|
|
31
|
+
import { SetErrorBarContext } from '../context/ErrorBarContext.tsrx';
|
|
32
|
+
import { GraphicalItemClipPath, useNeedsClip } from './GraphicalItemClipPath.tsrx';
|
|
33
|
+
import { useChartLayout } from '../context/chartLayoutContext.ts';
|
|
34
|
+
import { selectBarRectangles } from '../state/selectors/barSelectors';
|
|
35
|
+
import { useAppSelector } from '../state/hooks';
|
|
36
|
+
import { useIsPanorama } from '../context/PanoramaContext.ts';
|
|
37
|
+
import {
|
|
38
|
+
selectActiveTooltipDataKey,
|
|
39
|
+
selectActiveTooltipIndex,
|
|
40
|
+
} from '../state/selectors/tooltipSelectors';
|
|
41
|
+
import { SetLegendPayload } from '../state/SetLegendPayload';
|
|
42
|
+
import { resolveDefaultProps } from '../util/resolveDefaultProps';
|
|
43
|
+
import { RegisterGraphicalItemId } from '../context/RegisterGraphicalItemId.tsrx';
|
|
44
|
+
import { SetCartesianGraphicalItem } from '../state/SetGraphicalItem';
|
|
45
|
+
import {
|
|
46
|
+
svgPropertiesNoEvents,
|
|
47
|
+
svgPropertiesNoEventsFromUnknown,
|
|
48
|
+
} from '../util/svgPropertiesNoEvents';
|
|
49
|
+
import { AnimatedItems, useAnimationCallbacks } from '../animation/AnimatedItems.tsrx';
|
|
50
|
+
import { matchAppend } from '../animation/matchBy';
|
|
51
|
+
import { ZIndexLayer } from '../zIndex/ZIndexLayer.tsrx';
|
|
52
|
+
import { DefaultZIndexes } from '../zIndex/DefaultZIndexes';
|
|
53
|
+
import { getZIndexFromUnknown } from '../zIndex/getZIndexFromUnknown';
|
|
54
|
+
import { propsAreEqual } from '../util/propsAreEqual';
|
|
55
|
+
import { BarStackClipLayer, useStackId } from './BarStack.tsrx';
|
|
56
|
+
import { CellsContext, useCellRegistry } from '../context/CellsContext';
|
|
57
|
+
|
|
58
|
+
const computeLegendPayloadFromBarData = (props) => {
|
|
59
|
+
const { dataKey, name, fill, legendType, hide } = props;
|
|
60
|
+
return [
|
|
61
|
+
{
|
|
62
|
+
inactive: hide,
|
|
63
|
+
dataKey,
|
|
64
|
+
type: legendType,
|
|
65
|
+
color: fill,
|
|
66
|
+
value: getTooltipNameProp(name, dataKey),
|
|
67
|
+
payload: props,
|
|
68
|
+
},
|
|
69
|
+
];
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
const SetBarTooltipEntrySettings = memo((props) => {
|
|
73
|
+
const {
|
|
74
|
+
dataKey,
|
|
75
|
+
stroke,
|
|
76
|
+
strokeWidth,
|
|
77
|
+
fill,
|
|
78
|
+
name,
|
|
79
|
+
hide,
|
|
80
|
+
unit,
|
|
81
|
+
formatter,
|
|
82
|
+
tooltipType,
|
|
83
|
+
id,
|
|
84
|
+
} = props;
|
|
85
|
+
const tooltipEntrySettings = {
|
|
86
|
+
dataDefinedOnItem: undefined,
|
|
87
|
+
getPosition: noop,
|
|
88
|
+
settings: {
|
|
89
|
+
stroke,
|
|
90
|
+
strokeWidth,
|
|
91
|
+
fill,
|
|
92
|
+
dataKey,
|
|
93
|
+
nameKey: undefined,
|
|
94
|
+
name: getTooltipNameProp(name, dataKey),
|
|
95
|
+
hide,
|
|
96
|
+
type: tooltipType,
|
|
97
|
+
color: fill,
|
|
98
|
+
unit,
|
|
99
|
+
formatter,
|
|
100
|
+
graphicalItemId: id,
|
|
101
|
+
},
|
|
102
|
+
};
|
|
103
|
+
return <SetTooltipEntrySettings tooltipEntrySettings={tooltipEntrySettings} />;
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
function BarBackground(props) {
|
|
107
|
+
const activeIndex = useAppSelector(selectActiveTooltipIndex);
|
|
108
|
+
const { data, dataKey, background: backgroundFromProps, allOtherBarProps } = props;
|
|
109
|
+
const {
|
|
110
|
+
onMouseEnter: onMouseEnterFromProps,
|
|
111
|
+
onMouseLeave: onMouseLeaveFromProps,
|
|
112
|
+
onClick: onItemClickFromProps,
|
|
113
|
+
...restOfAllOtherProps
|
|
114
|
+
} = allOtherBarProps;
|
|
115
|
+
const onMouseEnterFromContext = useMouseEnterItemDispatch(
|
|
116
|
+
onMouseEnterFromProps,
|
|
117
|
+
dataKey,
|
|
118
|
+
allOtherBarProps.id,
|
|
119
|
+
);
|
|
120
|
+
const onMouseLeaveFromContext = useMouseLeaveItemDispatch(onMouseLeaveFromProps);
|
|
121
|
+
const onClickFromContext = useMouseClickItemDispatch(
|
|
122
|
+
onItemClickFromProps,
|
|
123
|
+
dataKey,
|
|
124
|
+
allOtherBarProps.id,
|
|
125
|
+
);
|
|
126
|
+
if (!backgroundFromProps || data == null) {
|
|
127
|
+
return null;
|
|
128
|
+
}
|
|
129
|
+
const backgroundProps = svgPropertiesNoEventsFromUnknown(backgroundFromProps);
|
|
130
|
+
return <ZIndexLayer
|
|
131
|
+
zIndex={getZIndexFromUnknown(backgroundFromProps, DefaultZIndexes.barBackground)}
|
|
132
|
+
>{data.map((entry, i) => {
|
|
133
|
+
const { value, background: backgroundFromDataEntry, tooltipPosition, ...rest } = entry;
|
|
134
|
+
if (!backgroundFromDataEntry) {
|
|
135
|
+
return null;
|
|
136
|
+
}
|
|
137
|
+
const onMouseEnter = onMouseEnterFromContext(entry, entry.originalDataIndex);
|
|
138
|
+
const onMouseLeave = onMouseLeaveFromContext(entry, entry.originalDataIndex);
|
|
139
|
+
const onClick = onClickFromContext(entry, entry.originalDataIndex);
|
|
140
|
+
const barRectangleProps = {
|
|
141
|
+
option: backgroundFromProps,
|
|
142
|
+
isActive: String(entry.originalDataIndex) === activeIndex,
|
|
143
|
+
...rest,
|
|
144
|
+
fill: '#eee',
|
|
145
|
+
...backgroundFromDataEntry,
|
|
146
|
+
...backgroundProps,
|
|
147
|
+
...adaptEventsOfChild(restOfAllOtherProps, entry, i),
|
|
148
|
+
onMouseEnter,
|
|
149
|
+
onMouseLeave,
|
|
150
|
+
onClick,
|
|
151
|
+
dataKey,
|
|
152
|
+
index: i,
|
|
153
|
+
className: 'recharts-bar-background-rectangle',
|
|
154
|
+
};
|
|
155
|
+
return <BarRectangle key={'background-bar-' + i} {...barRectangleProps} />;
|
|
156
|
+
})}</ZIndexLayer>;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
function BarLabelListProvider(props) @{
|
|
160
|
+
const { showLabels, children, rects } = props;
|
|
161
|
+
const labelListEntries = rects?.map((entry) => {
|
|
162
|
+
const viewBox = {
|
|
163
|
+
x: entry.x,
|
|
164
|
+
y: entry.y,
|
|
165
|
+
width: entry.width,
|
|
166
|
+
lowerWidth: entry.width,
|
|
167
|
+
upperWidth: entry.width,
|
|
168
|
+
height: entry.height,
|
|
169
|
+
};
|
|
170
|
+
return {
|
|
171
|
+
...viewBox,
|
|
172
|
+
value: entry.value,
|
|
173
|
+
payload: entry.payload,
|
|
174
|
+
parentViewBox: entry.parentViewBox,
|
|
175
|
+
viewBox,
|
|
176
|
+
fill: entry.fill,
|
|
177
|
+
};
|
|
178
|
+
});
|
|
179
|
+
<CartesianLabelListContextProvider
|
|
180
|
+
value={showLabels ? labelListEntries : undefined}
|
|
181
|
+
>{children}</CartesianLabelListContextProvider>
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
function BarRectangleWithActiveState(props) {
|
|
185
|
+
const { shape, activeBar, baseProps, entry, index, dataKey } = props;
|
|
186
|
+
const activeIndex = useAppSelector(selectActiveTooltipIndex);
|
|
187
|
+
const activeDataKey = useAppSelector(selectActiveTooltipDataKey);
|
|
188
|
+
// Only highlight this bar when it matches the active index AND (for
|
|
189
|
+
// non-shared tooltips) the active dataKey. originalDataIndex matches
|
|
190
|
+
// against the pre-filter data slice.
|
|
191
|
+
const isActive =
|
|
192
|
+
activeBar && String(entry.originalDataIndex) === activeIndex &&
|
|
193
|
+
(activeDataKey == null || dataKey === activeDataKey);
|
|
194
|
+
const [stayInLayer, setStayInLayer] = useState(false);
|
|
195
|
+
const [hasMountedActive, setHasMountedActive] = useState(false);
|
|
196
|
+
useEffect(() => {
|
|
197
|
+
let rafId;
|
|
198
|
+
if (isActive) {
|
|
199
|
+
// 1. Enter the layer immediately
|
|
200
|
+
setStayInLayer(true);
|
|
201
|
+
// 2. After the browser paints the inactive state in the new layer,
|
|
202
|
+
// flip to active to trigger the CSS transition.
|
|
203
|
+
rafId = requestAnimationFrame(() => {
|
|
204
|
+
setHasMountedActive(true);
|
|
205
|
+
});
|
|
206
|
+
} else {
|
|
207
|
+
setHasMountedActive(false);
|
|
208
|
+
}
|
|
209
|
+
return () => {
|
|
210
|
+
cancelAnimationFrame(rafId);
|
|
211
|
+
};
|
|
212
|
+
}, [isActive]);
|
|
213
|
+
const handleTransitionEnd = useCallback(() => {
|
|
214
|
+
// 4. Leave the layer only when the exit transition finishes
|
|
215
|
+
if (!isActive) {
|
|
216
|
+
setStayInLayer(false);
|
|
217
|
+
}
|
|
218
|
+
}, [isActive]);
|
|
219
|
+
const isVisuallyActive = isActive && hasMountedActive;
|
|
220
|
+
const shouldRenderInLayer = isActive || stayInLayer;
|
|
221
|
+
let option;
|
|
222
|
+
if (isActive) {
|
|
223
|
+
if (activeBar === true) {
|
|
224
|
+
option = shape;
|
|
225
|
+
} else {
|
|
226
|
+
option = activeBar;
|
|
227
|
+
}
|
|
228
|
+
} else {
|
|
229
|
+
option = shape;
|
|
230
|
+
}
|
|
231
|
+
const content = <BarRectangle
|
|
232
|
+
{...baseProps}
|
|
233
|
+
name={String(baseProps.name)}
|
|
234
|
+
{...entry}
|
|
235
|
+
isActive={isVisuallyActive}
|
|
236
|
+
option={option}
|
|
237
|
+
index={index}
|
|
238
|
+
dataKey={dataKey}
|
|
239
|
+
animationElapsedTime={props.animationElapsedTime}
|
|
240
|
+
isAnimating={props.isAnimating}
|
|
241
|
+
isEntrance={props.isEntrance}
|
|
242
|
+
onTransitionEnd={handleTransitionEnd}
|
|
243
|
+
/>;
|
|
244
|
+
if (shouldRenderInLayer) {
|
|
245
|
+
return <ZIndexLayer zIndex={DefaultZIndexes.activeBar}>
|
|
246
|
+
<BarStackClipLayer index={entry.originalDataIndex}>{content}</BarStackClipLayer>
|
|
247
|
+
</ZIndexLayer>;
|
|
248
|
+
}
|
|
249
|
+
return content;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
function BarRectangleNeverActive(props) {
|
|
253
|
+
const { shape, baseProps, entry, index, dataKey } = props;
|
|
254
|
+
return <BarRectangle
|
|
255
|
+
{...baseProps}
|
|
256
|
+
name={String(baseProps.name)}
|
|
257
|
+
{...entry}
|
|
258
|
+
isActive={false}
|
|
259
|
+
option={shape}
|
|
260
|
+
index={index}
|
|
261
|
+
dataKey={dataKey}
|
|
262
|
+
animationElapsedTime={props.animationElapsedTime}
|
|
263
|
+
isAnimating={props.isAnimating}
|
|
264
|
+
isEntrance={props.isEntrance}
|
|
265
|
+
/>;
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
function BarRectangles(rectanglesProps) {
|
|
269
|
+
const { data, props, animationElapsedTime, isAnimating, isEntrance } = rectanglesProps;
|
|
270
|
+
const { id, ...baseProps } = svgPropertiesNoEvents(props) ?? {};
|
|
271
|
+
const { shape, dataKey, activeBar } = props;
|
|
272
|
+
const {
|
|
273
|
+
onMouseEnter: onMouseEnterFromProps,
|
|
274
|
+
onClick: onItemClickFromProps,
|
|
275
|
+
onMouseLeave: onMouseLeaveFromProps,
|
|
276
|
+
...restOfAllOtherProps
|
|
277
|
+
} = props;
|
|
278
|
+
const onMouseEnterFromContext = useMouseEnterItemDispatch(onMouseEnterFromProps, dataKey, id);
|
|
279
|
+
const onMouseLeaveFromContext = useMouseLeaveItemDispatch(onMouseLeaveFromProps);
|
|
280
|
+
const onClickFromContext = useMouseClickItemDispatch(onItemClickFromProps, dataKey, id);
|
|
281
|
+
if (!data) {
|
|
282
|
+
return null;
|
|
283
|
+
}
|
|
284
|
+
return <>
|
|
285
|
+
{data.map((entry, i) => {
|
|
286
|
+
return <BarStackClipLayer
|
|
287
|
+
index={entry.originalDataIndex}
|
|
288
|
+
key={'rectangle-' + entry?.x + '-' + entry?.y + '-' + entry?.value + '-' + i}
|
|
289
|
+
className="recharts-bar-rectangle"
|
|
290
|
+
{...adaptEventsOfChild(restOfAllOtherProps, entry, i)}
|
|
291
|
+
onMouseEnter={onMouseEnterFromContext(entry, entry.originalDataIndex)}
|
|
292
|
+
onMouseLeave={onMouseLeaveFromContext(entry, entry.originalDataIndex)}
|
|
293
|
+
onClick={onClickFromContext(entry, entry.originalDataIndex)}
|
|
294
|
+
>
|
|
295
|
+
{activeBar
|
|
296
|
+
? <BarRectangleWithActiveState
|
|
297
|
+
shape={shape}
|
|
298
|
+
activeBar={activeBar}
|
|
299
|
+
baseProps={baseProps}
|
|
300
|
+
entry={entry}
|
|
301
|
+
index={i}
|
|
302
|
+
dataKey={dataKey}
|
|
303
|
+
animationElapsedTime={animationElapsedTime}
|
|
304
|
+
isAnimating={isAnimating}
|
|
305
|
+
isEntrance={isEntrance}
|
|
306
|
+
/>
|
|
307
|
+
: // activeBar falsy: the hook-free variant (skips the active-index
|
|
308
|
+
// selectors entirely — they'd never be used).
|
|
309
|
+
<BarRectangleNeverActive
|
|
310
|
+
shape={shape}
|
|
311
|
+
baseProps={baseProps}
|
|
312
|
+
entry={entry}
|
|
313
|
+
index={i}
|
|
314
|
+
dataKey={dataKey}
|
|
315
|
+
animationElapsedTime={animationElapsedTime}
|
|
316
|
+
isAnimating={isAnimating}
|
|
317
|
+
isEntrance={isEntrance}
|
|
318
|
+
/>}
|
|
319
|
+
</BarStackClipLayer>;
|
|
320
|
+
})}
|
|
321
|
+
</>;
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
const defaultBarAnimateItems = (items, animationElapsedTime, layout) => {
|
|
325
|
+
if (items == null) return [];
|
|
326
|
+
if (animationElapsedTime === 1) {
|
|
327
|
+
return items.flatMap((item) => (item.status === 'removed' ? [] : [item.next]));
|
|
328
|
+
}
|
|
329
|
+
return items.flatMap((item) => {
|
|
330
|
+
if (item.status === 'removed') {
|
|
331
|
+
// animate removed items to 0 height/width respective of layout
|
|
332
|
+
if (layout === 'horizontal') {
|
|
333
|
+
return [
|
|
334
|
+
{
|
|
335
|
+
...item.prev,
|
|
336
|
+
height: interpolate(item.prev.height, 0, animationElapsedTime),
|
|
337
|
+
y: interpolate(item.prev.y, item.prev.y + item.prev.height, animationElapsedTime),
|
|
338
|
+
},
|
|
339
|
+
];
|
|
340
|
+
}
|
|
341
|
+
return [
|
|
342
|
+
{ ...item.prev, width: interpolate(item.prev.width, 0, animationElapsedTime) },
|
|
343
|
+
];
|
|
344
|
+
}
|
|
345
|
+
if (item.status === 'matched') {
|
|
346
|
+
return [
|
|
347
|
+
{
|
|
348
|
+
...item.next,
|
|
349
|
+
x: interpolate(item.prev.x, item.next.x, animationElapsedTime),
|
|
350
|
+
y: interpolate(item.prev.y, item.next.y, animationElapsedTime),
|
|
351
|
+
width: interpolate(item.prev.width, item.next.width, animationElapsedTime),
|
|
352
|
+
height: interpolate(item.prev.height, item.next.height, animationElapsedTime),
|
|
353
|
+
},
|
|
354
|
+
];
|
|
355
|
+
}
|
|
356
|
+
// added
|
|
357
|
+
const { next } = item;
|
|
358
|
+
if (layout === 'horizontal') {
|
|
359
|
+
return [
|
|
360
|
+
{
|
|
361
|
+
...next,
|
|
362
|
+
height: interpolate(0, next.height, animationElapsedTime),
|
|
363
|
+
y: interpolate(next.stackedBarStart, next.y, animationElapsedTime),
|
|
364
|
+
},
|
|
365
|
+
];
|
|
366
|
+
}
|
|
367
|
+
return [
|
|
368
|
+
{
|
|
369
|
+
...next,
|
|
370
|
+
width: interpolate(0, next.width, animationElapsedTime),
|
|
371
|
+
x: interpolate(next.stackedBarStart, next.x, animationElapsedTime),
|
|
372
|
+
},
|
|
373
|
+
];
|
|
374
|
+
});
|
|
375
|
+
};
|
|
376
|
+
|
|
377
|
+
function RectanglesWithAnimation(rectanglesWithAnimationProps) {
|
|
378
|
+
const { props, previousRectanglesRef } = rectanglesWithAnimationProps;
|
|
379
|
+
const {
|
|
380
|
+
data,
|
|
381
|
+
isAnimationActive,
|
|
382
|
+
animationBegin,
|
|
383
|
+
animationDuration,
|
|
384
|
+
animationEasing,
|
|
385
|
+
animationInterpolateFn,
|
|
386
|
+
layout,
|
|
387
|
+
} = props;
|
|
388
|
+
const { isAnimating, handleAnimationStart, handleAnimationEnd } = useAnimationCallbacks(
|
|
389
|
+
props.onAnimationStart,
|
|
390
|
+
props.onAnimationEnd,
|
|
391
|
+
);
|
|
392
|
+
return <BarLabelListProvider showLabels={!isAnimating} rects={data}>
|
|
393
|
+
<AnimatedItems
|
|
394
|
+
animationInput={data}
|
|
395
|
+
animationIdPrefix="recharts-bar-"
|
|
396
|
+
items={data}
|
|
397
|
+
previousItemsRef={previousRectanglesRef}
|
|
398
|
+
isAnimationActive={isAnimationActive}
|
|
399
|
+
animationBegin={animationBegin}
|
|
400
|
+
animationDuration={animationDuration}
|
|
401
|
+
animationEasing={animationEasing}
|
|
402
|
+
onAnimationStart={handleAnimationStart}
|
|
403
|
+
onAnimationEnd={handleAnimationEnd}
|
|
404
|
+
animationInterpolateFn={animationInterpolateFn}
|
|
405
|
+
animationMatchBy={props.animationMatchBy}
|
|
406
|
+
layout={layout}
|
|
407
|
+
>
|
|
408
|
+
{(stepData, animationElapsedTime, isEntrance) => <Layer>
|
|
409
|
+
<BarRectangles
|
|
410
|
+
props={props}
|
|
411
|
+
data={stepData}
|
|
412
|
+
animationElapsedTime={animationElapsedTime}
|
|
413
|
+
isAnimating={isAnimating || animationElapsedTime < 1}
|
|
414
|
+
isEntrance={isEntrance}
|
|
415
|
+
/>
|
|
416
|
+
</Layer>}
|
|
417
|
+
</AnimatedItems>
|
|
418
|
+
<LabelListFromLabelProp label={props.label} />
|
|
419
|
+
{props.children}
|
|
420
|
+
</BarLabelListProvider>;
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
function RenderRectangles(props) {
|
|
424
|
+
const previousRectanglesRef = useRef(null);
|
|
425
|
+
return <RectanglesWithAnimation previousRectanglesRef={previousRectanglesRef} props={props} />;
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
const defaultMinPointSize = 0;
|
|
429
|
+
|
|
430
|
+
const errorBarDataPointFormatter = (dataPoint, dataKey) => {
|
|
431
|
+
// A value array means a stacked bar: arr[1] is the bar's end value.
|
|
432
|
+
const value = Array.isArray(dataPoint.value) ? dataPoint.value[1] : dataPoint.value;
|
|
433
|
+
return {
|
|
434
|
+
x: dataPoint.x,
|
|
435
|
+
y: dataPoint.y,
|
|
436
|
+
value,
|
|
437
|
+
// getValueByDataKey does not validate the output type
|
|
438
|
+
errorVal: getValueByDataKey(dataPoint, dataKey),
|
|
439
|
+
};
|
|
440
|
+
};
|
|
441
|
+
|
|
442
|
+
function BarWithState(props) @{
|
|
443
|
+
const { hide, data, dataKey, className, xAxisId, yAxisId, needClip, background, id } = props;
|
|
444
|
+
if (hide || data == null) {
|
|
445
|
+
return null;
|
|
446
|
+
}
|
|
447
|
+
const layerClass = clsx('recharts-bar', className);
|
|
448
|
+
const clipPathId = id;
|
|
449
|
+
<Layer className={layerClass} id={id}>
|
|
450
|
+
@if (needClip) {
|
|
451
|
+
<defs>
|
|
452
|
+
<GraphicalItemClipPath clipPathId={clipPathId} xAxisId={xAxisId} yAxisId={yAxisId} />
|
|
453
|
+
</defs>
|
|
454
|
+
}
|
|
455
|
+
<Layer
|
|
456
|
+
className="recharts-bar-rectangles"
|
|
457
|
+
clipPath={needClip ? 'url(#clipPath-' + clipPathId + ')' : undefined}
|
|
458
|
+
>
|
|
459
|
+
<BarBackground
|
|
460
|
+
data={data}
|
|
461
|
+
dataKey={dataKey}
|
|
462
|
+
background={background}
|
|
463
|
+
allOtherBarProps={props}
|
|
464
|
+
/>
|
|
465
|
+
<RenderRectangles {...props} />
|
|
466
|
+
</Layer>
|
|
467
|
+
</Layer>
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
export const defaultBarProps = {
|
|
471
|
+
activeBar: false,
|
|
472
|
+
animationBegin: 0,
|
|
473
|
+
animationDuration: 400,
|
|
474
|
+
animationEasing: 'ease',
|
|
475
|
+
animationInterpolateFn: defaultBarAnimateItems,
|
|
476
|
+
animationMatchBy: matchAppend,
|
|
477
|
+
background: false,
|
|
478
|
+
hide: false,
|
|
479
|
+
isAnimationActive: 'auto',
|
|
480
|
+
label: false,
|
|
481
|
+
legendType: 'rect',
|
|
482
|
+
minPointSize: defaultMinPointSize,
|
|
483
|
+
shape: defaultBarShape,
|
|
484
|
+
xAxisId: 0,
|
|
485
|
+
yAxisId: 0,
|
|
486
|
+
zIndex: DefaultZIndexes.bar,
|
|
487
|
+
};
|
|
488
|
+
|
|
489
|
+
function BarImpl(props) {
|
|
490
|
+
const {
|
|
491
|
+
xAxisId,
|
|
492
|
+
yAxisId,
|
|
493
|
+
hide,
|
|
494
|
+
legendType,
|
|
495
|
+
minPointSize,
|
|
496
|
+
activeBar,
|
|
497
|
+
animationBegin,
|
|
498
|
+
animationDuration,
|
|
499
|
+
animationEasing,
|
|
500
|
+
isAnimationActive,
|
|
501
|
+
} = props;
|
|
502
|
+
const { needClip } = useNeedsClip(xAxisId, yAxisId);
|
|
503
|
+
const layout = useChartLayout();
|
|
504
|
+
const isPanorama = useIsPanorama();
|
|
505
|
+
// octane divergence: cells arrive via registration (children render inside
|
|
506
|
+
// the CellsContext provider below), not children introspection.
|
|
507
|
+
const [cells, cellRegistry] = useCellRegistry();
|
|
508
|
+
const rects = useAppSelector((state) => selectBarRectangles(state, props.id, isPanorama, cells));
|
|
509
|
+
if (layout !== 'vertical' && layout !== 'horizontal') {
|
|
510
|
+
return null;
|
|
511
|
+
}
|
|
512
|
+
let errorBarOffset;
|
|
513
|
+
const firstDataPoint = rects?.[0];
|
|
514
|
+
if (firstDataPoint == null || firstDataPoint.height == null || firstDataPoint.width == null) {
|
|
515
|
+
errorBarOffset = 0;
|
|
516
|
+
} else {
|
|
517
|
+
errorBarOffset = layout === 'vertical' ? firstDataPoint.height / 2 : firstDataPoint.width / 2;
|
|
518
|
+
}
|
|
519
|
+
return <SetErrorBarContext
|
|
520
|
+
xAxisId={xAxisId}
|
|
521
|
+
yAxisId={yAxisId}
|
|
522
|
+
data={rects}
|
|
523
|
+
dataPointFormatter={errorBarDataPointFormatter}
|
|
524
|
+
errorBarOffset={errorBarOffset}
|
|
525
|
+
>
|
|
526
|
+
<CellsContext.Provider value={cellRegistry}>
|
|
527
|
+
<BarWithState
|
|
528
|
+
{...props}
|
|
529
|
+
layout={layout}
|
|
530
|
+
needClip={needClip}
|
|
531
|
+
data={rects}
|
|
532
|
+
xAxisId={xAxisId}
|
|
533
|
+
yAxisId={yAxisId}
|
|
534
|
+
hide={hide}
|
|
535
|
+
legendType={legendType}
|
|
536
|
+
minPointSize={minPointSize}
|
|
537
|
+
activeBar={activeBar}
|
|
538
|
+
animationBegin={animationBegin}
|
|
539
|
+
animationDuration={animationDuration}
|
|
540
|
+
animationEasing={animationEasing}
|
|
541
|
+
isAnimationActive={isAnimationActive}
|
|
542
|
+
/>
|
|
543
|
+
</CellsContext.Provider>
|
|
544
|
+
</SetErrorBarContext>;
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
export function computeBarRectangles({
|
|
548
|
+
layout,
|
|
549
|
+
barSettings: { dataKey, minPointSize: minPointSizeProp, hasCustomShape },
|
|
550
|
+
pos,
|
|
551
|
+
bandSize,
|
|
552
|
+
xAxis,
|
|
553
|
+
yAxis,
|
|
554
|
+
xAxisTicks,
|
|
555
|
+
yAxisTicks,
|
|
556
|
+
stackedData,
|
|
557
|
+
displayedData,
|
|
558
|
+
offset,
|
|
559
|
+
cells,
|
|
560
|
+
parentViewBox,
|
|
561
|
+
dataStartIndex,
|
|
562
|
+
}) {
|
|
563
|
+
const numericAxis =
|
|
564
|
+
layout === 'horizontal' ? yAxis : xAxis;
|
|
565
|
+
const stackedDomain =
|
|
566
|
+
stackedData ? numericAxis.scale.domain() : null;
|
|
567
|
+
const baseValue = getBaseValueOfBar({ numericAxis });
|
|
568
|
+
const stackedBarStart = numericAxis.scale.map(baseValue);
|
|
569
|
+
return displayedData.map((entry, index) => {
|
|
570
|
+
let value, x, y, width, height, background;
|
|
571
|
+
if (stackedData) {
|
|
572
|
+
// Use dataStartIndex to access the correct element in the full stackedData array
|
|
573
|
+
const untruncatedValue = stackedData[index + dataStartIndex];
|
|
574
|
+
if (untruncatedValue == null) {
|
|
575
|
+
return null;
|
|
576
|
+
}
|
|
577
|
+
value = truncateByDomain(untruncatedValue, stackedDomain);
|
|
578
|
+
} else {
|
|
579
|
+
value = getValueByDataKey(entry, dataKey);
|
|
580
|
+
if (!Array.isArray(value)) {
|
|
581
|
+
value = [baseValue, value];
|
|
582
|
+
}
|
|
583
|
+
}
|
|
584
|
+
const minPointSize = minPointSizeCallback(minPointSizeProp, defaultMinPointSize)(
|
|
585
|
+
value[1],
|
|
586
|
+
index,
|
|
587
|
+
);
|
|
588
|
+
if (layout === 'horizontal') {
|
|
589
|
+
const baseValueScale = yAxis.scale.map(value[0]);
|
|
590
|
+
const currentValueScale = yAxis.scale.map(value[1]);
|
|
591
|
+
if (baseValueScale == null || currentValueScale == null) {
|
|
592
|
+
return null;
|
|
593
|
+
}
|
|
594
|
+
x = getCateCoordinateOfBar({
|
|
595
|
+
axis: xAxis,
|
|
596
|
+
ticks: xAxisTicks,
|
|
597
|
+
bandSize,
|
|
598
|
+
offset: pos.offset,
|
|
599
|
+
entry,
|
|
600
|
+
index,
|
|
601
|
+
});
|
|
602
|
+
y = currentValueScale ?? baseValueScale ?? undefined;
|
|
603
|
+
width = pos.size;
|
|
604
|
+
const computedHeight = baseValueScale - currentValueScale;
|
|
605
|
+
height = isNan(computedHeight) ? 0 : computedHeight;
|
|
606
|
+
background = { x, y: offset.top, width, height: offset.height };
|
|
607
|
+
if (Math.abs(minPointSize) > 0 && Math.abs(height) < Math.abs(minPointSize)) {
|
|
608
|
+
const delta =
|
|
609
|
+
mathSign(height || minPointSize) * (Math.abs(minPointSize) - Math.abs(height));
|
|
610
|
+
y -= delta;
|
|
611
|
+
height += delta;
|
|
612
|
+
}
|
|
613
|
+
} else {
|
|
614
|
+
const baseValueScale = xAxis.scale.map(value[0]);
|
|
615
|
+
const currentValueScale = xAxis.scale.map(value[1]);
|
|
616
|
+
if (baseValueScale == null || currentValueScale == null) {
|
|
617
|
+
return null;
|
|
618
|
+
}
|
|
619
|
+
x = baseValueScale;
|
|
620
|
+
y = getCateCoordinateOfBar({
|
|
621
|
+
axis: yAxis,
|
|
622
|
+
ticks: yAxisTicks,
|
|
623
|
+
bandSize,
|
|
624
|
+
offset: pos.offset,
|
|
625
|
+
entry,
|
|
626
|
+
index,
|
|
627
|
+
});
|
|
628
|
+
width = currentValueScale - baseValueScale;
|
|
629
|
+
height = pos.size;
|
|
630
|
+
background = { x: offset.left, y, width: offset.width, height };
|
|
631
|
+
if (Math.abs(minPointSize) > 0 && Math.abs(width) < Math.abs(minPointSize)) {
|
|
632
|
+
const delta = mathSign(width || minPointSize) * (Math.abs(minPointSize) - Math.abs(width));
|
|
633
|
+
width += delta;
|
|
634
|
+
}
|
|
635
|
+
}
|
|
636
|
+
// Filter out 0-dimension rectangles early (unless a custom shape may
|
|
637
|
+
// still draw something there). Sparse arrays stay index-stable via
|
|
638
|
+
// originalDataIndex.
|
|
639
|
+
if (
|
|
640
|
+
x == null || y == null || width == null || height == null ||
|
|
641
|
+
!hasCustomShape && (width === 0 || height === 0)
|
|
642
|
+
) {
|
|
643
|
+
return null;
|
|
644
|
+
}
|
|
645
|
+
return {
|
|
646
|
+
...entry,
|
|
647
|
+
stackedBarStart,
|
|
648
|
+
x,
|
|
649
|
+
y,
|
|
650
|
+
width,
|
|
651
|
+
height,
|
|
652
|
+
value: stackedData ? value : value[1],
|
|
653
|
+
payload: entry,
|
|
654
|
+
background,
|
|
655
|
+
tooltipPosition: { x: x + width / 2, y: y + height / 2 },
|
|
656
|
+
parentViewBox,
|
|
657
|
+
originalDataIndex: index,
|
|
658
|
+
...cells && cells[index] && cells[index].props,
|
|
659
|
+
};
|
|
660
|
+
}).filter(Boolean);
|
|
661
|
+
}
|
|
662
|
+
|
|
663
|
+
function BarFn(outsideProps) {
|
|
664
|
+
const props = resolveDefaultProps(outsideProps, defaultBarProps);
|
|
665
|
+
// stackId may arrive from props or from BarStack context
|
|
666
|
+
const stackId = useStackId(props.stackId);
|
|
667
|
+
const isPanorama = useIsPanorama();
|
|
668
|
+
// Report all props to the store first, before any other hooks, to avoid
|
|
669
|
+
// circular dependencies.
|
|
670
|
+
return <RegisterGraphicalItemId id={props.id} type="bar">
|
|
671
|
+
{(id) => <>
|
|
672
|
+
<SetLegendPayload legendPayload={computeLegendPayloadFromBarData(props)} />
|
|
673
|
+
<SetBarTooltipEntrySettings
|
|
674
|
+
dataKey={props.dataKey}
|
|
675
|
+
stroke={props.stroke}
|
|
676
|
+
strokeWidth={props.strokeWidth}
|
|
677
|
+
fill={props.fill}
|
|
678
|
+
name={props.name}
|
|
679
|
+
hide={props.hide}
|
|
680
|
+
unit={props.unit}
|
|
681
|
+
formatter={props.formatter}
|
|
682
|
+
tooltipType={props.tooltipType}
|
|
683
|
+
id={id}
|
|
684
|
+
/>
|
|
685
|
+
<SetCartesianGraphicalItem
|
|
686
|
+
type="bar"
|
|
687
|
+
id={id}
|
|
688
|
+
data={undefined}
|
|
689
|
+
xAxisId={props.xAxisId}
|
|
690
|
+
yAxisId={props.yAxisId}
|
|
691
|
+
zAxisId={0}
|
|
692
|
+
dataKey={props.dataKey}
|
|
693
|
+
stackId={stackId}
|
|
694
|
+
hide={props.hide}
|
|
695
|
+
barSize={props.barSize}
|
|
696
|
+
minPointSize={props.minPointSize}
|
|
697
|
+
maxBarSize={props.maxBarSize}
|
|
698
|
+
isPanorama={isPanorama}
|
|
699
|
+
hasCustomShape={props.shape != null && props.shape !== defaultBarShape}
|
|
700
|
+
/>
|
|
701
|
+
<ZIndexLayer zIndex={props.zIndex}>
|
|
702
|
+
<BarImpl {...props} id={id} />
|
|
703
|
+
</ZIndexLayer>
|
|
704
|
+
</>}
|
|
705
|
+
</RegisterGraphicalItemId>;
|
|
706
|
+
}
|
|
707
|
+
|
|
708
|
+
/**
|
|
709
|
+
* @provides ErrorBarContext
|
|
710
|
+
* @provides LabelListContext
|
|
711
|
+
* @provides CellReader
|
|
712
|
+
* @consumes CartesianChartContext
|
|
713
|
+
* @consumes BarStackContext
|
|
714
|
+
*/
|
|
715
|
+
export const Bar = memo(BarFn, propsAreEqual);
|
|
716
|
+
Bar.displayName = 'Bar';
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
// Type declaration for the .tsrx component (resolved by relative path).
|
|
2
|
+
export declare const defaultBarProps: Record<string, unknown>;
|
|
3
|
+
export declare const Bar: (props: Record<string, unknown>) => unknown;
|
|
4
|
+
export declare function computeBarRectangles(input: Record<string, unknown>): unknown[];
|