flikkui 0.1.0-beta.3 → 0.1.0-beta.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +155 -0
- package/dist/components/charts/AreaChart/AreaChart.js +434 -0
- package/dist/components/charts/AreaChart/AreaChart.types.js +7 -0
- package/dist/components/charts/BarChart/BarChart.js +402 -0
- package/dist/components/charts/BarChart/BarChart.types.js +7 -0
- package/dist/components/charts/ChartContainer.js +38 -0
- package/dist/components/charts/Heatmap/Heatmap.js +153 -0
- package/dist/components/charts/Heatmap/HeatmapCell.js +100 -0
- package/dist/components/charts/Heatmap/HeatmapLegend.js +20 -0
- package/dist/components/charts/Heatmap/utils/heatmapUtils.js +174 -0
- package/dist/components/charts/LineChart/LineChart.js +396 -0
- package/dist/components/charts/LineChart/LineChart.types.js +7 -0
- package/dist/components/charts/hooks/useChartAccessibility.js +127 -0
- package/dist/components/charts/hooks/useChartTheme.js +86 -0
- package/dist/components/charts/hooks/useChartValidation.js +59 -0
- package/dist/components/charts/hooks/useTooltipPosition.js +292 -0
- package/dist/components/charts/shared/ChartAxis/XAxis.js +30 -0
- package/dist/components/charts/shared/ChartAxis/YAxis.js +97 -0
- package/dist/components/charts/shared/ChartCrosshair/ChartCrosshair.js +35 -0
- package/dist/components/charts/shared/ChartCrosshair/ChartCrosshair.theme.js +11 -0
- package/dist/components/charts/shared/ChartErrorBoundary/ChartErrorBoundary.js +66 -0
- package/dist/components/charts/shared/ChartGrid/HorizontalGrid.js +22 -0
- package/dist/components/charts/shared/ChartLegend/ChartLegend.js +30 -0
- package/dist/components/charts/shared/ChartLegend/ChartLegendContent.js +22 -0
- package/dist/components/charts/shared/ChartMarker/ChartMarker.js +25 -0
- package/dist/components/charts/shared/ChartMarker/ChartMarker.theme.js +9 -0
- package/dist/components/charts/shared/ChartText/ChartText.js +33 -0
- package/dist/components/charts/shared/ChartText/ChartText.theme.js +9 -0
- package/dist/components/charts/shared/ChartTooltip/ChartTooltip.js +62 -0
- package/dist/components/charts/theme/chart.theme.js +73 -0
- package/dist/components/charts/types/chart.types.js +29 -0
- package/dist/components/charts/utils/chart-validation.js +292 -0
- package/dist/components/charts/utils/color-utils.js +175 -0
- package/dist/components/core/Accordion/Accordion.animations.js +45 -0
- package/dist/components/core/Accordion/Accordion.js +52 -0
- package/dist/components/core/Accordion/Accordion.theme.js +8 -0
- package/dist/components/core/Accordion/AccordionContent.js +25 -0
- package/dist/components/core/Accordion/AccordionItem.js +56 -0
- package/dist/components/core/Accordion/AccordionTrigger.js +32 -0
- package/dist/components/core/Accordion/index.js +5 -0
- package/dist/components/core/Avatar/Avatar.js +94 -0
- package/dist/components/core/Avatar/Avatar.theme.js +25 -0
- package/dist/components/core/AvatarGroup/AvatarGroup.animations.js +79 -0
- package/dist/components/core/AvatarGroup/AvatarGroup.js +67 -0
- package/dist/components/core/AvatarGroup/AvatarGroup.theme.js +23 -0
- package/dist/components/core/Badge/Badge.animations.js +109 -0
- package/dist/components/core/Badge/Badge.js +101 -0
- package/dist/components/core/Badge/Badge.theme.js +41 -0
- package/dist/components/core/Breadcrumbs/Breadcrumbs.theme.js +8 -8
- package/dist/components/core/Button/Button.theme.js +5 -5
- package/dist/components/core/Card/Card.js +46 -0
- package/dist/components/core/Card/Card.theme.js +5 -0
- package/dist/components/core/Divider/Divider.js +21 -0
- package/dist/components/core/Divider/Divider.theme.js +19 -0
- package/dist/components/core/Pagination/Pagination.js +113 -0
- package/dist/components/core/Pagination/Pagination.theme.js +27 -0
- package/dist/components/core/Segmented/Segmented.js +69 -0
- package/dist/components/core/Segmented/Segmented.theme.js +40 -0
- package/dist/components/core/Segmented/SegmentedContext.js +8 -0
- package/dist/components/core/Segmented/SegmentedItem.js +30 -0
- package/dist/components/core/Stepper/Stepper.js +57 -0
- package/dist/components/core/Stepper/Stepper.theme.js +9 -0
- package/dist/components/core/Stepper/components/ConnectorLine.js +42 -0
- package/dist/components/core/Stepper/components/IconCircle.js +44 -0
- package/dist/components/core/Stepper/components/ProgressIndicator.js +12 -0
- package/dist/components/core/Stepper/components/StepContent.js +36 -0
- package/dist/components/core/Stepper/components/StepperItem.js +22 -0
- package/dist/components/core/Tabs/Tabs.theme.js +2 -2
- package/dist/components/core/Tooltip/Tooltip.animations.js +46 -0
- package/dist/components/core/Tooltip/Tooltip.js +85 -0
- package/dist/components/core/Tooltip/Tooltip.theme.js +11 -0
- package/dist/components/core/Tooltip/useTooltipPositioning.js +59 -0
- package/dist/components/core/Tree/Tree.animations.js +38 -0
- package/dist/components/core/Tree/Tree.js +177 -0
- package/dist/components/core/Tree/Tree.theme.js +11 -0
- package/dist/components/data-display/Table/Table.js +177 -0
- package/dist/components/data-display/Table/Table.theme.js +28 -0
- package/dist/components/data-display/Table/Table.utils.js +28 -0
- package/dist/components/data-display/Table/components/DeclarativeComponents.js +123 -0
- package/dist/components/data-display/Table/components/TableActions/TableActions.js +56 -0
- package/dist/components/data-display/Table/components/TableActions/TableActionsMenu.js +29 -0
- package/dist/components/data-display/Table/components/TableColumnManager/TableColumnManager.js +85 -0
- package/dist/components/data-display/Table/components/TableColumnManager/TableColumnManager.theme.js +21 -0
- package/dist/components/data-display/Table/components/TablePagination/TablePagination.js +51 -0
- package/dist/components/data-display/Table/components/TableSelectionHeader/TableSelectionHeader.js +29 -0
- package/dist/components/data-display/Table/components/core/TableBody.js +32 -0
- package/dist/components/data-display/Table/components/core/TableCell.js +47 -0
- package/dist/components/data-display/Table/components/core/TableHeader.js +77 -0
- package/dist/components/data-display/Table/components/core/TableRow.js +46 -0
- package/dist/components/data-display/Table/index.js +20 -0
- package/dist/components/feedback/Alert/Alert.js +36 -0
- package/dist/components/feedback/Alert/Alert.theme.js +17 -0
- package/dist/components/feedback/ChatMessage/ChatMessage.js +26 -0
- package/dist/components/feedback/ChatMessage/ChatMessage.theme.js +16 -0
- package/dist/components/feedback/Empty/Empty.js +26 -0
- package/dist/components/feedback/Empty/Empty.theme.js +13 -0
- package/dist/components/feedback/Notification/Notification.js +41 -0
- package/dist/components/feedback/Notification/Notification.theme.js +49 -0
- package/dist/components/feedback/Spinner/Spinner.theme.js +3 -3
- package/dist/components/feedback/Toast/Toast.animations.js +58 -0
- package/dist/components/feedback/Toast/Toast.js +67 -0
- package/dist/components/feedback/Toast/Toast.theme.js +18 -0
- package/dist/components/feedback/Toast/ToastProvider.js +73 -0
- package/dist/components/feedback/Toast/useToast.js +91 -0
- package/dist/components/forms/Checkbox/Checkbox.theme.js +1 -1
- package/dist/components/forms/FormLabel/FormLabel.theme.js +2 -2
- package/dist/components/forms/Input/Input.theme.js +4 -4
- package/dist/components/forms/Radio/Radio.theme.js +2 -2
- package/dist/components/forms/Select/Select.js +1 -1
- package/dist/components/forms/Select/Select.theme.js +5 -5
- package/dist/components/forms/Switch/Switch.theme.js +1 -1
- package/dist/components/forms/TimePicker/TimePicker.theme.js +19 -19
- package/dist/components/forms/forms.theme.js +8 -8
- package/dist/components/navigation/NavItem/NavItem.js +93 -0
- package/dist/components/navigation/NavItem/NavItem.theme.js +27 -0
- package/dist/components/navigation/Sidebar/Sidebar.js +28 -0
- package/dist/components/navigation/Sidebar/Sidebar.theme.js +16 -0
- package/dist/components/navigation/Sidebar/SidebarContent.js +12 -0
- package/dist/components/navigation/Sidebar/SidebarContext.js +38 -0
- package/dist/components/navigation/Sidebar/SidebarFooter.js +11 -0
- package/dist/components/navigation/Sidebar/SidebarHeader.js +22 -0
- package/dist/components/navigation/Sidebar/SidebarNav.js +11 -0
- package/dist/components/navigation/Sidebar/SidebarNavGroup.js +19 -0
- package/dist/components/navigation/Sidebar/SidebarToggle.js +26 -0
- package/dist/icons/core/TickIcon.js +3 -1
- package/dist/index.d.ts +29 -4
- package/dist/index.js +64 -4
- package/dist/node_modules/@heroicons/react/20/solid/esm/ChevronDownIcon.js +26 -0
- package/dist/node_modules/@heroicons/react/24/outline/esm/ChevronDoubleLeftIcon.js +28 -0
- package/dist/node_modules/@heroicons/react/24/outline/esm/ChevronDoubleRightIcon.js +28 -0
- package/dist/node_modules/@heroicons/react/24/outline/esm/ChevronLeftIcon.js +28 -0
- package/dist/node_modules/@heroicons/react/24/outline/esm/Cog6ToothIcon.js +32 -0
- package/dist/node_modules/@heroicons/react/24/outline/esm/DocumentIcon.js +28 -0
- package/dist/node_modules/@heroicons/react/24/outline/esm/EllipsisVerticalIcon.js +28 -0
- package/dist/node_modules/@heroicons/react/24/outline/esm/PlusIcon.js +28 -0
- package/dist/node_modules/@heroicons/react/24/solid/esm/ArrowPathIcon.js +26 -0
- package/dist/node_modules/@heroicons/react/24/solid/esm/BellIcon.js +26 -0
- package/dist/node_modules/@heroicons/react/24/solid/esm/CheckCircleIcon.js +26 -0
- package/dist/node_modules/@heroicons/react/24/solid/esm/ExclamationTriangleIcon.js +26 -0
- package/dist/node_modules/@heroicons/react/24/solid/esm/InformationCircleIcon.js +26 -0
- package/dist/node_modules/@heroicons/react/24/solid/esm/XCircleIcon.js +26 -0
- package/dist/node_modules/@heroicons/react/24/solid/esm/XMarkIcon.js +26 -0
- package/dist/node_modules/tslib/tslib.es6.js +15 -1
- package/dist/utils/dateUtils.js +32 -0
- package/dist/utils/debounce.js +21 -0
- package/package.json +3 -4
- package/dist/styles.css +0 -2
|
@@ -0,0 +1,396 @@
|
|
|
1
|
+
import { __rest, __assign } from '../../../node_modules/tslib/tslib.es6.js';
|
|
2
|
+
import React__default, { useRef, useState, useEffect } from 'react';
|
|
3
|
+
import { cn } from '../../../utils/cn.js';
|
|
4
|
+
import { useChartTheme } from '../hooks/useChartTheme.js';
|
|
5
|
+
import { useTooltipPosition } from '../hooks/useTooltipPosition.js';
|
|
6
|
+
import { useChartAccessibility } from '../hooks/useChartAccessibility.js';
|
|
7
|
+
import { XAxis } from '../shared/ChartAxis/XAxis.js';
|
|
8
|
+
import { YAxis } from '../shared/ChartAxis/YAxis.js';
|
|
9
|
+
import { HorizontalGrid } from '../shared/ChartGrid/HorizontalGrid.js';
|
|
10
|
+
import { ChartTooltip } from '../shared/ChartTooltip/ChartTooltip.js';
|
|
11
|
+
import { ChartMarker } from '../shared/ChartMarker/ChartMarker.js';
|
|
12
|
+
import { ChartCrosshair } from '../shared/ChartCrosshair/ChartCrosshair.js';
|
|
13
|
+
import { getColorValue } from '../utils/color-utils.js';
|
|
14
|
+
import { LINE_CHART_DEFAULTS } from './LineChart.types.js';
|
|
15
|
+
|
|
16
|
+
// Color configuration for data series
|
|
17
|
+
var getSeriesColorClass = function (index) {
|
|
18
|
+
var colors = [
|
|
19
|
+
"stroke-primary-base",
|
|
20
|
+
"stroke-warning-base",
|
|
21
|
+
"stroke-success-base",
|
|
22
|
+
"stroke-error-base",
|
|
23
|
+
"stroke-info-base",
|
|
24
|
+
"stroke-secondary-base",
|
|
25
|
+
];
|
|
26
|
+
return colors[index % colors.length];
|
|
27
|
+
};
|
|
28
|
+
// Monotone cubic interpolation implementation based on D3's curveMonotoneX
|
|
29
|
+
var generateMonotonePath = function (points) {
|
|
30
|
+
if (points.length === 0)
|
|
31
|
+
return "";
|
|
32
|
+
if (points.length === 1)
|
|
33
|
+
return "M ".concat(points[0].x, " ").concat(points[0].y);
|
|
34
|
+
var path = "M ".concat(points[0].x, " ").concat(points[0].y);
|
|
35
|
+
for (var i = 1; i < points.length; i++) {
|
|
36
|
+
var prev = points[i - 1];
|
|
37
|
+
var curr = points[i];
|
|
38
|
+
// Calculate control points for smooth curve
|
|
39
|
+
var dx = curr.x - prev.x;
|
|
40
|
+
curr.y - prev.y;
|
|
41
|
+
// Control point distance (adjust for smoothness)
|
|
42
|
+
var controlDistance = dx * 0.3;
|
|
43
|
+
var cp1x = prev.x + controlDistance;
|
|
44
|
+
var cp1y = prev.y;
|
|
45
|
+
var cp2x = curr.x - controlDistance;
|
|
46
|
+
var cp2y = curr.y;
|
|
47
|
+
path += " C ".concat(cp1x, " ").concat(cp1y, ", ").concat(cp2x, " ").concat(cp2y, ", ").concat(curr.x, " ").concat(curr.y);
|
|
48
|
+
}
|
|
49
|
+
return path;
|
|
50
|
+
};
|
|
51
|
+
var generateLinearPath = function (points) {
|
|
52
|
+
if (points.length === 0)
|
|
53
|
+
return "";
|
|
54
|
+
var path = "M ".concat(points[0].x, " ").concat(points[0].y);
|
|
55
|
+
for (var i = 1; i < points.length; i++) {
|
|
56
|
+
path += " L ".concat(points[i].x, " ").concat(points[i].y);
|
|
57
|
+
}
|
|
58
|
+
return path;
|
|
59
|
+
};
|
|
60
|
+
// Simple curve implementation
|
|
61
|
+
var generateCurvePath = function (points, curveType) {
|
|
62
|
+
if (curveType === void 0) { curveType = "monotone"; }
|
|
63
|
+
if (points.length === 0)
|
|
64
|
+
return "";
|
|
65
|
+
if (points.length === 1)
|
|
66
|
+
return "M ".concat(points[0].x, " ").concat(points[0].y);
|
|
67
|
+
switch (curveType) {
|
|
68
|
+
case "monotone":
|
|
69
|
+
return generateMonotonePath(points);
|
|
70
|
+
case "linear":
|
|
71
|
+
return generateLinearPath(points);
|
|
72
|
+
default:
|
|
73
|
+
return generateLinearPath(points);
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
var LineChart = function (_a) {
|
|
77
|
+
var data = _a.data, config = _a.config,
|
|
78
|
+
// Standardized display props with defaults
|
|
79
|
+
_b = _a.showGrid,
|
|
80
|
+
// Standardized display props with defaults
|
|
81
|
+
showGrid = _b === void 0 ? LINE_CHART_DEFAULTS.showGrid : _b, _c = _a.showXAxis, showXAxis = _c === void 0 ? LINE_CHART_DEFAULTS.showXAxis : _c, _d = _a.showYAxis, showYAxis = _d === void 0 ? LINE_CHART_DEFAULTS.showYAxis : _d, _e = _a.showNullValues, showNullValues = _e === void 0 ? LINE_CHART_DEFAULTS.showNullValues : _e, propMinValue = _a.minValue, propMaxValue = _a.maxValue, _f = _a.variant, variant = _f === void 0 ? LINE_CHART_DEFAULTS.variant : _f, theme = _a.theme,
|
|
82
|
+
// Standardized visual props with defaults (renamed from line-specific names)
|
|
83
|
+
_g = _a.radius,
|
|
84
|
+
// Standardized visual props with defaults (renamed from line-specific names)
|
|
85
|
+
radius = _g === void 0 ? LINE_CHART_DEFAULTS.radius : _g, _h = _a.strokeWidth, strokeWidth = _h === void 0 ? LINE_CHART_DEFAULTS.strokeWidth : _h, _j = _a.curved, curved = _j === void 0 ? LINE_CHART_DEFAULTS.curved : _j, _k = _a.curveType, curveType = _k === void 0 ? LINE_CHART_DEFAULTS.curveType : _k, _l = _a.showDots, showDots = _l === void 0 ? LINE_CHART_DEFAULTS.showDots : _l,
|
|
86
|
+
// Base props
|
|
87
|
+
className = _a.className, title = _a.title, description = _a.description, _m = _a.enableKeyboardNavigation, enableKeyboardNavigation = _m === void 0 ? LINE_CHART_DEFAULTS.enableKeyboardNavigation : _m, children = _a.children, props = __rest(_a, ["data", "config", "showGrid", "showXAxis", "showYAxis", "showNullValues", "minValue", "maxValue", "variant", "theme", "radius", "strokeWidth", "curved", "curveType", "showDots", "className", "title", "description", "enableKeyboardNavigation", "children"]);
|
|
88
|
+
// Use the new theme system
|
|
89
|
+
var _o = useChartTheme({ config: config, variant: variant, theme: theme }); _o.getSeriesColor; _o.getColorClass; _o.getOpacityClass; _o.getTransitionClass;
|
|
90
|
+
// Legacy support
|
|
91
|
+
_o.getThemeValue;
|
|
92
|
+
var containerRef = useRef(null);
|
|
93
|
+
var _p = useState({ width: 600, height: 400 }), dimensions = _p[0], setDimensions = _p[1];
|
|
94
|
+
var _q = useState(null), hoveredPoint = _q[0], setHoveredPoint = _q[1];
|
|
95
|
+
// Detect if device is mobile/touch
|
|
96
|
+
var isMobile = typeof window !== 'undefined' &&
|
|
97
|
+
('ontouchstart' in window || navigator.maxTouchPoints > 0);
|
|
98
|
+
// Use the new tooltip positioning hook
|
|
99
|
+
var _r = useTooltipPosition({
|
|
100
|
+
containerRef: containerRef,
|
|
101
|
+
isMobile: isMobile,
|
|
102
|
+
}), tooltipData = _r.tooltipData, tooltipRef = _r.tooltipRef, handleMouseEnter = _r.handleMouseEnter, handleMouseMove = _r.handleMouseMove, handleMouseLeave = _r.handleMouseLeave;
|
|
103
|
+
// Use accessibility hook
|
|
104
|
+
var _s = useChartAccessibility({
|
|
105
|
+
chartType: 'line',
|
|
106
|
+
data: data,
|
|
107
|
+
config: config,
|
|
108
|
+
title: title,
|
|
109
|
+
description: description,
|
|
110
|
+
enableKeyboardNavigation: enableKeyboardNavigation,
|
|
111
|
+
}), chartAccessibilityProps = _s.chartAccessibilityProps, descriptionProps = _s.descriptionProps, focusedElementIndex = _s.focusedElementIndex, isKeyboardMode = _s.isKeyboardMode, handleMouseInteraction = _s.handleMouseInteraction;
|
|
112
|
+
// Measure container dimensions
|
|
113
|
+
useEffect(function () {
|
|
114
|
+
var updateDimensions = function () {
|
|
115
|
+
if (containerRef.current) {
|
|
116
|
+
var _a = containerRef.current.getBoundingClientRect(), width = _a.width, height = _a.height;
|
|
117
|
+
setDimensions({
|
|
118
|
+
width: width || 600,
|
|
119
|
+
height: height || 400,
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
updateDimensions();
|
|
124
|
+
var resizeObserver = new ResizeObserver(updateDimensions);
|
|
125
|
+
if (containerRef.current) {
|
|
126
|
+
resizeObserver.observe(containerRef.current);
|
|
127
|
+
}
|
|
128
|
+
return function () {
|
|
129
|
+
resizeObserver.disconnect();
|
|
130
|
+
};
|
|
131
|
+
}, []);
|
|
132
|
+
// Early return if no data
|
|
133
|
+
if (!data || data.length === 0) {
|
|
134
|
+
return (React__default.createElement("div", __assign({ className: cn("chart-container flex items-center justify-center text-neutral-500", className), role: "img", "aria-label": "Empty line chart" }, props),
|
|
135
|
+
React__default.createElement("span", null, "No data available")));
|
|
136
|
+
}
|
|
137
|
+
// Calculate dimensions
|
|
138
|
+
var margin = {
|
|
139
|
+
top: 0,
|
|
140
|
+
right: 0,
|
|
141
|
+
bottom: showXAxis ? 40 : 0, // Reduce bottom margin when X-axis is hidden
|
|
142
|
+
left: showYAxis ? 60 : 0, // Reduce left margin when Y-axis is hidden
|
|
143
|
+
};
|
|
144
|
+
var innerWidth = dimensions.width - margin.left - margin.right;
|
|
145
|
+
var innerHeight = dimensions.height - margin.top - margin.bottom;
|
|
146
|
+
// Get all data keys from config
|
|
147
|
+
var dataKeys = Object.keys(config);
|
|
148
|
+
// Calculate scales
|
|
149
|
+
var rawMaxValue = Math.max.apply(Math, data.map(function (item) {
|
|
150
|
+
return Math.max.apply(Math, dataKeys.map(function (key) {
|
|
151
|
+
var value = item[key];
|
|
152
|
+
return typeof value === "number" ? value : 0;
|
|
153
|
+
}));
|
|
154
|
+
}));
|
|
155
|
+
var minValue = propMinValue !== null && propMinValue !== void 0 ? propMinValue : 0;
|
|
156
|
+
var maxValue = propMaxValue !== null && propMaxValue !== void 0 ? propMaxValue : (function () {
|
|
157
|
+
if (rawMaxValue <= 10)
|
|
158
|
+
return Math.ceil(rawMaxValue);
|
|
159
|
+
if (rawMaxValue <= 100)
|
|
160
|
+
return Math.ceil(rawMaxValue / 5) * 5;
|
|
161
|
+
if (rawMaxValue <= 1000)
|
|
162
|
+
return Math.ceil(rawMaxValue / 50) * 50;
|
|
163
|
+
if (rawMaxValue <= 10000)
|
|
164
|
+
return Math.ceil(rawMaxValue / 500) * 500;
|
|
165
|
+
return Math.ceil(rawMaxValue / 1000) * 1000;
|
|
166
|
+
})();
|
|
167
|
+
// Calculate point position
|
|
168
|
+
var getPointPosition = function (dataIndex, value) {
|
|
169
|
+
// Spread points evenly across the full width
|
|
170
|
+
// First point at left edge (margin.left), last point at right edge (margin.left + innerWidth)
|
|
171
|
+
var x = data.length === 1
|
|
172
|
+
? margin.left + innerWidth / 2 // Center single point
|
|
173
|
+
: margin.left + (dataIndex / (data.length - 1)) * innerWidth;
|
|
174
|
+
var y = margin.top +
|
|
175
|
+
innerHeight -
|
|
176
|
+
((value - minValue) / (maxValue - minValue)) * innerHeight;
|
|
177
|
+
return { x: x, y: y };
|
|
178
|
+
};
|
|
179
|
+
// Generate SVG path for line with null value handling
|
|
180
|
+
var generatePath = function (key) {
|
|
181
|
+
if (!showNullValues) {
|
|
182
|
+
// Original behavior: skip null values entirely
|
|
183
|
+
var points_1 = [];
|
|
184
|
+
data.forEach(function (item, index) {
|
|
185
|
+
var rawValue = item[key];
|
|
186
|
+
var isNull = rawValue === null || rawValue === undefined;
|
|
187
|
+
var value = isNull ? 0 : typeof rawValue === "number" ? rawValue : 0;
|
|
188
|
+
if (!isNull) {
|
|
189
|
+
var _a = getPointPosition(index, value), x = _a.x, y = _a.y;
|
|
190
|
+
points_1.push({ x: x, y: y });
|
|
191
|
+
}
|
|
192
|
+
});
|
|
193
|
+
return generateCurvePath(points_1, curved ? curveType : "linear");
|
|
194
|
+
}
|
|
195
|
+
else {
|
|
196
|
+
// New behavior: break lines at null values
|
|
197
|
+
var segments_1 = [];
|
|
198
|
+
var currentSegment_1 = [];
|
|
199
|
+
data.forEach(function (item, index) {
|
|
200
|
+
var rawValue = item[key];
|
|
201
|
+
var isNull = rawValue === null || rawValue === undefined;
|
|
202
|
+
if (isNull) {
|
|
203
|
+
// End current segment and start a new one
|
|
204
|
+
if (currentSegment_1.length > 0) {
|
|
205
|
+
segments_1.push(currentSegment_1);
|
|
206
|
+
currentSegment_1 = [];
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
else {
|
|
210
|
+
var value = typeof rawValue === "number" ? rawValue : 0;
|
|
211
|
+
var _a = getPointPosition(index, value), x = _a.x, y = _a.y;
|
|
212
|
+
currentSegment_1.push({ x: x, y: y });
|
|
213
|
+
}
|
|
214
|
+
});
|
|
215
|
+
// Add the last segment if it has points
|
|
216
|
+
if (currentSegment_1.length > 0) {
|
|
217
|
+
segments_1.push(currentSegment_1);
|
|
218
|
+
}
|
|
219
|
+
// Generate path for each segment
|
|
220
|
+
return segments_1
|
|
221
|
+
.map(function (segment) { return generateCurvePath(segment, curved ? curveType : "linear"); })
|
|
222
|
+
.join(" ");
|
|
223
|
+
}
|
|
224
|
+
};
|
|
225
|
+
// Handle keyboard focus tooltips
|
|
226
|
+
useEffect(function () {
|
|
227
|
+
if (isKeyboardMode && focusedElementIndex >= 0 && focusedElementIndex < data.length) {
|
|
228
|
+
var item_1 = data[focusedElementIndex];
|
|
229
|
+
// Create multi-series tooltip data
|
|
230
|
+
var seriesData = dataKeys.map(function (seriesKey, keyIndex) {
|
|
231
|
+
var _a, _b;
|
|
232
|
+
var seriesValue = item_1[seriesKey];
|
|
233
|
+
var numValue = typeof seriesValue === 'number' ? seriesValue : 0;
|
|
234
|
+
var colorClass = getSeriesColorClass(keyIndex);
|
|
235
|
+
return {
|
|
236
|
+
key: seriesKey,
|
|
237
|
+
label: ((_a = config[seriesKey]) === null || _a === void 0 ? void 0 : _a.label) || seriesKey,
|
|
238
|
+
value: numValue,
|
|
239
|
+
color: ((_b = config[seriesKey]) === null || _b === void 0 ? void 0 : _b.color) || getColorValue(colorClass)
|
|
240
|
+
};
|
|
241
|
+
});
|
|
242
|
+
var content = {
|
|
243
|
+
category: item_1.name || "Category ".concat(focusedElementIndex + 1),
|
|
244
|
+
series: seriesData
|
|
245
|
+
};
|
|
246
|
+
// Calculate position for focused point
|
|
247
|
+
var pointX = data.length === 1
|
|
248
|
+
? margin.left + innerWidth / 2
|
|
249
|
+
: margin.left + (focusedElementIndex / (data.length - 1)) * innerWidth;
|
|
250
|
+
var svgCoordinates = {
|
|
251
|
+
x: pointX,
|
|
252
|
+
y: margin.top + innerHeight / 2,
|
|
253
|
+
dimensions: dimensions
|
|
254
|
+
};
|
|
255
|
+
// Simulate mouse enter for keyboard focus
|
|
256
|
+
var syntheticEvent = new MouseEvent('mouseenter', {
|
|
257
|
+
clientX: pointX,
|
|
258
|
+
clientY: margin.top + innerHeight / 2,
|
|
259
|
+
});
|
|
260
|
+
handleMouseEnter(syntheticEvent, content, svgCoordinates);
|
|
261
|
+
}
|
|
262
|
+
else if (isKeyboardMode && focusedElementIndex === -1) {
|
|
263
|
+
// Only clear tooltip when explicitly exiting keyboard mode (Escape key)
|
|
264
|
+
handleMouseLeave();
|
|
265
|
+
}
|
|
266
|
+
// Don't clear tooltips when switching from keyboard to mouse mode
|
|
267
|
+
}, [isKeyboardMode, focusedElementIndex, data, config, dimensions, margin, innerWidth, innerHeight, dataKeys, handleMouseEnter, handleMouseLeave]);
|
|
268
|
+
return (React__default.createElement("div", __assign({ ref: containerRef, className: cn("chart-container w-full h-full", className) }, chartAccessibilityProps, { onMouseEnter: handleMouseInteraction, onMouseMove: handleMouseInteraction }, props),
|
|
269
|
+
descriptionProps && React__default.createElement("div", __assign({}, descriptionProps)),
|
|
270
|
+
React__default.createElement("svg", { width: "100%", height: "100%", viewBox: "0 0 ".concat(dimensions.width, " ").concat(dimensions.height), className: "overflow-visible", role: "presentation" },
|
|
271
|
+
React__default.createElement("defs", null,
|
|
272
|
+
React__default.createElement("filter", { id: "line-shadow", x: "-20%", y: "-20%", width: "140%", height: "140%" },
|
|
273
|
+
React__default.createElement("feDropShadow", { dx: "8", dy: "8", stdDeviation: "8", floodOpacity: "0.15", floodColor: "#000000" })),
|
|
274
|
+
React__default.createElement("linearGradient", { id: "vertical-fade", x1: "0%", y1: "0%", x2: "0%", y2: "100%" },
|
|
275
|
+
React__default.createElement("stop", { offset: "0%", stopColor: "#6b7280", stopOpacity: "0" }),
|
|
276
|
+
React__default.createElement("stop", { offset: "40%", stopColor: "#6b7280", stopOpacity: "0.3" }),
|
|
277
|
+
React__default.createElement("stop", { offset: "50%", stopColor: "#6b7280", stopOpacity: "0.5" }),
|
|
278
|
+
React__default.createElement("stop", { offset: "60%", stopColor: "#6b7280", stopOpacity: "0.3" }),
|
|
279
|
+
React__default.createElement("stop", { offset: "100%", stopColor: "#6b7280", stopOpacity: "0" })),
|
|
280
|
+
React__default.createElement("linearGradient", { id: "horizontal-fade", x1: "0%", y1: "0%", x2: "100%", y2: "0%" },
|
|
281
|
+
React__default.createElement("stop", { offset: "0%", stopColor: "#6b7280", stopOpacity: "0" }),
|
|
282
|
+
React__default.createElement("stop", { offset: "40%", stopColor: "#6b7280", stopOpacity: "0.3" }),
|
|
283
|
+
React__default.createElement("stop", { offset: "50%", stopColor: "#6b7280", stopOpacity: "0.5" }),
|
|
284
|
+
React__default.createElement("stop", { offset: "60%", stopColor: "#6b7280", stopOpacity: "0.3" }),
|
|
285
|
+
React__default.createElement("stop", { offset: "100%", stopColor: "#6b7280", stopOpacity: "0" }))),
|
|
286
|
+
React__default.createElement(HorizontalGrid, { show: showGrid, x: margin.left, y: margin.top, width: innerWidth, height: innerHeight, lineCount: 5 }),
|
|
287
|
+
React__default.createElement(ChartCrosshair, { show: hoveredPoint !== null, x: hoveredPoint !== null ? (data.length === 1
|
|
288
|
+
? margin.left + innerWidth / 2
|
|
289
|
+
: margin.left + (hoveredPoint.index / (data.length - 1)) * innerWidth) : 0, y: hoveredPoint !== null && dataKeys.length === 1 ? (function () {
|
|
290
|
+
var item = data[hoveredPoint.index];
|
|
291
|
+
var singleKey = dataKeys[0];
|
|
292
|
+
var singleValue = item[singleKey];
|
|
293
|
+
var numValue = typeof singleValue === 'number' ? singleValue : 0;
|
|
294
|
+
return margin.top + innerHeight - ((numValue - minValue) / (maxValue - minValue)) * innerHeight;
|
|
295
|
+
})() : undefined, margin: margin, innerWidth: innerWidth, innerHeight: innerHeight, showHorizontal: dataKeys.length === 1 }),
|
|
296
|
+
React__default.createElement(YAxis, { show: showYAxis, min: minValue, max: maxValue, x: margin.left, y: margin.top, height: innerHeight, showGrid: false, gridWidth: innerWidth, tickFormatter: function (value) {
|
|
297
|
+
if (value >= 1000)
|
|
298
|
+
return "".concat((value / 1000).toFixed(0), "k");
|
|
299
|
+
return value.toString();
|
|
300
|
+
} }),
|
|
301
|
+
React__default.createElement("g", { className: "chart-lines" }, dataKeys.map(function (key, keyIndex) {
|
|
302
|
+
var targetPath = generatePath(key);
|
|
303
|
+
var colorClass = getSeriesColorClass(keyIndex);
|
|
304
|
+
return (React__default.createElement("g", { key: key },
|
|
305
|
+
React__default.createElement("path", { d: targetPath, fill: "none", strokeWidth: strokeWidth, strokeLinecap: "round", className: cn("transition-all duration-200", colorClass), filter: "url(#line-shadow)" }),
|
|
306
|
+
showDots &&
|
|
307
|
+
data.map(function (item, dataIndex) {
|
|
308
|
+
var rawValue = item[key];
|
|
309
|
+
var isNull = rawValue === null || rawValue === undefined;
|
|
310
|
+
var value = isNull
|
|
311
|
+
? 0
|
|
312
|
+
: typeof rawValue === "number"
|
|
313
|
+
? rawValue
|
|
314
|
+
: 0;
|
|
315
|
+
// Don't render dots for null values regardless of showNullValues
|
|
316
|
+
if (isNull)
|
|
317
|
+
return null;
|
|
318
|
+
var _a = getPointPosition(dataIndex, value), x = _a.x, y = _a.y;
|
|
319
|
+
(hoveredPoint === null || hoveredPoint === void 0 ? void 0 : hoveredPoint.index) === dataIndex && hoveredPoint.key === key;
|
|
320
|
+
var isFocused = isKeyboardMode && focusedElementIndex === dataIndex;
|
|
321
|
+
return (React__default.createElement("g", { key: "".concat(key, "-").concat(dataIndex) },
|
|
322
|
+
React__default.createElement(ChartMarker, { cx: x, cy: y, radius: isFocused ? radius + 2 : radius, colorClass: cn(colorClass.replace("stroke-", "stroke-"), isFocused && "stroke-primary-600 stroke-2") })));
|
|
323
|
+
})));
|
|
324
|
+
})),
|
|
325
|
+
!showDots && hoveredPoint !== null && (React__default.createElement("g", { className: "chart-hover-markers" }, dataKeys.map(function (key, keyIndex) {
|
|
326
|
+
var item = data[hoveredPoint.index];
|
|
327
|
+
var rawValue = item[key];
|
|
328
|
+
var isNull = rawValue === null || rawValue === undefined;
|
|
329
|
+
var value = isNull
|
|
330
|
+
? 0
|
|
331
|
+
: typeof rawValue === "number"
|
|
332
|
+
? rawValue
|
|
333
|
+
: 0;
|
|
334
|
+
// Don't render hover markers for null values
|
|
335
|
+
if (isNull)
|
|
336
|
+
return null;
|
|
337
|
+
var _a = getPointPosition(hoveredPoint.index, value), x = _a.x, y = _a.y;
|
|
338
|
+
var colorClass = getSeriesColorClass(keyIndex);
|
|
339
|
+
return (React__default.createElement(ChartMarker, { key: "hover-".concat(key, "-").concat(hoveredPoint.index), cx: x, cy: y, radius: radius, colorClass: colorClass.replace("stroke-", "stroke-") }));
|
|
340
|
+
}))),
|
|
341
|
+
React__default.createElement("g", { className: "chart-hover-areas" }, data.map(function (item, dataIndex) {
|
|
342
|
+
// Calculate hover area based on new point positioning
|
|
343
|
+
var pointX = data.length === 1
|
|
344
|
+
? margin.left + innerWidth / 2
|
|
345
|
+
: margin.left + (dataIndex / (data.length - 1)) * innerWidth;
|
|
346
|
+
// Create hover area around each point
|
|
347
|
+
var hoverWidth = data.length === 1 ? innerWidth : innerWidth / (data.length - 1);
|
|
348
|
+
var hoverX = data.length === 1
|
|
349
|
+
? margin.left
|
|
350
|
+
: Math.max(margin.left, pointX - hoverWidth / 2);
|
|
351
|
+
// Ensure hover area doesn't exceed chart bounds
|
|
352
|
+
var adjustedWidth = data.length === 1
|
|
353
|
+
? innerWidth
|
|
354
|
+
: Math.min(hoverWidth, margin.left + innerWidth - hoverX);
|
|
355
|
+
return (React__default.createElement("rect", { key: "hover-".concat(dataIndex), x: hoverX, y: margin.top, width: adjustedWidth, height: innerHeight, fill: "transparent", className: "cursor-pointer", onMouseEnter: function (e) {
|
|
356
|
+
setHoveredPoint({ index: dataIndex, key: dataKeys[0] });
|
|
357
|
+
// Create multi-series tooltip data
|
|
358
|
+
var seriesData = dataKeys.map(function (seriesKey, keyIndex) {
|
|
359
|
+
var _a, _b;
|
|
360
|
+
var seriesValue = item[seriesKey];
|
|
361
|
+
var numValue = typeof seriesValue === 'number' ? seriesValue : 0;
|
|
362
|
+
var colorClass = getSeriesColorClass(keyIndex);
|
|
363
|
+
return {
|
|
364
|
+
key: seriesKey,
|
|
365
|
+
label: ((_a = config[seriesKey]) === null || _a === void 0 ? void 0 : _a.label) || seriesKey,
|
|
366
|
+
value: numValue,
|
|
367
|
+
color: ((_b = config[seriesKey]) === null || _b === void 0 ? void 0 : _b.color) || getColorValue(colorClass)
|
|
368
|
+
};
|
|
369
|
+
});
|
|
370
|
+
var content = {
|
|
371
|
+
category: item.name || "Category ".concat(dataIndex + 1),
|
|
372
|
+
series: seriesData
|
|
373
|
+
};
|
|
374
|
+
var svgCoordinates = {
|
|
375
|
+
x: pointX,
|
|
376
|
+
y: margin.top + innerHeight / 2,
|
|
377
|
+
dimensions: dimensions
|
|
378
|
+
};
|
|
379
|
+
handleMouseEnter(e, content, svgCoordinates);
|
|
380
|
+
}, onMouseMove: function (e) {
|
|
381
|
+
if ((hoveredPoint === null || hoveredPoint === void 0 ? void 0 : hoveredPoint.index) === dataIndex) {
|
|
382
|
+
var svgCoordinates = {
|
|
383
|
+
x: pointX,
|
|
384
|
+
y: margin.top + innerHeight / 2,
|
|
385
|
+
dimensions: dimensions
|
|
386
|
+
};
|
|
387
|
+
handleMouseMove(e, svgCoordinates);
|
|
388
|
+
}
|
|
389
|
+
}, onMouseLeave: handleMouseLeave }));
|
|
390
|
+
})),
|
|
391
|
+
React__default.createElement(XAxis, { show: showXAxis, data: data, x: margin.left, y: margin.top + innerHeight, width: innerWidth, categoryWidth: innerWidth / data.length, categoryGap: 0 })),
|
|
392
|
+
React__default.createElement(ChartTooltip, { active: !!tooltipData, position: tooltipData ? { x: tooltipData.x, y: tooltipData.y } : { x: 0, y: 0 }, tooltipRef: tooltipRef, content: tooltipData === null || tooltipData === void 0 ? void 0 : tooltipData.content, chartType: "line" }),
|
|
393
|
+
children));
|
|
394
|
+
};
|
|
395
|
+
|
|
396
|
+
export { LineChart };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { __assign } from '../../../node_modules/tslib/tslib.es6.js';
|
|
2
|
+
import { CHART_DEFAULTS } from '../types/chart.types.js';
|
|
3
|
+
|
|
4
|
+
// Default values using centralized defaults
|
|
5
|
+
var LINE_CHART_DEFAULTS = __assign(__assign({}, CHART_DEFAULTS), { radius: CHART_DEFAULTS.radius, strokeWidth: CHART_DEFAULTS.strokeWidth, curved: CHART_DEFAULTS.curved, curveType: CHART_DEFAULTS.curveType, showDots: CHART_DEFAULTS.showDots });
|
|
6
|
+
|
|
7
|
+
export { LINE_CHART_DEFAULTS };
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { useState, useRef, useCallback } from 'react';
|
|
2
|
+
|
|
3
|
+
function useChartAccessibility(_a) {
|
|
4
|
+
var chartType = _a.chartType, data = _a.data, config = _a.config, title = _a.title, description = _a.description, _b = _a.enableKeyboardNavigation, enableKeyboardNavigation = _b === void 0 ? true : _b;
|
|
5
|
+
var _c = useState(-1), focusedElementIndex = _c[0], setFocusedElementIndex = _c[1];
|
|
6
|
+
var _d = useState(false), isKeyboardMode = _d[0], setIsKeyboardMode = _d[1];
|
|
7
|
+
var descriptionId = useRef("chart-description-".concat(Math.random().toString(36).substr(2, 9)));
|
|
8
|
+
// Generate chart summary for screen readers
|
|
9
|
+
var generateChartSummary = useCallback(function () {
|
|
10
|
+
var _a;
|
|
11
|
+
var dataKeys = Object.keys(config);
|
|
12
|
+
var dataCount = data.length;
|
|
13
|
+
var summary = '';
|
|
14
|
+
// Chart type and basic info
|
|
15
|
+
switch (chartType) {
|
|
16
|
+
case 'bar':
|
|
17
|
+
summary = "Bar chart with ".concat(dataCount, " categories");
|
|
18
|
+
break;
|
|
19
|
+
case 'line':
|
|
20
|
+
summary = "Line chart with ".concat(dataCount, " data points");
|
|
21
|
+
break;
|
|
22
|
+
case 'area':
|
|
23
|
+
summary = "Area chart with ".concat(dataCount, " data points");
|
|
24
|
+
break;
|
|
25
|
+
case 'heatmap':
|
|
26
|
+
summary = "Heatmap with ".concat(dataCount, " data cells");
|
|
27
|
+
break;
|
|
28
|
+
}
|
|
29
|
+
// Add series information
|
|
30
|
+
if (dataKeys.length > 1) {
|
|
31
|
+
summary += " showing ".concat(dataKeys.length, " data series: ").concat(dataKeys.map(function (key) { var _a; return ((_a = config[key]) === null || _a === void 0 ? void 0 : _a.label) || key; }).join(', '));
|
|
32
|
+
}
|
|
33
|
+
else if (dataKeys.length === 1) {
|
|
34
|
+
var seriesLabel = ((_a = config[dataKeys[0]]) === null || _a === void 0 ? void 0 : _a.label) || dataKeys[0];
|
|
35
|
+
summary += " showing ".concat(seriesLabel);
|
|
36
|
+
}
|
|
37
|
+
// Add data range information for numeric charts
|
|
38
|
+
if (chartType !== 'heatmap' && data.length > 0) {
|
|
39
|
+
var values = data.flatMap(function (item) {
|
|
40
|
+
return dataKeys.map(function (key) { return typeof item[key] === 'number' ? item[key] : 0; });
|
|
41
|
+
}).filter(function (val) { return val !== 0; });
|
|
42
|
+
if (values.length > 0) {
|
|
43
|
+
var min = Math.min.apply(Math, values);
|
|
44
|
+
var max = Math.max.apply(Math, values);
|
|
45
|
+
summary += ". Values range from ".concat(min, " to ").concat(max);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return summary;
|
|
49
|
+
}, [chartType, data, config]);
|
|
50
|
+
// Generate ARIA label
|
|
51
|
+
var generateAriaLabel = useCallback(function () {
|
|
52
|
+
if (title) {
|
|
53
|
+
return "".concat(title, ". ").concat(generateChartSummary());
|
|
54
|
+
}
|
|
55
|
+
return generateChartSummary();
|
|
56
|
+
}, [title, generateChartSummary]);
|
|
57
|
+
// Handle keyboard navigation
|
|
58
|
+
var handleKeyDown = useCallback(function (event) {
|
|
59
|
+
if (!enableKeyboardNavigation)
|
|
60
|
+
return;
|
|
61
|
+
// Enable keyboard mode on first keyboard interaction
|
|
62
|
+
if (!isKeyboardMode) {
|
|
63
|
+
setIsKeyboardMode(true);
|
|
64
|
+
}
|
|
65
|
+
var maxIndex = data.length - 1;
|
|
66
|
+
switch (event.key) {
|
|
67
|
+
case 'ArrowRight':
|
|
68
|
+
case 'ArrowDown':
|
|
69
|
+
event.preventDefault();
|
|
70
|
+
setFocusedElementIndex(function (prev) {
|
|
71
|
+
return prev >= maxIndex ? 0 : prev + 1;
|
|
72
|
+
});
|
|
73
|
+
break;
|
|
74
|
+
case 'ArrowLeft':
|
|
75
|
+
case 'ArrowUp':
|
|
76
|
+
event.preventDefault();
|
|
77
|
+
setFocusedElementIndex(function (prev) {
|
|
78
|
+
return prev <= 0 ? maxIndex : prev - 1;
|
|
79
|
+
});
|
|
80
|
+
break;
|
|
81
|
+
case 'Home':
|
|
82
|
+
event.preventDefault();
|
|
83
|
+
setFocusedElementIndex(0);
|
|
84
|
+
break;
|
|
85
|
+
case 'End':
|
|
86
|
+
event.preventDefault();
|
|
87
|
+
setFocusedElementIndex(maxIndex);
|
|
88
|
+
break;
|
|
89
|
+
case 'Escape':
|
|
90
|
+
event.preventDefault();
|
|
91
|
+
setFocusedElementIndex(-1);
|
|
92
|
+
setIsKeyboardMode(false);
|
|
93
|
+
break;
|
|
94
|
+
}
|
|
95
|
+
}, [enableKeyboardNavigation, isKeyboardMode, data.length]);
|
|
96
|
+
// Reset keyboard mode on mouse interaction
|
|
97
|
+
var handleMouseInteraction = useCallback(function () {
|
|
98
|
+
if (isKeyboardMode) {
|
|
99
|
+
setIsKeyboardMode(false);
|
|
100
|
+
setFocusedElementIndex(-1);
|
|
101
|
+
}
|
|
102
|
+
}, [isKeyboardMode]);
|
|
103
|
+
// Chart container accessibility props
|
|
104
|
+
var chartAccessibilityProps = {
|
|
105
|
+
role: 'img',
|
|
106
|
+
'aria-label': generateAriaLabel(),
|
|
107
|
+
'aria-describedby': description ? descriptionId.current : undefined,
|
|
108
|
+
tabIndex: enableKeyboardNavigation ? 0 : -1,
|
|
109
|
+
onKeyDown: handleKeyDown,
|
|
110
|
+
};
|
|
111
|
+
// Description element props
|
|
112
|
+
var descriptionProps = description ? {
|
|
113
|
+
id: descriptionId.current,
|
|
114
|
+
className: 'sr-only',
|
|
115
|
+
children: description,
|
|
116
|
+
} : null;
|
|
117
|
+
return {
|
|
118
|
+
chartAccessibilityProps: chartAccessibilityProps,
|
|
119
|
+
descriptionProps: descriptionProps,
|
|
120
|
+
focusedElementIndex: focusedElementIndex,
|
|
121
|
+
isKeyboardMode: isKeyboardMode,
|
|
122
|
+
handleMouseInteraction: handleMouseInteraction,
|
|
123
|
+
generateChartSummary: generateChartSummary,
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
export { useChartAccessibility };
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { __assign } from '../../../node_modules/tslib/tslib.es6.js';
|
|
2
|
+
import { useMemo } from 'react';
|
|
3
|
+
import { chartTheme } from '../theme/chart.theme.js';
|
|
4
|
+
|
|
5
|
+
function useChartTheme(_a) {
|
|
6
|
+
var config = _a.config, _b = _a.variant, variant = _b === void 0 ? 'default' : _b, theme = _a.theme;
|
|
7
|
+
var resolvedTheme = useMemo(function () {
|
|
8
|
+
var _a, _b, _c;
|
|
9
|
+
// Merge default theme with overrides
|
|
10
|
+
var mergedTheme = __assign(__assign({}, chartTheme), { baseStyle: __assign(__assign(__assign({}, chartTheme.baseStyle), ((theme === null || theme === void 0 ? void 0 : theme.baseStyle) || {})), { colors: __assign(__assign({}, chartTheme.baseStyle.colors), (((_a = theme === null || theme === void 0 ? void 0 : theme.baseStyle) === null || _a === void 0 ? void 0 : _a.colors) || {})), opacity: __assign(__assign({}, chartTheme.baseStyle.opacity), (((_b = theme === null || theme === void 0 ? void 0 : theme.baseStyle) === null || _b === void 0 ? void 0 : _b.opacity) || {})), transitions: __assign(__assign({}, chartTheme.baseStyle.transitions), (((_c = theme === null || theme === void 0 ? void 0 : theme.baseStyle) === null || _c === void 0 ? void 0 : _c.transitions) || {})) }), variants: __assign(__assign({}, chartTheme.variants), theme === null || theme === void 0 ? void 0 : theme.variants) });
|
|
11
|
+
return mergedTheme;
|
|
12
|
+
}, [theme]);
|
|
13
|
+
var getSeriesColor = useMemo(function () {
|
|
14
|
+
return function (dataKey, index) {
|
|
15
|
+
var _a, _b, _c;
|
|
16
|
+
// Add null check for config
|
|
17
|
+
if (!config || typeof config !== 'object') {
|
|
18
|
+
// Use base series colors as fallback
|
|
19
|
+
var seriesColors_1 = resolvedTheme.baseStyle.colors.series;
|
|
20
|
+
return seriesColors_1[index % seriesColors_1.length];
|
|
21
|
+
}
|
|
22
|
+
// Priority 1: Check if config has a specific color for this dataKey
|
|
23
|
+
if ((_a = config[dataKey]) === null || _a === void 0 ? void 0 : _a.color) {
|
|
24
|
+
return config[dataKey].color;
|
|
25
|
+
}
|
|
26
|
+
// Priority 2: Use variant colors if available
|
|
27
|
+
var variantColors = (_c = (_b = resolvedTheme.variants) === null || _b === void 0 ? void 0 : _b[variant]) === null || _c === void 0 ? void 0 : _c.colors;
|
|
28
|
+
if (variantColors && variantColors.length > 0) {
|
|
29
|
+
return variantColors[index % variantColors.length];
|
|
30
|
+
}
|
|
31
|
+
// Priority 3: Use base series colors
|
|
32
|
+
var seriesColors = resolvedTheme.baseStyle.colors.series;
|
|
33
|
+
return seriesColors[index % seriesColors.length];
|
|
34
|
+
};
|
|
35
|
+
}, [config, variant, resolvedTheme]);
|
|
36
|
+
var getColorClass = useMemo(function () {
|
|
37
|
+
return function (type) {
|
|
38
|
+
return resolvedTheme.baseStyle.colors[type];
|
|
39
|
+
};
|
|
40
|
+
}, [resolvedTheme]);
|
|
41
|
+
var getOpacityClass = useMemo(function () {
|
|
42
|
+
return function (type) {
|
|
43
|
+
return resolvedTheme.baseStyle.opacity[type];
|
|
44
|
+
};
|
|
45
|
+
}, [resolvedTheme]);
|
|
46
|
+
var getTransitionClass = useMemo(function () {
|
|
47
|
+
return function (type) {
|
|
48
|
+
return resolvedTheme.baseStyle.transitions[type];
|
|
49
|
+
};
|
|
50
|
+
}, [resolvedTheme]);
|
|
51
|
+
// Generate CSS variables for dynamic colors (for cases where Tailwind classes aren't enough)
|
|
52
|
+
var chartColors = useMemo(function () {
|
|
53
|
+
var colors = {};
|
|
54
|
+
// Add null check for config
|
|
55
|
+
if (!config || typeof config !== 'object') {
|
|
56
|
+
return colors;
|
|
57
|
+
}
|
|
58
|
+
Object.entries(config).forEach(function (_a) {
|
|
59
|
+
var key = _a[0], value = _a[1];
|
|
60
|
+
if (value === null || value === void 0 ? void 0 : value.color) {
|
|
61
|
+
colors["--color-".concat(key)] = value.color;
|
|
62
|
+
}
|
|
63
|
+
else if ((value === null || value === void 0 ? void 0 : value.theme) && typeof value.theme === 'string') {
|
|
64
|
+
// Handle theme-based colors
|
|
65
|
+
colors["--color-".concat(key)] = value.theme;
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
return colors;
|
|
69
|
+
}, [config]);
|
|
70
|
+
var getThemeValue = function (key) {
|
|
71
|
+
return "var(--color-".concat(key, ")");
|
|
72
|
+
};
|
|
73
|
+
return {
|
|
74
|
+
// New theme utilities
|
|
75
|
+
getSeriesColor: getSeriesColor,
|
|
76
|
+
getColorClass: getColorClass,
|
|
77
|
+
getOpacityClass: getOpacityClass,
|
|
78
|
+
getTransitionClass: getTransitionClass,
|
|
79
|
+
resolvedTheme: resolvedTheme,
|
|
80
|
+
// Legacy utilities (for backward compatibility)
|
|
81
|
+
chartColors: chartColors,
|
|
82
|
+
getThemeValue: getThemeValue,
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export { useChartTheme };
|