@monolith-forensics/monolith-ui 1.8.1-dev.4 → 1.9.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/Button/Button.js +58 -9
- package/dist/Calendar/Calendar.d.ts +2 -7
- package/dist/Calendar/Calendar.js +49 -226
- package/dist/Calendar/CalendarStyles.d.ts +2 -6
- package/dist/Calendar/CalendarStyles.js +33 -153
- package/dist/Calendar/calendarHelpers.d.ts +2 -6
- package/dist/Calendar/calendarHelpers.js +5 -13
- package/dist/CheckBox/CheckBox.js +19 -36
- package/dist/DateInput/DateInput.js +143 -198
- package/dist/DropDownMenu/DropDownMenu.js +15 -25
- package/dist/DropDownMenu/components/MenuComponent.js +2 -8
- package/dist/DropDownMenu/components/MenuItem.d.ts +0 -2
- package/dist/DropDownMenu/components/MenuItem.js +21 -25
- package/dist/DropDownMenu/components/MenuItemList.d.ts +0 -3
- package/dist/DropDownMenu/components/MenuItemList.js +86 -192
- package/dist/DropDownMenu/components/StyledContent.js +2 -1
- package/dist/DropDownMenu/components/StyledFloatContainer.js +1 -1
- package/dist/DropDownMenu/types.d.ts +0 -3
- package/dist/FieldLabel/FieldLabel.js +12 -4
- package/dist/FileInputField/FileInputField.js +23 -4
- package/dist/FileViewer/viewers/ImageViewer.js +18 -75
- package/dist/FormSection/FormSection.js +25 -5
- package/dist/IconButton/IconButton.js +16 -2
- package/dist/Input/Input.js +56 -7
- package/dist/MonolithUIProvider/MonolithUIProvider.d.ts +0 -1
- package/dist/Pill/Pill.js +79 -8
- package/dist/Popover/Popover.context.d.ts +1 -2
- package/dist/Popover/Popover.js +2 -5
- package/dist/Popover/Popover.styles.d.ts +6 -1
- package/dist/Popover/Popover.styles.js +28 -11
- package/dist/Popover/Popover.transitions.d.ts +2 -4
- package/dist/Popover/Popover.transitions.js +49 -23
- package/dist/Popover/PopoverDropdown.js +8 -6
- package/dist/Popover/PopoverTarget.js +3 -6
- package/dist/QueryFilter/DefaultOperators.d.ts +76 -0
- package/dist/QueryFilter/DefaultOperators.js +21 -0
- package/dist/QueryFilter/QueryFilter.d.ts +1 -1
- package/dist/QueryFilter/QueryFilter.js +303 -3
- package/dist/QueryFilter/index.d.ts +2 -3
- package/dist/QueryFilter/index.js +2 -3
- package/dist/QueryFilter/{QueryFilter.types.d.ts → types.d.ts} +2 -11
- package/dist/QueryFilter/useQueryFilter.d.ts +1 -1
- package/dist/QueryFilter/useQueryFilter.js +19 -23
- package/dist/RichTextEditor/Extensions/getTiptapExtensions.js +15 -5
- package/dist/RichTextEditor/Plugins/UploadImagesPlugin.d.ts +0 -15
- package/dist/RichTextEditor/Plugins/UploadImagesPlugin.js +51 -115
- package/dist/RichTextEditor/Plugins/index.d.ts +0 -1
- package/dist/RichTextEditor/Plugins/index.js +0 -1
- package/dist/RichTextEditor/RichTextEditor.d.ts +2 -3
- package/dist/RichTextEditor/RichTextEditor.js +35 -309
- package/dist/RichTextEditor/Toolbar/Toolbar.js +2 -14
- package/dist/SegmentedControl/SegmentedControl.utils.d.ts +2 -2
- package/dist/SegmentedControl/SegmentedControl.utils.js +30 -3
- package/dist/SelectBox/SelectBox.js +5 -5
- package/dist/SelectBox/select-box.styled-components.d.ts +1 -4
- package/dist/SelectBox/select-box.styled-components.js +48 -11
- package/dist/SelectBox/types.d.ts +0 -1
- package/dist/Switch/Switch.d.ts +2 -2
- package/dist/Switch/Switch.js +83 -18
- package/dist/Table/ColumnResizer.d.ts +9 -6
- package/dist/Table/ColumnResizer.js +10 -30
- package/dist/Table/StateStorage.d.ts +0 -4
- package/dist/Table/StateStorage.js +0 -13
- package/dist/Table/Table.js +12 -160
- package/dist/Table/TableComponents.d.ts +0 -10
- package/dist/Table/TableComponents.js +10 -71
- package/dist/Table/TableDefaults.d.ts +0 -7
- package/dist/Table/TableDefaults.js +0 -7
- package/dist/Table/TableHeader.js +16 -31
- package/dist/Table/TableMenu/TableMenu.js +1 -1
- package/dist/Table/TableProvider.js +75 -354
- package/dist/Table/TableRow.js +16 -28
- package/dist/Table/Utils/index.d.ts +1 -0
- package/dist/Table/Utils/index.js +1 -0
- package/dist/Table/Utils/resizeHandler.d.ts +3 -0
- package/dist/Table/Utils/resizeHandler.js +84 -0
- package/dist/Table/types.d.ts +19 -70
- package/dist/Tabs/Tab.js +0 -8
- package/dist/TagBox/TagBox.d.ts +1 -1
- package/dist/TagBox/TagBox.js +208 -50
- package/dist/TagBox/types.d.ts +13 -1
- package/dist/TextArea/TextArea.js +23 -9
- package/dist/TextInput/TextInput.js +6 -12
- package/dist/Utilities/parseTimestamp.js +6 -11
- package/dist/core/ArrowButton.d.ts +0 -2
- package/dist/core/ArrowButton.js +3 -7
- package/dist/core/ClearButton.d.ts +0 -2
- package/dist/core/ClearButton.js +3 -7
- package/dist/core/controlSizes.d.ts +0 -26
- package/dist/core/controlSizes.js +0 -156
- package/dist/index.d.ts +0 -3
- package/dist/index.js +0 -2
- package/dist/theme/variants.js +0 -2
- package/package.json +18 -26
- package/dist/Charts/BarChart/BarChart.d.ts +0 -5
- package/dist/Charts/BarChart/BarChart.js +0 -549
- package/dist/Charts/BarChart/BarChart.lib.d.ts +0 -31
- package/dist/Charts/BarChart/BarChart.lib.js +0 -136
- package/dist/Charts/BarChart/BarChart.styled.d.ts +0 -51
- package/dist/Charts/BarChart/BarChart.styled.js +0 -115
- package/dist/Charts/BarChart/BarChart.types.d.ts +0 -171
- package/dist/Charts/BarChart/index.d.ts +0 -3
- package/dist/Charts/BarChart/index.js +0 -2
- package/dist/Charts/ChartPrimitives/ChartExportControl.d.ts +0 -11
- package/dist/Charts/ChartPrimitives/ChartExportControl.js +0 -29
- package/dist/Charts/ChartPrimitives/chartActions.styled.d.ts +0 -1
- package/dist/Charts/ChartPrimitives/chartActions.styled.js +0 -8
- package/dist/Charts/ChartPrimitives/chartLegend.styled.d.ts +0 -12
- package/dist/Charts/ChartPrimitives/chartLegend.styled.js +0 -52
- package/dist/Charts/ChartPrimitives/chartTooltip.styled.d.ts +0 -19
- package/dist/Charts/ChartPrimitives/chartTooltip.styled.js +0 -61
- package/dist/Charts/ChartPrimitives/index.d.ts +0 -4
- package/dist/Charts/ChartPrimitives/index.js +0 -4
- package/dist/Charts/ChartUtils/chartColors.d.ts +0 -8
- package/dist/Charts/ChartUtils/chartColors.js +0 -65
- package/dist/Charts/ChartUtils/chartExport.d.ts +0 -47
- package/dist/Charts/ChartUtils/chartExport.js +0 -311
- package/dist/Charts/ChartUtils/chartMath.d.ts +0 -3
- package/dist/Charts/ChartUtils/chartMath.js +0 -3
- package/dist/Charts/ChartUtils/index.d.ts +0 -3
- package/dist/Charts/ChartUtils/index.js +0 -3
- package/dist/Charts/HeatMap/HeatMap.d.ts +0 -5
- package/dist/Charts/HeatMap/HeatMap.js +0 -212
- package/dist/Charts/HeatMap/HeatMap.lib.d.ts +0 -30
- package/dist/Charts/HeatMap/HeatMap.lib.js +0 -115
- package/dist/Charts/HeatMap/HeatMap.styled.d.ts +0 -37
- package/dist/Charts/HeatMap/HeatMap.styled.js +0 -91
- package/dist/Charts/HeatMap/HeatMap.types.d.ts +0 -80
- package/dist/Charts/HeatMap/HeatMap.types.js +0 -1
- package/dist/Charts/HeatMap/index.d.ts +0 -3
- package/dist/Charts/HeatMap/index.js +0 -2
- package/dist/Charts/LineChart/LineChart.d.ts +0 -5
- package/dist/Charts/LineChart/LineChart.js +0 -529
- package/dist/Charts/LineChart/LineChart.lib.d.ts +0 -24
- package/dist/Charts/LineChart/LineChart.lib.js +0 -132
- package/dist/Charts/LineChart/LineChart.styled.d.ts +0 -59
- package/dist/Charts/LineChart/LineChart.styled.js +0 -147
- package/dist/Charts/LineChart/LineChart.types.d.ts +0 -193
- package/dist/Charts/LineChart/LineChart.types.js +0 -1
- package/dist/Charts/LineChart/index.d.ts +0 -3
- package/dist/Charts/LineChart/index.js +0 -2
- package/dist/Charts/PieChart/PieChart.d.ts +0 -4
- package/dist/Charts/PieChart/PieChart.js +0 -199
- package/dist/Charts/PieChart/PieChart.lib.d.ts +0 -5
- package/dist/Charts/PieChart/PieChart.lib.js +0 -19
- package/dist/Charts/PieChart/PieChart.styled.d.ts +0 -51
- package/dist/Charts/PieChart/PieChart.styled.js +0 -163
- package/dist/Charts/PieChart/PieChart.types.d.ts +0 -100
- package/dist/Charts/PieChart/PieChart.types.js +0 -1
- package/dist/Charts/PieChart/index.d.ts +0 -2
- package/dist/Charts/PieChart/index.js +0 -1
- package/dist/Charts/index.d.ts +0 -5
- package/dist/Charts/index.js +0 -4
- package/dist/QueryFilter/QueryFilter.constants.d.ts +0 -134
- package/dist/QueryFilter/QueryFilter.constants.js +0 -39
- package/dist/QueryFilter/QueryFilter.lib.d.ts +0 -14
- package/dist/QueryFilter/QueryFilter.lib.js +0 -84
- package/dist/QueryFilter/QueryFilter.styled.d.ts +0 -89
- package/dist/QueryFilter/QueryFilter.styled.js +0 -184
- package/dist/QueryFilter/QueryFilter.types.js +0 -1
- package/dist/QueryFilter/components/MultiSelectEditor.d.ts +0 -7
- package/dist/QueryFilter/components/MultiSelectEditor.js +0 -44
- package/dist/QueryFilter/components/RuleChip.d.ts +0 -8
- package/dist/QueryFilter/components/RuleChip.js +0 -37
- package/dist/QueryFilter/components/Rules.d.ts +0 -11
- package/dist/QueryFilter/components/Rules.js +0 -41
- package/dist/QueryFilter/components/UnavailableRuleChip.d.ts +0 -5
- package/dist/QueryFilter/components/UnavailableRuleChip.js +0 -7
- package/dist/QueryFilter/components/ValueEditor.d.ts +0 -7
- package/dist/QueryFilter/components/ValueEditor.js +0 -45
- package/dist/QueryFilter/components/ValueSelector.d.ts +0 -7
- package/dist/QueryFilter/components/ValueSelector.js +0 -34
- package/dist/QueryFilter/components/index.d.ts +0 -6
- package/dist/QueryFilter/components/index.js +0 -6
- package/dist/RichTextEditor/Plugins/ImageActionsPlugin.d.ts +0 -3
- package/dist/RichTextEditor/Plugins/ImageActionsPlugin.js +0 -241
- package/dist/SuperDatePicker/SuperDatePicker.constants.d.ts +0 -24
- package/dist/SuperDatePicker/SuperDatePicker.constants.js +0 -30
- package/dist/SuperDatePicker/SuperDatePicker.d.ts +0 -3
- package/dist/SuperDatePicker/SuperDatePicker.js +0 -31
- package/dist/SuperDatePicker/SuperDatePicker.lib.d.ts +0 -17
- package/dist/SuperDatePicker/SuperDatePicker.lib.js +0 -206
- package/dist/SuperDatePicker/SuperDatePicker.styled.d.ts +0 -60
- package/dist/SuperDatePicker/SuperDatePicker.styled.js +0 -256
- package/dist/SuperDatePicker/SuperDatePicker.types.d.ts +0 -48
- package/dist/SuperDatePicker/SuperDatePicker.types.js +0 -1
- package/dist/SuperDatePicker/components/CommonPresetGroups.d.ts +0 -7
- package/dist/SuperDatePicker/components/CommonPresetGroups.js +0 -6
- package/dist/SuperDatePicker/components/EndpointCalendarDropdown.d.ts +0 -10
- package/dist/SuperDatePicker/components/EndpointCalendarDropdown.js +0 -9
- package/dist/SuperDatePicker/components/EndpointDateInput.d.ts +0 -16
- package/dist/SuperDatePicker/components/EndpointDateInput.js +0 -26
- package/dist/SuperDatePicker/components/EndpointPopover.d.ts +0 -18
- package/dist/SuperDatePicker/components/EndpointPopover.js +0 -11
- package/dist/SuperDatePicker/components/QuickRangeDropdown.d.ts +0 -14
- package/dist/SuperDatePicker/components/QuickRangeDropdown.js +0 -19
- package/dist/SuperDatePicker/components/QuickRangePopover.d.ts +0 -18
- package/dist/SuperDatePicker/components/QuickRangePopover.js +0 -12
- package/dist/SuperDatePicker/components/index.d.ts +0 -6
- package/dist/SuperDatePicker/components/index.js +0 -6
- package/dist/SuperDatePicker/index.d.ts +0 -3
- package/dist/SuperDatePicker/index.js +0 -3
- package/dist/SuperDatePicker/useSuperDatePicker.d.ts +0 -32
- package/dist/SuperDatePicker/useSuperDatePicker.js +0 -125
- /package/dist/{Charts/BarChart/BarChart.types.js → QueryFilter/types.js} +0 -0
|
@@ -1,529 +0,0 @@
|
|
|
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 { scaleLinear, scalePoint, scaleTime } from "d3-scale";
|
|
23
|
-
import { forwardRef, useCallback, useEffect, useId, useImperativeHandle, useLayoutEffect, 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 { buildAreaPath, buildLinePath, clamp, easeOutCubic, formatDefaultValue, getGradientStops, getPointKey, getSeriesKey, getSeriesLabelText, getValueDomain, measureSvgPath, mergeChartMargin, normalizeTickValue, parseLineChartXValue, resolveXAxisType, useThemeColor, useThemeColors, } from "./LineChart.lib";
|
|
28
|
-
import { StyledArea, StyledAxisLine, StyledAxisText, StyledChartActions, StyledChartFrame, StyledChartScroller, StyledContainer, StyledEmptyState, StyledGridLine, StyledHoverTarget, StyledLegend, StyledLegendItem, StyledLegendLabel, StyledLegendLine, StyledLegendValue, StyledLine, StyledPoint, StyledSvg, StyledTooltip, StyledTooltipHeader, StyledTooltipLabel, StyledTooltipMeta, StyledTooltipSwatch, StyledValueLabel, } from "./LineChart.styled";
|
|
29
|
-
const LineChartInner = (_a, ref) => {
|
|
30
|
-
var _b, _c, _d;
|
|
31
|
-
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, showExportButton = false, exportFileName = "line-chart", exportFormats = DEFAULT_CHART_EXPORT_FORMATS, exportScale = 2, exportBackgroundColor, 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", "showExportButton", "exportFileName", "exportFormats", "exportScale", "exportBackgroundColor", "showTooltips", "valueFormatter", "xValueFormatter", "xTickFormatter", "yTickFormatter", "labelFormatter", "tooltipFormatter", "onPointClick", "className"]);
|
|
32
|
-
const descriptionId = useId();
|
|
33
|
-
const gradientBaseId = useId();
|
|
34
|
-
const theme = useTheme();
|
|
35
|
-
const containerRef = useRef(null);
|
|
36
|
-
const chartFrameRef = useRef(null);
|
|
37
|
-
const svgRef = useRef(null);
|
|
38
|
-
const tooltipRef = useRef(null);
|
|
39
|
-
const linePathRefs = useRef({});
|
|
40
|
-
const [activePointKey, setActivePointKey] = useState(null);
|
|
41
|
-
const [activeSeriesKey, setActiveSeriesKey] = useState(null);
|
|
42
|
-
const [activeTooltip, setActiveTooltip] = useState(null);
|
|
43
|
-
const [tooltipSize, setTooltipSize] = useState({ width: 0, height: 0 });
|
|
44
|
-
const [animationProgress, setAnimationProgress] = useState(animateOnRender ? 0 : 1);
|
|
45
|
-
const [lineLengths, setLineLengths] = useState({});
|
|
46
|
-
const themeLineColor = useThemeColor(lineColor);
|
|
47
|
-
const themeColors = useThemeColors(colors);
|
|
48
|
-
const resolvedMargin = mergeChartMargin(margin, showXAxisLabels, showYAxisLabels, showLabels);
|
|
49
|
-
const safeWidth = Math.max(width, 240);
|
|
50
|
-
const safeHeight = Math.max(height, 200);
|
|
51
|
-
const plotWidth = Math.max(safeWidth - resolvedMargin.left - resolvedMargin.right, 1);
|
|
52
|
-
const plotHeight = Math.max(safeHeight - resolvedMargin.top - resolvedMargin.bottom, 1);
|
|
53
|
-
const resolvedGlobalLineWidth = Math.max(lineWidth, 1);
|
|
54
|
-
const resolvedGlobalLineOpacity = clamp(lineOpacity, 0, 1);
|
|
55
|
-
const resolvedGlobalAreaOpacity = clamp(areaOpacity, 0, 1);
|
|
56
|
-
const resolvedGlobalPointRadius = Math.max(pointRadius, 0);
|
|
57
|
-
const resolvedGlobalActivePointRadius = Math.max(activePointRadius, resolvedGlobalPointRadius);
|
|
58
|
-
const resolvedPointOpacity = clamp(pointOpacity, 0, 1);
|
|
59
|
-
const resolvedExportBackgroundColor = exportBackgroundColor !== null && exportBackgroundColor !== void 0 ? exportBackgroundColor : theme.palette.background.paper;
|
|
60
|
-
useImperativeHandle(ref, () => ({
|
|
61
|
-
getSvgElement: () => svgRef.current,
|
|
62
|
-
downloadImage: (request) => __awaiter(void 0, void 0, void 0, function* () {
|
|
63
|
-
var _a, _b, _c, _d;
|
|
64
|
-
yield downloadChartImage({
|
|
65
|
-
rootElement: containerRef.current,
|
|
66
|
-
svg: svgRef.current,
|
|
67
|
-
format: (_a = request === null || request === void 0 ? void 0 : request.format) !== null && _a !== void 0 ? _a : "svg",
|
|
68
|
-
fileName: (_b = request === null || request === void 0 ? void 0 : request.fileName) !== null && _b !== void 0 ? _b : exportFileName,
|
|
69
|
-
scale: (_c = request === null || request === void 0 ? void 0 : request.scale) !== null && _c !== void 0 ? _c : exportScale,
|
|
70
|
-
backgroundColor: (_d = request === null || request === void 0 ? void 0 : request.backgroundColor) !== null && _d !== void 0 ? _d : resolvedExportBackgroundColor,
|
|
71
|
-
});
|
|
72
|
-
}),
|
|
73
|
-
copyImage: (request) => __awaiter(void 0, void 0, void 0, function* () {
|
|
74
|
-
var _a, _b, _c;
|
|
75
|
-
return copyChartImage({
|
|
76
|
-
rootElement: containerRef.current,
|
|
77
|
-
svg: svgRef.current,
|
|
78
|
-
format: (_a = request === null || request === void 0 ? void 0 : request.format) !== null && _a !== void 0 ? _a : "png",
|
|
79
|
-
scale: (_b = request === null || request === void 0 ? void 0 : request.scale) !== null && _b !== void 0 ? _b : exportScale,
|
|
80
|
-
backgroundColor: (_c = request === null || request === void 0 ? void 0 : request.backgroundColor) !== null && _c !== void 0 ? _c : resolvedExportBackgroundColor,
|
|
81
|
-
});
|
|
82
|
-
}),
|
|
83
|
-
}), [exportFileName, exportScale, resolvedExportBackgroundColor]);
|
|
84
|
-
const isMultiSeries = ((_b = series === null || series === void 0 ? void 0 : series.length) !== null && _b !== void 0 ? _b : 0) > 0;
|
|
85
|
-
const normalizedInputSeries = useMemo(() => {
|
|
86
|
-
if (series === null || series === void 0 ? void 0 : series.length) {
|
|
87
|
-
return series.map((seriesItem, seriesIndex) => {
|
|
88
|
-
const fallbackLabel = `Series ${seriesIndex + 1}`;
|
|
89
|
-
return {
|
|
90
|
-
key: getSeriesKey(seriesItem, seriesIndex),
|
|
91
|
-
label: seriesItem.label,
|
|
92
|
-
labelText: getSeriesLabelText(seriesItem.label, fallbackLabel),
|
|
93
|
-
sourceSeries: seriesItem,
|
|
94
|
-
color: seriesItem.color,
|
|
95
|
-
colorGradient: seriesItem.colorGradient,
|
|
96
|
-
lineDasharray: seriesItem.lineDasharray,
|
|
97
|
-
lineWidth: seriesItem.lineWidth,
|
|
98
|
-
lineOpacity: seriesItem.lineOpacity,
|
|
99
|
-
showArea: seriesItem.showArea,
|
|
100
|
-
areaColor: seriesItem.areaColor,
|
|
101
|
-
areaOpacity: seriesItem.areaOpacity,
|
|
102
|
-
showPoints: seriesItem.showPoints,
|
|
103
|
-
pointColor: seriesItem.pointColor,
|
|
104
|
-
pointRadius: seriesItem.pointRadius,
|
|
105
|
-
activePointRadius: seriesItem.activePointRadius,
|
|
106
|
-
data: seriesItem.data,
|
|
107
|
-
};
|
|
108
|
-
});
|
|
109
|
-
}
|
|
110
|
-
if (data === null || data === void 0 ? void 0 : data.length) {
|
|
111
|
-
return [
|
|
112
|
-
{
|
|
113
|
-
key: "series-0",
|
|
114
|
-
label: seriesLabel,
|
|
115
|
-
labelText: getSeriesLabelText(seriesLabel, "Series"),
|
|
116
|
-
data,
|
|
117
|
-
},
|
|
118
|
-
];
|
|
119
|
-
}
|
|
120
|
-
return [];
|
|
121
|
-
}, [data, series, seriesLabel]);
|
|
122
|
-
const parsedSeriesInput = useMemo(() => {
|
|
123
|
-
const seriesEntries = normalizedInputSeries.map((inputSeries, seriesIndex) => {
|
|
124
|
-
const parsedPoints = inputSeries.data
|
|
125
|
-
.map((datum, pointIndex) => {
|
|
126
|
-
const parsedX = parseLineChartXValue(datum.x);
|
|
127
|
-
if (parsedX == null || !Number.isFinite(datum.y))
|
|
128
|
-
return null;
|
|
129
|
-
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: "" });
|
|
130
|
-
})
|
|
131
|
-
.filter(Boolean);
|
|
132
|
-
return Object.assign(Object.assign({}, inputSeries), { points: parsedPoints });
|
|
133
|
-
});
|
|
134
|
-
const allPoints = seriesEntries.flatMap((entry) => entry.points);
|
|
135
|
-
return {
|
|
136
|
-
resolvedXAxisType: resolveXAxisType(allPoints, xAxisType),
|
|
137
|
-
seriesEntries,
|
|
138
|
-
};
|
|
139
|
-
}, [normalizedInputSeries, xAxisType]);
|
|
140
|
-
const resolvedSeries = useMemo(() => {
|
|
141
|
-
return parsedSeriesInput.seriesEntries
|
|
142
|
-
.map((seriesEntry, seriesIndex) => {
|
|
143
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
|
|
144
|
-
const resolvedColor = (_a = seriesEntry.color) !== null && _a !== void 0 ? _a : (normalizedInputSeries.length === 1
|
|
145
|
-
? themeLineColor
|
|
146
|
-
: themeColors[seriesIndex % themeColors.length]);
|
|
147
|
-
const resolvedGradientStops = getGradientStops((_b = seriesEntry.colorGradient) !== null && _b !== void 0 ? _b : (normalizedInputSeries.length === 1 ? colorGradient : undefined));
|
|
148
|
-
const resolvedPointRadius = Math.max((_c = seriesEntry.pointRadius) !== null && _c !== void 0 ? _c : resolvedGlobalPointRadius, 0);
|
|
149
|
-
const resolvedActivePointRadius = Math.max((_d = seriesEntry.activePointRadius) !== null && _d !== void 0 ? _d : resolvedGlobalActivePointRadius, resolvedPointRadius);
|
|
150
|
-
const points = seriesEntry.points
|
|
151
|
-
.map((point) => (Object.assign(Object.assign({}, point), { xType: parsedSeriesInput.resolvedXAxisType, seriesColor: resolvedColor })))
|
|
152
|
-
.sort((left, right) => {
|
|
153
|
-
if (parsedSeriesInput.resolvedXAxisType === "point") {
|
|
154
|
-
return left.index - right.index;
|
|
155
|
-
}
|
|
156
|
-
const leftValue = left.parsedX instanceof Date
|
|
157
|
-
? left.parsedX.getTime()
|
|
158
|
-
: Number(left.parsedX);
|
|
159
|
-
const rightValue = right.parsedX instanceof Date
|
|
160
|
-
? right.parsedX.getTime()
|
|
161
|
-
: Number(right.parsedX);
|
|
162
|
-
return leftValue - rightValue;
|
|
163
|
-
});
|
|
164
|
-
return {
|
|
165
|
-
key: seriesEntry.key,
|
|
166
|
-
label: seriesEntry.label,
|
|
167
|
-
labelText: seriesEntry.labelText,
|
|
168
|
-
color: resolvedColor,
|
|
169
|
-
gradientStops: resolvedGradientStops,
|
|
170
|
-
lineDasharray: (_e = seriesEntry.lineDasharray) !== null && _e !== void 0 ? _e : lineDasharray,
|
|
171
|
-
lineWidth: Math.max((_f = seriesEntry.lineWidth) !== null && _f !== void 0 ? _f : resolvedGlobalLineWidth, 1),
|
|
172
|
-
lineOpacity: clamp((_g = seriesEntry.lineOpacity) !== null && _g !== void 0 ? _g : resolvedGlobalLineOpacity, 0, 1),
|
|
173
|
-
showArea: (_h = seriesEntry.showArea) !== null && _h !== void 0 ? _h : showArea,
|
|
174
|
-
areaColor: (_k = (_j = seriesEntry.areaColor) !== null && _j !== void 0 ? _j : areaColor) !== null && _k !== void 0 ? _k : resolvedColor,
|
|
175
|
-
areaOpacity: clamp((_l = seriesEntry.areaOpacity) !== null && _l !== void 0 ? _l : resolvedGlobalAreaOpacity, 0, 1),
|
|
176
|
-
showPoints: (_m = seriesEntry.showPoints) !== null && _m !== void 0 ? _m : showPoints,
|
|
177
|
-
pointColor: (_p = (_o = seriesEntry.pointColor) !== null && _o !== void 0 ? _o : pointColor) !== null && _p !== void 0 ? _p : resolvedColor,
|
|
178
|
-
pointRadius: resolvedPointRadius,
|
|
179
|
-
activePointRadius: resolvedActivePointRadius,
|
|
180
|
-
sourceSeries: seriesEntry.sourceSeries,
|
|
181
|
-
points,
|
|
182
|
-
};
|
|
183
|
-
})
|
|
184
|
-
.filter((seriesEntry) => seriesEntry.points.length > 0);
|
|
185
|
-
}, [
|
|
186
|
-
areaColor,
|
|
187
|
-
colorGradient,
|
|
188
|
-
lineDasharray,
|
|
189
|
-
normalizedInputSeries.length,
|
|
190
|
-
parsedSeriesInput.resolvedXAxisType,
|
|
191
|
-
parsedSeriesInput.seriesEntries,
|
|
192
|
-
pointColor,
|
|
193
|
-
resolvedGlobalActivePointRadius,
|
|
194
|
-
resolvedGlobalAreaOpacity,
|
|
195
|
-
resolvedGlobalLineOpacity,
|
|
196
|
-
resolvedGlobalLineWidth,
|
|
197
|
-
resolvedGlobalPointRadius,
|
|
198
|
-
showArea,
|
|
199
|
-
showPoints,
|
|
200
|
-
themeColors,
|
|
201
|
-
themeLineColor,
|
|
202
|
-
]);
|
|
203
|
-
const allPoints = useMemo(() => resolvedSeries.flatMap((seriesEntry) => seriesEntry.points), [resolvedSeries]);
|
|
204
|
-
const resolvedXAxisType = parsedSeriesInput.resolvedXAxisType;
|
|
205
|
-
const resolvedPointBorderColor = pointBorderColor !== null && pointBorderColor !== void 0 ? pointBorderColor : theme.palette.background.paper;
|
|
206
|
-
const timeScale = useMemo(() => {
|
|
207
|
-
if (resolvedXAxisType !== "time")
|
|
208
|
-
return null;
|
|
209
|
-
const timeValues = allPoints
|
|
210
|
-
.map((point) => (point.parsedX instanceof Date ? point.parsedX.getTime() : null))
|
|
211
|
-
.filter((value) => value != null);
|
|
212
|
-
const min = Math.min(...timeValues);
|
|
213
|
-
const max = Math.max(...timeValues);
|
|
214
|
-
const scale = scaleTime()
|
|
215
|
-
.domain([new Date(min), new Date(max === min ? min + 1 : max)])
|
|
216
|
-
.range([0, plotWidth]);
|
|
217
|
-
scale.nice(Math.max(xTickCount, 2));
|
|
218
|
-
return scale;
|
|
219
|
-
}, [allPoints, plotWidth, resolvedXAxisType, xTickCount]);
|
|
220
|
-
const linearScale = useMemo(() => {
|
|
221
|
-
if (resolvedXAxisType !== "linear")
|
|
222
|
-
return null;
|
|
223
|
-
const numericValues = allPoints.map((point) => Number(point.parsedX));
|
|
224
|
-
const min = Math.min(...numericValues);
|
|
225
|
-
const max = Math.max(...numericValues);
|
|
226
|
-
const scale = scaleLinear()
|
|
227
|
-
.domain([min, max === min ? min + 1 : max])
|
|
228
|
-
.range([0, plotWidth]);
|
|
229
|
-
scale.nice(Math.max(xTickCount, 2));
|
|
230
|
-
return scale;
|
|
231
|
-
}, [allPoints, plotWidth, resolvedXAxisType, xTickCount]);
|
|
232
|
-
const pointScale = useMemo(() => {
|
|
233
|
-
if (resolvedXAxisType !== "point")
|
|
234
|
-
return null;
|
|
235
|
-
const domain = Array.from(new Set(allPoints.map((point) => String(point.parsedX))));
|
|
236
|
-
return scalePoint()
|
|
237
|
-
.domain(domain)
|
|
238
|
-
.range([0, plotWidth])
|
|
239
|
-
.padding(0.4);
|
|
240
|
-
}, [allPoints, plotWidth, resolvedXAxisType]);
|
|
241
|
-
const yScale = useMemo(() => {
|
|
242
|
-
const scale = scaleLinear()
|
|
243
|
-
.domain(getValueDomain(allPoints.map((point) => point.y), yMin, yMax))
|
|
244
|
-
.range([plotHeight, 0]);
|
|
245
|
-
if (yMin == null || yMax == null) {
|
|
246
|
-
scale.nice(Math.max(yTickCount, 2));
|
|
247
|
-
}
|
|
248
|
-
return scale;
|
|
249
|
-
}, [allPoints, plotHeight, yMax, yMin, yTickCount]);
|
|
250
|
-
const getPointX = useCallback((point) => {
|
|
251
|
-
var _a, _b, _c;
|
|
252
|
-
if (resolvedXAxisType === "time") {
|
|
253
|
-
return (_a = timeScale === null || timeScale === void 0 ? void 0 : timeScale(point.parsedX)) !== null && _a !== void 0 ? _a : 0;
|
|
254
|
-
}
|
|
255
|
-
if (resolvedXAxisType === "linear") {
|
|
256
|
-
return (_b = linearScale === null || linearScale === void 0 ? void 0 : linearScale(Number(point.parsedX))) !== null && _b !== void 0 ? _b : 0;
|
|
257
|
-
}
|
|
258
|
-
return (_c = pointScale === null || pointScale === void 0 ? void 0 : pointScale(String(point.parsedX))) !== null && _c !== void 0 ? _c : 0;
|
|
259
|
-
}, [linearScale, pointScale, resolvedXAxisType, timeScale]);
|
|
260
|
-
const getPointY = useCallback((point) => yScale(point.y), [yScale]);
|
|
261
|
-
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
|
|
262
|
-
? buildAreaPath(seriesEntry.points, getPointX, getPointY, plotHeight, curve)
|
|
263
|
-
: null }))), [curve, getPointX, gradientBaseId, plotHeight, resolvedSeries]);
|
|
264
|
-
const renderedSeriesKey = useMemo(() => renderedSeries
|
|
265
|
-
.map((seriesEntry) => {
|
|
266
|
-
var _a, _b;
|
|
267
|
-
return `${String(seriesEntry.key)}:${(_a = seriesEntry.linePath) !== null && _a !== void 0 ? _a : ""}:${(_b = seriesEntry.areaPath) !== null && _b !== void 0 ? _b : ""}`;
|
|
268
|
-
})
|
|
269
|
-
.join("|"), [renderedSeries]);
|
|
270
|
-
useLayoutEffect(() => {
|
|
271
|
-
const nextLineLengths = {};
|
|
272
|
-
renderedSeries.forEach((seriesEntry) => {
|
|
273
|
-
var _a;
|
|
274
|
-
nextLineLengths[String(seriesEntry.key)] = measureSvgPath((_a = linePathRefs.current[String(seriesEntry.key)]) !== null && _a !== void 0 ? _a : null);
|
|
275
|
-
});
|
|
276
|
-
setLineLengths((currentLineLengths) => {
|
|
277
|
-
const currentKeys = Object.keys(currentLineLengths);
|
|
278
|
-
const nextKeys = Object.keys(nextLineLengths);
|
|
279
|
-
if (currentKeys.length !== nextKeys.length) {
|
|
280
|
-
return nextLineLengths;
|
|
281
|
-
}
|
|
282
|
-
for (const key of nextKeys) {
|
|
283
|
-
if (currentLineLengths[key] !== nextLineLengths[key]) {
|
|
284
|
-
return nextLineLengths;
|
|
285
|
-
}
|
|
286
|
-
}
|
|
287
|
-
return currentLineLengths;
|
|
288
|
-
});
|
|
289
|
-
}, [renderedSeries, renderedSeriesKey]);
|
|
290
|
-
useLayoutEffect(() => {
|
|
291
|
-
var _a;
|
|
292
|
-
if (!animateOnRender || renderedSeries.every((seriesEntry) => !seriesEntry.linePath)) {
|
|
293
|
-
setAnimationProgress(1);
|
|
294
|
-
return;
|
|
295
|
-
}
|
|
296
|
-
const prefersReducedMotion = typeof window !== "undefined" &&
|
|
297
|
-
((_a = window.matchMedia) === null || _a === void 0 ? void 0 : _a.call(window, "(prefers-reduced-motion: reduce)").matches);
|
|
298
|
-
if (prefersReducedMotion) {
|
|
299
|
-
setAnimationProgress(1);
|
|
300
|
-
return;
|
|
301
|
-
}
|
|
302
|
-
let animationFrame = 0;
|
|
303
|
-
let startTime = null;
|
|
304
|
-
const safeDuration = Math.max(animationDuration, 0);
|
|
305
|
-
setAnimationProgress(0);
|
|
306
|
-
const runAnimation = (timestamp) => {
|
|
307
|
-
if (startTime == null)
|
|
308
|
-
startTime = timestamp;
|
|
309
|
-
const elapsed = timestamp - startTime;
|
|
310
|
-
const progress = safeDuration === 0 ? 1 : easeOutCubic(clamp(elapsed / safeDuration, 0, 1));
|
|
311
|
-
setAnimationProgress(progress);
|
|
312
|
-
if (progress < 1) {
|
|
313
|
-
animationFrame = window.requestAnimationFrame(runAnimation);
|
|
314
|
-
}
|
|
315
|
-
};
|
|
316
|
-
animationFrame = window.requestAnimationFrame(runAnimation);
|
|
317
|
-
return () => {
|
|
318
|
-
window.cancelAnimationFrame(animationFrame);
|
|
319
|
-
};
|
|
320
|
-
}, [animateOnRender, animationDuration, renderedSeriesKey]);
|
|
321
|
-
const xTicks = useMemo(() => {
|
|
322
|
-
var _a;
|
|
323
|
-
if (resolvedXAxisType === "time" && timeScale) {
|
|
324
|
-
return timeScale.ticks(Math.max(xTickCount, 2));
|
|
325
|
-
}
|
|
326
|
-
if (resolvedXAxisType === "linear" && linearScale) {
|
|
327
|
-
return linearScale
|
|
328
|
-
.ticks(Math.max(xTickCount, 2))
|
|
329
|
-
.map((tick) => normalizeTickValue(tick));
|
|
330
|
-
}
|
|
331
|
-
const domain = (_a = pointScale === null || pointScale === void 0 ? void 0 : pointScale.domain()) !== null && _a !== void 0 ? _a : [];
|
|
332
|
-
if (domain.length <= Math.max(xTickCount, 2))
|
|
333
|
-
return domain;
|
|
334
|
-
const step = Math.ceil(domain.length / Math.max(xTickCount, 2));
|
|
335
|
-
return domain.filter((_, index) => index % step === 0);
|
|
336
|
-
}, [linearScale, pointScale, resolvedXAxisType, timeScale, xTickCount]);
|
|
337
|
-
const yTicks = useMemo(() => Array.from(new Set(yScale
|
|
338
|
-
.ticks(Math.max(yTickCount, 2))
|
|
339
|
-
.map((tick) => normalizeTickValue(tick)))), [yScale, yTickCount]);
|
|
340
|
-
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); };
|
|
341
|
-
const formatXValue = (datum, sourceSeries) => {
|
|
342
|
-
var _a;
|
|
343
|
-
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));
|
|
344
|
-
};
|
|
345
|
-
const formatXTick = (value) => {
|
|
346
|
-
var _a;
|
|
347
|
-
return (_a = xTickFormatter === null || xTickFormatter === void 0 ? void 0 : xTickFormatter(value)) !== null && _a !== void 0 ? _a : (value instanceof Date
|
|
348
|
-
? new Intl.DateTimeFormat(undefined, {
|
|
349
|
-
month: "short",
|
|
350
|
-
day: "numeric",
|
|
351
|
-
}).format(value)
|
|
352
|
-
: String(value));
|
|
353
|
-
};
|
|
354
|
-
const formatYTick = (value) => { var _a; return (_a = yTickFormatter === null || yTickFormatter === void 0 ? void 0 : yTickFormatter(value)) !== null && _a !== void 0 ? _a : formatDefaultValue(value); };
|
|
355
|
-
const findNearestPoint = (clientX, clientY) => {
|
|
356
|
-
if (!chartFrameRef.current)
|
|
357
|
-
return null;
|
|
358
|
-
const chartRect = chartFrameRef.current.getBoundingClientRect();
|
|
359
|
-
const localX = clamp(clientX - chartRect.left - resolvedMargin.left, 0, plotWidth);
|
|
360
|
-
const localY = clamp(clientY - chartRect.top - resolvedMargin.top, 0, plotHeight);
|
|
361
|
-
let nearestPoint = null;
|
|
362
|
-
let nearestDistance = Number.POSITIVE_INFINITY;
|
|
363
|
-
for (const point of allPoints) {
|
|
364
|
-
const pointX = getPointX(point);
|
|
365
|
-
const pointY = getPointY(point);
|
|
366
|
-
const dx = pointX - localX;
|
|
367
|
-
const dy = pointY - localY;
|
|
368
|
-
const distance = dx * dx + dy * dy * 0.18;
|
|
369
|
-
if (distance < nearestDistance) {
|
|
370
|
-
nearestDistance = distance;
|
|
371
|
-
nearestPoint = point;
|
|
372
|
-
}
|
|
373
|
-
}
|
|
374
|
-
return nearestPoint;
|
|
375
|
-
};
|
|
376
|
-
const updateActivePointFromEvent = (event, triggerTooltip) => {
|
|
377
|
-
const nearestPoint = findNearestPoint(event.clientX, event.clientY);
|
|
378
|
-
if (!nearestPoint)
|
|
379
|
-
return;
|
|
380
|
-
setActivePointKey(nearestPoint.key);
|
|
381
|
-
if (!triggerTooltip)
|
|
382
|
-
return;
|
|
383
|
-
setActiveTooltip({
|
|
384
|
-
pointKey: nearestPoint.key,
|
|
385
|
-
x: resolvedMargin.left + getPointX(nearestPoint),
|
|
386
|
-
y: resolvedMargin.top + getPointY(nearestPoint),
|
|
387
|
-
});
|
|
388
|
-
};
|
|
389
|
-
const activePoint = (showTooltips || showPoints || onPointClick) && activePointKey != null
|
|
390
|
-
? allPoints.find((point) => point.key === activePointKey)
|
|
391
|
-
: null;
|
|
392
|
-
const highlightedSeriesKey = (_c = activeSeriesKey !== null && activeSeriesKey !== void 0 ? activeSeriesKey : activePoint === null || activePoint === void 0 ? void 0 : activePoint.seriesKey) !== null && _c !== void 0 ? _c : null;
|
|
393
|
-
const activeSeries = activePoint
|
|
394
|
-
? renderedSeries.find((seriesEntry) => seriesEntry.key === activePoint.seriesKey)
|
|
395
|
-
: null;
|
|
396
|
-
const tooltipStyle = useMemo(() => {
|
|
397
|
-
if (!activeTooltip ||
|
|
398
|
-
!containerRef.current ||
|
|
399
|
-
!chartFrameRef.current ||
|
|
400
|
-
!activePoint) {
|
|
401
|
-
return null;
|
|
402
|
-
}
|
|
403
|
-
const containerRect = containerRef.current.getBoundingClientRect();
|
|
404
|
-
const chartRect = chartFrameRef.current.getBoundingClientRect();
|
|
405
|
-
const chartLeft = chartRect.left - containerRect.left;
|
|
406
|
-
const chartTop = chartRect.top - containerRect.top;
|
|
407
|
-
const minLeft = chartLeft + 8;
|
|
408
|
-
const maxLeft = chartLeft + chartRect.width - tooltipSize.width - 8;
|
|
409
|
-
const minTop = chartTop + 8;
|
|
410
|
-
const maxTop = chartTop + chartRect.height - tooltipSize.height - 8;
|
|
411
|
-
return {
|
|
412
|
-
left: clamp(activeTooltip.x + 14, minLeft, Math.max(minLeft, maxLeft)),
|
|
413
|
-
top: clamp(activeTooltip.y - tooltipSize.height / 2, minTop, Math.max(minTop, maxTop)),
|
|
414
|
-
};
|
|
415
|
-
}, [activePoint, activeTooltip, tooltipSize.height, tooltipSize.width]);
|
|
416
|
-
useEffect(() => {
|
|
417
|
-
if (!activePoint || !tooltipRef.current) {
|
|
418
|
-
setTooltipSize({ width: 0, height: 0 });
|
|
419
|
-
return;
|
|
420
|
-
}
|
|
421
|
-
setTooltipSize({
|
|
422
|
-
width: tooltipRef.current.offsetWidth,
|
|
423
|
-
height: tooltipRef.current.offsetHeight,
|
|
424
|
-
});
|
|
425
|
-
}, [activePoint]);
|
|
426
|
-
const description = allPoints
|
|
427
|
-
.map((point) => `${point.seriesLabelText}, ${formatXValue(point, activeSeries === null || activeSeries === void 0 ? void 0 : activeSeries.sourceSeries)}: ${formatDefaultValue(point.y)}`)
|
|
428
|
-
.join(", ");
|
|
429
|
-
const shouldAnimateStroke = animateOnRender && animationProgress < 1;
|
|
430
|
-
const shouldShowDataLabels = showLabels && allPoints.length <= 24;
|
|
431
|
-
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: _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 }), _jsx("defs", { children: renderedSeries
|
|
432
|
-
.filter((seriesEntry) => { var _a; return (_a = seriesEntry.gradientStops) === null || _a === void 0 ? void 0 : _a.length; })
|
|
433
|
-
.map((seriesEntry) => {
|
|
434
|
-
var _a;
|
|
435
|
-
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) => {
|
|
436
|
-
var _a, _b;
|
|
437
|
-
return (_jsx("stop", { offset: `${((_a = seriesEntry.gradientStops) !== null && _a !== void 0 ? _a : []).length === 1
|
|
438
|
-
? 100
|
|
439
|
-
: (index /
|
|
440
|
-
(((_b = seriesEntry.gradientStops) !== null && _b !== void 0 ? _b : []).length - 1)) *
|
|
441
|
-
100}%`, stopColor: stop }, `${stop}-${index}`));
|
|
442
|
-
}) }, seriesEntry.gradientId));
|
|
443
|
-
}) }), showGridLines &&
|
|
444
|
-
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 &&
|
|
445
|
-
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 &&
|
|
446
|
-
xTicks.map((tick, index) => {
|
|
447
|
-
var _a, _b, _c;
|
|
448
|
-
const x = resolvedXAxisType === "time"
|
|
449
|
-
? (_a = timeScale === null || timeScale === void 0 ? void 0 : timeScale(tick)) !== null && _a !== void 0 ? _a : 0
|
|
450
|
-
: resolvedXAxisType === "linear"
|
|
451
|
-
? (_b = linearScale === null || linearScale === void 0 ? void 0 : linearScale(tick)) !== null && _b !== void 0 ? _b : 0
|
|
452
|
-
: (_c = pointScale === null || pointScale === void 0 ? void 0 : pointScale(String(tick))) !== null && _c !== void 0 ? _c : 0;
|
|
453
|
-
return (_jsx(StyledAxisText, { x: resolvedMargin.left + x, y: resolvedMargin.top + plotHeight + 20, textAnchor: "middle", children: formatXTick(tick) }, `tick-x-${index}`));
|
|
454
|
-
}), _jsxs("g", { transform: `translate(${resolvedMargin.left}, ${resolvedMargin.top})`, children: [_jsx(StyledHoverTarget, { x: 0, y: 0, width: plotWidth, height: plotHeight, onMouseEnter: (event) => {
|
|
455
|
-
if (!showTooltips && !showPoints && !onPointClick)
|
|
456
|
-
return;
|
|
457
|
-
updateActivePointFromEvent(event, showTooltips);
|
|
458
|
-
}, onMouseMove: (event) => {
|
|
459
|
-
if (!showTooltips && !showPoints && !onPointClick)
|
|
460
|
-
return;
|
|
461
|
-
updateActivePointFromEvent(event, showTooltips);
|
|
462
|
-
}, onMouseLeave: () => {
|
|
463
|
-
setActivePointKey(null);
|
|
464
|
-
setActiveTooltip(null);
|
|
465
|
-
}, onClick: (event) => {
|
|
466
|
-
if (!onPointClick)
|
|
467
|
-
return;
|
|
468
|
-
const nearestPoint = findNearestPoint(event.clientX, event.clientY);
|
|
469
|
-
const nearestSeries = nearestPoint
|
|
470
|
-
? renderedSeries.find((seriesEntry) => seriesEntry.key === nearestPoint.seriesKey)
|
|
471
|
-
: null;
|
|
472
|
-
if (nearestPoint) {
|
|
473
|
-
onPointClick(event, nearestPoint, nearestSeries === null || nearestSeries === void 0 ? void 0 : nearestSeries.sourceSeries);
|
|
474
|
-
}
|
|
475
|
-
} }), renderedSeries.map((seriesEntry) => {
|
|
476
|
-
var _a, _b;
|
|
477
|
-
const gradientReference = ((_a = seriesEntry.gradientStops) === null || _a === void 0 ? void 0 : _a.length)
|
|
478
|
-
? `url(#${seriesEntry.gradientId})`
|
|
479
|
-
: seriesEntry.color;
|
|
480
|
-
const lineLength = (_b = lineLengths[String(seriesEntry.key)]) !== null && _b !== void 0 ? _b : 0;
|
|
481
|
-
const isSeriesActive = highlightedSeriesKey === seriesEntry.key;
|
|
482
|
-
const isSeriesDimmed = highlightedSeriesKey != null && !isSeriesActive;
|
|
483
|
-
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 *
|
|
484
|
-
animationProgress *
|
|
485
|
-
(isSeriesDimmed ? 0.28 : isSeriesActive ? 1.08 : 1), style: {
|
|
486
|
-
filter: isSeriesActive
|
|
487
|
-
? "brightness(1.08) saturate(1.06)"
|
|
488
|
-
: undefined,
|
|
489
|
-
opacity: isSeriesDimmed ? 0.7 : 1,
|
|
490
|
-
} })), seriesEntry.linePath && (_jsx(StyledLine, { "$active": isSeriesActive, "$dimmed": isSeriesDimmed, ref: (node) => {
|
|
491
|
-
linePathRefs.current[String(seriesEntry.key)] = node;
|
|
492
|
-
}, d: seriesEntry.linePath, stroke: gradientReference, strokeWidth: isSeriesActive
|
|
493
|
-
? seriesEntry.lineWidth + 0.8
|
|
494
|
-
: seriesEntry.lineWidth, strokeOpacity: seriesEntry.lineOpacity, strokeDasharray: shouldAnimateStroke && lineLength > 0
|
|
495
|
-
? `${lineLength} ${lineLength}`
|
|
496
|
-
: seriesEntry.lineDasharray, strokeDashoffset: shouldAnimateStroke && lineLength > 0
|
|
497
|
-
? lineLength * (1 - animationProgress)
|
|
498
|
-
: 0 }))] }, seriesEntry.key));
|
|
499
|
-
}), (showPoints || activePoint != null) &&
|
|
500
|
-
renderedSeries.map((seriesEntry) => seriesEntry.points.map((point) => {
|
|
501
|
-
var _a;
|
|
502
|
-
const isActive = activePointKey === point.key;
|
|
503
|
-
const shouldRender = seriesEntry.showPoints || isActive;
|
|
504
|
-
if (!shouldRender)
|
|
505
|
-
return null;
|
|
506
|
-
return (_jsx(StyledPoint, { "$active": isActive, cx: getPointX(point), cy: getPointY(point), r: isActive
|
|
507
|
-
? seriesEntry.activePointRadius
|
|
508
|
-
: 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: () => {
|
|
509
|
-
if (!showTooltips)
|
|
510
|
-
setActivePointKey(null);
|
|
511
|
-
}, onClick: (event) => onPointClick === null || onPointClick === void 0 ? void 0 : onPointClick(event, point, seriesEntry.sourceSeries), onKeyDown: (event) => {
|
|
512
|
-
if (event.key !== "Enter" && event.key !== " ")
|
|
513
|
-
return;
|
|
514
|
-
event.preventDefault();
|
|
515
|
-
onPointClick === null || onPointClick === void 0 ? void 0 : onPointClick(event, point, seriesEntry.sourceSeries);
|
|
516
|
-
} }, point.key));
|
|
517
|
-
})), shouldShowDataLabels &&
|
|
518
|
-
renderedSeries.map((seriesEntry) => seriesEntry.points.map((point) => {
|
|
519
|
-
var _a;
|
|
520
|
-
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}`));
|
|
521
|
-
}))] })] })] }) })), 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) => {
|
|
522
|
-
const latestPoint = seriesEntry.points[seriesEntry.points.length - 1];
|
|
523
|
-
if (!latestPoint)
|
|
524
|
-
return null;
|
|
525
|
-
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}`));
|
|
526
|
-
}) }))] })));
|
|
527
|
-
};
|
|
528
|
-
export const LineChart = forwardRef(LineChartInner);
|
|
529
|
-
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;
|