@sybilion/uilib 1.8.3 → 1.8.5
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/dist/esm/src/components/ui/BarChart/BarChart.js +39 -7
- package/dist/esm/src/components/ui/Chart/components/BaseChartWrapper.js +71 -6
- package/dist/esm/src/components/ui/Chart/components/BaseChartWrapper.styl.js +2 -2
- package/dist/esm/src/components/ui/Chart/components/ChartAxes.js +11 -3
- package/dist/esm/src/components/ui/Chart/components/ChartTooltipContent.js +6 -3
- package/dist/esm/src/components/ui/Chart/components/QuantileBands.js +1 -1
- package/dist/esm/src/components/ui/Chart/components/SeriesLegend/SeriesLegend.js +20 -0
- package/dist/esm/src/components/ui/Chart/components/SeriesLegend/SeriesLegend.styl.js +7 -0
- package/dist/esm/src/components/ui/ChartAreaInteractive/ChartLines.js +49 -13
- package/dist/esm/src/components/ui/StackedAreaChart/StackedAreaChart.helpers.js +45 -11
- package/dist/esm/src/components/ui/StackedAreaChart/StackedAreaChart.js +39 -9
- package/dist/esm/src/components/ui/StackedAreaChart/StackedAreaChart.styl.js +2 -2
- package/dist/esm/types/src/components/ui/BarChart/BarChart.types.d.ts +22 -0
- package/dist/esm/types/src/components/ui/Chart/chartForecastVisualization.types.d.ts +5 -0
- package/dist/esm/types/src/components/ui/Chart/components/BaseChartWrapper.d.ts +22 -5
- package/dist/esm/types/src/components/ui/Chart/components/ChartAxes.d.ts +8 -1
- package/dist/esm/types/src/components/ui/Chart/components/SeriesLegend/SeriesLegend.d.ts +22 -0
- package/dist/esm/types/src/components/ui/Chart/components/SeriesLegend/index.d.ts +1 -0
- package/dist/esm/types/src/components/ui/ChartAreaInteractive/ChartLines.d.ts +10 -1
- package/dist/esm/types/src/components/ui/ChartAreaInteractive/chartHistories.d.ts +5 -0
- package/dist/esm/types/src/components/ui/StackedAreaChart/StackedAreaChart.helpers.d.ts +10 -3
- package/dist/esm/types/src/components/ui/StackedAreaChart/StackedAreaChart.tooltip.d.ts +1 -1
- package/dist/esm/types/src/components/ui/StackedAreaChart/StackedAreaChart.types.d.ts +14 -0
- package/dist/esm/types/tests/viewChartGaps.test.d.ts +1 -0
- package/package.json +1 -1
- package/src/components/ui/BarChart/AGENT.md +4 -0
- package/src/components/ui/BarChart/BarChart.styl.d.ts +1 -1
- package/src/components/ui/BarChart/BarChart.tsx +107 -21
- package/src/components/ui/BarChart/BarChart.types.ts +22 -0
- package/src/components/ui/Chart/AGENT.md +3 -0
- package/src/components/ui/Chart/chartForecastVisualization.types.ts +5 -0
- package/src/components/ui/Chart/components/BaseChartWrapper.styl +5 -0
- package/src/components/ui/Chart/components/BaseChartWrapper.styl.d.ts +1 -0
- package/src/components/ui/Chart/components/BaseChartWrapper.tsx +124 -5
- package/src/components/ui/Chart/components/ChartAxes.tsx +29 -5
- package/src/components/ui/Chart/components/ChartTooltipContent.tsx +6 -3
- package/src/components/ui/Chart/components/QuantileBands.tsx +1 -0
- package/src/components/ui/Chart/components/SeriesLegend/SeriesLegend.styl +34 -0
- package/src/components/ui/Chart/components/SeriesLegend/SeriesLegend.styl.d.ts +12 -0
- package/src/components/ui/Chart/components/SeriesLegend/SeriesLegend.tsx +70 -0
- package/src/components/ui/Chart/components/SeriesLegend/index.ts +1 -0
- package/src/components/ui/ChartAreaInteractive/ChartLines.tsx +110 -40
- package/src/components/ui/ChartAreaInteractive/chartHistories.ts +5 -0
- package/src/components/ui/StackedAreaChart/AGENT.md +2 -0
- package/src/components/ui/StackedAreaChart/StackedAreaChart.helpers.ts +54 -13
- package/src/components/ui/StackedAreaChart/StackedAreaChart.styl +3 -0
- package/src/components/ui/StackedAreaChart/StackedAreaChart.styl.d.ts +1 -0
- package/src/components/ui/StackedAreaChart/StackedAreaChart.tooltip.tsx +1 -1
- package/src/components/ui/StackedAreaChart/StackedAreaChart.tsx +80 -13
- package/src/components/ui/StackedAreaChart/StackedAreaChart.types.ts +14 -0
- package/src/docs/pages/StackedAreaChartPage.tsx +30 -0
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
|
|
2
2
|
import cn from 'classnames';
|
|
3
3
|
import { forwardRef, useMemo } from 'react';
|
|
4
|
-
import { ChartTooltip } from '../Chart/Chart.js';
|
|
5
4
|
import ChartS from '../Chart/Chart.styl.js';
|
|
6
5
|
import { getChartSeriesColor } from '../Chart/chartSeriesPalette.js';
|
|
6
|
+
import { ChartContainer } from '../Chart/components/ChartContainer.js';
|
|
7
|
+
import { ChartPlacedTooltip } from '../Chart/components/ChartPlacedTooltip.js';
|
|
7
8
|
import { useLegendState } from '../Chart/hooks/useLegendState.js';
|
|
8
|
-
import { ComposedChart, CartesianGrid, XAxis, YAxis, ReferenceArea, Bar, Area, Line } from 'recharts';
|
|
9
|
-
import { stackRows, stackWeights, valueAxis, chartTop, yearTicks, MARGIN_KEY, yearLabel, compareRowZones, compareZones } from './StackedAreaChart.helpers.js';
|
|
9
|
+
import { ComposedChart, CartesianGrid, XAxis, Label, YAxis, ReferenceArea, Bar, Area, Line } from 'recharts';
|
|
10
|
+
import { stackRows, stackWeights, valueAxis, chartBottom, chartTop, yearTicks, MARGIN_KEY, yearLabel, compareRowZones, compareZones } from './StackedAreaChart.helpers.js';
|
|
10
11
|
import S from './StackedAreaChart.styl.js';
|
|
11
12
|
import { StackedTooltip } from './StackedAreaChart.tooltip.js';
|
|
12
|
-
import { ChartContainer } from '../Chart/components/ChartContainer.js';
|
|
13
13
|
|
|
14
14
|
const STACK_ID = 'stack';
|
|
15
15
|
const DEFAULT_BARS_BELOW = 3;
|
|
@@ -32,13 +32,16 @@ const splitKeys = (joined) => joined.split(KEY_SEP).slice(1);
|
|
|
32
32
|
*/
|
|
33
33
|
const ZONE_Z_INDEX = 50;
|
|
34
34
|
const AXIS_LINE = { stroke: 'var(--border)', strokeWidth: 1 };
|
|
35
|
+
/** Room for an x-axis title under the ticks (recharts' default is 30). */
|
|
36
|
+
const X_AXIS_HEIGHT_WITH_LABEL = 44;
|
|
35
37
|
const layerColor = (layer, index) => layer.color ?? getChartSeriesColor(index);
|
|
36
38
|
const overlayColor = (overlay) => overlay.color ?? DEFAULT_OVERLAY_COLOR;
|
|
39
|
+
const LONE_DOT_RADIUS = 3;
|
|
37
40
|
function LegendEntry({ swatch, label, extra, dimmed, onClick, }) {
|
|
38
41
|
const content = (jsxs(Fragment, { children: [swatch, label, extra != null && jsx("span", { className: S.legendExtra, children: extra })] }));
|
|
39
42
|
return onClick ? (jsx("button", { type: "button", className: cn(ChartS.legendItem, S.legendButton, dimmed && S.dimmed), "aria-pressed": !dimmed, onClick: onClick, children: content })) : (jsx("span", { className: ChartS.legendItem, children: content }));
|
|
40
43
|
}
|
|
41
|
-
const StackedAreaChart = forwardRef(({ className, data, xKey, layers, overlays = NO_OVERLAYS, margin, showWeights = true, yearTicks: yearTicks$1 = false, barsBelow = DEFAULT_BARS_BELOW, zoneLabels = DEFAULT_ZONE_LABELS, hiddenKeys, onToggleKey, showLegend = true, showTooltip = true, showGrid = true, valueFormatter, xTickFormatter, tooltipLabelFormatter, height, ...props }, ref) => {
|
|
44
|
+
const StackedAreaChart = forwardRef(({ className, data, xKey, layers, overlays = NO_OVERLAYS, margin, showWeights = true, yearTicks: yearTicks$1 = false, barsBelow = DEFAULT_BARS_BELOW, zoneLabels = DEFAULT_ZONE_LABELS, hiddenKeys, onToggleKey, showLegend = true, showTooltip = true, showGrid = true, valueFormatter, tooltipValueFormatter = valueFormatter, xTickFormatter, tooltipLabelFormatter, xAxisLabel, yAxisLabel, height, ...props }, ref) => {
|
|
42
45
|
const legend = useLegendState();
|
|
43
46
|
const hidden = hiddenKeys ?? legend.hiddenSeries;
|
|
44
47
|
// With hiddenKeys and no onToggleKey nothing can change visibility, so
|
|
@@ -66,6 +69,18 @@ const StackedAreaChart = forwardRef(({ className, data, xKey, layers, overlays =
|
|
|
66
69
|
// does not change them.
|
|
67
70
|
const weights = useMemo(() => (showWeights ? stackWeights(data, visibleKeys) : undefined), [showWeights, data, visibleKeys]);
|
|
68
71
|
const asBars = rows.length < barsBelow;
|
|
72
|
+
// How many values each overlay has: a bridged line with one value draws
|
|
73
|
+
// nothing, so `dotLonePoints` dots it.
|
|
74
|
+
const overlayValueCounts = useMemo(() => {
|
|
75
|
+
const counts = {};
|
|
76
|
+
for (const overlay of overlays) {
|
|
77
|
+
counts[overlay.key] = data.filter(row => {
|
|
78
|
+
const value = row[overlay.key];
|
|
79
|
+
return typeof value === 'number' && Number.isFinite(value);
|
|
80
|
+
}).length;
|
|
81
|
+
}
|
|
82
|
+
return counts;
|
|
83
|
+
}, [data, overlays]);
|
|
69
84
|
const compareKey = overlays.find(o => o.compare)?.key;
|
|
70
85
|
const zonesOn = compareKey != null && !hidden.has(compareKey);
|
|
71
86
|
const zones = useMemo(() => {
|
|
@@ -76,7 +91,10 @@ const StackedAreaChart = forwardRef(({ className, data, xKey, layers, overlays =
|
|
|
76
91
|
}, [zonesOn, compareKey, asBars, rows, xKey, visibleKeys]);
|
|
77
92
|
const zoneKinds = ['above', 'below'].filter(kind => zones.some(zone => zone.kind === kind));
|
|
78
93
|
const visibleLinesJoined = joinKeys(overlays.filter(o => !hidden.has(o.key)).map(o => o.key));
|
|
79
|
-
const yAxis = useMemo(() =>
|
|
94
|
+
const yAxis = useMemo(() => {
|
|
95
|
+
const lines = splitKeys(visibleLinesJoined);
|
|
96
|
+
return valueAxis(chartTop(rows, visibleKeys, lines), undefined, undefined, chartBottom(rows, visibleKeys, lines));
|
|
97
|
+
}, [rows, visibleKeys, visibleLinesJoined]);
|
|
80
98
|
const ticks = useMemo(() => (yearTicks$1 ? yearTicks(data, xKey) : undefined), [yearTicks$1, data, xKey]);
|
|
81
99
|
const config = useMemo(() => {
|
|
82
100
|
const out = {};
|
|
@@ -104,16 +122,28 @@ const StackedAreaChart = forwardRef(({ className, data, xKey, layers, overlays =
|
|
|
104
122
|
return (jsxs("div", { ref: ref, className: cn(S.root, className), ...props, children: [jsx(ChartContainer, { config: config, style: height ? { height: `${height}px` } : undefined, children: jsxs(ComposedChart, { data: rows, accessibilityLayer: true, children: [showGrid && (jsx(CartesianGrid, { stroke: "var(--border)", strokeWidth: 0.6, vertical: false })), jsx(XAxis, { dataKey: xKey,
|
|
105
123
|
// A point scale runs the areas edge to edge and starts and ends
|
|
106
124
|
// each zone on its rows; bars keep a band each.
|
|
107
|
-
scale: asBars ? 'auto' : 'point', ticks: ticks, tickFormatter: ticks ? yearLabel : xTickFormatter, minTickGap: ticks ? 8 : 24, tickLine: false, axisLine: AXIS_LINE }), jsx(YAxis
|
|
125
|
+
scale: asBars ? 'auto' : 'point', ticks: ticks, tickFormatter: ticks ? yearLabel : xTickFormatter, minTickGap: ticks ? 8 : 24, tickLine: false, axisLine: AXIS_LINE, height: xAxisLabel ? X_AXIS_HEIGHT_WITH_LABEL : undefined, children: xAxisLabel && (jsx(Label, { value: xAxisLabel, position: "insideBottom", offset: 0 })) }), jsx(YAxis
|
|
108
126
|
// Our own steps: automatic rounding can double the axis when the
|
|
109
127
|
// margin nudges the top past a round number.
|
|
110
128
|
, {
|
|
111
129
|
// Our own steps: automatic rounding can double the axis when the
|
|
112
130
|
// margin nudges the top past a round number.
|
|
113
|
-
domain: [0, yAxis.max], ticks: yAxis.ticks, allowDataOverflow: true, tickFormatter: valueFormatter,
|
|
131
|
+
domain: [yAxis.min ?? 0, yAxis.max], ticks: yAxis.ticks, allowDataOverflow: true, tickFormatter: valueFormatter,
|
|
132
|
+
// Room for the rotated title beside the ticks.
|
|
133
|
+
width: yAxisLabel ? 72 : 56, tickLine: false, axisLine: AXIS_LINE, children: yAxisLabel && (jsx(Label, { value: yAxisLabel, angle: -90, position: "insideLeft" })) }), showTooltip && (jsx(ChartPlacedTooltip, { content: tooltip => (jsx(StackedTooltip, { active: tooltip.active, payload: tooltip.payload, label: tooltip.label, config: config, valueFormatter: tooltipValueFormatter, labelFormatter: tooltipLabelFormatter })) })), zones.map(zone => (jsx(ReferenceArea, { x1: zone.x1, x2: zone.x2, fill: ZONE_FILL[zone.kind], fillOpacity: 1, stroke: "none", ifOverflow: "hidden", zIndex: ZONE_Z_INDEX }, `${zone.kind}-${String(zone.x1)}`))), layers.map((layer, index) => asBars ? (jsx(Bar, { dataKey: layer.key, name: layer.key, fill: layerColor(layer, index), maxBarSize: 96, hide: hidden.has(layer.key), ...stackProps }, layer.key)) : (jsx(Area, { type: "monotone", dataKey: layer.key, name: layer.key, fill: layerColor(layer, index), fillOpacity: 1, hide: hidden.has(layer.key), ...stackProps }, layer.key))), margin &&
|
|
114
134
|
(asBars ? (jsx(Bar, { dataKey: MARGIN_KEY, name: MARGIN_KEY, fill: marginColor, maxBarSize: 96, hide: !marginOn, ...stackProps }, MARGIN_KEY)) : (jsx(Area, { type: "monotone", dataKey: MARGIN_KEY, name: MARGIN_KEY, fill: marginColor, fillOpacity: 1, hide: !marginOn, ...stackProps }, MARGIN_KEY))), overlays.map(overlay => {
|
|
115
135
|
const color = overlayColor(overlay);
|
|
116
|
-
|
|
136
|
+
const lone = !asBars &&
|
|
137
|
+
overlay.dotLonePoints &&
|
|
138
|
+
overlayValueCounts[overlay.key] === 1;
|
|
139
|
+
return (jsx(Line, { type: "linear", dataKey: overlay.key, name: overlay.key, stroke: color, strokeWidth: 1.75, dot: asBars
|
|
140
|
+
? { r: 4, fill: color, stroke: color }
|
|
141
|
+
: lone
|
|
142
|
+
? (props) => typeof props.value === 'number' &&
|
|
143
|
+
Number.isFinite(props.value) &&
|
|
144
|
+
props.cx != null &&
|
|
145
|
+
props.cy != null ? (jsx("circle", { className: S.loneDot, cx: props.cx, cy: props.cy, r: LONE_DOT_RADIUS, fill: color }, `lone-${overlay.key}-${props.index}`)) : (jsx("g", {}, `lone-${overlay.key}-${props.index}`))
|
|
146
|
+
: false, activeDot: false, connectNulls: true, isAnimationActive: false, hide: hidden.has(overlay.key) }, overlay.key));
|
|
117
147
|
})] }) }), showLegend && (jsxs("div", { className: cn(ChartS.legendContainer, S.legend), children: [layers.map((layer, index) => (jsx(LegendEntry, { swatch: jsx("span", { className: ChartS.legendIndicator, style: { backgroundColor: layerColor(layer, index) } }), label: layer.label ?? layer.key, extra: weights && !hidden.has(layer.key)
|
|
118
148
|
? `${weights[layer.key] ?? 0}%`
|
|
119
149
|
: undefined, dimmed: hidden.has(layer.key), onClick: toggle && (() => toggle(layer.key)) }, layer.key))), marginOn && (jsx(LegendEntry, { swatch: jsx("span", { className: ChartS.legendIndicator, style: { backgroundColor: marginColor } }), label: marginLabel })), overlays.map(overlay => (jsx(LegendEntry, { swatch: jsx("span", { className: S.legendLine, style: { backgroundColor: overlayColor(overlay) } }), label: overlay.label ?? overlay.key, dimmed: hidden.has(overlay.key), onClick: toggle && (() => toggle(overlay.key)) }, overlay.key))), zoneKinds.map(kind => (jsx(LegendEntry, { swatch: jsx("span", { className: cn(ChartS.legendIndicator, S.legendZone), style: { backgroundColor: ZONE_FILL[kind] } }), label: zoneLabels[kind] }, kind)))] }))] }));
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import styleInject from 'style-inject';
|
|
2
2
|
|
|
3
|
-
var css_248z = ".StackedAreaChart_root__BkxHH{width:100%}.StackedAreaChart_legend__JVlx8{flex-wrap:wrap;margin-top:.75rem;row-gap:.5rem}.StackedAreaChart_legendButton__-nJsf{-webkit-appearance:none;-moz-appearance:none;appearance:none;background:none;border:0;color:inherit;cursor:pointer;font:inherit;padding:0}.StackedAreaChart_dimmed__L-fX7{opacity:.4}.StackedAreaChart_legendExtra__xGgeV{color:var(--muted-foreground);font-feature-settings:\"tnum\";font-variant-numeric:tabular-nums}.StackedAreaChart_legendLine__UDtNb{border-radius:1px;flex-shrink:0;height:2px;width:14px}.StackedAreaChart_legendZone__-47oB{border:1px solid var(--border)}";
|
|
4
|
-
var S = {"root":"StackedAreaChart_root__BkxHH","legend":"StackedAreaChart_legend__JVlx8","legendButton":"StackedAreaChart_legendButton__-nJsf","dimmed":"StackedAreaChart_dimmed__L-fX7","legendExtra":"StackedAreaChart_legendExtra__xGgeV","legendLine":"StackedAreaChart_legendLine__UDtNb","legendZone":"StackedAreaChart_legendZone__-47oB"};
|
|
3
|
+
var css_248z = ".StackedAreaChart_root__BkxHH{width:100%}.StackedAreaChart_legend__JVlx8{flex-wrap:wrap;margin-top:.75rem;row-gap:.5rem}.StackedAreaChart_legendButton__-nJsf{-webkit-appearance:none;-moz-appearance:none;appearance:none;background:none;border:0;color:inherit;cursor:pointer;font:inherit;padding:0}.StackedAreaChart_dimmed__L-fX7{opacity:.4}.StackedAreaChart_legendExtra__xGgeV{color:var(--muted-foreground);font-feature-settings:\"tnum\";font-variant-numeric:tabular-nums}.StackedAreaChart_legendLine__UDtNb{border-radius:1px;flex-shrink:0;height:2px;width:14px}.StackedAreaChart_loneDot__08-V7{pointer-events:none}.StackedAreaChart_legendZone__-47oB{border:1px solid var(--border)}";
|
|
4
|
+
var S = {"root":"StackedAreaChart_root__BkxHH","legend":"StackedAreaChart_legend__JVlx8","legendButton":"StackedAreaChart_legendButton__-nJsf","dimmed":"StackedAreaChart_dimmed__L-fX7","legendExtra":"StackedAreaChart_legendExtra__xGgeV","legendLine":"StackedAreaChart_legendLine__UDtNb","loneDot":"StackedAreaChart_loneDot__08-V7","legendZone":"StackedAreaChart_legendZone__-47oB"};
|
|
5
5
|
styleInject(css_248z);
|
|
6
6
|
|
|
7
7
|
export { S as default };
|
|
@@ -23,6 +23,28 @@ export interface BarChartProps extends Omit<HTMLAttributes<HTMLDivElement>, 'chi
|
|
|
23
23
|
showGrid?: boolean;
|
|
24
24
|
/** Formats numeric axis tick values. */
|
|
25
25
|
valueFormatter?: (value: number) => string;
|
|
26
|
+
/** Formats the tooltip's values (for example with a unit); without it they print as they are. */
|
|
27
|
+
tooltipValueFormatter?: (value: number) => string;
|
|
28
|
+
/** Formats the category axis's ticks. */
|
|
29
|
+
categoryTickFormatter?: (value: string | number) => string;
|
|
30
|
+
/** Formats the tooltip's category label. */
|
|
31
|
+
tooltipLabelFormatter?: (value: string | number) => string;
|
|
32
|
+
/** Title of the category axis. */
|
|
33
|
+
categoryAxisLabel?: string;
|
|
34
|
+
/** Title of the value axis. */
|
|
35
|
+
valueAxisLabel?: string;
|
|
36
|
+
/**
|
|
37
|
+
* Keys of hidden series. With it, the host owns visibility; without it
|
|
38
|
+
* (and with onToggleKey) the chart keeps the hidden set itself.
|
|
39
|
+
*/
|
|
40
|
+
hiddenKeys?: ReadonlySet<string>;
|
|
41
|
+
/**
|
|
42
|
+
* Called with a series key when its legend entry is clicked. Without it the
|
|
43
|
+
* legend is plain text.
|
|
44
|
+
*/
|
|
45
|
+
onToggleKey?: (key: string) => void;
|
|
26
46
|
/** Fixed chart height in px; defaults to a 16:9 responsive box. */
|
|
27
47
|
height?: number;
|
|
48
|
+
/** Draw the bars at once, without the grow-in animation. */
|
|
49
|
+
disableAnimation?: boolean;
|
|
28
50
|
}
|
|
@@ -83,6 +83,11 @@ export interface QuantileBandConfig {
|
|
|
83
83
|
strokeOpacity?: number;
|
|
84
84
|
type?: 'monotone' | 'linear' | 'step' | 'stepBefore' | 'stepAfter' | 'basis' | 'natural';
|
|
85
85
|
fillPattern?: 'solid' | 'dots' | 'lines';
|
|
86
|
+
/**
|
|
87
|
+
* List the range in the tooltip (default true). Read by the Recharts charts'
|
|
88
|
+
* bands (BaseChartWrapper, ChartAreaInteractive's default mode).
|
|
89
|
+
*/
|
|
90
|
+
showInTooltip?: boolean;
|
|
86
91
|
/**
|
|
87
92
|
* Fill across months with no range (default true). Read by the Recharts
|
|
88
93
|
* charts' bands (BaseChartWrapper, ChartAreaInteractive's default mode),
|
|
@@ -53,6 +53,12 @@ export interface BaseChartWrapperProps {
|
|
|
53
53
|
historyOnTop?: boolean;
|
|
54
54
|
/** Mark each line's last point with a dot (default: on). */
|
|
55
55
|
showEndDots?: boolean;
|
|
56
|
+
/**
|
|
57
|
+
* Dot a point a line would leave invisible, so it still shows: with no
|
|
58
|
+
* value on either side on a line not drawn across gaps, or a line's only
|
|
59
|
+
* value on one drawn across them (default: off).
|
|
60
|
+
*/
|
|
61
|
+
dotLonePoints?: boolean;
|
|
56
62
|
formatDate?: (value: string, detailed?: boolean) => string;
|
|
57
63
|
labelFormatter?: (value: unknown) => string;
|
|
58
64
|
onLegendClick?: (data: LegendPayload, index: number, event: any) => void;
|
|
@@ -81,6 +87,13 @@ export interface BaseChartWrapperProps {
|
|
|
81
87
|
showChartAxesLegend?: boolean;
|
|
82
88
|
xAxisLabel?: string;
|
|
83
89
|
yAxisLabel?: string;
|
|
90
|
+
/**
|
|
91
|
+
* `category` (default) gives every row one slot; `number` places the rows
|
|
92
|
+
* by their `date` read as a number (`'12.5'`), spaced by value.
|
|
93
|
+
*/
|
|
94
|
+
xAxisType?: 'category' | 'number';
|
|
95
|
+
/** The x values to label (for example the first day of each month). */
|
|
96
|
+
xTicks?: ReadonlyArray<string | number>;
|
|
84
97
|
showActiveDots?: boolean;
|
|
85
98
|
overlayElements?: ReactNode;
|
|
86
99
|
hiddenSeries?: Set<string>;
|
|
@@ -91,7 +104,15 @@ export interface BaseChartWrapperProps {
|
|
|
91
104
|
onFailedAnalysisClick?: (analysisId?: number | string) => void;
|
|
92
105
|
maxVisibleItems?: number;
|
|
93
106
|
preventDeselection?: boolean;
|
|
94
|
-
|
|
107
|
+
/**
|
|
108
|
+
* `default`: the analyses legend (forecast icons, +N overflow, latest
|
|
109
|
+
* first). `svg`: drawn into the chart for export. `plain`: one entry per
|
|
110
|
+
* line, in `legendOrder` (else histories then forecasts), each a button
|
|
111
|
+
* that hides or shows it through `onLegendClick`.
|
|
112
|
+
*/
|
|
113
|
+
legendVariant?: 'default' | 'svg' | 'plain';
|
|
114
|
+
/** With `legendVariant="plain"`: the lines' data keys in legend order. */
|
|
115
|
+
legendOrder?: string[];
|
|
95
116
|
legendWidth?: number;
|
|
96
117
|
legendMarginLeft?: number;
|
|
97
118
|
containerProps?: Omit<ComponentProps<typeof ChartContainer>, 'config' | 'className' | 'children'>;
|
|
@@ -111,8 +132,4 @@ export interface BaseChartWrapperProps {
|
|
|
111
132
|
/** Isolate a single series by data key; `allDataKeys` lists every toggleable key. */
|
|
112
133
|
onShowOnly?: (dataKey: string, allDataKeys: string[]) => void;
|
|
113
134
|
}
|
|
114
|
-
/**
|
|
115
|
-
* Base chart wrapper component with common structure
|
|
116
|
-
* Handles container, grid, axes, tooltip, and legend
|
|
117
|
-
*/
|
|
118
135
|
export declare function BaseChartWrapper(props: BaseChartWrapperProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -10,6 +10,13 @@ interface ChartAxesProps {
|
|
|
10
10
|
yMin?: number;
|
|
11
11
|
yMax?: number;
|
|
12
12
|
autoScaleYAxis?: boolean;
|
|
13
|
+
/**
|
|
14
|
+
* `category` (default) gives every row one slot; `number` places the rows
|
|
15
|
+
* by their `date` read as a number, from the smallest to the largest.
|
|
16
|
+
*/
|
|
17
|
+
xAxisType?: 'category' | 'number';
|
|
18
|
+
/** The x values to label; without it recharts picks them. */
|
|
19
|
+
xTicks?: ReadonlyArray<string | number>;
|
|
13
20
|
/**
|
|
14
21
|
* Draw no axes. A hidden x-axis is kept, so the tooltip still names the
|
|
15
22
|
* row's date. The y-axis keeps fixed `yMin`/`yMax` (with `autoScaleYAxis`
|
|
@@ -18,5 +25,5 @@ interface ChartAxesProps {
|
|
|
18
25
|
*/
|
|
19
26
|
hide?: boolean;
|
|
20
27
|
}
|
|
21
|
-
export declare function ChartAxes({ xAxisClassName, yAxisClassName, xAxisLabel, yAxisLabel, formatDate, formatNumber, xMin, xMax, yMin, yMax, autoScaleYAxis, hide, }: ChartAxesProps): import("react/jsx-runtime").JSX.Element;
|
|
28
|
+
export declare function ChartAxes({ xAxisClassName, yAxisClassName, xAxisLabel, yAxisLabel, formatDate, formatNumber, xMin, xMax, yMin, yMax, autoScaleYAxis, xAxisType, xTicks, hide, }: ChartAxesProps): import("react/jsx-runtime").JSX.Element;
|
|
22
29
|
export {};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { ReactNode } from 'react';
|
|
2
|
+
export type SeriesLegendItem = {
|
|
3
|
+
/** The series' data key; the legend hands it back on a click. */
|
|
4
|
+
dataKey: string;
|
|
5
|
+
label: ReactNode;
|
|
6
|
+
color: string;
|
|
7
|
+
/** Draw the swatch as a dashed line (a forecast line). */
|
|
8
|
+
dashed?: boolean;
|
|
9
|
+
/** Draw the swatch as a filled square (a bar or an area) instead of a line. */
|
|
10
|
+
square?: boolean;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* A plain legend: one entry per series, in the order given, each a button
|
|
14
|
+
* that hides or shows its series. A hidden series' entry is dimmed.
|
|
15
|
+
*/
|
|
16
|
+
export declare function SeriesLegend({ items, hiddenSeries, onToggle, className, }: {
|
|
17
|
+
items: SeriesLegendItem[];
|
|
18
|
+
hiddenSeries?: ReadonlySet<string>;
|
|
19
|
+
/** Without it the entries are text, not buttons. */
|
|
20
|
+
onToggle?: (dataKey: string) => void;
|
|
21
|
+
className?: string;
|
|
22
|
+
}): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { SeriesLegend, type SeriesLegendItem } from './SeriesLegend';
|
|
@@ -19,6 +19,11 @@ export type ForecastItemData = {
|
|
|
19
19
|
* histories, a forecast joins one only when this names it.
|
|
20
20
|
*/
|
|
21
21
|
continues?: string | number;
|
|
22
|
+
/**
|
|
23
|
+
* Draw this line across rows it has no value for. Without it the chart's
|
|
24
|
+
* `connectForecastNulls` decides.
|
|
25
|
+
*/
|
|
26
|
+
connectNulls?: boolean;
|
|
22
27
|
};
|
|
23
28
|
export type Dot = {
|
|
24
29
|
x: number;
|
|
@@ -43,6 +48,8 @@ export type HistoryLine = {
|
|
|
43
48
|
dataKey: string;
|
|
44
49
|
name: string;
|
|
45
50
|
color: string;
|
|
51
|
+
/** The line's own `connectNulls`, when it sets one. */
|
|
52
|
+
connectNulls?: boolean;
|
|
46
53
|
};
|
|
47
54
|
/** Default colour of the history at `index`: the forecast palette from its far end. */
|
|
48
55
|
export declare function getHistoryColor(index: number): string;
|
|
@@ -50,7 +57,7 @@ export declare function getHistoryColor(index: number): string;
|
|
|
50
57
|
export declare function resolveHistoryLines(histories?: HistoryItemData[]): HistoryLine[];
|
|
51
58
|
/** Same tint logic as intervals/threshold overlays: band fill follows forecast line hex when known. */
|
|
52
59
|
export declare function resolveQuantileBandFillForForecastLine(lineColor: string, forecastIndex: number): string;
|
|
53
|
-
export declare const ChartLines: import("react").MemoExoticComponent<({ chartData, forecastData, historyData, hiddenSeries, isDarkTheme, shouldAnimate, historicalLineColor, showLegend, forecastLineStyle, disableAnimation, disableHistoricalAnimation, connectHistoryNulls, connectForecastNulls, historyOnTop, showEndDots, }: {
|
|
60
|
+
export declare const ChartLines: import("react").MemoExoticComponent<({ chartData, forecastData, historyData, hiddenSeries, isDarkTheme, shouldAnimate, historicalLineColor, showLegend, forecastLineStyle, disableAnimation, disableHistoricalAnimation, connectHistoryNulls, connectForecastNulls, historyOnTop, showEndDots, dotLonePoints, }: {
|
|
54
61
|
chartData: ChartDataPoint[];
|
|
55
62
|
forecastData?: ForecastItemData[];
|
|
56
63
|
/** Several history lines (one per product). Omit for the single `historical` line. */
|
|
@@ -74,4 +81,6 @@ export declare const ChartLines: import("react").MemoExoticComponent<({ chartDat
|
|
|
74
81
|
historyOnTop?: boolean;
|
|
75
82
|
/** Mark each line's last point with a dot (default: on). */
|
|
76
83
|
showEndDots?: boolean;
|
|
84
|
+
/** Dot a point a gapped line leaves alone (default: off). */
|
|
85
|
+
dotLonePoints?: boolean;
|
|
77
86
|
}) => import("react/jsx-runtime").JSX.Element>;
|
|
@@ -21,6 +21,11 @@ export type HistoryItemData = {
|
|
|
21
21
|
* colour to both.
|
|
22
22
|
*/
|
|
23
23
|
color?: string;
|
|
24
|
+
/**
|
|
25
|
+
* Draw this line across rows it has no value for. Without it the chart's
|
|
26
|
+
* `connectHistoryNulls` decides.
|
|
27
|
+
*/
|
|
28
|
+
connectNulls?: boolean;
|
|
24
29
|
};
|
|
25
30
|
/** Data key of one history line in `chartData` rows. */
|
|
26
31
|
export declare function historySeriesKey(id: string | number): string;
|
|
@@ -48,13 +48,20 @@ export declare function compareRowZones(rows: readonly StackedAreaChartDatum[],
|
|
|
48
48
|
* A value axis from 0 for a top value: at most `maxIntervals` steps of
|
|
49
49
|
* 1, 2, 2.5 or 5 × 10ⁿ, with a little headroom above the top. Small changes
|
|
50
50
|
* in the top (a margin being typed) move the axis by one step at most,
|
|
51
|
-
* instead of doubling it the way automatic rounding can.
|
|
51
|
+
* instead of doubling it the way automatic rounding can. A `bottom` below 0
|
|
52
|
+
* (a negative layer or line) starts the axis at a step below it, as `min`.
|
|
52
53
|
*/
|
|
53
|
-
export declare function valueAxis(top: number, maxIntervals?: number, headroom?: number): {
|
|
54
|
+
export declare function valueAxis(top: number, maxIntervals?: number, headroom?: number, bottom?: number): {
|
|
55
|
+
min?: number;
|
|
54
56
|
max: number;
|
|
55
57
|
ticks: number[];
|
|
56
58
|
};
|
|
57
|
-
/**
|
|
59
|
+
/**
|
|
60
|
+
* The lowest point the stack (a negative layer or margin pulls it below 0)
|
|
61
|
+
* or a line reaches; 0 when nothing is negative.
|
|
62
|
+
*/
|
|
63
|
+
export declare function chartBottom(rows: readonly StackedAreaChartDatum[], layerKeys: readonly string[], lineKeys: readonly string[]): number;
|
|
64
|
+
/** The highest point the stack (layers plus margin) or a line reaches. */
|
|
58
65
|
export declare function chartTop(rows: readonly StackedAreaChartDatum[], layerKeys: readonly string[], lineKeys: readonly string[]): number;
|
|
59
66
|
/**
|
|
60
67
|
* The x value of the first row in each year, when x values are date strings
|
|
@@ -21,6 +21,11 @@ export interface StackedAreaChartOverlay {
|
|
|
21
21
|
* line. At most one overlay should set it; the first one that does is used.
|
|
22
22
|
*/
|
|
23
23
|
compare?: boolean;
|
|
24
|
+
/**
|
|
25
|
+
* Dot the line's only value. Gaps are bridged, so a line with a single
|
|
26
|
+
* value would otherwise draw nothing.
|
|
27
|
+
*/
|
|
28
|
+
dotLonePoints?: boolean;
|
|
24
29
|
}
|
|
25
30
|
export interface StackedAreaChartMargin {
|
|
26
31
|
/**
|
|
@@ -76,6 +81,15 @@ export interface StackedAreaChartProps extends Omit<HTMLAttributes<HTMLDivElemen
|
|
|
76
81
|
showGrid?: boolean;
|
|
77
82
|
/** Formats numeric y-axis ticks and tooltip values. */
|
|
78
83
|
valueFormatter?: (value: number) => string;
|
|
84
|
+
/**
|
|
85
|
+
* Formats the tooltip's values (for example with a unit), when they should
|
|
86
|
+
* read differently from the axis. Defaults to `valueFormatter`.
|
|
87
|
+
*/
|
|
88
|
+
tooltipValueFormatter?: (value: number) => string;
|
|
89
|
+
/** Title under the x axis. */
|
|
90
|
+
xAxisLabel?: string;
|
|
91
|
+
/** Title along the y axis. */
|
|
92
|
+
yAxisLabel?: string;
|
|
79
93
|
/** Formats x-axis ticks (ignored for year ticks, which show the year). */
|
|
80
94
|
xTickFormatter?: (value: string | number) => string;
|
|
81
95
|
/** Formats the tooltip's x label. */
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import '@testing-library/jest-dom';
|
package/package.json
CHANGED
|
@@ -14,3 +14,7 @@ BarChart compares values across categories. Provide rows of data, a category key
|
|
|
14
14
|
## Do
|
|
15
15
|
|
|
16
16
|
- Start the value axis at zero so bar lengths stay proportional.
|
|
17
|
+
- Pass `valueFormatter` for the axis and `tooltipValueFormatter` for the tooltip (for example with a unit; without it the tooltip prints the raw value); `categoryTickFormatter` and `tooltipLabelFormatter` format the categories (dates, for instance).
|
|
18
|
+
- Name the axes with `categoryAxisLabel` and `valueAxisLabel`.
|
|
19
|
+
- The legend sits under the chart box (it adds its own height to `height`). It is plain text unless `onToggleKey` is passed; then a click hides or shows a series. Pass `hiddenKeys` too when the host must remember which are hidden.
|
|
20
|
+
- `disableAnimation` draws the bars at once (for a page that is exported or printed).
|
|
@@ -1,18 +1,19 @@
|
|
|
1
1
|
import cn from 'classnames';
|
|
2
2
|
import { forwardRef, useMemo } from 'react';
|
|
3
3
|
|
|
4
|
-
import type { ChartConfig } from '#uilib/components/ui/Chart';
|
|
5
|
-
import {
|
|
6
|
-
ChartContainer,
|
|
7
|
-
ChartLegend,
|
|
8
|
-
ChartLegendContent,
|
|
9
|
-
ChartTooltip,
|
|
10
|
-
ChartTooltipContent,
|
|
11
|
-
} from '#uilib/components/ui/Chart';
|
|
4
|
+
import type { ChartConfig } from '#uilib/components/ui/Chart/Chart.types';
|
|
12
5
|
import { getChartSeriesColor } from '#uilib/components/ui/Chart/chartSeriesPalette';
|
|
6
|
+
// Straight from the components, not the Chart index, which also loads the
|
|
7
|
+
// canvas chart (lightweight-charts) and its styles.
|
|
8
|
+
import { ChartContainer } from '#uilib/components/ui/Chart/components/ChartContainer';
|
|
9
|
+
import { ChartPlacedTooltip as ChartTooltip } from '#uilib/components/ui/Chart/components/ChartPlacedTooltip';
|
|
10
|
+
import { ChartTooltipContent } from '#uilib/components/ui/Chart/components/ChartTooltipContent';
|
|
11
|
+
import { SeriesLegend } from '#uilib/components/ui/Chart/components/SeriesLegend';
|
|
12
|
+
import { useLegendState } from '#uilib/components/ui/Chart/hooks/useLegendState';
|
|
13
13
|
import {
|
|
14
14
|
Bar,
|
|
15
15
|
CartesianGrid,
|
|
16
|
+
Label,
|
|
16
17
|
BarChart as RechartsBarChart,
|
|
17
18
|
XAxis,
|
|
18
19
|
YAxis,
|
|
@@ -22,6 +23,11 @@ import S from './BarChart.styl';
|
|
|
22
23
|
import { BarChartProps, BarChartSeries } from './BarChart.types';
|
|
23
24
|
|
|
24
25
|
const STACK_ID = 'stack';
|
|
26
|
+
/** Room for an axis title beside the ticks (recharts' default is 30). */
|
|
27
|
+
const CATEGORY_AXIS_HEIGHT_WITH_LABEL = 44;
|
|
28
|
+
|
|
29
|
+
const seriesColor = (item: BarChartSeries, index: number) =>
|
|
30
|
+
item.color ?? getChartSeriesColor(index);
|
|
25
31
|
|
|
26
32
|
function buildChartConfig(series: BarChartSeries[]): ChartConfig {
|
|
27
33
|
const config: ChartConfig = {};
|
|
@@ -29,7 +35,7 @@ function buildChartConfig(series: BarChartSeries[]): ChartConfig {
|
|
|
29
35
|
series.forEach((item, index) => {
|
|
30
36
|
config[item.key] = {
|
|
31
37
|
label: item.label ?? item.key,
|
|
32
|
-
color: item
|
|
38
|
+
color: seriesColor(item, index),
|
|
33
39
|
};
|
|
34
40
|
});
|
|
35
41
|
|
|
@@ -49,18 +55,58 @@ const BarChart = forwardRef<HTMLDivElement, BarChartProps>(
|
|
|
49
55
|
showTooltip = true,
|
|
50
56
|
showGrid = true,
|
|
51
57
|
valueFormatter,
|
|
58
|
+
tooltipValueFormatter,
|
|
59
|
+
categoryTickFormatter,
|
|
60
|
+
tooltipLabelFormatter,
|
|
61
|
+
categoryAxisLabel,
|
|
62
|
+
valueAxisLabel,
|
|
63
|
+
hiddenKeys,
|
|
64
|
+
onToggleKey,
|
|
52
65
|
height,
|
|
66
|
+
disableAnimation,
|
|
53
67
|
...props
|
|
54
68
|
},
|
|
55
69
|
ref,
|
|
56
70
|
) => {
|
|
57
71
|
const config = useMemo(() => buildChartConfig(series), [series]);
|
|
72
|
+
const legend = useLegendState();
|
|
73
|
+
const hidden: ReadonlySet<string> = hiddenKeys ?? legend.hiddenSeries;
|
|
74
|
+
// The legend entries are buttons only for a host that asked for toggling
|
|
75
|
+
// (onToggleKey); without hiddenKeys the chart keeps the hidden set itself.
|
|
76
|
+
const toggle = onToggleKey
|
|
77
|
+
? (key: string) => {
|
|
78
|
+
onToggleKey(key);
|
|
79
|
+
if (!hiddenKeys) legend.toggleSeries(key);
|
|
80
|
+
}
|
|
81
|
+
: undefined;
|
|
58
82
|
|
|
59
83
|
const isHorizontal = orientation === 'horizontal';
|
|
60
84
|
const stackId = mode === 'stacked' ? STACK_ID : undefined;
|
|
61
85
|
const barRadius: [number, number, number, number] | number =
|
|
62
86
|
mode === 'stacked' ? 0 : isHorizontal ? [0, 3, 3, 0] : [3, 3, 0, 0];
|
|
63
87
|
|
|
88
|
+
const axisLine = { stroke: 'var(--border)', strokeWidth: 1 };
|
|
89
|
+
const categoryLabel = categoryAxisLabel ? (
|
|
90
|
+
isHorizontal ? (
|
|
91
|
+
<Label value={categoryAxisLabel} angle={-90} position="insideLeft" />
|
|
92
|
+
) : (
|
|
93
|
+
<Label value={categoryAxisLabel} position="insideBottom" offset={0} />
|
|
94
|
+
)
|
|
95
|
+
) : null;
|
|
96
|
+
const valueLabel = valueAxisLabel ? (
|
|
97
|
+
isHorizontal ? (
|
|
98
|
+
<Label value={valueAxisLabel} position="insideBottom" offset={0} />
|
|
99
|
+
) : (
|
|
100
|
+
<Label value={valueAxisLabel} angle={-90} position="insideLeft" />
|
|
101
|
+
)
|
|
102
|
+
) : null;
|
|
103
|
+
const labelFormatter = tooltipLabelFormatter
|
|
104
|
+
? (label: unknown) =>
|
|
105
|
+
tooltipLabelFormatter(
|
|
106
|
+
typeof label === 'number' ? label : String(label ?? ''),
|
|
107
|
+
)
|
|
108
|
+
: undefined;
|
|
109
|
+
|
|
64
110
|
return (
|
|
65
111
|
<div ref={ref} className={cn(S.root, className)} {...props}>
|
|
66
112
|
<ChartContainer
|
|
@@ -85,16 +131,25 @@ const BarChart = forwardRef<HTMLDivElement, BarChartProps>(
|
|
|
85
131
|
<XAxis
|
|
86
132
|
type="number"
|
|
87
133
|
tickLine={false}
|
|
88
|
-
axisLine={
|
|
134
|
+
axisLine={axisLine}
|
|
89
135
|
tickFormatter={valueFormatter}
|
|
90
|
-
|
|
136
|
+
height={
|
|
137
|
+
valueAxisLabel ? CATEGORY_AXIS_HEIGHT_WITH_LABEL : undefined
|
|
138
|
+
}
|
|
139
|
+
>
|
|
140
|
+
{valueLabel}
|
|
141
|
+
</XAxis>
|
|
91
142
|
<YAxis
|
|
92
143
|
type="category"
|
|
93
144
|
dataKey={categoryKey}
|
|
94
145
|
tickLine={false}
|
|
95
|
-
axisLine={
|
|
96
|
-
|
|
97
|
-
|
|
146
|
+
axisLine={axisLine}
|
|
147
|
+
tickFormatter={categoryTickFormatter}
|
|
148
|
+
// Room for the rotated title beside the category names.
|
|
149
|
+
width={categoryAxisLabel ? 96 : 80}
|
|
150
|
+
>
|
|
151
|
+
{categoryLabel}
|
|
152
|
+
</YAxis>
|
|
98
153
|
</>
|
|
99
154
|
) : (
|
|
100
155
|
<>
|
|
@@ -102,21 +157,38 @@ const BarChart = forwardRef<HTMLDivElement, BarChartProps>(
|
|
|
102
157
|
type="category"
|
|
103
158
|
dataKey={categoryKey}
|
|
104
159
|
tickLine={false}
|
|
105
|
-
axisLine={
|
|
106
|
-
|
|
160
|
+
axisLine={axisLine}
|
|
161
|
+
tickFormatter={categoryTickFormatter}
|
|
162
|
+
height={
|
|
163
|
+
categoryAxisLabel
|
|
164
|
+
? CATEGORY_AXIS_HEIGHT_WITH_LABEL
|
|
165
|
+
: undefined
|
|
166
|
+
}
|
|
167
|
+
>
|
|
168
|
+
{categoryLabel}
|
|
169
|
+
</XAxis>
|
|
107
170
|
<YAxis
|
|
108
171
|
type="number"
|
|
109
172
|
tickLine={false}
|
|
110
|
-
axisLine={
|
|
111
|
-
|
|
173
|
+
axisLine={axisLine}
|
|
174
|
+
// Room for the title beside the tick labels.
|
|
175
|
+
width={valueAxisLabel ? 64 : 48}
|
|
112
176
|
tickFormatter={valueFormatter}
|
|
113
|
-
|
|
177
|
+
>
|
|
178
|
+
{valueLabel}
|
|
179
|
+
</YAxis>
|
|
114
180
|
</>
|
|
115
181
|
)}
|
|
116
182
|
{showTooltip && (
|
|
117
183
|
<ChartTooltip
|
|
118
184
|
cursor={{ fill: 'var(--muted)' }}
|
|
119
|
-
content={
|
|
185
|
+
content={
|
|
186
|
+
<ChartTooltipContent
|
|
187
|
+
indicator="dot"
|
|
188
|
+
valueFormatter={tooltipValueFormatter}
|
|
189
|
+
labelFormatter={labelFormatter}
|
|
190
|
+
/>
|
|
191
|
+
}
|
|
120
192
|
/>
|
|
121
193
|
)}
|
|
122
194
|
{series.map(item => (
|
|
@@ -127,11 +199,25 @@ const BarChart = forwardRef<HTMLDivElement, BarChartProps>(
|
|
|
127
199
|
stackId={stackId}
|
|
128
200
|
radius={barRadius}
|
|
129
201
|
maxBarSize={48}
|
|
202
|
+
hide={hidden.has(item.key)}
|
|
203
|
+
isAnimationActive={!disableAnimation}
|
|
130
204
|
/>
|
|
131
205
|
))}
|
|
132
|
-
{showLegend && <ChartLegend content={<ChartLegendContent />} />}
|
|
133
206
|
</RechartsBarChart>
|
|
134
207
|
</ChartContainer>
|
|
208
|
+
|
|
209
|
+
{showLegend && (
|
|
210
|
+
<SeriesLegend
|
|
211
|
+
items={series.map((item, index) => ({
|
|
212
|
+
dataKey: item.key,
|
|
213
|
+
label: item.label ?? item.key,
|
|
214
|
+
color: seriesColor(item, index),
|
|
215
|
+
square: true,
|
|
216
|
+
}))}
|
|
217
|
+
hiddenSeries={hidden}
|
|
218
|
+
onToggle={toggle}
|
|
219
|
+
/>
|
|
220
|
+
)}
|
|
135
221
|
</div>
|
|
136
222
|
);
|
|
137
223
|
},
|
|
@@ -31,6 +31,28 @@ export interface BarChartProps extends Omit<
|
|
|
31
31
|
showGrid?: boolean;
|
|
32
32
|
/** Formats numeric axis tick values. */
|
|
33
33
|
valueFormatter?: (value: number) => string;
|
|
34
|
+
/** Formats the tooltip's values (for example with a unit); without it they print as they are. */
|
|
35
|
+
tooltipValueFormatter?: (value: number) => string;
|
|
36
|
+
/** Formats the category axis's ticks. */
|
|
37
|
+
categoryTickFormatter?: (value: string | number) => string;
|
|
38
|
+
/** Formats the tooltip's category label. */
|
|
39
|
+
tooltipLabelFormatter?: (value: string | number) => string;
|
|
40
|
+
/** Title of the category axis. */
|
|
41
|
+
categoryAxisLabel?: string;
|
|
42
|
+
/** Title of the value axis. */
|
|
43
|
+
valueAxisLabel?: string;
|
|
44
|
+
/**
|
|
45
|
+
* Keys of hidden series. With it, the host owns visibility; without it
|
|
46
|
+
* (and with onToggleKey) the chart keeps the hidden set itself.
|
|
47
|
+
*/
|
|
48
|
+
hiddenKeys?: ReadonlySet<string>;
|
|
49
|
+
/**
|
|
50
|
+
* Called with a series key when its legend entry is clicked. Without it the
|
|
51
|
+
* legend is plain text.
|
|
52
|
+
*/
|
|
53
|
+
onToggleKey?: (key: string) => void;
|
|
34
54
|
/** Fixed chart height in px; defaults to a 16:9 responsive box. */
|
|
35
55
|
height?: number;
|
|
56
|
+
/** Draw the bars at once, without the grow-in animation. */
|
|
57
|
+
disableAnimation?: boolean;
|
|
36
58
|
}
|