@octanejs/recharts 0.1.61 → 0.1.63
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/package.json +5 -5
- package/src/animation/AnimatedItems.tsrx +36 -31
- package/src/animation/CSSTransitionAnimate.tsrx +1 -2
- package/src/animation/JavascriptAnimate.tsrx +1 -2
- package/src/cartesian/Area.tsrx +414 -386
- package/src/cartesian/AreaRevealShape.tsrx +103 -84
- package/src/cartesian/Bar.tsrx +343 -317
- package/src/cartesian/BarStack.tsrx +33 -28
- package/src/cartesian/CartesianAxis.tsrx +168 -165
- package/src/cartesian/CartesianGrid.tsrx +256 -272
- package/src/cartesian/ErrorBar.tsrx +108 -104
- package/src/cartesian/Funnel.tsrx +405 -382
- package/src/cartesian/GraphicalItemClipPath.tsrx +4 -8
- package/src/cartesian/Line.tsrx +190 -177
- package/src/cartesian/LineDrawShape.tsrx +14 -15
- package/src/cartesian/ReferenceLine.tsrx +119 -105
- package/src/cartesian/Scatter.tsrx +416 -398
- package/src/cartesian/XAxis.tsrx +39 -32
- package/src/cartesian/YAxis.tsrx +47 -37
- package/src/cartesian/ZAxis.tsrx +76 -73
- package/src/chart/AreaChart.tsrx +15 -11
- package/src/chart/BarChart.tsrx +15 -11
- package/src/chart/CategoricalChart.tsrx +32 -26
- package/src/chart/ComposedChart.tsrx +15 -11
- package/src/chart/FunnelChart.tsrx +15 -11
- package/src/chart/LineChart.tsrx +15 -11
- package/src/chart/PieChart.tsrx +15 -11
- package/src/chart/PolarChart.tsrx +45 -48
- package/src/chart/RadarChart.tsrx +38 -32
- package/src/chart/RadialBarChart.tsrx +15 -11
- package/src/chart/RechartsWrapper.tsrx +214 -162
- package/src/chart/Sankey.tsrx +412 -378
- package/src/chart/ScatterChart.tsrx +15 -11
- package/src/chart/SunburstChart.tsrx +162 -155
- package/src/component/ActivePoints.tsrx +19 -13
- package/src/component/Cursor.tsrx +25 -18
- package/src/component/DefaultLegendContent.tsrx +131 -127
- package/src/component/DefaultTooltipContent.tsrx +46 -42
- package/src/component/Dots.tsrx +11 -5
- package/src/component/Label.tsrx +69 -55
- package/src/component/LabelList.tsrx +32 -27
- package/src/component/Legend.tsrx +120 -123
- package/src/component/ResponsiveContainer.tsrx +18 -11
- package/src/component/Text.tsrx +50 -43
- package/src/component/Tooltip.tsrx +234 -223
- package/src/component/TooltipBoundingBox.tsrx +34 -34
- package/src/container/ClipPathProvider.tsrx +1 -3
- package/src/container/Layer.tsrx +5 -1
- package/src/container/RootSurface.tsrx +31 -21
- package/src/container/Surface.tsrx +15 -13
- package/src/context/ErrorBarContext.tsrx +5 -5
- package/src/polar/Pie.tsrx +541 -487
- package/src/polar/PolarAngleAxis.tsrx +245 -227
- package/src/polar/PolarGrid.tsrx +139 -127
- package/src/polar/PolarRadiusAxis.tsrx +204 -185
- package/src/polar/Radar.tsrx +274 -264
- package/src/polar/RadialBar.tsrx +408 -361
- package/src/shape/Cross.tsrx +13 -7
- package/src/shape/Curve.tsrx +54 -44
- package/src/shape/Dot.tsrx +10 -8
- package/src/shape/Polygon.tsrx +38 -29
- package/src/shape/Rectangle.tsrx +73 -28
- package/src/shape/Sector.tsrx +30 -18
- package/src/shape/Symbols.tsrx +13 -11
- package/src/shape/Trapezoid.tsrx +16 -11
- package/src/state/RechartsStoreProvider.tsrx +5 -1
- package/src/synchronisation/useChartSynchronisation.tsrx +8 -7
- package/src/util/BarUtils.tsrx +43 -40
- package/src/util/FunnelUtils.tsrx +5 -5
- package/src/util/RadialBarUtils.tsrx +3 -4
- package/src/util/ScatterUtils.tsrx +13 -8
- package/src/zIndex/ZIndexLayer.tsrx +2 -2
- package/src/zIndex/ZIndexPortal.tsrx +2 -8
package/src/cartesian/Bar.tsrx
CHANGED
|
@@ -59,16 +59,14 @@ export interface BarRectangleItem extends RectangleProps {
|
|
|
59
59
|
stackedBarStart: number | undefined;
|
|
60
60
|
originalDataIndex: number;
|
|
61
61
|
}
|
|
62
|
-
export type BarShapeProps =
|
|
63
|
-
|
|
62
|
+
export type BarShapeProps = BarRectangleItem &
|
|
63
|
+
ShapeAnimationProps & {
|
|
64
64
|
isActive: boolean;
|
|
65
65
|
index: number;
|
|
66
66
|
};
|
|
67
67
|
export type BarBackgroundShapeProps = Omit<BarShapeProps, 'value' | 'tooltipPosition'>;
|
|
68
|
-
interface BarProps<DataPointType, ValueAxisType>
|
|
69
|
-
DataPointType,
|
|
70
|
-
ValueAxisType
|
|
71
|
-
>, ZIndexable {
|
|
68
|
+
interface BarProps<DataPointType, ValueAxisType>
|
|
69
|
+
extends DataConsumer<DataPointType, ValueAxisType>, ZIndexable {
|
|
72
70
|
className?: string;
|
|
73
71
|
index?: Key;
|
|
74
72
|
xAxisId?: AxisId;
|
|
@@ -99,8 +97,11 @@ interface BarProps<DataPointType, ValueAxisType> extends DataConsumer<
|
|
|
99
97
|
label?: ImplicitLabelListType;
|
|
100
98
|
zIndex?: number;
|
|
101
99
|
}
|
|
102
|
-
type BarMouseEvent =
|
|
103
|
-
|
|
100
|
+
type BarMouseEvent = (
|
|
101
|
+
data: BarRectangleItem,
|
|
102
|
+
index: number,
|
|
103
|
+
event: NativeMouseEvent<SVGGElement>,
|
|
104
|
+
) => void;
|
|
104
105
|
interface BarEvents {
|
|
105
106
|
onClick: BarMouseEvent;
|
|
106
107
|
onMouseEnter: BarMouseEvent;
|
|
@@ -145,13 +146,13 @@ type InternalBarProps = {
|
|
|
145
146
|
id: GraphicalItemId;
|
|
146
147
|
label?: ImplicitLabelListType;
|
|
147
148
|
};
|
|
148
|
-
type BarSvgProps =
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
149
|
+
type BarSvgProps = Omit<
|
|
150
|
+
PresentationAttributesAdaptChildEvent<BarRectangleItem, SVGGElement>,
|
|
151
|
+
'radius' | 'name' | 'ref'
|
|
152
|
+
>;
|
|
153
|
+
export type Props<DataPointType = any, ValueAxisType = any> = Partial<BarEvents> &
|
|
154
|
+
BarProps<DataPointType, ValueAxisType> &
|
|
155
|
+
Omit<BarSvgProps, keyof BarEvents>;
|
|
155
156
|
type InternalProps = BarSvgProps & InternalBarProps;
|
|
156
157
|
type BarBackgroundProps = {
|
|
157
158
|
background?: ActiveShape<BarBackgroundShapeProps, SVGPathElement>;
|
|
@@ -159,14 +160,12 @@ type BarBackgroundProps = {
|
|
|
159
160
|
dataKey: DataKey<any> | undefined;
|
|
160
161
|
allOtherBarProps: InternalProps;
|
|
161
162
|
};
|
|
162
|
-
type BarRectanglesProps =
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
children?: OctaneNode;
|
|
169
|
-
};
|
|
163
|
+
type BarRectanglesProps = InternalProps & {
|
|
164
|
+
data: ReadonlyArray<BarRectangleItem> | undefined;
|
|
165
|
+
};
|
|
166
|
+
type BarImplProps = Omit<InternalBarProps, 'layout' | 'data'> & {
|
|
167
|
+
children?: OctaneNode;
|
|
168
|
+
};
|
|
170
169
|
// Port of cartesian/Bar.tsx — the bar graphical item: redux registration
|
|
171
170
|
// (graphical item, legend, tooltip settings), store-computed rectangles,
|
|
172
171
|
// background bars, active-bar highlight, stack clipping, labels, animation.
|
|
@@ -243,53 +242,45 @@ const computeLegendPayloadFromBarData = (props: Props) => {
|
|
|
243
242
|
];
|
|
244
243
|
};
|
|
245
244
|
|
|
246
|
-
const SetBarTooltipEntrySettings = memo(
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
dataKey,
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
color: fill,
|
|
286
|
-
unit,
|
|
287
|
-
formatter,
|
|
288
|
-
graphicalItemId: id,
|
|
289
|
-
},
|
|
290
|
-
};
|
|
291
|
-
return <SetTooltipEntrySettings tooltipEntrySettings={tooltipEntrySettings} />;
|
|
292
|
-
});
|
|
245
|
+
const SetBarTooltipEntrySettings = memo(
|
|
246
|
+
(
|
|
247
|
+
props: Pick<
|
|
248
|
+
InternalProps,
|
|
249
|
+
| 'dataKey'
|
|
250
|
+
| 'stroke'
|
|
251
|
+
| 'strokeWidth'
|
|
252
|
+
| 'fill'
|
|
253
|
+
| 'name'
|
|
254
|
+
| 'hide'
|
|
255
|
+
| 'unit'
|
|
256
|
+
| 'formatter'
|
|
257
|
+
| 'tooltipType'
|
|
258
|
+
| 'id'
|
|
259
|
+
>,
|
|
260
|
+
) => {
|
|
261
|
+
const { dataKey, stroke, strokeWidth, fill, name, hide, unit, formatter, tooltipType, id } =
|
|
262
|
+
props;
|
|
263
|
+
const tooltipEntrySettings: TooltipPayloadConfiguration = {
|
|
264
|
+
dataDefinedOnItem: undefined,
|
|
265
|
+
getPosition: noop,
|
|
266
|
+
settings: {
|
|
267
|
+
stroke,
|
|
268
|
+
strokeWidth,
|
|
269
|
+
fill,
|
|
270
|
+
dataKey,
|
|
271
|
+
nameKey: undefined,
|
|
272
|
+
name: getTooltipNameProp(name, dataKey),
|
|
273
|
+
hide,
|
|
274
|
+
type: tooltipType,
|
|
275
|
+
color: fill,
|
|
276
|
+
unit,
|
|
277
|
+
formatter,
|
|
278
|
+
graphicalItemId: id,
|
|
279
|
+
},
|
|
280
|
+
};
|
|
281
|
+
return <SetTooltipEntrySettings tooltipEntrySettings={tooltipEntrySettings} />;
|
|
282
|
+
},
|
|
283
|
+
);
|
|
293
284
|
|
|
294
285
|
function BarBackground(props: BarBackgroundProps) {
|
|
295
286
|
const activeIndex = useAppSelector(selectActiveTooltipIndex);
|
|
@@ -315,33 +306,35 @@ function BarBackground(props: BarBackgroundProps) {
|
|
|
315
306
|
return null;
|
|
316
307
|
}
|
|
317
308
|
const backgroundProps = svgPropertiesNoEventsFromUnknown(backgroundFromProps);
|
|
318
|
-
return
|
|
319
|
-
zIndex={getZIndexFromUnknown(backgroundFromProps, DefaultZIndexes.barBackground)}
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
309
|
+
return (
|
|
310
|
+
<ZIndexLayer zIndex={getZIndexFromUnknown(backgroundFromProps, DefaultZIndexes.barBackground)}>
|
|
311
|
+
{data.map((entry, i) => {
|
|
312
|
+
const { value, background: backgroundFromDataEntry, tooltipPosition, ...rest } = entry;
|
|
313
|
+
if (!backgroundFromDataEntry) {
|
|
314
|
+
return null;
|
|
315
|
+
}
|
|
316
|
+
const onMouseEnter = onMouseEnterFromContext(entry, entry.originalDataIndex);
|
|
317
|
+
const onMouseLeave = onMouseLeaveFromContext(entry, entry.originalDataIndex);
|
|
318
|
+
const onClick = onClickFromContext(entry, entry.originalDataIndex);
|
|
319
|
+
const barRectangleProps: BarBackgroundRectangleProps = {
|
|
320
|
+
option: backgroundFromProps,
|
|
321
|
+
isActive: String(entry.originalDataIndex) === activeIndex,
|
|
322
|
+
...rest,
|
|
323
|
+
fill: '#eee',
|
|
324
|
+
...backgroundFromDataEntry,
|
|
325
|
+
...backgroundProps,
|
|
326
|
+
...adaptEventsOfChild(restOfAllOtherProps, entry, i),
|
|
327
|
+
onMouseEnter,
|
|
328
|
+
onMouseLeave,
|
|
329
|
+
onClick,
|
|
330
|
+
dataKey,
|
|
331
|
+
index: i,
|
|
332
|
+
className: 'recharts-bar-background-rectangle',
|
|
333
|
+
};
|
|
334
|
+
return <BarBackgroundRectangle key={'background-bar-' + i} {...barRectangleProps} />;
|
|
335
|
+
})}
|
|
336
|
+
</ZIndexLayer>
|
|
337
|
+
);
|
|
345
338
|
}
|
|
346
339
|
|
|
347
340
|
function BarLabelListProvider(props: {
|
|
@@ -350,39 +343,41 @@ function BarLabelListProvider(props: {
|
|
|
350
343
|
rects: ReadonlyArray<BarRectangleItem> | undefined;
|
|
351
344
|
}) @{
|
|
352
345
|
const { showLabels, children, rects } = props;
|
|
353
|
-
const labelListEntries: ReadonlyArray<CartesianLabelListEntry> | undefined = rects?.map(
|
|
354
|
-
entry: BarRectangleItem
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
}
|
|
372
|
-
|
|
373
|
-
<CartesianLabelListContextProvider
|
|
374
|
-
|
|
375
|
-
|
|
346
|
+
const labelListEntries: ReadonlyArray<CartesianLabelListEntry> | undefined = rects?.map(
|
|
347
|
+
(entry: BarRectangleItem) => {
|
|
348
|
+
const viewBox: TrapezoidViewBox = {
|
|
349
|
+
x: entry.x,
|
|
350
|
+
y: entry.y,
|
|
351
|
+
width: entry.width,
|
|
352
|
+
lowerWidth: entry.width,
|
|
353
|
+
upperWidth: entry.width,
|
|
354
|
+
height: entry.height,
|
|
355
|
+
};
|
|
356
|
+
return {
|
|
357
|
+
...viewBox,
|
|
358
|
+
value: entry.value,
|
|
359
|
+
payload: entry.payload,
|
|
360
|
+
parentViewBox: entry.parentViewBox,
|
|
361
|
+
viewBox,
|
|
362
|
+
fill: entry.fill,
|
|
363
|
+
};
|
|
364
|
+
},
|
|
365
|
+
);
|
|
366
|
+
<CartesianLabelListContextProvider value={showLabels ? labelListEntries : undefined}>
|
|
367
|
+
{children}
|
|
368
|
+
</CartesianLabelListContextProvider>
|
|
376
369
|
}
|
|
377
370
|
|
|
378
|
-
function BarRectangleWithActiveState(
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
371
|
+
function BarRectangleWithActiveState(
|
|
372
|
+
props: ShapeAnimationProps & {
|
|
373
|
+
shape: ActiveShape<BarShapeProps, SVGPathElement>;
|
|
374
|
+
activeBar: ActiveShape<BarShapeProps, SVGPathElement>;
|
|
375
|
+
baseProps: WithoutId<SVGPropsNoEvents<BarRectanglesProps>>;
|
|
376
|
+
entry: BarRectangleItem;
|
|
377
|
+
index: number;
|
|
378
|
+
dataKey: DataKey<any> | undefined;
|
|
379
|
+
},
|
|
380
|
+
) {
|
|
386
381
|
const { shape, activeBar, baseProps, entry, index, dataKey } = props;
|
|
387
382
|
const activeIndex = useAppSelector(selectActiveTooltipIndex);
|
|
388
383
|
const activeDataKey = useAppSelector(selectActiveTooltipDataKey);
|
|
@@ -390,8 +385,9 @@ function BarRectangleWithActiveState(props: ShapeAnimationProps & {
|
|
|
390
385
|
// non-shared tooltips) the active dataKey. originalDataIndex matches
|
|
391
386
|
// against the pre-filter data slice.
|
|
392
387
|
const isActive: boolean =
|
|
393
|
-
activeBar &&
|
|
394
|
-
|
|
388
|
+
activeBar &&
|
|
389
|
+
String(entry.originalDataIndex) === activeIndex &&
|
|
390
|
+
(activeDataKey == null || dataKey === activeDataKey);
|
|
395
391
|
const [stayInLayer, setStayInLayer] = useState(false);
|
|
396
392
|
const [hasMountedActive, setHasMountedActive] = useState(false);
|
|
397
393
|
useEffect(() => {
|
|
@@ -429,53 +425,63 @@ function BarRectangleWithActiveState(props: ShapeAnimationProps & {
|
|
|
429
425
|
} else {
|
|
430
426
|
option = shape;
|
|
431
427
|
}
|
|
432
|
-
const content =
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
428
|
+
const content = (
|
|
429
|
+
<BarRectangle
|
|
430
|
+
{...baseProps}
|
|
431
|
+
name={String(baseProps.name)}
|
|
432
|
+
{...entry}
|
|
433
|
+
isActive={isVisuallyActive}
|
|
434
|
+
option={option}
|
|
435
|
+
index={index}
|
|
436
|
+
dataKey={dataKey}
|
|
437
|
+
animationElapsedTime={props.animationElapsedTime}
|
|
438
|
+
isAnimating={props.isAnimating}
|
|
439
|
+
isEntrance={props.isEntrance}
|
|
440
|
+
onTransitionEnd={handleTransitionEnd}
|
|
441
|
+
/>
|
|
442
|
+
);
|
|
445
443
|
if (shouldRenderInLayer) {
|
|
446
|
-
return
|
|
447
|
-
<
|
|
448
|
-
|
|
444
|
+
return (
|
|
445
|
+
<ZIndexLayer zIndex={DefaultZIndexes.activeBar}>
|
|
446
|
+
<BarStackClipLayer index={entry.originalDataIndex}>{content}</BarStackClipLayer>
|
|
447
|
+
</ZIndexLayer>
|
|
448
|
+
);
|
|
449
449
|
}
|
|
450
450
|
return content;
|
|
451
451
|
}
|
|
452
452
|
|
|
453
|
-
function BarRectangleNeverActive(
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
453
|
+
function BarRectangleNeverActive(
|
|
454
|
+
props: ShapeAnimationProps & {
|
|
455
|
+
shape: ActiveShape<BarShapeProps, SVGPathElement>;
|
|
456
|
+
baseProps: WithoutId<SVGPropsNoEvents<BarRectanglesProps>>;
|
|
457
|
+
entry: BarRectangleItem;
|
|
458
|
+
index: number;
|
|
459
|
+
dataKey: DataKey<any> | undefined;
|
|
460
|
+
},
|
|
461
|
+
) {
|
|
460
462
|
const { shape, baseProps, entry, index, dataKey } = props;
|
|
461
|
-
return
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
463
|
+
return (
|
|
464
|
+
<BarRectangle
|
|
465
|
+
{...baseProps}
|
|
466
|
+
name={String(baseProps.name)}
|
|
467
|
+
{...entry}
|
|
468
|
+
isActive={false}
|
|
469
|
+
option={shape}
|
|
470
|
+
index={index}
|
|
471
|
+
dataKey={dataKey}
|
|
472
|
+
animationElapsedTime={props.animationElapsedTime}
|
|
473
|
+
isAnimating={props.isAnimating}
|
|
474
|
+
isEntrance={props.isEntrance}
|
|
475
|
+
/>
|
|
476
|
+
);
|
|
473
477
|
}
|
|
474
478
|
|
|
475
|
-
function BarRectangles(
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
+
function BarRectangles(
|
|
480
|
+
rectanglesProps: ShapeAnimationProps & {
|
|
481
|
+
data: ReadonlyArray<BarRectangleItem> | undefined;
|
|
482
|
+
props: BarRectanglesProps;
|
|
483
|
+
},
|
|
484
|
+
) {
|
|
479
485
|
const { data, props, animationElapsedTime, isAnimating, isEntrance } = rectanglesProps;
|
|
480
486
|
const { id, ...baseProps } = svgPropertiesNoEvents(props) ?? {};
|
|
481
487
|
const { shape, dataKey, activeBar } = props;
|
|
@@ -491,44 +497,50 @@ function BarRectangles(rectanglesProps: ShapeAnimationProps & {
|
|
|
491
497
|
if (!data) {
|
|
492
498
|
return null;
|
|
493
499
|
}
|
|
494
|
-
return
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
500
|
+
return (
|
|
501
|
+
<>
|
|
502
|
+
{data.map((entry, i) => {
|
|
503
|
+
return (
|
|
504
|
+
<BarStackClipLayer
|
|
505
|
+
index={entry.originalDataIndex}
|
|
506
|
+
key={'rectangle-' + entry?.x + '-' + entry?.y + '-' + entry?.value + '-' + i}
|
|
507
|
+
className="recharts-bar-rectangle"
|
|
508
|
+
{...adaptEventsOfChild(restOfAllOtherProps, entry, i)}
|
|
509
|
+
onMouseEnter={onMouseEnterFromContext(entry, entry.originalDataIndex)}
|
|
510
|
+
onMouseLeave={onMouseLeaveFromContext(entry, entry.originalDataIndex)}
|
|
511
|
+
onClick={onClickFromContext(entry, entry.originalDataIndex)}
|
|
512
|
+
>
|
|
513
|
+
{activeBar ? (
|
|
514
|
+
<BarRectangleWithActiveState
|
|
515
|
+
shape={shape}
|
|
516
|
+
activeBar={activeBar}
|
|
517
|
+
baseProps={baseProps}
|
|
518
|
+
entry={entry}
|
|
519
|
+
index={i}
|
|
520
|
+
dataKey={dataKey}
|
|
521
|
+
animationElapsedTime={animationElapsedTime}
|
|
522
|
+
isAnimating={isAnimating}
|
|
523
|
+
isEntrance={isEntrance}
|
|
524
|
+
/>
|
|
525
|
+
) : (
|
|
526
|
+
// activeBar falsy: the hook-free variant (skips the active-index
|
|
527
|
+
// selectors entirely — they'd never be used).
|
|
528
|
+
<BarRectangleNeverActive
|
|
529
|
+
shape={shape}
|
|
530
|
+
baseProps={baseProps}
|
|
531
|
+
entry={entry}
|
|
532
|
+
index={i}
|
|
533
|
+
dataKey={dataKey}
|
|
534
|
+
animationElapsedTime={animationElapsedTime}
|
|
535
|
+
isAnimating={isAnimating}
|
|
536
|
+
isEntrance={isEntrance}
|
|
537
|
+
/>
|
|
538
|
+
)}
|
|
539
|
+
</BarStackClipLayer>
|
|
540
|
+
);
|
|
541
|
+
})}
|
|
542
|
+
</>
|
|
543
|
+
);
|
|
532
544
|
}
|
|
533
545
|
|
|
534
546
|
const defaultBarAnimateItems: AnimationInterpolateFn<BarRectangleItem, CartesianLayout> = (
|
|
@@ -552,9 +564,7 @@ const defaultBarAnimateItems: AnimationInterpolateFn<BarRectangleItem, Cartesian
|
|
|
552
564
|
},
|
|
553
565
|
];
|
|
554
566
|
}
|
|
555
|
-
return [
|
|
556
|
-
{ ...item.prev, width: interpolate(item.prev.width, 0, animationElapsedTime) },
|
|
557
|
-
];
|
|
567
|
+
return [{ ...item.prev, width: interpolate(item.prev.width, 0, animationElapsedTime) }];
|
|
558
568
|
}
|
|
559
569
|
if (item.status === 'matched') {
|
|
560
570
|
return [
|
|
@@ -606,35 +616,39 @@ function RectanglesWithAnimation(rectanglesWithAnimationProps: {
|
|
|
606
616
|
props.onAnimationStart,
|
|
607
617
|
props.onAnimationEnd,
|
|
608
618
|
);
|
|
609
|
-
return
|
|
610
|
-
<
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
619
|
+
return (
|
|
620
|
+
<BarLabelListProvider showLabels={!isAnimating} rects={data}>
|
|
621
|
+
<AnimatedItems
|
|
622
|
+
animationInput={data}
|
|
623
|
+
animationIdPrefix="recharts-bar-"
|
|
624
|
+
items={data}
|
|
625
|
+
previousItemsRef={previousRectanglesRef}
|
|
626
|
+
isAnimationActive={isAnimationActive}
|
|
627
|
+
animationBegin={animationBegin}
|
|
628
|
+
animationDuration={animationDuration}
|
|
629
|
+
animationEasing={animationEasing}
|
|
630
|
+
onAnimationStart={handleAnimationStart}
|
|
631
|
+
onAnimationEnd={handleAnimationEnd}
|
|
632
|
+
animationInterpolateFn={animationInterpolateFn}
|
|
633
|
+
animationMatchBy={props.animationMatchBy}
|
|
634
|
+
layout={layout}
|
|
635
|
+
>
|
|
636
|
+
{(stepData, animationElapsedTime, isEntrance) => (
|
|
637
|
+
<Layer>
|
|
638
|
+
<BarRectangles
|
|
639
|
+
props={props}
|
|
640
|
+
data={stepData}
|
|
641
|
+
animationElapsedTime={animationElapsedTime}
|
|
642
|
+
isAnimating={isAnimating || animationElapsedTime < 1}
|
|
643
|
+
isEntrance={isEntrance}
|
|
644
|
+
/>
|
|
645
|
+
</Layer>
|
|
646
|
+
)}
|
|
647
|
+
</AnimatedItems>
|
|
648
|
+
<LabelListFromLabelProp label={props.label} />
|
|
649
|
+
{props.children}
|
|
650
|
+
</BarLabelListProvider>
|
|
651
|
+
);
|
|
638
652
|
}
|
|
639
653
|
|
|
640
654
|
function RenderRectangles(props: InternalProps) {
|
|
@@ -725,8 +739,8 @@ function BarImpl(props: BarImplProps) {
|
|
|
725
739
|
// octane divergence: cells arrive via registration (children render inside
|
|
726
740
|
// the CellsContext provider below), not children introspection.
|
|
727
741
|
const [cells, cellRegistry] = useCellRegistry();
|
|
728
|
-
const rects: ReadonlyArray<BarRectangleItem> | undefined = useAppSelector(
|
|
729
|
-
|
|
742
|
+
const rects: ReadonlyArray<BarRectangleItem> | undefined = useAppSelector((state) =>
|
|
743
|
+
selectBarRectangles(state, props.id, isPanorama, cells),
|
|
730
744
|
);
|
|
731
745
|
if (layout !== 'vertical' && layout !== 'horizontal') {
|
|
732
746
|
return null;
|
|
@@ -738,32 +752,34 @@ function BarImpl(props: BarImplProps) {
|
|
|
738
752
|
} else {
|
|
739
753
|
errorBarOffset = layout === 'vertical' ? firstDataPoint.height / 2 : firstDataPoint.width / 2;
|
|
740
754
|
}
|
|
741
|
-
return
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
<
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
755
|
+
return (
|
|
756
|
+
<SetErrorBarContext
|
|
757
|
+
xAxisId={xAxisId}
|
|
758
|
+
yAxisId={yAxisId}
|
|
759
|
+
data={rects}
|
|
760
|
+
dataPointFormatter={errorBarDataPointFormatter}
|
|
761
|
+
errorBarOffset={errorBarOffset}
|
|
762
|
+
>
|
|
763
|
+
<CellsContext value={cellRegistry}>
|
|
764
|
+
<BarWithState
|
|
765
|
+
{...props}
|
|
766
|
+
layout={layout}
|
|
767
|
+
needClip={needClip}
|
|
768
|
+
data={rects}
|
|
769
|
+
xAxisId={xAxisId}
|
|
770
|
+
yAxisId={yAxisId}
|
|
771
|
+
hide={hide}
|
|
772
|
+
legendType={legendType}
|
|
773
|
+
minPointSize={minPointSize}
|
|
774
|
+
activeBar={activeBar}
|
|
775
|
+
animationBegin={animationBegin}
|
|
776
|
+
animationDuration={animationDuration}
|
|
777
|
+
animationEasing={animationEasing}
|
|
778
|
+
isAnimationActive={isAnimationActive}
|
|
779
|
+
/>
|
|
780
|
+
</CellsContext>
|
|
781
|
+
</SetErrorBarContext>
|
|
782
|
+
);
|
|
767
783
|
}
|
|
768
784
|
|
|
769
785
|
export function computeBarRectangles({
|
|
@@ -797,16 +813,20 @@ export function computeBarRectangles({
|
|
|
797
813
|
parentViewBox: CartesianViewBoxRequired;
|
|
798
814
|
dataStartIndex: number;
|
|
799
815
|
}) {
|
|
800
|
-
const numericAxis =
|
|
801
|
-
|
|
802
|
-
const stackedDomain = stackedData ? numericAxis.scale.domain() as readonly number[] : null;
|
|
816
|
+
const numericAxis = layout === 'horizontal' ? yAxis : xAxis;
|
|
817
|
+
const stackedDomain = stackedData ? (numericAxis.scale.domain() as readonly number[]) : null;
|
|
803
818
|
const baseValue = getBaseValueOfBar({ numericAxis });
|
|
804
819
|
const stackedBarStart: number | undefined = numericAxis.scale.map(baseValue);
|
|
805
820
|
const rectangles = displayedData.map((entry, index) => {
|
|
806
|
-
let value,
|
|
807
|
-
x: number | null
|
|
808
|
-
y
|
|
809
|
-
|
|
821
|
+
let value,
|
|
822
|
+
x: number | null,
|
|
823
|
+
y,
|
|
824
|
+
width,
|
|
825
|
+
height,
|
|
826
|
+
background: Omit<BarRectangleType, 'x' | 'y'> & {
|
|
827
|
+
x: number | null;
|
|
828
|
+
y: number | null;
|
|
829
|
+
};
|
|
810
830
|
if (stackedData) {
|
|
811
831
|
// Use dataStartIndex to access the correct element in the full stackedData array
|
|
812
832
|
const untruncatedValue = stackedData[index + dataStartIndex];
|
|
@@ -876,13 +896,16 @@ export function computeBarRectangles({
|
|
|
876
896
|
// still draw something there). Sparse arrays stay index-stable via
|
|
877
897
|
// originalDataIndex.
|
|
878
898
|
if (
|
|
879
|
-
x == null ||
|
|
880
|
-
|
|
899
|
+
x == null ||
|
|
900
|
+
y == null ||
|
|
901
|
+
width == null ||
|
|
902
|
+
height == null ||
|
|
903
|
+
(!hasCustomShape && (width === 0 || height === 0))
|
|
881
904
|
) {
|
|
882
905
|
return null;
|
|
883
906
|
}
|
|
884
907
|
return {
|
|
885
|
-
...entry as Record<string, unknown
|
|
908
|
+
...(entry as Record<string, unknown>),
|
|
886
909
|
stackedBarStart,
|
|
887
910
|
x,
|
|
888
911
|
y,
|
|
@@ -896,14 +919,13 @@ export function computeBarRectangles({
|
|
|
896
919
|
tooltipPosition: { x: x + width / 2, y: y + height / 2 },
|
|
897
920
|
parentViewBox,
|
|
898
921
|
originalDataIndex: index,
|
|
899
|
-
...cells && cells[index] && cells[index].props as CellPropsFor<SVGPathElement
|
|
922
|
+
...(cells && cells[index] && (cells[index].props as CellPropsFor<SVGPathElement>)),
|
|
900
923
|
};
|
|
901
924
|
});
|
|
902
925
|
// This map returns only objects or null, so Boolean removes exactly the nulls.
|
|
903
926
|
return rectangles.filter(
|
|
904
|
-
Boolean as BooleanConstructor &
|
|
905
|
-
typeof rectangle
|
|
906
|
-
>),
|
|
927
|
+
Boolean as BooleanConstructor &
|
|
928
|
+
((rectangle: (typeof rectangles)[number]) => rectangle is NonNullable<typeof rectangle>),
|
|
907
929
|
);
|
|
908
930
|
}
|
|
909
931
|
|
|
@@ -916,42 +938,46 @@ function BarFn<DataPointType = any, ValueAxisType = any>(
|
|
|
916
938
|
const isPanorama = useIsPanorama();
|
|
917
939
|
// Report all props to the store first, before any other hooks, to avoid
|
|
918
940
|
// circular dependencies.
|
|
919
|
-
return
|
|
920
|
-
{
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
941
|
+
return (
|
|
942
|
+
<RegisterGraphicalItemId id={props.id} type="bar">
|
|
943
|
+
{(id) => (
|
|
944
|
+
<>
|
|
945
|
+
<SetLegendPayload legendPayload={computeLegendPayloadFromBarData(props)} />
|
|
946
|
+
<SetBarTooltipEntrySettings
|
|
947
|
+
dataKey={props.dataKey}
|
|
948
|
+
stroke={props.stroke}
|
|
949
|
+
strokeWidth={props.strokeWidth}
|
|
950
|
+
fill={props.fill}
|
|
951
|
+
name={props.name}
|
|
952
|
+
hide={props.hide}
|
|
953
|
+
unit={props.unit}
|
|
954
|
+
formatter={props.formatter}
|
|
955
|
+
tooltipType={props.tooltipType}
|
|
956
|
+
id={id}
|
|
957
|
+
/>
|
|
958
|
+
<SetCartesianGraphicalItem
|
|
959
|
+
type="bar"
|
|
960
|
+
id={id}
|
|
961
|
+
data={undefined}
|
|
962
|
+
xAxisId={props.xAxisId}
|
|
963
|
+
yAxisId={props.yAxisId}
|
|
964
|
+
zAxisId={0}
|
|
965
|
+
dataKey={props.dataKey}
|
|
966
|
+
stackId={stackId}
|
|
967
|
+
hide={props.hide}
|
|
968
|
+
barSize={props.barSize}
|
|
969
|
+
minPointSize={props.minPointSize}
|
|
970
|
+
maxBarSize={props.maxBarSize}
|
|
971
|
+
isPanorama={isPanorama}
|
|
972
|
+
hasCustomShape={props.shape != null && props.shape !== defaultBarShape}
|
|
973
|
+
/>
|
|
974
|
+
<ZIndexLayer zIndex={props.zIndex}>
|
|
975
|
+
<BarImpl {...props} id={id} />
|
|
976
|
+
</ZIndexLayer>
|
|
977
|
+
</>
|
|
978
|
+
)}
|
|
979
|
+
</RegisterGraphicalItemId>
|
|
980
|
+
);
|
|
955
981
|
}
|
|
956
982
|
|
|
957
983
|
/**
|