@monolith-forensics/monolith-ui 1.8.0 → 1.8.1-dev.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/dist/BarChart/BarChart.d.ts +3 -0
- package/dist/BarChart/BarChart.js +511 -0
- package/dist/BarChart/BarChart.lib.d.ts +31 -0
- package/dist/BarChart/BarChart.lib.js +136 -0
- package/dist/BarChart/BarChart.styled.d.ts +49 -0
- package/dist/BarChart/BarChart.styled.js +111 -0
- package/dist/BarChart/BarChart.types.d.ts +170 -0
- package/dist/BarChart/BarChart.types.js +1 -0
- package/dist/BarChart/index.d.ts +3 -0
- package/dist/BarChart/index.js +2 -0
- package/dist/Button/Button.js +9 -58
- package/dist/Calendar/Calendar.d.ts +3 -1
- package/dist/Calendar/Calendar.js +134 -33
- package/dist/Calendar/CalendarStyles.d.ts +3 -0
- package/dist/Calendar/CalendarStyles.js +92 -14
- package/dist/Calendar/calendarHelpers.d.ts +5 -1
- package/dist/Calendar/calendarHelpers.js +13 -5
- package/dist/ChartPrimitives/chartLegend.styled.d.ts +12 -0
- package/dist/ChartPrimitives/chartLegend.styled.js +52 -0
- package/dist/ChartPrimitives/chartTooltip.styled.d.ts +19 -0
- package/dist/ChartPrimitives/chartTooltip.styled.js +61 -0
- package/dist/ChartPrimitives/index.d.ts +2 -0
- package/dist/ChartPrimitives/index.js +2 -0
- package/dist/ChartUtils/chartColors.d.ts +8 -0
- package/dist/ChartUtils/chartColors.js +65 -0
- package/dist/ChartUtils/chartMath.d.ts +3 -0
- package/dist/ChartUtils/chartMath.js +3 -0
- package/dist/ChartUtils/index.d.ts +2 -0
- package/dist/ChartUtils/index.js +2 -0
- package/dist/Charts/BarChart/BarChart.d.ts +5 -0
- package/dist/Charts/BarChart/BarChart.js +549 -0
- package/dist/Charts/BarChart/BarChart.lib.d.ts +31 -0
- package/dist/Charts/BarChart/BarChart.lib.js +136 -0
- package/dist/Charts/BarChart/BarChart.styled.d.ts +51 -0
- package/dist/Charts/BarChart/BarChart.styled.js +115 -0
- package/dist/Charts/BarChart/BarChart.types.d.ts +171 -0
- package/dist/Charts/BarChart/BarChart.types.js +1 -0
- package/dist/Charts/BarChart/index.d.ts +3 -0
- package/dist/Charts/BarChart/index.js +2 -0
- package/dist/Charts/ChartPrimitives/ChartExportControl.d.ts +11 -0
- package/dist/Charts/ChartPrimitives/ChartExportControl.js +29 -0
- package/dist/Charts/ChartPrimitives/chartActions.styled.d.ts +1 -0
- package/dist/Charts/ChartPrimitives/chartActions.styled.js +8 -0
- package/dist/Charts/ChartPrimitives/chartLegend.styled.d.ts +12 -0
- package/dist/Charts/ChartPrimitives/chartLegend.styled.js +52 -0
- package/dist/Charts/ChartPrimitives/chartTooltip.styled.d.ts +19 -0
- package/dist/Charts/ChartPrimitives/chartTooltip.styled.js +61 -0
- package/dist/Charts/ChartPrimitives/index.d.ts +4 -0
- package/dist/Charts/ChartPrimitives/index.js +4 -0
- package/dist/Charts/ChartUtils/chartColors.d.ts +8 -0
- package/dist/Charts/ChartUtils/chartColors.js +65 -0
- package/dist/Charts/ChartUtils/chartExport.d.ts +47 -0
- package/dist/Charts/ChartUtils/chartExport.js +311 -0
- package/dist/Charts/ChartUtils/chartMath.d.ts +3 -0
- package/dist/Charts/ChartUtils/chartMath.js +3 -0
- package/dist/Charts/ChartUtils/index.d.ts +3 -0
- package/dist/Charts/ChartUtils/index.js +3 -0
- package/dist/Charts/HeatMap/HeatMap.d.ts +5 -0
- package/dist/Charts/HeatMap/HeatMap.js +212 -0
- package/dist/Charts/HeatMap/HeatMap.lib.d.ts +30 -0
- package/dist/Charts/HeatMap/HeatMap.lib.js +115 -0
- package/dist/Charts/HeatMap/HeatMap.styled.d.ts +37 -0
- package/dist/Charts/HeatMap/HeatMap.styled.js +91 -0
- package/dist/Charts/HeatMap/HeatMap.types.d.ts +80 -0
- package/dist/Charts/HeatMap/HeatMap.types.js +1 -0
- package/dist/Charts/HeatMap/index.d.ts +3 -0
- package/dist/Charts/HeatMap/index.js +2 -0
- package/dist/Charts/LineChart/LineChart.d.ts +5 -0
- package/dist/Charts/LineChart/LineChart.js +529 -0
- package/dist/Charts/LineChart/LineChart.lib.d.ts +24 -0
- package/dist/Charts/LineChart/LineChart.lib.js +132 -0
- package/dist/Charts/LineChart/LineChart.styled.d.ts +59 -0
- package/dist/Charts/LineChart/LineChart.styled.js +147 -0
- package/dist/Charts/LineChart/LineChart.types.d.ts +193 -0
- package/dist/Charts/LineChart/LineChart.types.js +1 -0
- package/dist/Charts/LineChart/index.d.ts +3 -0
- package/dist/Charts/LineChart/index.js +2 -0
- package/dist/Charts/PieChart/PieChart.d.ts +4 -0
- package/dist/Charts/PieChart/PieChart.js +199 -0
- package/dist/Charts/PieChart/PieChart.lib.d.ts +5 -0
- package/dist/Charts/PieChart/PieChart.lib.js +19 -0
- package/dist/Charts/PieChart/PieChart.styled.d.ts +51 -0
- package/dist/Charts/PieChart/PieChart.styled.js +163 -0
- package/dist/Charts/PieChart/PieChart.types.d.ts +100 -0
- package/dist/Charts/PieChart/PieChart.types.js +1 -0
- package/dist/Charts/PieChart/index.d.ts +2 -0
- package/dist/Charts/PieChart/index.js +1 -0
- package/dist/Charts/index.d.ts +5 -0
- package/dist/Charts/index.js +4 -0
- package/dist/CheckBox/CheckBox.js +2 -16
- package/dist/DateInput/DateInput.js +198 -143
- package/dist/DropDownMenu/components/MenuComponent.js +2 -1
- package/dist/DropDownMenu/components/MenuItem.js +5 -14
- package/dist/DropDownMenu/components/MenuItemList.js +7 -24
- package/dist/DropDownMenu/components/StyledFloatContainer.js +1 -1
- package/dist/FieldLabel/FieldLabel.js +4 -12
- package/dist/FileInputField/FileInputField.js +4 -23
- package/dist/FormSection/FormSection.js +5 -25
- package/dist/HeatMap/HeatMap.d.ts +3 -0
- package/dist/HeatMap/HeatMap.js +174 -0
- package/dist/HeatMap/HeatMap.lib.d.ts +30 -0
- package/dist/HeatMap/HeatMap.lib.js +115 -0
- package/dist/HeatMap/HeatMap.styled.d.ts +34 -0
- package/dist/HeatMap/HeatMap.styled.js +83 -0
- package/dist/HeatMap/HeatMap.types.d.ts +79 -0
- package/dist/HeatMap/HeatMap.types.js +1 -0
- package/dist/HeatMap/index.d.ts +3 -0
- package/dist/HeatMap/index.js +2 -0
- package/dist/IconButton/IconButton.js +2 -16
- package/dist/Input/Input.js +7 -56
- package/dist/LineChart/LineChart.d.ts +3 -0
- package/dist/LineChart/LineChart.js +491 -0
- package/dist/LineChart/LineChart.lib.d.ts +24 -0
- package/dist/LineChart/LineChart.lib.js +132 -0
- package/dist/LineChart/LineChart.styled.d.ts +57 -0
- package/dist/LineChart/LineChart.styled.js +150 -0
- package/dist/LineChart/LineChart.types.d.ts +192 -0
- package/dist/LineChart/LineChart.types.js +1 -0
- package/dist/LineChart/index.d.ts +3 -0
- package/dist/LineChart/index.js +2 -0
- package/dist/PieChart/PieChart.d.ts +2 -0
- package/dist/PieChart/PieChart.js +161 -0
- package/dist/PieChart/PieChart.lib.d.ts +5 -0
- package/dist/PieChart/PieChart.lib.js +19 -0
- package/dist/PieChart/PieChart.styled.d.ts +49 -0
- package/dist/PieChart/PieChart.styled.js +161 -0
- package/dist/PieChart/PieChart.types.d.ts +99 -0
- package/dist/PieChart/PieChart.types.js +1 -0
- package/dist/PieChart/index.d.ts +2 -0
- package/dist/PieChart/index.js +1 -0
- package/dist/Pill/Pill.js +8 -79
- package/dist/Popover/Popover.context.d.ts +2 -1
- package/dist/Popover/Popover.js +5 -2
- package/dist/Popover/Popover.styles.d.ts +1 -6
- package/dist/Popover/Popover.styles.js +11 -28
- package/dist/Popover/Popover.transitions.d.ts +4 -2
- package/dist/Popover/Popover.transitions.js +23 -49
- package/dist/Popover/PopoverDropdown.js +6 -8
- package/dist/Popover/PopoverTarget.js +6 -3
- package/dist/SegmentedControl/SegmentedControl.utils.d.ts +2 -2
- package/dist/SegmentedControl/SegmentedControl.utils.js +3 -30
- package/dist/SelectBox/SelectBox.js +3 -3
- package/dist/SelectBox/select-box.styled-components.d.ts +3 -1
- package/dist/SelectBox/select-box.styled-components.js +10 -48
- package/dist/SuperDatePicker/SuperDatePicker.d.ts +74 -0
- package/dist/SuperDatePicker/SuperDatePicker.js +557 -0
- package/dist/SuperDatePicker/index.d.ts +2 -0
- package/dist/SuperDatePicker/index.js +2 -0
- package/dist/Switch/Switch.d.ts +2 -2
- package/dist/Switch/Switch.js +18 -83
- package/dist/Table/StateStorage.d.ts +4 -0
- package/dist/Table/StateStorage.js +13 -0
- package/dist/Table/Table.js +160 -12
- package/dist/Table/TableComponents.d.ts +10 -0
- package/dist/Table/TableComponents.js +57 -0
- package/dist/Table/TableDefaults.d.ts +7 -0
- package/dist/Table/TableDefaults.js +7 -0
- package/dist/Table/TableProvider.js +263 -71
- package/dist/Table/TableRow.js +15 -10
- package/dist/Table/types.d.ts +64 -0
- package/dist/TagBox/TagBox.js +18 -76
- package/dist/TextArea/TextArea.js +4 -23
- package/dist/TextInput/TextInput.js +12 -6
- package/dist/Utilities/parseTimestamp.js +11 -6
- package/dist/core/ArrowButton.d.ts +2 -0
- package/dist/core/ArrowButton.js +7 -3
- package/dist/core/ClearButton.d.ts +2 -0
- package/dist/core/ClearButton.js +7 -3
- package/dist/core/controlSizes.d.ts +34 -0
- package/dist/core/controlSizes.js +190 -0
- package/dist/core/index.d.ts +1 -0
- package/dist/core/index.js +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/package.json +5 -1
|
@@ -0,0 +1,549 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
11
|
+
var t = {};
|
|
12
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
13
|
+
t[p] = s[p];
|
|
14
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
15
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
16
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
17
|
+
t[p[i]] = s[p[i]];
|
|
18
|
+
}
|
|
19
|
+
return t;
|
|
20
|
+
};
|
|
21
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
22
|
+
import { scaleBand, scaleLinear } from "d3-scale";
|
|
23
|
+
import { forwardRef, useEffect, useId, useImperativeHandle, useMemo, useRef, useState, } from "react";
|
|
24
|
+
import { useTheme } from "styled-components";
|
|
25
|
+
import { ChartExportControl } from "../ChartPrimitives";
|
|
26
|
+
import { DEFAULT_CHART_EXPORT_FORMATS, copyChartImage, downloadChartImage, } from "../ChartUtils";
|
|
27
|
+
import { clamp, easeOutCubic, formatDefaultValue, getBandPadding, getBarKey, getCategoryKey, getGradientColor, getGradientColorFromStops, getGradientStops, getRoundedBarPath, getSeriesKey, getSeriesLabelText, getValueDomain, mergeChartMargin, normalizeTickValue, useThemeColors, } from "./BarChart.lib";
|
|
28
|
+
import { StyledAxisLine, StyledAxisText, StyledBar, StyledChartActions, StyledChartFrame, StyledChartScroller, StyledContainer, StyledEmptyState, StyledGridLine, StyledLegend, StyledLegendItem, StyledLegendLabel, StyledLegendValue, StyledSvg, StyledSwatch, StyledTooltip, StyledTooltipHeader, StyledTooltipLabel, StyledTooltipList, StyledTooltipMeta, StyledTooltipRow, StyledTooltipSwatch, StyledTooltipValue, StyledValueLabel, } from "./BarChart.styled";
|
|
29
|
+
const BarChartInner = (_a, ref) => {
|
|
30
|
+
var _b, _c, _d;
|
|
31
|
+
var { data, series, width = 640, height = 320, orientation = "vertical", seriesLayout = "grouped", margin, barGap = 10, groupBarGap, maxBarThickness, barRadius = 3, colors, colorGradient, barOpacity = 1, barBorderColor, barBorderWidth = 1, barBorderOpacity = 1, minValue, maxValue, valueTickCount = 5, showGridLines = true, showAxisLines = true, showCategoryAxisLabels = true, showValueAxisLabels = true, showLegend = false, showLegendSwatches = true, showLegendLabels = true, showLegendValues = true, showLabels = false, emptyLabel = "No data", ariaLabel = "Bar chart", animateOnRender = false, animationDuration = 520, animationStagger = 35, showExportButton = false, exportFileName = "bar-chart", exportFormats = DEFAULT_CHART_EXPORT_FORMATS, exportScale = 2, exportBackgroundColor, showTooltips = false, valueFormatter, categoryLabelFormatter, tickFormatter, labelFormatter, tooltipFormatter, onBarClick, onLegendItemClick, onSeriesLegendItemClick, className } = _a, props = __rest(_a, ["data", "series", "width", "height", "orientation", "seriesLayout", "margin", "barGap", "groupBarGap", "maxBarThickness", "barRadius", "colors", "colorGradient", "barOpacity", "barBorderColor", "barBorderWidth", "barBorderOpacity", "minValue", "maxValue", "valueTickCount", "showGridLines", "showAxisLines", "showCategoryAxisLabels", "showValueAxisLabels", "showLegend", "showLegendSwatches", "showLegendLabels", "showLegendValues", "showLabels", "emptyLabel", "ariaLabel", "animateOnRender", "animationDuration", "animationStagger", "showExportButton", "exportFileName", "exportFormats", "exportScale", "exportBackgroundColor", "showTooltips", "valueFormatter", "categoryLabelFormatter", "tickFormatter", "labelFormatter", "tooltipFormatter", "onBarClick", "onLegendItemClick", "onSeriesLegendItemClick", "className"]);
|
|
32
|
+
const descriptionId = useId();
|
|
33
|
+
const theme = useTheme();
|
|
34
|
+
const containerRef = useRef(null);
|
|
35
|
+
const chartFrameRef = useRef(null);
|
|
36
|
+
const svgRef = useRef(null);
|
|
37
|
+
const tooltipRef = useRef(null);
|
|
38
|
+
const [activeBarKey, setActiveBarKey] = useState(null);
|
|
39
|
+
const [activeSeriesKey, setActiveSeriesKey] = useState(null);
|
|
40
|
+
const [activeTooltip, setActiveTooltip] = useState(null);
|
|
41
|
+
const [tooltipSize, setTooltipSize] = useState({ width: 0, height: 0 });
|
|
42
|
+
const [animationElapsed, setAnimationElapsed] = useState(animateOnRender ? 0 : Number.POSITIVE_INFINITY);
|
|
43
|
+
const themeColors = useThemeColors(colors);
|
|
44
|
+
const isMultiSeries = ((_b = series === null || series === void 0 ? void 0 : series.length) !== null && _b !== void 0 ? _b : 0) > 0;
|
|
45
|
+
const normalizedInputSeries = useMemo(() => {
|
|
46
|
+
if (series === null || series === void 0 ? void 0 : series.length) {
|
|
47
|
+
return series.map((seriesItem, seriesIndex) => {
|
|
48
|
+
const fallbackLabel = `Series ${seriesIndex + 1}`;
|
|
49
|
+
return {
|
|
50
|
+
key: getSeriesKey(seriesItem, seriesIndex),
|
|
51
|
+
label: seriesItem.label,
|
|
52
|
+
labelText: getSeriesLabelText(seriesItem.label, fallbackLabel),
|
|
53
|
+
color: seriesItem.color,
|
|
54
|
+
colorGradient: seriesItem.colorGradient,
|
|
55
|
+
sourceSeries: seriesItem,
|
|
56
|
+
data: seriesItem.data.filter((datum) => Number.isFinite(datum.value)),
|
|
57
|
+
};
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
return [
|
|
61
|
+
{
|
|
62
|
+
key: "series-0",
|
|
63
|
+
label: "Series",
|
|
64
|
+
labelText: "Series",
|
|
65
|
+
color: undefined,
|
|
66
|
+
colorGradient: undefined,
|
|
67
|
+
sourceSeries: undefined,
|
|
68
|
+
data: (data !== null && data !== void 0 ? data : []).filter((datum) => Number.isFinite(datum.value)),
|
|
69
|
+
},
|
|
70
|
+
];
|
|
71
|
+
}, [data, series]);
|
|
72
|
+
const safeWidth = Math.max(width, 180);
|
|
73
|
+
const safeHeight = Math.max(height, 180);
|
|
74
|
+
const safeBarRadius = Math.max(barRadius, 0);
|
|
75
|
+
const safeBarGap = Math.max(barGap, 0);
|
|
76
|
+
const safeGroupBarGap = Math.max(groupBarGap !== null && groupBarGap !== void 0 ? groupBarGap : barGap, 0);
|
|
77
|
+
const safeMaxBarThickness = maxBarThickness != null ? Math.max(maxBarThickness, 1) : undefined;
|
|
78
|
+
const resolvedBarOpacity = clamp(barOpacity, 0, 1);
|
|
79
|
+
const resolvedBarBorderWidth = Math.max(barBorderWidth, 0);
|
|
80
|
+
const resolvedBarBorderOpacity = clamp(barBorderOpacity, 0, 1);
|
|
81
|
+
const resolvedBarBorderColor = barBorderColor !== null && barBorderColor !== void 0 ? barBorderColor : theme.palette.divider;
|
|
82
|
+
const resolvedExportBackgroundColor = exportBackgroundColor !== null && exportBackgroundColor !== void 0 ? exportBackgroundColor : theme.palette.background.paper;
|
|
83
|
+
useImperativeHandle(ref, () => ({
|
|
84
|
+
getSvgElement: () => svgRef.current,
|
|
85
|
+
downloadImage: (request) => __awaiter(void 0, void 0, void 0, function* () {
|
|
86
|
+
var _a, _b, _c, _d;
|
|
87
|
+
yield downloadChartImage({
|
|
88
|
+
rootElement: containerRef.current,
|
|
89
|
+
svg: svgRef.current,
|
|
90
|
+
format: (_a = request === null || request === void 0 ? void 0 : request.format) !== null && _a !== void 0 ? _a : "svg",
|
|
91
|
+
fileName: (_b = request === null || request === void 0 ? void 0 : request.fileName) !== null && _b !== void 0 ? _b : exportFileName,
|
|
92
|
+
scale: (_c = request === null || request === void 0 ? void 0 : request.scale) !== null && _c !== void 0 ? _c : exportScale,
|
|
93
|
+
backgroundColor: (_d = request === null || request === void 0 ? void 0 : request.backgroundColor) !== null && _d !== void 0 ? _d : resolvedExportBackgroundColor,
|
|
94
|
+
});
|
|
95
|
+
}),
|
|
96
|
+
copyImage: (request) => __awaiter(void 0, void 0, void 0, function* () {
|
|
97
|
+
var _a, _b, _c;
|
|
98
|
+
return copyChartImage({
|
|
99
|
+
rootElement: containerRef.current,
|
|
100
|
+
svg: svgRef.current,
|
|
101
|
+
format: (_a = request === null || request === void 0 ? void 0 : request.format) !== null && _a !== void 0 ? _a : "png",
|
|
102
|
+
scale: (_b = request === null || request === void 0 ? void 0 : request.scale) !== null && _b !== void 0 ? _b : exportScale,
|
|
103
|
+
backgroundColor: (_c = request === null || request === void 0 ? void 0 : request.backgroundColor) !== null && _c !== void 0 ? _c : resolvedExportBackgroundColor,
|
|
104
|
+
});
|
|
105
|
+
}),
|
|
106
|
+
}), [exportFileName, exportScale, resolvedExportBackgroundColor]);
|
|
107
|
+
const resolvedMargin = mergeChartMargin(orientation, margin, showCategoryAxisLabels, showValueAxisLabels, showLabels);
|
|
108
|
+
const plotWidth = Math.max(safeWidth - resolvedMargin.left - resolvedMargin.right, 1);
|
|
109
|
+
const plotHeight = Math.max(safeHeight - resolvedMargin.top - resolvedMargin.bottom, 1);
|
|
110
|
+
const resolvedChart = useMemo(() => {
|
|
111
|
+
const categorySeedMap = new Map();
|
|
112
|
+
normalizedInputSeries.forEach((seriesEntry) => {
|
|
113
|
+
seriesEntry.data.forEach((datum) => {
|
|
114
|
+
const categoryKey = getCategoryKey(datum);
|
|
115
|
+
if (!categorySeedMap.has(categoryKey)) {
|
|
116
|
+
categorySeedMap.set(categoryKey, {
|
|
117
|
+
key: categoryKey,
|
|
118
|
+
label: datum.label,
|
|
119
|
+
representativeDatum: datum,
|
|
120
|
+
index: categorySeedMap.size,
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
});
|
|
124
|
+
});
|
|
125
|
+
const categorySeeds = Array.from(categorySeedMap.values());
|
|
126
|
+
const resolvedSeries = normalizedInputSeries.map((seriesEntry, seriesIndex) => {
|
|
127
|
+
var _a, _b, _c;
|
|
128
|
+
const dataByCategory = new Map();
|
|
129
|
+
seriesEntry.data.forEach((datum, datumIndex) => {
|
|
130
|
+
dataByCategory.set(getCategoryKey(datum), {
|
|
131
|
+
datum,
|
|
132
|
+
index: datumIndex,
|
|
133
|
+
});
|
|
134
|
+
});
|
|
135
|
+
const colorStops = getGradientStops(seriesEntry.colorGradient);
|
|
136
|
+
const gradientPreviewColor = getGradientColorFromStops(colorStops, Math.max(Math.floor((seriesEntry.data.length - 1) / 2), 0), Math.max(seriesEntry.data.length, 1));
|
|
137
|
+
return {
|
|
138
|
+
key: seriesEntry.key,
|
|
139
|
+
label: seriesEntry.label,
|
|
140
|
+
labelText: seriesEntry.labelText,
|
|
141
|
+
color: (_c = (_b = (_a = seriesEntry.color) !== null && _a !== void 0 ? _a : gradientPreviewColor) !== null && _b !== void 0 ? _b : getGradientColor(colorGradient, seriesIndex, normalizedInputSeries.length)) !== null && _c !== void 0 ? _c : themeColors[seriesIndex % themeColors.length],
|
|
142
|
+
colorStops,
|
|
143
|
+
index: seriesIndex,
|
|
144
|
+
totalValue: seriesEntry.data.reduce((sum, datum) => sum + datum.value, 0),
|
|
145
|
+
sourceSeries: seriesEntry.sourceSeries,
|
|
146
|
+
dataByCategory,
|
|
147
|
+
};
|
|
148
|
+
});
|
|
149
|
+
let renderIndex = 0;
|
|
150
|
+
const allBars = [];
|
|
151
|
+
const categories = categorySeeds.map((category) => {
|
|
152
|
+
let positiveTotal = 0;
|
|
153
|
+
let negativeTotal = 0;
|
|
154
|
+
const categoryBars = [];
|
|
155
|
+
resolvedSeries.forEach((seriesEntry) => {
|
|
156
|
+
var _a, _b;
|
|
157
|
+
const seriesDatum = seriesEntry.dataByCategory.get(category.key);
|
|
158
|
+
if (!seriesDatum)
|
|
159
|
+
return;
|
|
160
|
+
const datum = seriesDatum.datum;
|
|
161
|
+
let valueStart = 0;
|
|
162
|
+
let valueEnd = datum.value;
|
|
163
|
+
if (isMultiSeries && seriesLayout === "stacked") {
|
|
164
|
+
if (datum.value >= 0) {
|
|
165
|
+
valueStart = positiveTotal;
|
|
166
|
+
positiveTotal += datum.value;
|
|
167
|
+
valueEnd = positiveTotal;
|
|
168
|
+
}
|
|
169
|
+
else {
|
|
170
|
+
valueStart = negativeTotal;
|
|
171
|
+
negativeTotal += datum.value;
|
|
172
|
+
valueEnd = negativeTotal;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
const barKey = `${String(seriesEntry.key)}-${String(getBarKey(datum, seriesDatum.index))}-${category.key}`;
|
|
176
|
+
const color = (_b = (_a = datum.color) !== null && _a !== void 0 ? _a : getGradientColorFromStops(seriesEntry.colorStops, seriesDatum.index, Math.max(seriesEntry.dataByCategory.size, 1))) !== null && _b !== void 0 ? _b : seriesEntry.color;
|
|
177
|
+
const resolvedBar = Object.assign(Object.assign({}, datum), { key: barKey, keyString: String(barKey), color, index: seriesDatum.index, renderIndex, seriesKey: seriesEntry.key, seriesIndex: seriesEntry.index, seriesLabel: seriesEntry.label, seriesLabelText: seriesEntry.labelText, categoryKey: category.key, categoryLabel: category.label, valueStart,
|
|
178
|
+
valueEnd, sourceSeries: seriesEntry.sourceSeries });
|
|
179
|
+
renderIndex += 1;
|
|
180
|
+
categoryBars.push(resolvedBar);
|
|
181
|
+
allBars.push(resolvedBar);
|
|
182
|
+
});
|
|
183
|
+
return {
|
|
184
|
+
key: category.key,
|
|
185
|
+
label: category.label,
|
|
186
|
+
index: category.index,
|
|
187
|
+
representativeDatum: category.representativeDatum,
|
|
188
|
+
bars: categoryBars,
|
|
189
|
+
positiveTotal,
|
|
190
|
+
negativeTotal,
|
|
191
|
+
};
|
|
192
|
+
});
|
|
193
|
+
return {
|
|
194
|
+
bars: allBars,
|
|
195
|
+
categories,
|
|
196
|
+
series: resolvedSeries.map((_a) => {
|
|
197
|
+
var { colorStops: _colorStops, dataByCategory: _dataByCategory } = _a, seriesEntry = __rest(_a, ["colorStops", "dataByCategory"]);
|
|
198
|
+
return seriesEntry;
|
|
199
|
+
}),
|
|
200
|
+
};
|
|
201
|
+
}, [
|
|
202
|
+
colorGradient,
|
|
203
|
+
isMultiSeries,
|
|
204
|
+
normalizedInputSeries,
|
|
205
|
+
seriesLayout,
|
|
206
|
+
themeColors,
|
|
207
|
+
]);
|
|
208
|
+
const bars = resolvedChart.bars;
|
|
209
|
+
const categories = resolvedChart.categories;
|
|
210
|
+
const resolvedSeries = resolvedChart.series;
|
|
211
|
+
const { inner: categoryPaddingInner, outer: categoryPaddingOuter } = useMemo(() => getBandPadding(safeBarGap, orientation === "vertical" ? plotWidth : plotHeight, categories.length), [categories.length, orientation, plotHeight, plotWidth, safeBarGap]);
|
|
212
|
+
const categoryScale = useMemo(() => scaleBand()
|
|
213
|
+
.domain(categories.map((category) => category.key))
|
|
214
|
+
.range(orientation === "vertical" ? [0, plotWidth] : [0, plotHeight])
|
|
215
|
+
.paddingInner(categoryPaddingInner)
|
|
216
|
+
.paddingOuter(categoryPaddingOuter), [
|
|
217
|
+
categories,
|
|
218
|
+
categoryPaddingInner,
|
|
219
|
+
categoryPaddingOuter,
|
|
220
|
+
orientation,
|
|
221
|
+
plotHeight,
|
|
222
|
+
plotWidth,
|
|
223
|
+
]);
|
|
224
|
+
const groupScale = useMemo(() => {
|
|
225
|
+
if (!isMultiSeries || seriesLayout !== "grouped")
|
|
226
|
+
return null;
|
|
227
|
+
const { inner, outer } = getBandPadding(safeGroupBarGap, categoryScale.bandwidth(), resolvedSeries.length);
|
|
228
|
+
return scaleBand()
|
|
229
|
+
.domain(resolvedSeries.map((seriesEntry) => String(seriesEntry.key)))
|
|
230
|
+
.range([0, categoryScale.bandwidth()])
|
|
231
|
+
.paddingInner(inner)
|
|
232
|
+
.paddingOuter(outer);
|
|
233
|
+
}, [
|
|
234
|
+
categoryScale,
|
|
235
|
+
isMultiSeries,
|
|
236
|
+
resolvedSeries,
|
|
237
|
+
safeGroupBarGap,
|
|
238
|
+
seriesLayout,
|
|
239
|
+
]);
|
|
240
|
+
const domainValues = useMemo(() => {
|
|
241
|
+
if (isMultiSeries && seriesLayout === "stacked") {
|
|
242
|
+
return categories.flatMap((category) => [
|
|
243
|
+
category.negativeTotal,
|
|
244
|
+
category.positiveTotal,
|
|
245
|
+
]);
|
|
246
|
+
}
|
|
247
|
+
return bars.map((bar) => bar.value);
|
|
248
|
+
}, [bars, categories, isMultiSeries, seriesLayout]);
|
|
249
|
+
const valueScale = useMemo(() => {
|
|
250
|
+
const scale = scaleLinear()
|
|
251
|
+
.domain(getValueDomain(domainValues, minValue, maxValue))
|
|
252
|
+
.range(orientation === "vertical" ? [plotHeight, 0] : [0, plotWidth]);
|
|
253
|
+
if (minValue == null || maxValue == null) {
|
|
254
|
+
scale.nice(Math.max(valueTickCount, 2));
|
|
255
|
+
}
|
|
256
|
+
return scale;
|
|
257
|
+
}, [
|
|
258
|
+
domainValues,
|
|
259
|
+
maxValue,
|
|
260
|
+
minValue,
|
|
261
|
+
orientation,
|
|
262
|
+
plotHeight,
|
|
263
|
+
plotWidth,
|
|
264
|
+
valueTickCount,
|
|
265
|
+
]);
|
|
266
|
+
const zeroPosition = valueScale(0);
|
|
267
|
+
const tickValues = useMemo(() => Array.from(new Set(valueScale
|
|
268
|
+
.ticks(Math.max(valueTickCount, 2))
|
|
269
|
+
.map((tick) => normalizeTickValue(tick)))), [valueScale, valueTickCount]);
|
|
270
|
+
const stackTerminalBarKeys = useMemo(() => {
|
|
271
|
+
const nextKeys = new Set();
|
|
272
|
+
if (!isMultiSeries || seriesLayout !== "stacked") {
|
|
273
|
+
return nextKeys;
|
|
274
|
+
}
|
|
275
|
+
categories.forEach((category) => {
|
|
276
|
+
const positiveBars = category.bars.filter((bar) => bar.value > 0);
|
|
277
|
+
const negativeBars = category.bars.filter((bar) => bar.value < 0);
|
|
278
|
+
const topBar = positiveBars[positiveBars.length - 1];
|
|
279
|
+
const bottomBar = negativeBars[negativeBars.length - 1];
|
|
280
|
+
if (topBar)
|
|
281
|
+
nextKeys.add(String(topBar.key));
|
|
282
|
+
if (bottomBar)
|
|
283
|
+
nextKeys.add(String(bottomBar.key));
|
|
284
|
+
});
|
|
285
|
+
return nextKeys;
|
|
286
|
+
}, [categories, isMultiSeries, seriesLayout]);
|
|
287
|
+
const safeAnimationDuration = Math.max(animationDuration, 0);
|
|
288
|
+
const safeAnimationStagger = Math.max(animationStagger, 0);
|
|
289
|
+
const totalAnimationDuration = safeAnimationDuration +
|
|
290
|
+
Math.max(bars.length - 1, 0) * safeAnimationStagger;
|
|
291
|
+
useEffect(() => {
|
|
292
|
+
var _a;
|
|
293
|
+
if (!animateOnRender || bars.length === 0) {
|
|
294
|
+
setAnimationElapsed(Number.POSITIVE_INFINITY);
|
|
295
|
+
return;
|
|
296
|
+
}
|
|
297
|
+
const prefersReducedMotion = typeof window !== "undefined" &&
|
|
298
|
+
((_a = window.matchMedia) === null || _a === void 0 ? void 0 : _a.call(window, "(prefers-reduced-motion: reduce)").matches);
|
|
299
|
+
if (prefersReducedMotion) {
|
|
300
|
+
setAnimationElapsed(Number.POSITIVE_INFINITY);
|
|
301
|
+
return;
|
|
302
|
+
}
|
|
303
|
+
let animationFrame = 0;
|
|
304
|
+
let startTime = null;
|
|
305
|
+
setAnimationElapsed(0);
|
|
306
|
+
const runAnimation = (timestamp) => {
|
|
307
|
+
if (startTime == null)
|
|
308
|
+
startTime = timestamp;
|
|
309
|
+
const elapsed = timestamp - startTime;
|
|
310
|
+
setAnimationElapsed(elapsed);
|
|
311
|
+
if (elapsed < totalAnimationDuration) {
|
|
312
|
+
animationFrame = window.requestAnimationFrame(runAnimation);
|
|
313
|
+
}
|
|
314
|
+
};
|
|
315
|
+
animationFrame = window.requestAnimationFrame(runAnimation);
|
|
316
|
+
return () => {
|
|
317
|
+
window.cancelAnimationFrame(animationFrame);
|
|
318
|
+
};
|
|
319
|
+
}, [
|
|
320
|
+
animateOnRender,
|
|
321
|
+
bars.length,
|
|
322
|
+
safeAnimationDuration,
|
|
323
|
+
safeAnimationStagger,
|
|
324
|
+
totalAnimationDuration,
|
|
325
|
+
]);
|
|
326
|
+
const getBarAnimationProgress = (index) => {
|
|
327
|
+
if (!animateOnRender || safeAnimationDuration === 0)
|
|
328
|
+
return 1;
|
|
329
|
+
const elapsed = animationElapsed - index * safeAnimationStagger;
|
|
330
|
+
return easeOutCubic(clamp(elapsed / safeAnimationDuration, 0, 1));
|
|
331
|
+
};
|
|
332
|
+
const formatValue = (datum, sourceSeries) => { var _a; return (_a = valueFormatter === null || valueFormatter === void 0 ? void 0 : valueFormatter(datum.value, datum, sourceSeries)) !== null && _a !== void 0 ? _a : formatDefaultValue(datum.value); };
|
|
333
|
+
const formatCategoryLabel = (category) => {
|
|
334
|
+
var _a, _b;
|
|
335
|
+
return (_b = categoryLabelFormatter === null || categoryLabelFormatter === void 0 ? void 0 : categoryLabelFormatter(category.representativeDatum, category.index, (_a = category.bars[0]) === null || _a === void 0 ? void 0 : _a.sourceSeries)) !== null && _b !== void 0 ? _b : category.label;
|
|
336
|
+
};
|
|
337
|
+
const formatTick = (value) => { var _a; return (_a = tickFormatter === null || tickFormatter === void 0 ? void 0 : tickFormatter(value)) !== null && _a !== void 0 ? _a : formatDefaultValue(value); };
|
|
338
|
+
const formatSeriesValue = (seriesEntry) => {
|
|
339
|
+
var _a;
|
|
340
|
+
const totalDatum = {
|
|
341
|
+
label: seriesEntry.labelText,
|
|
342
|
+
value: seriesEntry.totalValue,
|
|
343
|
+
};
|
|
344
|
+
return ((_a = valueFormatter === null || valueFormatter === void 0 ? void 0 : valueFormatter(seriesEntry.totalValue, totalDatum, seriesEntry.sourceSeries)) !== null && _a !== void 0 ? _a : formatDefaultValue(seriesEntry.totalValue));
|
|
345
|
+
};
|
|
346
|
+
const updateTooltipPosition = (event, barKey) => {
|
|
347
|
+
if (!showTooltips || !containerRef.current)
|
|
348
|
+
return;
|
|
349
|
+
const containerRect = containerRef.current.getBoundingClientRect();
|
|
350
|
+
setActiveTooltip({
|
|
351
|
+
barKey,
|
|
352
|
+
x: event.clientX - containerRect.left,
|
|
353
|
+
y: event.clientY - containerRect.top,
|
|
354
|
+
});
|
|
355
|
+
};
|
|
356
|
+
const activeTooltipBar = showTooltips && activeTooltip
|
|
357
|
+
? (_c = bars.find((bar) => bar.key === activeTooltip.barKey)) !== null && _c !== void 0 ? _c : null
|
|
358
|
+
: null;
|
|
359
|
+
const activeTooltipCategory = isMultiSeries && activeTooltipBar
|
|
360
|
+
? (_d = categories.find((category) => category.key === activeTooltipBar.categoryKey)) !== null && _d !== void 0 ? _d : null
|
|
361
|
+
: null;
|
|
362
|
+
const tooltipStyle = useMemo(() => {
|
|
363
|
+
if (!activeTooltip ||
|
|
364
|
+
!containerRef.current ||
|
|
365
|
+
!chartFrameRef.current ||
|
|
366
|
+
!activeTooltipBar) {
|
|
367
|
+
return null;
|
|
368
|
+
}
|
|
369
|
+
const containerRect = containerRef.current.getBoundingClientRect();
|
|
370
|
+
const chartFrameRect = chartFrameRef.current.getBoundingClientRect();
|
|
371
|
+
const chartFrameLeft = chartFrameRect.left - containerRect.left;
|
|
372
|
+
const chartFrameTop = chartFrameRect.top - containerRect.top;
|
|
373
|
+
const minLeft = chartFrameLeft + 8;
|
|
374
|
+
const maxLeft = chartFrameLeft + chartFrameRect.width - tooltipSize.width - 8;
|
|
375
|
+
const minTop = chartFrameTop + 8;
|
|
376
|
+
const maxTop = chartFrameTop + chartFrameRect.height - tooltipSize.height - 8;
|
|
377
|
+
return {
|
|
378
|
+
left: clamp(activeTooltip.x + 12, minLeft, Math.max(minLeft, maxLeft)),
|
|
379
|
+
top: clamp(activeTooltip.y - tooltipSize.height / 2, minTop, Math.max(minTop, maxTop)),
|
|
380
|
+
transform: "none",
|
|
381
|
+
};
|
|
382
|
+
}, [activeTooltip, activeTooltipBar, tooltipSize.height, tooltipSize.width]);
|
|
383
|
+
const shouldShowLegend = showLegend &&
|
|
384
|
+
(isMultiSeries ? resolvedSeries.length > 0 : bars.length > 0) &&
|
|
385
|
+
(showLegendSwatches || showLegendLabels || showLegendValues);
|
|
386
|
+
const description = useMemo(() => {
|
|
387
|
+
if (isMultiSeries) {
|
|
388
|
+
return categories
|
|
389
|
+
.map((category) => {
|
|
390
|
+
const seriesValues = category.bars
|
|
391
|
+
.map((bar) => `${bar.seriesLabelText}: ${formatDefaultValue(bar.value)}`)
|
|
392
|
+
.join(", ");
|
|
393
|
+
return `${category.label}: ${seriesValues}`;
|
|
394
|
+
})
|
|
395
|
+
.join(". ");
|
|
396
|
+
}
|
|
397
|
+
return bars
|
|
398
|
+
.map((bar) => `${bar.label}: ${formatDefaultValue(bar.value)}`)
|
|
399
|
+
.join(", ");
|
|
400
|
+
}, [bars, categories, isMultiSeries]);
|
|
401
|
+
useEffect(() => {
|
|
402
|
+
if (!tooltipRef.current ||
|
|
403
|
+
!activeTooltipBar ||
|
|
404
|
+
(isMultiSeries && !activeTooltipCategory)) {
|
|
405
|
+
setTooltipSize({ width: 0, height: 0 });
|
|
406
|
+
return;
|
|
407
|
+
}
|
|
408
|
+
setTooltipSize({
|
|
409
|
+
width: tooltipRef.current.offsetWidth,
|
|
410
|
+
height: tooltipRef.current.offsetHeight,
|
|
411
|
+
});
|
|
412
|
+
}, [activeTooltipBar, activeTooltipCategory, isMultiSeries]);
|
|
413
|
+
return (_jsxs(StyledContainer, Object.assign({ ref: containerRef, className: className }, props, { children: [bars.length === 0 ? (_jsx(StyledEmptyState, { "$width": safeWidth, "$height": safeHeight, children: emptyLabel })) : (_jsx(StyledChartScroller, { children: _jsxs(StyledChartFrame, { ref: chartFrameRef, children: [showExportButton && exportFormats.length > 0 && (_jsx(StyledChartActions, { "data-chart-export-ignore": "true", children: _jsx(ChartExportControl, { rootRef: containerRef, svgRef: svgRef, fileName: exportFileName, formats: exportFormats, scale: exportScale, backgroundColor: resolvedExportBackgroundColor }) })), _jsxs(StyledSvg, { ref: svgRef, width: safeWidth, height: safeHeight, viewBox: `0 0 ${safeWidth} ${safeHeight}`, role: "img", "aria-label": ariaLabel, "aria-describedby": descriptionId, children: [_jsx("desc", { id: descriptionId, children: description }), showGridLines &&
|
|
414
|
+
tickValues.map((tick) => {
|
|
415
|
+
const tickPosition = valueScale(tick);
|
|
416
|
+
return orientation === "vertical" ? (_jsx(StyledGridLine, { x1: resolvedMargin.left, x2: resolvedMargin.left + plotWidth, y1: resolvedMargin.top + tickPosition, y2: resolvedMargin.top + tickPosition }, `grid-${tick}`)) : (_jsx(StyledGridLine, { x1: resolvedMargin.left + tickPosition, x2: resolvedMargin.left + tickPosition, y1: resolvedMargin.top, y2: resolvedMargin.top + plotHeight }, `grid-${tick}`));
|
|
417
|
+
}), showAxisLines && (_jsx(_Fragment, { children: orientation === "vertical" ? (_jsxs(_Fragment, { children: [_jsx(StyledAxisLine, { x1: resolvedMargin.left, x2: resolvedMargin.left, y1: resolvedMargin.top, y2: resolvedMargin.top + plotHeight }), _jsx(StyledAxisLine, { x1: resolvedMargin.left, x2: resolvedMargin.left + plotWidth, y1: resolvedMargin.top + zeroPosition, y2: resolvedMargin.top + zeroPosition })] })) : (_jsxs(_Fragment, { children: [_jsx(StyledAxisLine, { x1: resolvedMargin.left, x2: resolvedMargin.left + plotWidth, y1: resolvedMargin.top + plotHeight, y2: resolvedMargin.top + plotHeight }), _jsx(StyledAxisLine, { x1: resolvedMargin.left + zeroPosition, x2: resolvedMargin.left + zeroPosition, y1: resolvedMargin.top, y2: resolvedMargin.top + plotHeight })] })) })), showValueAxisLabels &&
|
|
418
|
+
tickValues.map((tick) => {
|
|
419
|
+
const tickPosition = valueScale(tick);
|
|
420
|
+
return orientation === "vertical" ? (_jsx(StyledAxisText, { x: resolvedMargin.left - 10, y: resolvedMargin.top + tickPosition, textAnchor: "end", dominantBaseline: "middle", children: formatTick(tick) }, `value-tick-${tick}`)) : (_jsx(StyledAxisText, { x: resolvedMargin.left + tickPosition, y: resolvedMargin.top + plotHeight + 18, textAnchor: "middle", children: formatTick(tick) }, `value-tick-${tick}`));
|
|
421
|
+
}), categories.map((category) => {
|
|
422
|
+
var _a;
|
|
423
|
+
const categoryBandStart = (_a = categoryScale(category.key)) !== null && _a !== void 0 ? _a : 0;
|
|
424
|
+
return category.bars.map((bar) => {
|
|
425
|
+
var _a, _b, _c;
|
|
426
|
+
const groupBandStart = (_a = groupScale === null || groupScale === void 0 ? void 0 : groupScale(String(bar.seriesKey))) !== null && _a !== void 0 ? _a : 0;
|
|
427
|
+
const groupBandWidth = (_b = groupScale === null || groupScale === void 0 ? void 0 : groupScale.bandwidth()) !== null && _b !== void 0 ? _b : categoryScale.bandwidth();
|
|
428
|
+
const thickness = safeMaxBarThickness
|
|
429
|
+
? Math.min(groupBandWidth, safeMaxBarThickness)
|
|
430
|
+
: groupBandWidth;
|
|
431
|
+
const thicknessOffset = (groupBandWidth - thickness) / 2;
|
|
432
|
+
const animationProgress = getBarAnimationProgress(bar.renderIndex);
|
|
433
|
+
const startPosition = valueScale(bar.valueStart);
|
|
434
|
+
const endPosition = valueScale(bar.valueEnd);
|
|
435
|
+
const animatedStartPosition = zeroPosition +
|
|
436
|
+
(startPosition - zeroPosition) * animationProgress;
|
|
437
|
+
const animatedEndPosition = zeroPosition + (endPosition - zeroPosition) * animationProgress;
|
|
438
|
+
const x = orientation === "vertical"
|
|
439
|
+
? resolvedMargin.left +
|
|
440
|
+
categoryBandStart +
|
|
441
|
+
groupBandStart +
|
|
442
|
+
thicknessOffset
|
|
443
|
+
: resolvedMargin.left +
|
|
444
|
+
Math.min(animatedStartPosition, animatedEndPosition);
|
|
445
|
+
const y = orientation === "vertical"
|
|
446
|
+
? resolvedMargin.top +
|
|
447
|
+
Math.min(animatedStartPosition, animatedEndPosition)
|
|
448
|
+
: resolvedMargin.top +
|
|
449
|
+
categoryBandStart +
|
|
450
|
+
groupBandStart +
|
|
451
|
+
thicknessOffset;
|
|
452
|
+
const barWidth = orientation === "vertical"
|
|
453
|
+
? thickness
|
|
454
|
+
: Math.abs(animatedEndPosition - animatedStartPosition);
|
|
455
|
+
const barHeight = orientation === "vertical"
|
|
456
|
+
? Math.abs(animatedEndPosition - animatedStartPosition)
|
|
457
|
+
: thickness;
|
|
458
|
+
const isStackTerminal = seriesLayout !== "stacked" ||
|
|
459
|
+
stackTerminalBarKeys.has(String(bar.key));
|
|
460
|
+
const path = getRoundedBarPath({
|
|
461
|
+
x,
|
|
462
|
+
y,
|
|
463
|
+
width: barWidth,
|
|
464
|
+
height: barHeight,
|
|
465
|
+
radius: isStackTerminal ? safeBarRadius : 0,
|
|
466
|
+
orientation,
|
|
467
|
+
value: bar.value,
|
|
468
|
+
});
|
|
469
|
+
const isPositive = bar.value >= 0;
|
|
470
|
+
const outerValuePosition = valueScale(bar.valueEnd);
|
|
471
|
+
const valueLabelX = orientation === "vertical"
|
|
472
|
+
? resolvedMargin.left +
|
|
473
|
+
categoryBandStart +
|
|
474
|
+
groupBandStart +
|
|
475
|
+
thicknessOffset +
|
|
476
|
+
thickness / 2
|
|
477
|
+
: resolvedMargin.left +
|
|
478
|
+
(isPositive
|
|
479
|
+
? Math.max(outerValuePosition, zeroPosition) + 8
|
|
480
|
+
: Math.min(outerValuePosition, zeroPosition) - 8);
|
|
481
|
+
const valueLabelY = orientation === "vertical"
|
|
482
|
+
? resolvedMargin.top +
|
|
483
|
+
(isPositive
|
|
484
|
+
? Math.min(outerValuePosition, zeroPosition) - 8
|
|
485
|
+
: Math.max(outerValuePosition, zeroPosition) + 14)
|
|
486
|
+
: resolvedMargin.top +
|
|
487
|
+
categoryBandStart +
|
|
488
|
+
groupBandStart +
|
|
489
|
+
thicknessOffset +
|
|
490
|
+
thickness / 2;
|
|
491
|
+
const shouldShowValueLabel = showLabels &&
|
|
492
|
+
animationProgress >= 0.92 &&
|
|
493
|
+
(seriesLayout !== "stacked" || isStackTerminal);
|
|
494
|
+
const isActive = activeBarKey === bar.key ||
|
|
495
|
+
(isMultiSeries && activeSeriesKey === bar.seriesKey);
|
|
496
|
+
return (_jsxs("g", { children: [_jsx(StyledBar, { "$active": isActive, d: path || undefined, fill: bar.color, fillOpacity: resolvedBarOpacity, stroke: resolvedBarBorderColor, strokeWidth: resolvedBarBorderWidth, strokeOpacity: resolvedBarBorderOpacity, tabIndex: 0, "aria-label": isMultiSeries
|
|
497
|
+
? `${bar.seriesLabelText}, ${bar.categoryLabel}: ${formatDefaultValue(bar.value)}`
|
|
498
|
+
: `${bar.label}: ${formatDefaultValue(bar.value)}`, onFocus: () => {
|
|
499
|
+
setActiveBarKey(bar.key);
|
|
500
|
+
setActiveSeriesKey(bar.seriesKey);
|
|
501
|
+
}, onBlur: () => {
|
|
502
|
+
setActiveBarKey(null);
|
|
503
|
+
setActiveSeriesKey(null);
|
|
504
|
+
}, onMouseEnter: (event) => {
|
|
505
|
+
setActiveBarKey(bar.key);
|
|
506
|
+
setActiveSeriesKey(bar.seriesKey);
|
|
507
|
+
updateTooltipPosition(event, bar.key);
|
|
508
|
+
}, onMouseMove: (event) => updateTooltipPosition(event, bar.key), onMouseLeave: () => {
|
|
509
|
+
setActiveBarKey(null);
|
|
510
|
+
setActiveSeriesKey(null);
|
|
511
|
+
setActiveTooltip(null);
|
|
512
|
+
}, onClick: (event) => onBarClick === null || onBarClick === void 0 ? void 0 : onBarClick(event, bar, bar.sourceSeries), onKeyDown: (event) => {
|
|
513
|
+
if (event.key !== "Enter" && event.key !== " ")
|
|
514
|
+
return;
|
|
515
|
+
event.preventDefault();
|
|
516
|
+
onBarClick === null || onBarClick === void 0 ? void 0 : onBarClick(event, bar, bar.sourceSeries);
|
|
517
|
+
} }), shouldShowValueLabel && (_jsx(StyledValueLabel, { x: valueLabelX, y: valueLabelY, textAnchor: orientation === "vertical"
|
|
518
|
+
? "middle"
|
|
519
|
+
: isPositive
|
|
520
|
+
? "start"
|
|
521
|
+
: "end", dominantBaseline: orientation === "vertical" ? "middle" : "central", children: (_c = labelFormatter === null || labelFormatter === void 0 ? void 0 : labelFormatter(bar, bar.index, bar.sourceSeries)) !== null && _c !== void 0 ? _c : formatValue(bar, bar.sourceSeries) }))] }, bar.key));
|
|
522
|
+
});
|
|
523
|
+
}), showCategoryAxisLabels &&
|
|
524
|
+
categories.map((category) => {
|
|
525
|
+
var _a, _b;
|
|
526
|
+
return orientation === "vertical" ? (_jsx(StyledAxisText, { x: resolvedMargin.left +
|
|
527
|
+
((_a = categoryScale(category.key)) !== null && _a !== void 0 ? _a : 0) +
|
|
528
|
+
categoryScale.bandwidth() / 2, y: resolvedMargin.top + plotHeight + 20, textAnchor: "middle", children: formatCategoryLabel(category) }, `category-${category.key}`)) : (_jsx(StyledAxisText, { x: resolvedMargin.left - 10, y: resolvedMargin.top +
|
|
529
|
+
((_b = categoryScale(category.key)) !== null && _b !== void 0 ? _b : 0) +
|
|
530
|
+
categoryScale.bandwidth() / 2, textAnchor: "end", dominantBaseline: "middle", children: formatCategoryLabel(category) }, `category-${category.key}`));
|
|
531
|
+
})] })] }) })), activeTooltip && activeTooltipBar && tooltipStyle && (_jsx(StyledTooltip, { ref: tooltipRef, style: tooltipStyle, children: tooltipFormatter ? (tooltipFormatter(activeTooltipBar, activeTooltipBar.index, activeTooltipBar.sourceSeries)) : isMultiSeries && activeTooltipCategory ? (_jsxs(_Fragment, { children: [_jsx(StyledTooltipHeader, { children: _jsx(StyledTooltipLabel, { children: activeTooltipCategory.label }) }), _jsxs(StyledTooltipMeta, { children: [formatDefaultValue(activeTooltipCategory.bars.reduce((sum, bar) => sum + bar.value, 0)), " ", "total"] }), _jsx(StyledTooltipList, { children: activeTooltipCategory.bars.map((bar) => (_jsxs(StyledTooltipRow, { children: [_jsx(StyledTooltipSwatch, { "$color": bar.color }), _jsx(StyledTooltipLabel, { children: bar.seriesLabel }), _jsx(StyledTooltipValue, { children: formatValue(bar, bar.sourceSeries) })] }, `tooltip-${bar.key}`))) })] })) : (_jsxs(_Fragment, { children: [_jsxs(StyledTooltipHeader, { children: [_jsx(StyledTooltipSwatch, { "$color": activeTooltipBar.color }), _jsx(StyledTooltipLabel, { children: activeTooltipBar.label })] }), _jsx(StyledTooltipMeta, { children: formatValue(activeTooltipBar, activeTooltipBar.sourceSeries) })] })) })), shouldShowLegend && (_jsx(StyledLegend, { children: isMultiSeries
|
|
532
|
+
? resolvedSeries.map((seriesEntry) => (_jsxs(StyledLegendItem, { "$active": activeSeriesKey === seriesEntry.key, "$showSwatch": showLegendSwatches, "$showLabel": showLegendLabels, "$showValue": showLegendValues, tabIndex: 0, onMouseEnter: () => setActiveSeriesKey(seriesEntry.key), onMouseLeave: () => setActiveSeriesKey(null), onFocus: () => setActiveSeriesKey(seriesEntry.key), onBlur: () => setActiveSeriesKey(null), onClick: (event) => seriesEntry.sourceSeries &&
|
|
533
|
+
(onSeriesLegendItemClick === null || onSeriesLegendItemClick === void 0 ? void 0 : onSeriesLegendItemClick(event, seriesEntry.sourceSeries)), onKeyDown: (event) => {
|
|
534
|
+
if (event.key !== "Enter" && event.key !== " ")
|
|
535
|
+
return;
|
|
536
|
+
event.preventDefault();
|
|
537
|
+
if (seriesEntry.sourceSeries) {
|
|
538
|
+
onSeriesLegendItemClick === null || onSeriesLegendItemClick === void 0 ? void 0 : onSeriesLegendItemClick(event, seriesEntry.sourceSeries);
|
|
539
|
+
}
|
|
540
|
+
}, children: [showLegendSwatches && _jsx(StyledSwatch, { "$color": seriesEntry.color }), showLegendLabels && (_jsx(StyledLegendLabel, { children: seriesEntry.label })), showLegendValues && (_jsx(StyledLegendValue, { children: formatSeriesValue(seriesEntry) }))] }, `legend-${seriesEntry.key}`)))
|
|
541
|
+
: bars.map((bar) => (_jsxs(StyledLegendItem, { "$active": activeBarKey === bar.key, "$showSwatch": showLegendSwatches, "$showLabel": showLegendLabels, "$showValue": showLegendValues, tabIndex: 0, onMouseEnter: () => setActiveBarKey(bar.key), onMouseLeave: () => setActiveBarKey(null), onFocus: () => setActiveBarKey(bar.key), onBlur: () => setActiveBarKey(null), onClick: (event) => onLegendItemClick === null || onLegendItemClick === void 0 ? void 0 : onLegendItemClick(event, bar), onKeyDown: (event) => {
|
|
542
|
+
if (event.key !== "Enter" && event.key !== " ")
|
|
543
|
+
return;
|
|
544
|
+
event.preventDefault();
|
|
545
|
+
onLegendItemClick === null || onLegendItemClick === void 0 ? void 0 : onLegendItemClick(event, bar);
|
|
546
|
+
}, children: [showLegendSwatches && _jsx(StyledSwatch, { "$color": bar.color }), showLegendLabels && _jsx(StyledLegendLabel, { children: bar.label }), showLegendValues && (_jsx(StyledLegendValue, { children: formatValue(bar, bar.sourceSeries) }))] }, bar.key))) }))] })));
|
|
547
|
+
};
|
|
548
|
+
export const BarChart = forwardRef(BarChartInner);
|
|
549
|
+
export default BarChart;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { ReactNode } from "react";
|
|
2
|
+
import { clamp, easeOutCubic, formatDefaultValue, getGradientColor, getGradientColorFromStops, getGradientStops, mixColors } from "../ChartUtils";
|
|
3
|
+
import { BarChartDatum, BarChartMargin, BarChartOrientation, BarChartSeries } from "./BarChart.types";
|
|
4
|
+
export { clamp, easeOutCubic, formatDefaultValue, getGradientColor, getGradientColorFromStops, getGradientStops, mixColors, };
|
|
5
|
+
export declare const getBarKey: (datum: BarChartDatum<unknown>, index: number) => string | number;
|
|
6
|
+
export declare const getSeriesKey: (series: BarChartSeries<unknown>, index: number) => string | number;
|
|
7
|
+
export declare const getSeriesLabelText: (label: ReactNode, fallbackLabel: string) => string;
|
|
8
|
+
export declare const getCategoryKey: (datum: BarChartDatum<unknown>) => string;
|
|
9
|
+
export declare const useThemeColors: (colors?: string[]) => string[];
|
|
10
|
+
export declare const getBandPadding: (barGap: number, span: number, count: number) => {
|
|
11
|
+
inner: number;
|
|
12
|
+
outer: number;
|
|
13
|
+
};
|
|
14
|
+
export declare const getValueDomain: (values: number[], minValue?: number, maxValue?: number) => [number, number];
|
|
15
|
+
export declare const getDefaultMargin: (orientation: BarChartOrientation, showCategoryAxisLabels: boolean, showValueAxisLabels: boolean, showLabels: boolean) => BarChartMargin;
|
|
16
|
+
export declare const mergeChartMargin: (orientation: BarChartOrientation, margin: Partial<BarChartMargin> | undefined, showCategoryAxisLabels: boolean, showValueAxisLabels: boolean, showLabels: boolean) => {
|
|
17
|
+
top: number;
|
|
18
|
+
right: number;
|
|
19
|
+
bottom: number;
|
|
20
|
+
left: number;
|
|
21
|
+
};
|
|
22
|
+
export declare const normalizeTickValue: (value: number) => number;
|
|
23
|
+
export declare const getRoundedBarPath: ({ x, y, width, height, radius, orientation, value, }: {
|
|
24
|
+
x: number;
|
|
25
|
+
y: number;
|
|
26
|
+
width: number;
|
|
27
|
+
height: number;
|
|
28
|
+
radius: number;
|
|
29
|
+
orientation: BarChartOrientation;
|
|
30
|
+
value: number;
|
|
31
|
+
}) => string;
|