@monolith-forensics/monolith-ui 1.8.1-dev.0 → 1.8.1-dev.2
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/Calendar/CalendarStyles.js +7 -4
- package/dist/DropDownMenu/DropDownMenu.js +2 -2
- package/dist/DropDownMenu/components/MenuItem.d.ts +2 -0
- package/dist/DropDownMenu/components/MenuItem.js +16 -9
- package/dist/DropDownMenu/components/MenuItemList.d.ts +1 -0
- package/dist/DropDownMenu/components/MenuItemList.js +101 -59
- package/dist/DropDownMenu/types.d.ts +2 -0
- package/dist/SelectBox/SelectBox.js +2 -2
- package/dist/SelectBox/select-box.styled-components.d.ts +1 -0
- package/dist/SelectBox/select-box.styled-components.js +3 -2
- package/dist/SelectBox/types.d.ts +1 -0
- package/dist/TagBox/TagBox.d.ts +1 -1
- package/dist/TagBox/TagBox.js +6 -6
- package/dist/TagBox/types.d.ts +1 -0
- package/dist/TextArea/TextArea.js +5 -0
- package/package.json +1 -1
- package/dist/BarChart/BarChart.d.ts +0 -3
- package/dist/BarChart/BarChart.js +0 -511
- package/dist/BarChart/BarChart.lib.d.ts +0 -31
- package/dist/BarChart/BarChart.lib.js +0 -136
- package/dist/BarChart/BarChart.styled.d.ts +0 -49
- package/dist/BarChart/BarChart.styled.js +0 -111
- package/dist/BarChart/BarChart.types.d.ts +0 -170
- package/dist/BarChart/BarChart.types.js +0 -1
- package/dist/BarChart/index.d.ts +0 -3
- package/dist/BarChart/index.js +0 -2
- package/dist/ChartPrimitives/chartLegend.styled.d.ts +0 -12
- package/dist/ChartPrimitives/chartLegend.styled.js +0 -52
- package/dist/ChartPrimitives/chartTooltip.styled.d.ts +0 -19
- package/dist/ChartPrimitives/chartTooltip.styled.js +0 -61
- package/dist/ChartPrimitives/index.d.ts +0 -2
- package/dist/ChartPrimitives/index.js +0 -2
- package/dist/ChartUtils/chartColors.d.ts +0 -8
- package/dist/ChartUtils/chartColors.js +0 -65
- package/dist/ChartUtils/chartMath.d.ts +0 -3
- package/dist/ChartUtils/chartMath.js +0 -3
- package/dist/ChartUtils/index.d.ts +0 -2
- package/dist/ChartUtils/index.js +0 -2
- package/dist/HeatMap/HeatMap.d.ts +0 -3
- package/dist/HeatMap/HeatMap.js +0 -174
- package/dist/HeatMap/HeatMap.lib.d.ts +0 -30
- package/dist/HeatMap/HeatMap.lib.js +0 -115
- package/dist/HeatMap/HeatMap.styled.d.ts +0 -34
- package/dist/HeatMap/HeatMap.styled.js +0 -83
- package/dist/HeatMap/HeatMap.types.d.ts +0 -79
- package/dist/HeatMap/HeatMap.types.js +0 -1
- package/dist/HeatMap/index.d.ts +0 -3
- package/dist/HeatMap/index.js +0 -2
- package/dist/LineChart/LineChart.d.ts +0 -3
- package/dist/LineChart/LineChart.js +0 -491
- package/dist/LineChart/LineChart.lib.d.ts +0 -24
- package/dist/LineChart/LineChart.lib.js +0 -132
- package/dist/LineChart/LineChart.styled.d.ts +0 -57
- package/dist/LineChart/LineChart.styled.js +0 -150
- package/dist/LineChart/LineChart.types.d.ts +0 -192
- package/dist/LineChart/LineChart.types.js +0 -1
- package/dist/LineChart/index.d.ts +0 -3
- package/dist/LineChart/index.js +0 -2
- package/dist/PieChart/PieChart.d.ts +0 -2
- package/dist/PieChart/PieChart.js +0 -161
- package/dist/PieChart/PieChart.lib.d.ts +0 -5
- package/dist/PieChart/PieChart.lib.js +0 -19
- package/dist/PieChart/PieChart.styled.d.ts +0 -49
- package/dist/PieChart/PieChart.styled.js +0 -161
- package/dist/PieChart/PieChart.types.d.ts +0 -99
- package/dist/PieChart/PieChart.types.js +0 -1
- package/dist/PieChart/index.d.ts +0 -2
- package/dist/PieChart/index.js +0 -1
- package/dist/SuperDatePicker/SuperDatePicker.d.ts +0 -74
- package/dist/SuperDatePicker/SuperDatePicker.js +0 -557
- package/dist/SuperDatePicker/index.d.ts +0 -2
- package/dist/SuperDatePicker/index.js +0 -2
|
@@ -1,491 +0,0 @@
|
|
|
1
|
-
var __rest = (this && this.__rest) || function (s, e) {
|
|
2
|
-
var t = {};
|
|
3
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
4
|
-
t[p] = s[p];
|
|
5
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
6
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
7
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
8
|
-
t[p[i]] = s[p[i]];
|
|
9
|
-
}
|
|
10
|
-
return t;
|
|
11
|
-
};
|
|
12
|
-
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
13
|
-
import { scaleLinear, scalePoint, scaleTime } from "d3-scale";
|
|
14
|
-
import { useCallback, useEffect, useId, useMemo, useRef, useState, } from "react";
|
|
15
|
-
import { useTheme } from "styled-components";
|
|
16
|
-
import { buildAreaPath, buildLinePath, clamp, easeOutCubic, formatDefaultValue, getGradientStops, getPointKey, getSeriesKey, getSeriesLabelText, getValueDomain, measureSvgPath, mergeChartMargin, normalizeTickValue, parseLineChartXValue, resolveXAxisType, useThemeColor, useThemeColors, } from "./LineChart.lib";
|
|
17
|
-
import { StyledArea, StyledAxisLine, StyledAxisText, StyledChartFrame, StyledChartScroller, StyledContainer, StyledEmptyState, StyledGridLine, StyledHoverTarget, StyledLegend, StyledLegendItem, StyledLegendLabel, StyledLegendLine, StyledLegendValue, StyledLine, StyledPoint, StyledSvg, StyledTooltip, StyledTooltipHeader, StyledTooltipLabel, StyledTooltipMeta, StyledTooltipSwatch, StyledValueLabel, } from "./LineChart.styled";
|
|
18
|
-
export const LineChart = (_a) => {
|
|
19
|
-
var _b, _c, _d;
|
|
20
|
-
var { data, series, seriesLabel = "Series", width = 720, height = 320, margin, xAxisType = "auto", curve = "monotone", lineColor, colors, colorGradient, lineWidth = 2.5, lineOpacity = 1, lineDasharray, showArea = false, areaColor, areaOpacity = 0.14, showPoints = false, pointRadius = 3, activePointRadius = 4, pointColor, pointBorderColor, pointBorderWidth = 1.5, pointOpacity = 1, yMin, yMax, xTickCount = 6, yTickCount = 5, showGridLines = true, showAxisLines = true, showXAxisLabels = true, showYAxisLabels = true, showLegend = false, showLabels = false, emptyLabel = "No data", ariaLabel = "Line chart", animateOnRender = false, animationDuration = 720, showTooltips = false, valueFormatter, xValueFormatter, xTickFormatter, yTickFormatter, labelFormatter, tooltipFormatter, onPointClick, className } = _a, props = __rest(_a, ["data", "series", "seriesLabel", "width", "height", "margin", "xAxisType", "curve", "lineColor", "colors", "colorGradient", "lineWidth", "lineOpacity", "lineDasharray", "showArea", "areaColor", "areaOpacity", "showPoints", "pointRadius", "activePointRadius", "pointColor", "pointBorderColor", "pointBorderWidth", "pointOpacity", "yMin", "yMax", "xTickCount", "yTickCount", "showGridLines", "showAxisLines", "showXAxisLabels", "showYAxisLabels", "showLegend", "showLabels", "emptyLabel", "ariaLabel", "animateOnRender", "animationDuration", "showTooltips", "valueFormatter", "xValueFormatter", "xTickFormatter", "yTickFormatter", "labelFormatter", "tooltipFormatter", "onPointClick", "className"]);
|
|
21
|
-
const descriptionId = useId();
|
|
22
|
-
const gradientBaseId = useId();
|
|
23
|
-
const theme = useTheme();
|
|
24
|
-
const containerRef = useRef(null);
|
|
25
|
-
const chartFrameRef = useRef(null);
|
|
26
|
-
const tooltipRef = useRef(null);
|
|
27
|
-
const linePathRefs = useRef({});
|
|
28
|
-
const [activePointKey, setActivePointKey] = useState(null);
|
|
29
|
-
const [activeSeriesKey, setActiveSeriesKey] = useState(null);
|
|
30
|
-
const [activeTooltip, setActiveTooltip] = useState(null);
|
|
31
|
-
const [tooltipSize, setTooltipSize] = useState({ width: 0, height: 0 });
|
|
32
|
-
const [animationProgress, setAnimationProgress] = useState(animateOnRender ? 0 : 1);
|
|
33
|
-
const [lineLengths, setLineLengths] = useState({});
|
|
34
|
-
const themeLineColor = useThemeColor(lineColor);
|
|
35
|
-
const themeColors = useThemeColors(colors);
|
|
36
|
-
const resolvedMargin = mergeChartMargin(margin, showXAxisLabels, showYAxisLabels, showLabels);
|
|
37
|
-
const safeWidth = Math.max(width, 240);
|
|
38
|
-
const safeHeight = Math.max(height, 200);
|
|
39
|
-
const plotWidth = Math.max(safeWidth - resolvedMargin.left - resolvedMargin.right, 1);
|
|
40
|
-
const plotHeight = Math.max(safeHeight - resolvedMargin.top - resolvedMargin.bottom, 1);
|
|
41
|
-
const resolvedGlobalLineWidth = Math.max(lineWidth, 1);
|
|
42
|
-
const resolvedGlobalLineOpacity = clamp(lineOpacity, 0, 1);
|
|
43
|
-
const resolvedGlobalAreaOpacity = clamp(areaOpacity, 0, 1);
|
|
44
|
-
const resolvedGlobalPointRadius = Math.max(pointRadius, 0);
|
|
45
|
-
const resolvedGlobalActivePointRadius = Math.max(activePointRadius, resolvedGlobalPointRadius);
|
|
46
|
-
const resolvedPointOpacity = clamp(pointOpacity, 0, 1);
|
|
47
|
-
const isMultiSeries = ((_b = series === null || series === void 0 ? void 0 : series.length) !== null && _b !== void 0 ? _b : 0) > 0;
|
|
48
|
-
const normalizedInputSeries = useMemo(() => {
|
|
49
|
-
if (series === null || series === void 0 ? void 0 : series.length) {
|
|
50
|
-
return series.map((seriesItem, seriesIndex) => {
|
|
51
|
-
const fallbackLabel = `Series ${seriesIndex + 1}`;
|
|
52
|
-
return {
|
|
53
|
-
key: getSeriesKey(seriesItem, seriesIndex),
|
|
54
|
-
label: seriesItem.label,
|
|
55
|
-
labelText: getSeriesLabelText(seriesItem.label, fallbackLabel),
|
|
56
|
-
sourceSeries: seriesItem,
|
|
57
|
-
color: seriesItem.color,
|
|
58
|
-
colorGradient: seriesItem.colorGradient,
|
|
59
|
-
lineDasharray: seriesItem.lineDasharray,
|
|
60
|
-
lineWidth: seriesItem.lineWidth,
|
|
61
|
-
lineOpacity: seriesItem.lineOpacity,
|
|
62
|
-
showArea: seriesItem.showArea,
|
|
63
|
-
areaColor: seriesItem.areaColor,
|
|
64
|
-
areaOpacity: seriesItem.areaOpacity,
|
|
65
|
-
showPoints: seriesItem.showPoints,
|
|
66
|
-
pointColor: seriesItem.pointColor,
|
|
67
|
-
pointRadius: seriesItem.pointRadius,
|
|
68
|
-
activePointRadius: seriesItem.activePointRadius,
|
|
69
|
-
data: seriesItem.data,
|
|
70
|
-
};
|
|
71
|
-
});
|
|
72
|
-
}
|
|
73
|
-
if (data === null || data === void 0 ? void 0 : data.length) {
|
|
74
|
-
return [
|
|
75
|
-
{
|
|
76
|
-
key: "series-0",
|
|
77
|
-
label: seriesLabel,
|
|
78
|
-
labelText: getSeriesLabelText(seriesLabel, "Series"),
|
|
79
|
-
data,
|
|
80
|
-
},
|
|
81
|
-
];
|
|
82
|
-
}
|
|
83
|
-
return [];
|
|
84
|
-
}, [data, series, seriesLabel]);
|
|
85
|
-
const parsedSeriesInput = useMemo(() => {
|
|
86
|
-
const seriesEntries = normalizedInputSeries.map((inputSeries, seriesIndex) => {
|
|
87
|
-
const parsedPoints = inputSeries.data
|
|
88
|
-
.map((datum, pointIndex) => {
|
|
89
|
-
const parsedX = parseLineChartXValue(datum.x);
|
|
90
|
-
if (parsedX == null || !Number.isFinite(datum.y))
|
|
91
|
-
return null;
|
|
92
|
-
return Object.assign(Object.assign({}, datum), { key: `${String(inputSeries.key)}-${getPointKey(datum, pointIndex)}`, index: pointIndex, parsedX, xType: "point", seriesKey: inputSeries.key, seriesIndex, seriesLabel: inputSeries.label, seriesLabelText: inputSeries.labelText, seriesColor: "" });
|
|
93
|
-
})
|
|
94
|
-
.filter(Boolean);
|
|
95
|
-
return Object.assign(Object.assign({}, inputSeries), { points: parsedPoints });
|
|
96
|
-
});
|
|
97
|
-
const allPoints = seriesEntries.flatMap((entry) => entry.points);
|
|
98
|
-
return {
|
|
99
|
-
resolvedXAxisType: resolveXAxisType(allPoints, xAxisType),
|
|
100
|
-
seriesEntries,
|
|
101
|
-
};
|
|
102
|
-
}, [normalizedInputSeries, xAxisType]);
|
|
103
|
-
const resolvedSeries = useMemo(() => {
|
|
104
|
-
return parsedSeriesInput.seriesEntries
|
|
105
|
-
.map((seriesEntry, seriesIndex) => {
|
|
106
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
|
|
107
|
-
const resolvedColor = (_a = seriesEntry.color) !== null && _a !== void 0 ? _a : (normalizedInputSeries.length === 1
|
|
108
|
-
? themeLineColor
|
|
109
|
-
: themeColors[seriesIndex % themeColors.length]);
|
|
110
|
-
const resolvedGradientStops = getGradientStops((_b = seriesEntry.colorGradient) !== null && _b !== void 0 ? _b : (normalizedInputSeries.length === 1 ? colorGradient : undefined));
|
|
111
|
-
const resolvedPointRadius = Math.max((_c = seriesEntry.pointRadius) !== null && _c !== void 0 ? _c : resolvedGlobalPointRadius, 0);
|
|
112
|
-
const resolvedActivePointRadius = Math.max((_d = seriesEntry.activePointRadius) !== null && _d !== void 0 ? _d : resolvedGlobalActivePointRadius, resolvedPointRadius);
|
|
113
|
-
const points = seriesEntry.points
|
|
114
|
-
.map((point) => (Object.assign(Object.assign({}, point), { xType: parsedSeriesInput.resolvedXAxisType, seriesColor: resolvedColor })))
|
|
115
|
-
.sort((left, right) => {
|
|
116
|
-
if (parsedSeriesInput.resolvedXAxisType === "point") {
|
|
117
|
-
return left.index - right.index;
|
|
118
|
-
}
|
|
119
|
-
const leftValue = left.parsedX instanceof Date
|
|
120
|
-
? left.parsedX.getTime()
|
|
121
|
-
: Number(left.parsedX);
|
|
122
|
-
const rightValue = right.parsedX instanceof Date
|
|
123
|
-
? right.parsedX.getTime()
|
|
124
|
-
: Number(right.parsedX);
|
|
125
|
-
return leftValue - rightValue;
|
|
126
|
-
});
|
|
127
|
-
return {
|
|
128
|
-
key: seriesEntry.key,
|
|
129
|
-
label: seriesEntry.label,
|
|
130
|
-
labelText: seriesEntry.labelText,
|
|
131
|
-
color: resolvedColor,
|
|
132
|
-
gradientStops: resolvedGradientStops,
|
|
133
|
-
lineDasharray: (_e = seriesEntry.lineDasharray) !== null && _e !== void 0 ? _e : lineDasharray,
|
|
134
|
-
lineWidth: Math.max((_f = seriesEntry.lineWidth) !== null && _f !== void 0 ? _f : resolvedGlobalLineWidth, 1),
|
|
135
|
-
lineOpacity: clamp((_g = seriesEntry.lineOpacity) !== null && _g !== void 0 ? _g : resolvedGlobalLineOpacity, 0, 1),
|
|
136
|
-
showArea: (_h = seriesEntry.showArea) !== null && _h !== void 0 ? _h : showArea,
|
|
137
|
-
areaColor: (_k = (_j = seriesEntry.areaColor) !== null && _j !== void 0 ? _j : areaColor) !== null && _k !== void 0 ? _k : resolvedColor,
|
|
138
|
-
areaOpacity: clamp((_l = seriesEntry.areaOpacity) !== null && _l !== void 0 ? _l : resolvedGlobalAreaOpacity, 0, 1),
|
|
139
|
-
showPoints: (_m = seriesEntry.showPoints) !== null && _m !== void 0 ? _m : showPoints,
|
|
140
|
-
pointColor: (_p = (_o = seriesEntry.pointColor) !== null && _o !== void 0 ? _o : pointColor) !== null && _p !== void 0 ? _p : resolvedColor,
|
|
141
|
-
pointRadius: resolvedPointRadius,
|
|
142
|
-
activePointRadius: resolvedActivePointRadius,
|
|
143
|
-
sourceSeries: seriesEntry.sourceSeries,
|
|
144
|
-
points,
|
|
145
|
-
};
|
|
146
|
-
})
|
|
147
|
-
.filter((seriesEntry) => seriesEntry.points.length > 0);
|
|
148
|
-
}, [
|
|
149
|
-
areaColor,
|
|
150
|
-
colorGradient,
|
|
151
|
-
lineDasharray,
|
|
152
|
-
normalizedInputSeries.length,
|
|
153
|
-
parsedSeriesInput.resolvedXAxisType,
|
|
154
|
-
parsedSeriesInput.seriesEntries,
|
|
155
|
-
pointColor,
|
|
156
|
-
resolvedGlobalActivePointRadius,
|
|
157
|
-
resolvedGlobalAreaOpacity,
|
|
158
|
-
resolvedGlobalLineOpacity,
|
|
159
|
-
resolvedGlobalLineWidth,
|
|
160
|
-
resolvedGlobalPointRadius,
|
|
161
|
-
showArea,
|
|
162
|
-
showPoints,
|
|
163
|
-
themeColors,
|
|
164
|
-
themeLineColor,
|
|
165
|
-
]);
|
|
166
|
-
const allPoints = useMemo(() => resolvedSeries.flatMap((seriesEntry) => seriesEntry.points), [resolvedSeries]);
|
|
167
|
-
const resolvedXAxisType = parsedSeriesInput.resolvedXAxisType;
|
|
168
|
-
const resolvedPointBorderColor = pointBorderColor !== null && pointBorderColor !== void 0 ? pointBorderColor : theme.palette.background.paper;
|
|
169
|
-
const timeScale = useMemo(() => {
|
|
170
|
-
if (resolvedXAxisType !== "time")
|
|
171
|
-
return null;
|
|
172
|
-
const timeValues = allPoints
|
|
173
|
-
.map((point) => (point.parsedX instanceof Date ? point.parsedX.getTime() : null))
|
|
174
|
-
.filter((value) => value != null);
|
|
175
|
-
const min = Math.min(...timeValues);
|
|
176
|
-
const max = Math.max(...timeValues);
|
|
177
|
-
const scale = scaleTime()
|
|
178
|
-
.domain([new Date(min), new Date(max === min ? min + 1 : max)])
|
|
179
|
-
.range([0, plotWidth]);
|
|
180
|
-
scale.nice(Math.max(xTickCount, 2));
|
|
181
|
-
return scale;
|
|
182
|
-
}, [allPoints, plotWidth, resolvedXAxisType, xTickCount]);
|
|
183
|
-
const linearScale = useMemo(() => {
|
|
184
|
-
if (resolvedXAxisType !== "linear")
|
|
185
|
-
return null;
|
|
186
|
-
const numericValues = allPoints.map((point) => Number(point.parsedX));
|
|
187
|
-
const min = Math.min(...numericValues);
|
|
188
|
-
const max = Math.max(...numericValues);
|
|
189
|
-
const scale = scaleLinear()
|
|
190
|
-
.domain([min, max === min ? min + 1 : max])
|
|
191
|
-
.range([0, plotWidth]);
|
|
192
|
-
scale.nice(Math.max(xTickCount, 2));
|
|
193
|
-
return scale;
|
|
194
|
-
}, [allPoints, plotWidth, resolvedXAxisType, xTickCount]);
|
|
195
|
-
const pointScale = useMemo(() => {
|
|
196
|
-
if (resolvedXAxisType !== "point")
|
|
197
|
-
return null;
|
|
198
|
-
const domain = Array.from(new Set(allPoints.map((point) => String(point.parsedX))));
|
|
199
|
-
return scalePoint()
|
|
200
|
-
.domain(domain)
|
|
201
|
-
.range([0, plotWidth])
|
|
202
|
-
.padding(0.4);
|
|
203
|
-
}, [allPoints, plotWidth, resolvedXAxisType]);
|
|
204
|
-
const yScale = useMemo(() => {
|
|
205
|
-
const scale = scaleLinear()
|
|
206
|
-
.domain(getValueDomain(allPoints.map((point) => point.y), yMin, yMax))
|
|
207
|
-
.range([plotHeight, 0]);
|
|
208
|
-
if (yMin == null || yMax == null) {
|
|
209
|
-
scale.nice(Math.max(yTickCount, 2));
|
|
210
|
-
}
|
|
211
|
-
return scale;
|
|
212
|
-
}, [allPoints, plotHeight, yMax, yMin, yTickCount]);
|
|
213
|
-
const getPointX = useCallback((point) => {
|
|
214
|
-
var _a, _b, _c;
|
|
215
|
-
if (resolvedXAxisType === "time") {
|
|
216
|
-
return (_a = timeScale === null || timeScale === void 0 ? void 0 : timeScale(point.parsedX)) !== null && _a !== void 0 ? _a : 0;
|
|
217
|
-
}
|
|
218
|
-
if (resolvedXAxisType === "linear") {
|
|
219
|
-
return (_b = linearScale === null || linearScale === void 0 ? void 0 : linearScale(Number(point.parsedX))) !== null && _b !== void 0 ? _b : 0;
|
|
220
|
-
}
|
|
221
|
-
return (_c = pointScale === null || pointScale === void 0 ? void 0 : pointScale(String(point.parsedX))) !== null && _c !== void 0 ? _c : 0;
|
|
222
|
-
}, [linearScale, pointScale, resolvedXAxisType, timeScale]);
|
|
223
|
-
const getPointY = useCallback((point) => yScale(point.y), [yScale]);
|
|
224
|
-
const renderedSeries = useMemo(() => resolvedSeries.map((seriesEntry, seriesIndex) => (Object.assign(Object.assign({}, seriesEntry), { gradientId: `${gradientBaseId}-${seriesIndex}`, linePath: buildLinePath(seriesEntry.points, getPointX, getPointY, curve), areaPath: seriesEntry.showArea
|
|
225
|
-
? buildAreaPath(seriesEntry.points, getPointX, getPointY, plotHeight, curve)
|
|
226
|
-
: null }))), [curve, getPointX, gradientBaseId, plotHeight, resolvedSeries]);
|
|
227
|
-
const renderedSeriesKey = useMemo(() => renderedSeries
|
|
228
|
-
.map((seriesEntry) => {
|
|
229
|
-
var _a, _b;
|
|
230
|
-
return `${String(seriesEntry.key)}:${(_a = seriesEntry.linePath) !== null && _a !== void 0 ? _a : ""}:${(_b = seriesEntry.areaPath) !== null && _b !== void 0 ? _b : ""}`;
|
|
231
|
-
})
|
|
232
|
-
.join("|"), [renderedSeries]);
|
|
233
|
-
useEffect(() => {
|
|
234
|
-
const nextLineLengths = {};
|
|
235
|
-
renderedSeries.forEach((seriesEntry) => {
|
|
236
|
-
var _a;
|
|
237
|
-
nextLineLengths[String(seriesEntry.key)] = measureSvgPath((_a = linePathRefs.current[String(seriesEntry.key)]) !== null && _a !== void 0 ? _a : null);
|
|
238
|
-
});
|
|
239
|
-
setLineLengths((currentLineLengths) => {
|
|
240
|
-
const currentKeys = Object.keys(currentLineLengths);
|
|
241
|
-
const nextKeys = Object.keys(nextLineLengths);
|
|
242
|
-
if (currentKeys.length !== nextKeys.length) {
|
|
243
|
-
return nextLineLengths;
|
|
244
|
-
}
|
|
245
|
-
for (const key of nextKeys) {
|
|
246
|
-
if (currentLineLengths[key] !== nextLineLengths[key]) {
|
|
247
|
-
return nextLineLengths;
|
|
248
|
-
}
|
|
249
|
-
}
|
|
250
|
-
return currentLineLengths;
|
|
251
|
-
});
|
|
252
|
-
}, [renderedSeries, renderedSeriesKey]);
|
|
253
|
-
useEffect(() => {
|
|
254
|
-
var _a;
|
|
255
|
-
if (!animateOnRender || renderedSeries.every((seriesEntry) => !seriesEntry.linePath)) {
|
|
256
|
-
setAnimationProgress(1);
|
|
257
|
-
return;
|
|
258
|
-
}
|
|
259
|
-
const prefersReducedMotion = typeof window !== "undefined" &&
|
|
260
|
-
((_a = window.matchMedia) === null || _a === void 0 ? void 0 : _a.call(window, "(prefers-reduced-motion: reduce)").matches);
|
|
261
|
-
if (prefersReducedMotion) {
|
|
262
|
-
setAnimationProgress(1);
|
|
263
|
-
return;
|
|
264
|
-
}
|
|
265
|
-
let animationFrame = 0;
|
|
266
|
-
let startTime = null;
|
|
267
|
-
const safeDuration = Math.max(animationDuration, 0);
|
|
268
|
-
setAnimationProgress(0);
|
|
269
|
-
const runAnimation = (timestamp) => {
|
|
270
|
-
if (startTime == null)
|
|
271
|
-
startTime = timestamp;
|
|
272
|
-
const elapsed = timestamp - startTime;
|
|
273
|
-
const progress = safeDuration === 0 ? 1 : easeOutCubic(clamp(elapsed / safeDuration, 0, 1));
|
|
274
|
-
setAnimationProgress(progress);
|
|
275
|
-
if (progress < 1) {
|
|
276
|
-
animationFrame = window.requestAnimationFrame(runAnimation);
|
|
277
|
-
}
|
|
278
|
-
};
|
|
279
|
-
animationFrame = window.requestAnimationFrame(runAnimation);
|
|
280
|
-
return () => {
|
|
281
|
-
window.cancelAnimationFrame(animationFrame);
|
|
282
|
-
};
|
|
283
|
-
}, [animateOnRender, animationDuration, renderedSeriesKey]);
|
|
284
|
-
const xTicks = useMemo(() => {
|
|
285
|
-
var _a;
|
|
286
|
-
if (resolvedXAxisType === "time" && timeScale) {
|
|
287
|
-
return timeScale.ticks(Math.max(xTickCount, 2));
|
|
288
|
-
}
|
|
289
|
-
if (resolvedXAxisType === "linear" && linearScale) {
|
|
290
|
-
return linearScale
|
|
291
|
-
.ticks(Math.max(xTickCount, 2))
|
|
292
|
-
.map((tick) => normalizeTickValue(tick));
|
|
293
|
-
}
|
|
294
|
-
const domain = (_a = pointScale === null || pointScale === void 0 ? void 0 : pointScale.domain()) !== null && _a !== void 0 ? _a : [];
|
|
295
|
-
if (domain.length <= Math.max(xTickCount, 2))
|
|
296
|
-
return domain;
|
|
297
|
-
const step = Math.ceil(domain.length / Math.max(xTickCount, 2));
|
|
298
|
-
return domain.filter((_, index) => index % step === 0);
|
|
299
|
-
}, [linearScale, pointScale, resolvedXAxisType, timeScale, xTickCount]);
|
|
300
|
-
const yTicks = useMemo(() => Array.from(new Set(yScale
|
|
301
|
-
.ticks(Math.max(yTickCount, 2))
|
|
302
|
-
.map((tick) => normalizeTickValue(tick)))), [yScale, yTickCount]);
|
|
303
|
-
const formatValue = (datum, sourceSeries) => { var _a; return (_a = valueFormatter === null || valueFormatter === void 0 ? void 0 : valueFormatter(datum.y, datum, sourceSeries)) !== null && _a !== void 0 ? _a : formatDefaultValue(datum.y); };
|
|
304
|
-
const formatXValue = (datum, sourceSeries) => {
|
|
305
|
-
var _a;
|
|
306
|
-
return (_a = xValueFormatter === null || xValueFormatter === void 0 ? void 0 : xValueFormatter(datum.x, datum, sourceSeries)) !== null && _a !== void 0 ? _a : (datum.x instanceof Date ? datum.x.toLocaleDateString() : String(datum.x));
|
|
307
|
-
};
|
|
308
|
-
const formatXTick = (value) => {
|
|
309
|
-
var _a;
|
|
310
|
-
return (_a = xTickFormatter === null || xTickFormatter === void 0 ? void 0 : xTickFormatter(value)) !== null && _a !== void 0 ? _a : (value instanceof Date
|
|
311
|
-
? new Intl.DateTimeFormat(undefined, {
|
|
312
|
-
month: "short",
|
|
313
|
-
day: "numeric",
|
|
314
|
-
}).format(value)
|
|
315
|
-
: String(value));
|
|
316
|
-
};
|
|
317
|
-
const formatYTick = (value) => { var _a; return (_a = yTickFormatter === null || yTickFormatter === void 0 ? void 0 : yTickFormatter(value)) !== null && _a !== void 0 ? _a : formatDefaultValue(value); };
|
|
318
|
-
const findNearestPoint = (clientX, clientY) => {
|
|
319
|
-
if (!chartFrameRef.current)
|
|
320
|
-
return null;
|
|
321
|
-
const chartRect = chartFrameRef.current.getBoundingClientRect();
|
|
322
|
-
const localX = clamp(clientX - chartRect.left - resolvedMargin.left, 0, plotWidth);
|
|
323
|
-
const localY = clamp(clientY - chartRect.top - resolvedMargin.top, 0, plotHeight);
|
|
324
|
-
let nearestPoint = null;
|
|
325
|
-
let nearestDistance = Number.POSITIVE_INFINITY;
|
|
326
|
-
for (const point of allPoints) {
|
|
327
|
-
const pointX = getPointX(point);
|
|
328
|
-
const pointY = getPointY(point);
|
|
329
|
-
const dx = pointX - localX;
|
|
330
|
-
const dy = pointY - localY;
|
|
331
|
-
const distance = dx * dx + dy * dy * 0.18;
|
|
332
|
-
if (distance < nearestDistance) {
|
|
333
|
-
nearestDistance = distance;
|
|
334
|
-
nearestPoint = point;
|
|
335
|
-
}
|
|
336
|
-
}
|
|
337
|
-
return nearestPoint;
|
|
338
|
-
};
|
|
339
|
-
const updateActivePointFromEvent = (event, triggerTooltip) => {
|
|
340
|
-
const nearestPoint = findNearestPoint(event.clientX, event.clientY);
|
|
341
|
-
if (!nearestPoint)
|
|
342
|
-
return;
|
|
343
|
-
setActivePointKey(nearestPoint.key);
|
|
344
|
-
if (!triggerTooltip)
|
|
345
|
-
return;
|
|
346
|
-
setActiveTooltip({
|
|
347
|
-
pointKey: nearestPoint.key,
|
|
348
|
-
x: resolvedMargin.left + getPointX(nearestPoint),
|
|
349
|
-
y: resolvedMargin.top + getPointY(nearestPoint),
|
|
350
|
-
});
|
|
351
|
-
};
|
|
352
|
-
const activePoint = (showTooltips || showPoints || onPointClick) && activePointKey != null
|
|
353
|
-
? allPoints.find((point) => point.key === activePointKey)
|
|
354
|
-
: null;
|
|
355
|
-
const highlightedSeriesKey = (_c = activeSeriesKey !== null && activeSeriesKey !== void 0 ? activeSeriesKey : activePoint === null || activePoint === void 0 ? void 0 : activePoint.seriesKey) !== null && _c !== void 0 ? _c : null;
|
|
356
|
-
const activeSeries = activePoint
|
|
357
|
-
? renderedSeries.find((seriesEntry) => seriesEntry.key === activePoint.seriesKey)
|
|
358
|
-
: null;
|
|
359
|
-
const tooltipStyle = useMemo(() => {
|
|
360
|
-
if (!activeTooltip ||
|
|
361
|
-
!containerRef.current ||
|
|
362
|
-
!chartFrameRef.current ||
|
|
363
|
-
!activePoint) {
|
|
364
|
-
return null;
|
|
365
|
-
}
|
|
366
|
-
const containerRect = containerRef.current.getBoundingClientRect();
|
|
367
|
-
const chartRect = chartFrameRef.current.getBoundingClientRect();
|
|
368
|
-
const chartLeft = chartRect.left - containerRect.left;
|
|
369
|
-
const chartTop = chartRect.top - containerRect.top;
|
|
370
|
-
const minLeft = chartLeft + 8;
|
|
371
|
-
const maxLeft = chartLeft + chartRect.width - tooltipSize.width - 8;
|
|
372
|
-
const minTop = chartTop + 8;
|
|
373
|
-
const maxTop = chartTop + chartRect.height - tooltipSize.height - 8;
|
|
374
|
-
return {
|
|
375
|
-
left: clamp(activeTooltip.x + 14, minLeft, Math.max(minLeft, maxLeft)),
|
|
376
|
-
top: clamp(activeTooltip.y - tooltipSize.height / 2, minTop, Math.max(minTop, maxTop)),
|
|
377
|
-
};
|
|
378
|
-
}, [activePoint, activeTooltip, tooltipSize.height, tooltipSize.width]);
|
|
379
|
-
useEffect(() => {
|
|
380
|
-
if (!activePoint || !tooltipRef.current) {
|
|
381
|
-
setTooltipSize({ width: 0, height: 0 });
|
|
382
|
-
return;
|
|
383
|
-
}
|
|
384
|
-
setTooltipSize({
|
|
385
|
-
width: tooltipRef.current.offsetWidth,
|
|
386
|
-
height: tooltipRef.current.offsetHeight,
|
|
387
|
-
});
|
|
388
|
-
}, [activePoint]);
|
|
389
|
-
const description = allPoints
|
|
390
|
-
.map((point) => `${point.seriesLabelText}, ${formatXValue(point, activeSeries === null || activeSeries === void 0 ? void 0 : activeSeries.sourceSeries)}: ${formatDefaultValue(point.y)}`)
|
|
391
|
-
.join(", ");
|
|
392
|
-
const shouldAnimateStroke = animateOnRender && animationProgress < 1;
|
|
393
|
-
const shouldShowDataLabels = showLabels && allPoints.length <= 24;
|
|
394
|
-
return (_jsxs(StyledContainer, Object.assign({ ref: containerRef, className: className }, props, { children: [allPoints.length === 0 ? (_jsx(StyledEmptyState, { "$width": safeWidth, "$height": safeHeight, children: emptyLabel })) : (_jsx(StyledChartScroller, { children: _jsx(StyledChartFrame, { ref: chartFrameRef, children: _jsxs(StyledSvg, { width: safeWidth, height: safeHeight, viewBox: `0 0 ${safeWidth} ${safeHeight}`, role: "img", "aria-label": ariaLabel, "aria-describedby": descriptionId, children: [_jsx("desc", { id: descriptionId, children: description }), _jsx("defs", { children: renderedSeries
|
|
395
|
-
.filter((seriesEntry) => { var _a; return (_a = seriesEntry.gradientStops) === null || _a === void 0 ? void 0 : _a.length; })
|
|
396
|
-
.map((seriesEntry) => {
|
|
397
|
-
var _a;
|
|
398
|
-
return (_jsx("linearGradient", { id: seriesEntry.gradientId, x1: "0%", y1: "0%", x2: "100%", y2: "0%", children: ((_a = seriesEntry.gradientStops) !== null && _a !== void 0 ? _a : []).map((stop, index) => {
|
|
399
|
-
var _a, _b;
|
|
400
|
-
return (_jsx("stop", { offset: `${((_a = seriesEntry.gradientStops) !== null && _a !== void 0 ? _a : []).length === 1
|
|
401
|
-
? 100
|
|
402
|
-
: (index /
|
|
403
|
-
(((_b = seriesEntry.gradientStops) !== null && _b !== void 0 ? _b : []).length - 1)) *
|
|
404
|
-
100}%`, stopColor: stop }, `${stop}-${index}`));
|
|
405
|
-
}) }, seriesEntry.gradientId));
|
|
406
|
-
}) }), showGridLines &&
|
|
407
|
-
yTicks.map((tick) => (_jsx(StyledGridLine, { x1: resolvedMargin.left, x2: resolvedMargin.left + plotWidth, y1: resolvedMargin.top + yScale(tick), y2: resolvedMargin.top + yScale(tick) }, `grid-y-${tick}`))), showAxisLines && (_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 + plotHeight, y2: resolvedMargin.top + plotHeight })] })), showYAxisLabels &&
|
|
408
|
-
yTicks.map((tick) => (_jsx(StyledAxisText, { x: resolvedMargin.left - 10, y: resolvedMargin.top + yScale(tick), textAnchor: "end", dominantBaseline: "middle", children: formatYTick(tick) }, `tick-y-${tick}`))), showXAxisLabels &&
|
|
409
|
-
xTicks.map((tick, index) => {
|
|
410
|
-
var _a, _b, _c;
|
|
411
|
-
const x = resolvedXAxisType === "time"
|
|
412
|
-
? (_a = timeScale === null || timeScale === void 0 ? void 0 : timeScale(tick)) !== null && _a !== void 0 ? _a : 0
|
|
413
|
-
: resolvedXAxisType === "linear"
|
|
414
|
-
? (_b = linearScale === null || linearScale === void 0 ? void 0 : linearScale(tick)) !== null && _b !== void 0 ? _b : 0
|
|
415
|
-
: (_c = pointScale === null || pointScale === void 0 ? void 0 : pointScale(String(tick))) !== null && _c !== void 0 ? _c : 0;
|
|
416
|
-
return (_jsx(StyledAxisText, { x: resolvedMargin.left + x, y: resolvedMargin.top + plotHeight + 20, textAnchor: "middle", children: formatXTick(tick) }, `tick-x-${index}`));
|
|
417
|
-
}), _jsxs("g", { transform: `translate(${resolvedMargin.left}, ${resolvedMargin.top})`, children: [_jsx(StyledHoverTarget, { x: 0, y: 0, width: plotWidth, height: plotHeight, onMouseEnter: (event) => {
|
|
418
|
-
if (!showTooltips && !showPoints && !onPointClick)
|
|
419
|
-
return;
|
|
420
|
-
updateActivePointFromEvent(event, showTooltips);
|
|
421
|
-
}, onMouseMove: (event) => {
|
|
422
|
-
if (!showTooltips && !showPoints && !onPointClick)
|
|
423
|
-
return;
|
|
424
|
-
updateActivePointFromEvent(event, showTooltips);
|
|
425
|
-
}, onMouseLeave: () => {
|
|
426
|
-
setActivePointKey(null);
|
|
427
|
-
setActiveTooltip(null);
|
|
428
|
-
}, onClick: (event) => {
|
|
429
|
-
if (!onPointClick)
|
|
430
|
-
return;
|
|
431
|
-
const nearestPoint = findNearestPoint(event.clientX, event.clientY);
|
|
432
|
-
const nearestSeries = nearestPoint
|
|
433
|
-
? renderedSeries.find((seriesEntry) => seriesEntry.key === nearestPoint.seriesKey)
|
|
434
|
-
: null;
|
|
435
|
-
if (nearestPoint) {
|
|
436
|
-
onPointClick(event, nearestPoint, nearestSeries === null || nearestSeries === void 0 ? void 0 : nearestSeries.sourceSeries);
|
|
437
|
-
}
|
|
438
|
-
} }), renderedSeries.map((seriesEntry) => {
|
|
439
|
-
var _a, _b;
|
|
440
|
-
const gradientReference = ((_a = seriesEntry.gradientStops) === null || _a === void 0 ? void 0 : _a.length)
|
|
441
|
-
? `url(#${seriesEntry.gradientId})`
|
|
442
|
-
: seriesEntry.color;
|
|
443
|
-
const lineLength = (_b = lineLengths[String(seriesEntry.key)]) !== null && _b !== void 0 ? _b : 0;
|
|
444
|
-
const isSeriesActive = highlightedSeriesKey === seriesEntry.key;
|
|
445
|
-
const isSeriesDimmed = highlightedSeriesKey != null && !isSeriesActive;
|
|
446
|
-
return (_jsxs("g", { children: [seriesEntry.showArea && seriesEntry.areaPath && (_jsx(StyledArea, { d: seriesEntry.areaPath, fill: gradientReference !== null && gradientReference !== void 0 ? gradientReference : seriesEntry.areaColor, fillOpacity: seriesEntry.areaOpacity *
|
|
447
|
-
animationProgress *
|
|
448
|
-
(isSeriesDimmed ? 0.28 : isSeriesActive ? 1.08 : 1), style: {
|
|
449
|
-
filter: isSeriesActive
|
|
450
|
-
? "brightness(1.08) saturate(1.06)"
|
|
451
|
-
: undefined,
|
|
452
|
-
opacity: isSeriesDimmed ? 0.7 : 1,
|
|
453
|
-
} })), seriesEntry.linePath && (_jsx(StyledLine, { "$active": isSeriesActive, "$dimmed": isSeriesDimmed, ref: (node) => {
|
|
454
|
-
linePathRefs.current[String(seriesEntry.key)] = node;
|
|
455
|
-
}, d: seriesEntry.linePath, stroke: gradientReference, strokeWidth: isSeriesActive
|
|
456
|
-
? seriesEntry.lineWidth + 0.8
|
|
457
|
-
: seriesEntry.lineWidth, strokeOpacity: seriesEntry.lineOpacity, strokeDasharray: shouldAnimateStroke && lineLength > 0
|
|
458
|
-
? `${lineLength} ${lineLength}`
|
|
459
|
-
: seriesEntry.lineDasharray, strokeDashoffset: shouldAnimateStroke && lineLength > 0
|
|
460
|
-
? lineLength * (1 - animationProgress)
|
|
461
|
-
: 0 }))] }, seriesEntry.key));
|
|
462
|
-
}), (showPoints || activePoint != null) &&
|
|
463
|
-
renderedSeries.map((seriesEntry) => seriesEntry.points.map((point) => {
|
|
464
|
-
var _a;
|
|
465
|
-
const isActive = activePointKey === point.key;
|
|
466
|
-
const shouldRender = seriesEntry.showPoints || isActive;
|
|
467
|
-
if (!shouldRender)
|
|
468
|
-
return null;
|
|
469
|
-
return (_jsx(StyledPoint, { "$active": isActive, cx: getPointX(point), cy: getPointY(point), r: isActive
|
|
470
|
-
? seriesEntry.activePointRadius
|
|
471
|
-
: seriesEntry.pointRadius, fill: (_a = point.color) !== null && _a !== void 0 ? _a : seriesEntry.pointColor, fillOpacity: resolvedPointOpacity, stroke: resolvedPointBorderColor, strokeWidth: pointBorderWidth, tabIndex: 0, "aria-label": `${point.seriesLabelText}, ${formatXValue(point, seriesEntry.sourceSeries)}: ${formatDefaultValue(point.y)}`, onFocus: () => setActivePointKey(point.key), onBlur: () => setActivePointKey(null), onMouseEnter: () => setActivePointKey(point.key), onMouseLeave: () => {
|
|
472
|
-
if (!showTooltips)
|
|
473
|
-
setActivePointKey(null);
|
|
474
|
-
}, onClick: (event) => onPointClick === null || onPointClick === void 0 ? void 0 : onPointClick(event, point, seriesEntry.sourceSeries), onKeyDown: (event) => {
|
|
475
|
-
if (event.key !== "Enter" && event.key !== " ")
|
|
476
|
-
return;
|
|
477
|
-
event.preventDefault();
|
|
478
|
-
onPointClick === null || onPointClick === void 0 ? void 0 : onPointClick(event, point, seriesEntry.sourceSeries);
|
|
479
|
-
} }, point.key));
|
|
480
|
-
})), shouldShowDataLabels &&
|
|
481
|
-
renderedSeries.map((seriesEntry) => seriesEntry.points.map((point) => {
|
|
482
|
-
var _a;
|
|
483
|
-
return (_jsx(StyledValueLabel, { x: getPointX(point), y: getPointY(point) - 10, textAnchor: "middle", children: (_a = labelFormatter === null || labelFormatter === void 0 ? void 0 : labelFormatter(point, point.index, seriesEntry.sourceSeries)) !== null && _a !== void 0 ? _a : formatValue(point, seriesEntry.sourceSeries) }, `label-${point.key}`));
|
|
484
|
-
}))] })] }) }) })), activeTooltip && activePoint && activeSeries && tooltipStyle && (_jsx(StyledTooltip, { ref: tooltipRef, style: tooltipStyle, children: tooltipFormatter ? (tooltipFormatter(activePoint, activePoint.index, activeSeries.sourceSeries)) : (_jsxs(_Fragment, { children: [_jsxs(StyledTooltipHeader, { children: [_jsx(StyledTooltipSwatch, { "$color": (_d = activePoint.color) !== null && _d !== void 0 ? _d : activeSeries.pointColor }), _jsx(StyledTooltipLabel, { children: formatXValue(activePoint, activeSeries.sourceSeries) })] }), _jsxs(StyledTooltipMeta, { children: [_jsx("span", { children: activePoint.seriesLabel }), _jsx("span", { children: formatValue(activePoint, activeSeries.sourceSeries) })] })] })) })), showLegend && (_jsx(StyledLegend, { children: renderedSeries.map((seriesEntry) => {
|
|
485
|
-
const latestPoint = seriesEntry.points[seriesEntry.points.length - 1];
|
|
486
|
-
if (!latestPoint)
|
|
487
|
-
return null;
|
|
488
|
-
return (_jsxs(StyledLegendItem, { "$active": highlightedSeriesKey === seriesEntry.key, tabIndex: 0, onMouseEnter: () => setActiveSeriesKey(seriesEntry.key), onMouseLeave: () => setActiveSeriesKey(null), onFocus: () => setActiveSeriesKey(seriesEntry.key), onBlur: () => setActiveSeriesKey(null), children: [_jsx(StyledLegendLine, { "$color": seriesEntry.color }), _jsx(StyledLegendLabel, { children: seriesEntry.label }), _jsx(StyledLegendValue, { children: formatValue(latestPoint, seriesEntry.sourceSeries) })] }, `legend-${seriesEntry.key}`));
|
|
489
|
-
}) }))] })));
|
|
490
|
-
};
|
|
491
|
-
export default LineChart;
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { ReactNode } from "react";
|
|
2
|
-
import { clamp, easeOutCubic, formatDefaultValue, getGradientColor, getGradientStops, mixColors } from "../ChartUtils";
|
|
3
|
-
import { LineChartCurve, LineChartDatum, LineChartMargin, LineChartSeries, LineChartXAxisType, ResolvedLinePoint } from "./LineChart.types";
|
|
4
|
-
export { clamp, easeOutCubic, formatDefaultValue, getGradientColor, getGradientStops, mixColors };
|
|
5
|
-
export declare const getPointKey: (datum: LineChartDatum<unknown>, index: number) => string | number;
|
|
6
|
-
export declare const getSeriesKey: (series: Pick<LineChartSeries<unknown>, "id" | "label">, index: number) => string | number;
|
|
7
|
-
export declare const useThemeColor: (lineColor?: string) => string;
|
|
8
|
-
export declare const useThemeColors: (colors?: string[]) => string[];
|
|
9
|
-
export declare const getSeriesLabelText: (label: ReactNode, fallback: string) => string;
|
|
10
|
-
export declare const parseLineChartXValue: (value: Date | number | string) => Date | number | string | null;
|
|
11
|
-
export declare const resolveXAxisType: <TData>(points: ResolvedLinePoint<TData>[], xAxisType: LineChartXAxisType) => "time" | "linear" | "point";
|
|
12
|
-
export declare const getDefaultMargin: (showXAxisLabels: boolean, showYAxisLabels: boolean, showLabels: boolean) => LineChartMargin;
|
|
13
|
-
export declare const mergeChartMargin: (margin: Partial<LineChartMargin> | undefined, showXAxisLabels: boolean, showYAxisLabels: boolean, showLabels: boolean) => {
|
|
14
|
-
top: number;
|
|
15
|
-
right: number;
|
|
16
|
-
bottom: number;
|
|
17
|
-
left: number;
|
|
18
|
-
};
|
|
19
|
-
export declare const getValueDomain: (values: number[], minValue?: number, maxValue?: number) => [number, number];
|
|
20
|
-
export declare const getCurveFactory: (curve: LineChartCurve) => import("d3-shape").CurveFactory;
|
|
21
|
-
export declare const buildLinePath: <TData>(points: ResolvedLinePoint<TData>[], getX: (point: ResolvedLinePoint<TData>) => number, getY: (point: ResolvedLinePoint<TData>) => number, curve: LineChartCurve) => string | null;
|
|
22
|
-
export declare const buildAreaPath: <TData>(points: ResolvedLinePoint<TData>[], getX: (point: ResolvedLinePoint<TData>) => number, getY: (point: ResolvedLinePoint<TData>) => number, y0: number, curve: LineChartCurve) => string | null;
|
|
23
|
-
export declare const measureSvgPath: (path: SVGPathElement | null) => number;
|
|
24
|
-
export declare const normalizeTickValue: (value: number) => number;
|
|
@@ -1,132 +0,0 @@
|
|
|
1
|
-
import { area, curveLinear, curveMonotoneX, curveNatural, curveStep, line, } from "d3-shape";
|
|
2
|
-
import { useMemo } from "react";
|
|
3
|
-
import { useTheme } from "styled-components";
|
|
4
|
-
import { clamp, easeOutCubic, formatDefaultValue, getGradientColor, getGradientStops, mixColors, } from "../ChartUtils";
|
|
5
|
-
export { clamp, easeOutCubic, formatDefaultValue, getGradientColor, getGradientStops, mixColors };
|
|
6
|
-
export const getPointKey = (datum, index) => { var _a; return (_a = datum.id) !== null && _a !== void 0 ? _a : `${String(datum.x)}-${index}`; };
|
|
7
|
-
export const getSeriesKey = (series, index) => {
|
|
8
|
-
var _a;
|
|
9
|
-
return (_a = series.id) !== null && _a !== void 0 ? _a : (typeof series.label === "string" || typeof series.label === "number"
|
|
10
|
-
? `${series.label}-${index}`
|
|
11
|
-
: `series-${index}`);
|
|
12
|
-
};
|
|
13
|
-
export const useThemeColor = (lineColor) => {
|
|
14
|
-
const theme = useTheme();
|
|
15
|
-
return useMemo(() => lineColor !== null && lineColor !== void 0 ? lineColor : theme.palette.primary.main, [lineColor, theme.palette.primary.main]);
|
|
16
|
-
};
|
|
17
|
-
export const useThemeColors = (colors) => {
|
|
18
|
-
const theme = useTheme();
|
|
19
|
-
return useMemo(() => (colors === null || colors === void 0 ? void 0 : colors.length)
|
|
20
|
-
? colors
|
|
21
|
-
: [
|
|
22
|
-
theme.palette.primary.main,
|
|
23
|
-
theme.alert.info.color,
|
|
24
|
-
theme.alert.success.color,
|
|
25
|
-
theme.alert.warning.color,
|
|
26
|
-
theme.alert.error.color,
|
|
27
|
-
theme.palette.fourth.main,
|
|
28
|
-
theme.button.text.secondary,
|
|
29
|
-
], [colors, theme]);
|
|
30
|
-
};
|
|
31
|
-
export const getSeriesLabelText = (label, fallback) => {
|
|
32
|
-
if (typeof label === "string" || typeof label === "number") {
|
|
33
|
-
return String(label);
|
|
34
|
-
}
|
|
35
|
-
return fallback;
|
|
36
|
-
};
|
|
37
|
-
export const parseLineChartXValue = (value) => {
|
|
38
|
-
if (value instanceof Date) {
|
|
39
|
-
return Number.isFinite(value.getTime()) ? value : null;
|
|
40
|
-
}
|
|
41
|
-
if (typeof value === "number") {
|
|
42
|
-
return Number.isFinite(value) ? value : null;
|
|
43
|
-
}
|
|
44
|
-
if (typeof value !== "string")
|
|
45
|
-
return null;
|
|
46
|
-
const trimmed = value.trim();
|
|
47
|
-
if (!trimmed)
|
|
48
|
-
return null;
|
|
49
|
-
const numeric = Number(trimmed);
|
|
50
|
-
if (!Number.isNaN(numeric) && trimmed === String(numeric)) {
|
|
51
|
-
return numeric;
|
|
52
|
-
}
|
|
53
|
-
const timestamp = Date.parse(trimmed);
|
|
54
|
-
if (!Number.isNaN(timestamp)) {
|
|
55
|
-
return new Date(timestamp);
|
|
56
|
-
}
|
|
57
|
-
return trimmed;
|
|
58
|
-
};
|
|
59
|
-
export const resolveXAxisType = (points, xAxisType) => {
|
|
60
|
-
var _a;
|
|
61
|
-
if (xAxisType !== "auto")
|
|
62
|
-
return xAxisType;
|
|
63
|
-
const firstValue = (_a = points[0]) === null || _a === void 0 ? void 0 : _a.parsedX;
|
|
64
|
-
if (firstValue instanceof Date)
|
|
65
|
-
return "time";
|
|
66
|
-
if (typeof firstValue === "number")
|
|
67
|
-
return "linear";
|
|
68
|
-
return "point";
|
|
69
|
-
};
|
|
70
|
-
export const getDefaultMargin = (showXAxisLabels, showYAxisLabels, showLabels) => ({
|
|
71
|
-
top: showLabels ? 24 : 16,
|
|
72
|
-
right: showLabels ? 52 : 20,
|
|
73
|
-
bottom: showXAxisLabels ? 42 : 18,
|
|
74
|
-
left: showYAxisLabels ? 56 : 18,
|
|
75
|
-
});
|
|
76
|
-
export const mergeChartMargin = (margin, showXAxisLabels, showYAxisLabels, showLabels) => {
|
|
77
|
-
var _a, _b, _c, _d;
|
|
78
|
-
const defaults = getDefaultMargin(showXAxisLabels, showYAxisLabels, showLabels);
|
|
79
|
-
return {
|
|
80
|
-
top: (_a = margin === null || margin === void 0 ? void 0 : margin.top) !== null && _a !== void 0 ? _a : defaults.top,
|
|
81
|
-
right: (_b = margin === null || margin === void 0 ? void 0 : margin.right) !== null && _b !== void 0 ? _b : defaults.right,
|
|
82
|
-
bottom: (_c = margin === null || margin === void 0 ? void 0 : margin.bottom) !== null && _c !== void 0 ? _c : defaults.bottom,
|
|
83
|
-
left: (_d = margin === null || margin === void 0 ? void 0 : margin.left) !== null && _d !== void 0 ? _d : defaults.left,
|
|
84
|
-
};
|
|
85
|
-
};
|
|
86
|
-
export const getValueDomain = (values, minValue, maxValue) => {
|
|
87
|
-
const actualMin = values.length ? Math.min(...values) : 0;
|
|
88
|
-
const actualMax = values.length ? Math.max(...values) : 0;
|
|
89
|
-
const resolvedMin = minValue !== null && minValue !== void 0 ? minValue : actualMin;
|
|
90
|
-
const resolvedMax = maxValue !== null && maxValue !== void 0 ? maxValue : actualMax;
|
|
91
|
-
if (resolvedMin === resolvedMax) {
|
|
92
|
-
if (resolvedMin === 0)
|
|
93
|
-
return [0, 1];
|
|
94
|
-
return [resolvedMin - 1, resolvedMax + 1];
|
|
95
|
-
}
|
|
96
|
-
return [resolvedMin, resolvedMax];
|
|
97
|
-
};
|
|
98
|
-
export const getCurveFactory = (curve) => {
|
|
99
|
-
switch (curve) {
|
|
100
|
-
case "linear":
|
|
101
|
-
return curveLinear;
|
|
102
|
-
case "step":
|
|
103
|
-
return curveStep;
|
|
104
|
-
case "natural":
|
|
105
|
-
return curveNatural;
|
|
106
|
-
case "monotone":
|
|
107
|
-
default:
|
|
108
|
-
return curveMonotoneX;
|
|
109
|
-
}
|
|
110
|
-
};
|
|
111
|
-
export const buildLinePath = (points, getX, getY, curve) => line()
|
|
112
|
-
.defined((point) => Number.isFinite(point.y))
|
|
113
|
-
.x(getX)
|
|
114
|
-
.y(getY)
|
|
115
|
-
.curve(getCurveFactory(curve))(points);
|
|
116
|
-
export const buildAreaPath = (points, getX, getY, y0, curve) => area()
|
|
117
|
-
.defined((point) => Number.isFinite(point.y))
|
|
118
|
-
.x(getX)
|
|
119
|
-
.y0(y0)
|
|
120
|
-
.y1(getY)
|
|
121
|
-
.curve(getCurveFactory(curve))(points);
|
|
122
|
-
export const measureSvgPath = (path) => {
|
|
123
|
-
if (!path)
|
|
124
|
-
return 0;
|
|
125
|
-
try {
|
|
126
|
-
return path.getTotalLength();
|
|
127
|
-
}
|
|
128
|
-
catch (_a) {
|
|
129
|
-
return 0;
|
|
130
|
-
}
|
|
131
|
-
};
|
|
132
|
-
export const normalizeTickValue = (value) => Math.abs(value) < 1e-9 ? 0 : value;
|