@kubit-ui-web/react-charts 0.1.0 → 1.1.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/README.md +31 -36
- package/dist/cjs/charts/barChart/barChart.js +12 -29
- package/dist/cjs/charts/barChart/barChart.type.js +1 -2
- package/dist/cjs/charts/barChart/barChartStructure.js +25 -29
- package/dist/cjs/charts/barChart/context/barChartContext.js +2 -5
- package/dist/cjs/charts/barChart/context/buildBarContextValues.js +17 -21
- package/dist/cjs/charts/barChart/fragments/barChartPath.js +12 -16
- package/dist/cjs/charts/barChart/fragments/barChartSeparator.js +10 -14
- package/dist/cjs/charts/barChart/fragments/barChartXAxis.js +10 -14
- package/dist/cjs/charts/barChart/fragments/barChartYAxis.js +13 -17
- package/dist/cjs/charts/barChart/fragments/fixture/barContextData.js +3 -6
- package/dist/cjs/charts/barChart/fragments/fixture/index.js +1 -5
- package/dist/cjs/charts/barChart/index.js +1 -17
- package/dist/cjs/charts/barChart/utils/countBarChildren.js +5 -9
- package/dist/cjs/charts/barChart/utils/getAxisExtraSpacing.js +31 -35
- package/dist/cjs/charts/barChart/utils/getBarDataValue.js +1 -5
- package/dist/cjs/charts/barChart/utils/getRoundedBarMaxValue.js +1 -5
- package/dist/cjs/charts/index.js +3 -19
- package/dist/cjs/charts/lineChart/context/buildLineContextValue.js +17 -21
- package/dist/cjs/charts/lineChart/context/index.js +2 -7
- package/dist/cjs/charts/lineChart/context/lineChartContext.js +2 -5
- package/dist/cjs/charts/lineChart/fragments/fixture/contextData.js +1 -4
- package/dist/cjs/charts/lineChart/fragments/fixture/index.js +1 -5
- package/dist/cjs/charts/lineChart/fragments/index.js +4 -11
- package/dist/cjs/charts/lineChart/fragments/lineChartPath.js +31 -35
- package/dist/cjs/charts/lineChart/fragments/lineChartProjection.js +6 -10
- package/dist/cjs/charts/lineChart/fragments/lineChartSeparator.js +10 -14
- package/dist/cjs/charts/lineChart/fragments/lineChartXAxis.js +14 -18
- package/dist/cjs/charts/lineChart/fragments/lineChartYAxis.js +17 -21
- package/dist/cjs/charts/lineChart/hook/index.js +3 -9
- package/dist/cjs/charts/lineChart/hook/useAutoClick.js +6 -10
- package/dist/cjs/charts/lineChart/hook/useHover.js +5 -9
- package/dist/cjs/charts/lineChart/hook/useIndicator.js +5 -9
- package/dist/cjs/charts/lineChart/index.js +1 -17
- package/dist/cjs/charts/lineChart/lineChart.js +12 -29
- package/dist/cjs/charts/lineChart/lineChart.type.js +1 -2
- package/dist/cjs/charts/lineChart/lineChartStructure.js +34 -38
- package/dist/cjs/charts/lineChart/utils/accessibilityTemplateProcessor.js +6 -10
- package/dist/cjs/charts/lineChart/utils/findSurroundingNumber.js +2 -7
- package/dist/cjs/charts/lineChart/utils/getDataValues.js +1 -5
- package/dist/cjs/charts/lineChart/utils/getExtraSpacing.js +26 -30
- package/dist/cjs/charts/lineChart/utils/getPathData.js +1 -5
- package/dist/cjs/charts/lineChart/utils/getProjection.js +1 -5
- package/dist/cjs/charts/lineChart/utils/getRoundedMaxValue.js +2 -7
- package/dist/cjs/charts/lineChart/utils/handleNodesFocus.js +1 -5
- package/dist/cjs/charts/lineChart/utils/index.js +6 -17
- package/dist/cjs/charts/pieChart/context/buildPieContextValue.js +8 -12
- package/dist/cjs/charts/pieChart/context/index.js +2 -7
- package/dist/cjs/charts/pieChart/context/pieChartContext.js +2 -5
- package/dist/cjs/charts/pieChart/fragments/index.js +2 -7
- package/dist/cjs/charts/pieChart/fragments/pieChartForeign.js +7 -11
- package/dist/cjs/charts/pieChart/fragments/pieChartPath.js +12 -16
- package/dist/cjs/charts/pieChart/fragments/pieChartSegment.js +6 -10
- package/dist/cjs/charts/pieChart/index.js +1 -17
- package/dist/cjs/charts/pieChart/pieChart.js +8 -25
- package/dist/cjs/charts/pieChart/pieChart.type.js +1 -2
- package/dist/cjs/charts/pieChart/pieChartStructure.js +16 -20
- package/dist/cjs/charts/pieChart/utils/buildL.js +1 -5
- package/dist/cjs/charts/pieChart/utils/calculatePoint.js +1 -5
- package/dist/cjs/charts/pieChart/utils/calculateSegmentPath.js +10 -14
- package/dist/cjs/charts/pieChart/utils/drawSegmentPath.js +6 -10
- package/dist/cjs/charts/pieChart/utils/index.js +2 -7
- package/dist/cjs/charts/pieChart/utils/rotationDirection.js +3 -7
- package/dist/cjs/components/axisChart/index.js +2 -18
- package/dist/cjs/components/axisChart/utils/filterLineProps/filterLineProps.js +1 -5
- package/dist/cjs/components/axisChart/utils/index.js +1 -17
- package/dist/cjs/components/axisChart/xAxis/index.js +2 -18
- package/dist/cjs/components/axisChart/xAxis/xAxis.js +14 -18
- package/dist/cjs/components/axisChart/xAxis/xAxis.types.js +1 -2
- package/dist/cjs/components/axisChart/yAxis/index.js +2 -18
- package/dist/cjs/components/axisChart/yAxis/yAxis.js +13 -17
- package/dist/cjs/components/axisChart/yAxis/yAxis.types.js +1 -2
- package/dist/cjs/components/bar/bar.js +9 -13
- package/dist/cjs/components/bar/bar.type.js +1 -4
- package/dist/cjs/components/bar/fragments/barChartSegment.js +3 -7
- package/dist/cjs/components/bar/index.js +2 -18
- package/dist/cjs/components/bar/utils/buildD.js +5 -9
- package/dist/cjs/components/bar/utils/getSegments.js +3 -7
- package/dist/cjs/components/chartText/chartText.js +3 -7
- package/dist/cjs/components/chartText/chartText.types.js +1 -2
- package/dist/cjs/components/chartText/index.js +2 -18
- package/dist/cjs/components/foreignObject/foreignObject.js +3 -7
- package/dist/cjs/components/foreignObject/foreignObject.types.js +1 -2
- package/dist/cjs/components/foreignObject/index.js +2 -18
- package/dist/cjs/components/index.js +10 -26
- package/dist/cjs/components/line/index.js +2 -18
- package/dist/cjs/components/line/line.js +3 -7
- package/dist/cjs/components/line/line.types.js +1 -2
- package/dist/cjs/components/node/components/circle/circle.js +4 -7
- package/dist/cjs/components/node/components/hexagon/hexagon.js +6 -9
- package/dist/cjs/components/node/components/pentagon/pentagon.js +6 -9
- package/dist/cjs/components/node/components/square/square.js +4 -7
- package/dist/cjs/components/node/components/star/star.js +6 -9
- package/dist/cjs/components/node/components/straight/straight.js +4 -7
- package/dist/cjs/components/node/components/triangle/triangle.js +4 -7
- package/dist/cjs/components/node/index.js +2 -18
- package/dist/cjs/components/node/node.js +22 -25
- package/dist/cjs/components/node/node.types.js +1 -4
- package/dist/cjs/components/node/utils/calculateShapePoints/calculateShapePoints.js +1 -5
- package/dist/cjs/components/path/components/nodePath/nodePath.js +9 -12
- package/dist/cjs/components/path/index.js +2 -18
- package/dist/cjs/components/path/path.js +20 -23
- package/dist/cjs/components/path/path.types.js +1 -2
- package/dist/cjs/components/plot/components/circle/circle.js +4 -7
- package/dist/cjs/components/plot/components/index.js +3 -19
- package/dist/cjs/components/plot/components/square/square.js +4 -7
- package/dist/cjs/components/plot/components/triangle/triangle.js +4 -7
- package/dist/cjs/components/plot/index.js +2 -18
- package/dist/cjs/components/plot/plot.js +21 -24
- package/dist/cjs/components/plot/plot.types.js +8 -11
- package/dist/cjs/components/svgContainer/index.js +1 -17
- package/dist/cjs/components/svgContainer/svgContainer.js +5 -8
- package/dist/cjs/components/svgContainer/svgContainer.types.js +1 -2
- package/dist/cjs/components/svgContainer/utils/buildViewBox/buildViewBox.js +1 -5
- package/dist/cjs/components/svgContainer/utils/index.js +1 -17
- package/dist/cjs/components/tick/index.js +2 -18
- package/dist/cjs/components/tick/tick.js +4 -8
- package/dist/cjs/components/tick/tick.types.js +1 -4
- package/dist/cjs/components/zoomArea/components/HandlerIcon.js +3 -7
- package/dist/cjs/components/zoomArea/components/LineRenderer.js +3 -7
- package/dist/cjs/components/zoomArea/components/SelectionArea.js +9 -14
- package/dist/cjs/components/zoomArea/components/ZoomHandler.js +6 -10
- package/dist/cjs/components/zoomArea/components/index.js +4 -12
- package/dist/cjs/components/zoomArea/hooks/index.js +5 -13
- package/dist/cjs/components/zoomArea/hooks/useDragInteraction.js +19 -23
- package/dist/cjs/components/zoomArea/hooks/useKeyboardNavigation.js +18 -22
- package/dist/cjs/components/zoomArea/hooks/useResponsiveCanvas.js +12 -16
- package/dist/cjs/components/zoomArea/hooks/useZoomAreaFocus.js +6 -10
- package/dist/cjs/components/zoomArea/hooks/useZoomData.js +8 -12
- package/dist/cjs/components/zoomArea/index.js +5 -21
- package/dist/cjs/components/zoomArea/utils/accessibilityLabels.js +6 -11
- package/dist/cjs/components/zoomArea/utils/index.js +3 -14
- package/dist/cjs/components/zoomArea/utils/indexRounding.js +5 -11
- package/dist/cjs/components/zoomArea/utils/interactionConfig.js +1 -5
- package/dist/cjs/components/zoomArea/utils/pathGeneration.js +4 -9
- package/dist/cjs/components/zoomArea/utils/rangeAndPositions.js +5 -13
- package/dist/cjs/components/zoomArea/utils/selectionConfig.js +1 -5
- package/dist/cjs/components/zoomArea/zoomArea.js +35 -39
- package/dist/cjs/components/zoomArea/zoomArea.type.js +1 -4
- package/dist/cjs/hooks/index.js +2 -18
- package/dist/cjs/hooks/useFocus/useFocus.js +5 -9
- package/dist/cjs/hooks/useFocus/useFocus.types.js +1 -2
- package/dist/cjs/hooks/useHover/useHover.js +5 -9
- package/dist/cjs/hooks/useHover/useHover.types.js +1 -2
- package/dist/cjs/index.js +3 -19
- package/dist/cjs/types/canvas.type.js +1 -4
- package/dist/cjs/types/errors.type.js +1 -4
- package/dist/cjs/types/focusConfig.type.js +1 -4
- package/dist/cjs/types/index.js +4 -20
- package/dist/cjs/types/position.enum.js +1 -4
- package/dist/cjs/types/unit.enum.js +1 -4
- package/dist/cjs/types/valueFormatter.type.js +1 -2
- package/dist/cjs/utils/ajustedTextSpace/ajustedTextSpace.js +1 -5
- package/dist/cjs/utils/buildErrors/buildErrors.js +3 -7
- package/dist/cjs/utils/buildTickValues/buildTickValues.js +2 -7
- package/dist/cjs/utils/calculateFocusOutline/calculateFocusOutline.js +8 -13
- package/dist/cjs/utils/classNames/classNames.js +1 -5
- package/dist/cjs/utils/cssGradientToSvg/cssGradientToSvg.js +4 -8
- package/dist/cjs/utils/cssGradientToSvg/cssGradientToSvg.types.js +1 -2
- package/dist/cjs/utils/cursorNear/isNear.js +1 -5
- package/dist/cjs/utils/getAxisData/getAxisData.js +1 -5
- package/dist/cjs/utils/getCanvasDimensions/getCanvasDimensions.js +8 -12
- package/dist/cjs/utils/getChildrenAttr/getChildrenAttr.js +4 -8
- package/dist/cjs/utils/getCoordinates/getCoordinates.js +9 -14
- package/dist/cjs/utils/getDataFingerprint/getDataFingerprint.js +1 -5
- package/dist/cjs/utils/getPoints/getPoints.js +1 -5
- package/dist/cjs/utils/getTickTextCoordinate/getTickTextCoordinates.js +5 -10
- package/dist/cjs/utils/getTicks/getTicks.js +2 -7
- package/dist/cjs/utils/index.js +8 -24
- package/dist/cjs/utils/parseStringToNumberPx.ts/parseStringToNumberPx.js +3 -7
- package/dist/cjs/utils/pickCustomAttributes/pickCustomAttributes.js +1 -5
- package/dist/cjs/utils/shadowSvg/shadowSvg.js +3 -7
- package/dist/cjs/utils/shadowSvg/shadowSvg.types.js +1 -2
- package/dist/cjs/utils/textBound/textBound.js +1 -5
- package/dist/kubit-ui-web-react-charts.cjs.js +1 -10
- package/dist/kubit-ui-web-react-charts.es.js +1 -10
- package/dist/kubit-ui-web-react-charts.umd.js +1 -10
- package/dist/types/charts/barChart/barChart.d.ts +5 -5
- package/dist/types/charts/barChart/barChart.type.d.ts +1 -1
- package/dist/types/charts/barChart/context/barChartContext.d.ts +1 -1
- package/dist/types/charts/barChart/fragments/barChartSeparator.d.ts +1 -1
- package/dist/types/charts/barChart/fragments/barChartXAxis.d.ts +1 -1
- package/dist/types/charts/barChart/fragments/barChartYAxis.d.ts +1 -1
- package/dist/types/charts/lineChart/context/lineChartContext.d.ts +1 -1
- package/dist/types/charts/lineChart/fragments/lineChartPath.d.ts +1 -1
- package/dist/types/charts/lineChart/fragments/lineChartProjection.d.ts +1 -1
- package/dist/types/charts/lineChart/fragments/lineChartSeparator.d.ts +1 -1
- package/dist/types/charts/lineChart/fragments/lineChartXAxis.d.ts +1 -1
- package/dist/types/charts/lineChart/lineChart.d.ts +5 -5
- package/dist/types/charts/lineChart/lineChart.type.d.ts +1 -1
- package/dist/types/charts/lineChart/lineChartStructure.d.ts +1 -1
- package/dist/types/charts/pieChart/context/pieChartContext.d.ts +1 -1
- package/dist/types/charts/pieChart/fragments/pieChartForeign.d.ts +1 -1
- package/dist/types/charts/pieChart/fragments/pieChartPath.d.ts +1 -1
- package/dist/types/charts/pieChart/pieChart.d.ts +3 -3
- package/dist/types/charts/pieChart/pieChart.type.d.ts +1 -1
- package/dist/types/charts/pieChart/pieChartStructure.d.ts +1 -1
- package/dist/types/components/axisChart/xAxis/xAxis.d.ts +1 -1
- package/dist/types/components/axisChart/yAxis/yAxis.d.ts +1 -1
- package/dist/types/components/bar/bar.d.ts +1 -1
- package/dist/types/components/bar/fragments/barChartSegment.d.ts +1 -1
- package/dist/types/components/chartText/chartText.d.ts +1 -1
- package/dist/types/components/foreignObject/foreignObject.d.ts +1 -1
- package/dist/types/components/foreignObject/foreignObject.types.d.ts +1 -1
- package/dist/types/components/line/line.d.ts +1 -1
- package/dist/types/components/node/components/circle/circle.d.ts +1 -1
- package/dist/types/components/node/components/hexagon/hexagon.d.ts +1 -1
- package/dist/types/components/node/components/pentagon/pentagon.d.ts +1 -1
- package/dist/types/components/node/components/square/square.d.ts +1 -1
- package/dist/types/components/node/components/star/star.d.ts +1 -1
- package/dist/types/components/node/components/straight/straight.d.ts +1 -1
- package/dist/types/components/node/components/triangle/triangle.d.ts +1 -1
- package/dist/types/components/node/node.d.ts +1 -1
- package/dist/types/components/path/components/nodePath/nodePath.d.ts +2 -2
- package/dist/types/components/path/path.d.ts +1 -1
- package/dist/types/components/path/path.types.d.ts +1 -1
- package/dist/types/components/plot/components/circle/circle.d.ts +1 -1
- package/dist/types/components/plot/components/square/square.d.ts +1 -1
- package/dist/types/components/plot/components/triangle/triangle.d.ts +1 -1
- package/dist/types/components/plot/plot.d.ts +1 -1
- package/dist/types/components/svgContainer/svgContainer.d.ts +1 -1
- package/dist/types/components/tick/tick.d.ts +1 -1
- package/dist/types/components/zoomArea/components/HandlerIcon.d.ts +1 -1
- package/dist/types/components/zoomArea/components/LineRenderer.d.ts +1 -1
- package/dist/types/components/zoomArea/components/SelectionArea.d.ts +1 -1
- package/dist/types/components/zoomArea/components/ZoomHandler.d.ts +1 -1
- package/dist/types/hooks/useFocus/useFocus.types.d.ts +1 -1
- package/dist/types/hooks/useHover/useHover.types.d.ts +1 -1
- package/dist/types/utils/getChildrenAttr/getChildrenAttr.d.ts +1 -1
- package/package.json +44 -47
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
-
const chartText_1 = require("../../components/chartText/chartText");
|
|
6
|
-
const line_1 = require("../../components/line/line");
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { ChartText } from '../../components/chartText/chartText';
|
|
3
|
+
import { Line } from '../../components/line/line';
|
|
7
4
|
/**
|
|
8
5
|
* Functional component for rendering a tick mark in a chart or graph.
|
|
9
6
|
*
|
|
@@ -19,5 +16,4 @@ const line_1 = require("../../components/line/line");
|
|
|
19
16
|
* @param {number} [props.y] - Optional y-coordinate for the position of the tick mark. Used for vertical placement.
|
|
20
17
|
* @returns A React functional component that renders the tick mark and its associated elements.
|
|
21
18
|
*/
|
|
22
|
-
const Tick = ({ showTickLines, tick, tickLine, tickText }) => ((
|
|
23
|
-
exports.Tick = Tick;
|
|
19
|
+
export const Tick = ({ showTickLines, tick, tickLine, tickText }) => (_jsxs("g", { children: [showTickLines && _jsx(Line, { ...tickLine }), tickText && _jsx(ChartText, { ...tickText, children: tick.value })] }));
|
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.TickDataUtils = void 0;
|
|
4
1
|
/**
|
|
5
2
|
* Utility functions for working with TickData.
|
|
6
3
|
*/
|
|
7
|
-
|
|
4
|
+
export const TickDataUtils = {
|
|
8
5
|
/**
|
|
9
6
|
* Formats the values of an array of TickData using the provided formatter function.
|
|
10
7
|
*
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.HandlerIcon = void 0;
|
|
4
|
-
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
5
2
|
/**
|
|
6
3
|
* Default color for handler icons
|
|
7
4
|
*/
|
|
@@ -20,7 +17,6 @@ const ICON_OFFSET = 5;
|
|
|
20
17
|
* The icon is centered on the handler by applying a translation of:
|
|
21
18
|
* x - ICON_OFFSET, y - ICON_OFFSET
|
|
22
19
|
*/
|
|
23
|
-
const HandlerIcon = ({ fill = DEFAULT_ICON_COLOR, x, y }) => {
|
|
24
|
-
return ((
|
|
20
|
+
export const HandlerIcon = ({ fill = DEFAULT_ICON_COLOR, x, y }) => {
|
|
21
|
+
return (_jsxs("g", { fill: fill, pointerEvents: "none", transform: `translate(${x - ICON_OFFSET}, ${y - ICON_OFFSET})`, children: [_jsx("path", { d: "M4.99948 9.99802C4.47168 9.99802 4.04419 9.64335 4.04419 9.20547V0.79255C4.04419 0.354666 4.47168 0 4.99948 0C5.52728 0 5.95477 0.354666 5.95477 0.79255V9.20745C5.95477 9.64533 5.52728 10 4.99948 10V9.99802Z" }), _jsx("path", { d: "M0.955289 8.78839C0.427492 8.78839 0 8.43372 0 7.99584V2.00416C0 1.56628 0.427492 1.21161 0.955289 1.21161C1.48309 1.21161 1.91058 1.56628 1.91058 2.00416V7.99584C1.91058 8.43372 1.48309 8.78839 0.955289 8.78839Z" }), _jsx("path", { d: "M8.08936 7.99584C8.08936 8.43372 8.51685 8.78839 9.04464 8.78839C9.57244 8.78839 9.99993 8.43372 9.99993 7.99584V2.00416C9.99993 1.56628 9.57244 1.21161 9.04464 1.21161C8.51685 1.21161 8.08936 1.56628 8.08936 2.00416V7.99584Z" })] }));
|
|
25
22
|
};
|
|
26
|
-
exports.HandlerIcon = HandlerIcon;
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.LineRenderer = void 0;
|
|
4
|
-
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
5
2
|
/**
|
|
6
3
|
* Default color for lines when no stroke is provided
|
|
7
4
|
*/
|
|
@@ -9,7 +6,6 @@ const DEFAULT_LINE_COLOR = '#0078D4';
|
|
|
9
6
|
/**
|
|
10
7
|
* Renders all lines and fill areas for the zoom area chart
|
|
11
8
|
*/
|
|
12
|
-
const LineRenderer = ({ linesData }) => {
|
|
13
|
-
return ((
|
|
9
|
+
export const LineRenderer = ({ linesData }) => {
|
|
10
|
+
return (_jsx(_Fragment, { children: linesData.map((lineData, index) => (_jsxs("g", { children: [lineData.config.fill && lineData.fillPath && (_jsx("path", { d: lineData.fillPath, fill: lineData.config.fill, fillOpacity: lineData.config.fillOpacity || 0.2, stroke: "none" })), _jsx("path", { d: lineData.linePath, fill: "none", stroke: lineData.config.stroke || DEFAULT_LINE_COLOR, strokeWidth: lineData.config.strokeWidth || 1 })] }, lineData.config.dataKey || lineData.config.yKey || index))) }));
|
|
14
11
|
};
|
|
15
|
-
exports.LineRenderer = LineRenderer;
|
|
@@ -1,13 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
-
const calculateFocusOutline_1 = require("../../../utils/calculateFocusOutline/calculateFocusOutline");
|
|
6
|
-
const rangeAndPositions_1 = require("../utils/rangeAndPositions");
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { calculateFocusOutline } from '../../../utils/calculateFocusOutline/calculateFocusOutline';
|
|
3
|
+
import { isFullRange } from '../utils/rangeAndPositions';
|
|
7
4
|
/**
|
|
8
5
|
* Focus ring for the selection area - rendered separately to control z-order
|
|
9
6
|
*/
|
|
10
|
-
const SelectionAreaFocusRing = ({ endX, focusConfig, height, isFocused, startX, }) => {
|
|
7
|
+
export const SelectionAreaFocusRing = ({ endX, focusConfig, height, isFocused, startX, }) => {
|
|
11
8
|
if (!isFocused) {
|
|
12
9
|
return null;
|
|
13
10
|
}
|
|
@@ -17,7 +14,7 @@ const SelectionAreaFocusRing = ({ endX, focusConfig, height, isFocused, startX,
|
|
|
17
14
|
const centerX = startX + selectionWidth / 2;
|
|
18
15
|
const centerY = height / 2;
|
|
19
16
|
// Calculate focus ring dimensions using the new util
|
|
20
|
-
const focusOutline =
|
|
17
|
+
const focusOutline = calculateFocusOutline({
|
|
21
18
|
elementHeight: selectionHeight,
|
|
22
19
|
elementPosition: { x: centerX, y: centerY },
|
|
23
20
|
elementStrokeWidth: 0, // Selection area typically has no border
|
|
@@ -35,19 +32,17 @@ const SelectionAreaFocusRing = ({ endX, focusConfig, height, isFocused, startX,
|
|
|
35
32
|
if (focusOutline.type !== 'rectangle') {
|
|
36
33
|
return null;
|
|
37
34
|
}
|
|
38
|
-
return ((
|
|
35
|
+
return (_jsxs("g", { pointerEvents: "none", children: [_jsx("rect", { fill: "none", height: focusOutline.outer.height, stroke: outlineColor, strokeWidth: outlineStrokeWidth, width: focusOutline.outer.width, x: focusOutline.outer.x, y: focusOutline.outer.y }), _jsx("rect", { fill: "none", height: focusOutline.inner.height, stroke: innerColor, strokeWidth: innerStrokeWidth, width: focusOutline.inner.width, x: focusOutline.inner.x, y: focusOutline.inner.y })] }));
|
|
39
36
|
};
|
|
40
|
-
exports.SelectionAreaFocusRing = SelectionAreaFocusRing;
|
|
41
37
|
/**
|
|
42
38
|
* Selection area overlay
|
|
43
39
|
*/
|
|
44
|
-
const SelectionArea = ({ currentRange, dataLength, dataTestId, endX, height, onBlur, onFocus, onKeyDown, onMouseDown, onTouchStart, screenReaderText, selectionConfig, startX, }) => {
|
|
40
|
+
export const SelectionArea = ({ currentRange, dataLength, dataTestId, endX, height, onBlur, onFocus, onKeyDown, onMouseDown, onTouchStart, screenReaderText, selectionConfig, startX, }) => {
|
|
45
41
|
// Check if overlay should be hidden based on design specs:
|
|
46
42
|
// "Only visible when a range is defined"
|
|
47
|
-
const shouldHideOverlay = selectionConfig.hideOverlayOnFullRange &&
|
|
48
|
-
return ((
|
|
43
|
+
const shouldHideOverlay = selectionConfig.hideOverlayOnFullRange && isFullRange(currentRange, dataLength);
|
|
44
|
+
return (_jsx(_Fragment, { children: _jsx("rect", { "aria-label": screenReaderText, "aria-valuemax": dataLength - 1, "aria-valuemin": 0, "aria-valuetext": screenReaderText, cursor: "grab", "data-testid": dataTestId, fill: selectionConfig.fill, fillOpacity: selectionConfig.fillOpacity, height: height, role: "slider", stroke: selectionConfig.stroke, strokeWidth: selectionConfig.strokeWidth, style: {
|
|
49
45
|
outline: 'none',
|
|
50
46
|
visibility: shouldHideOverlay ? 'hidden' : 'visible',
|
|
51
47
|
}, tabIndex: 0, width: endX - startX, x: startX, y: 0, onBlur: onBlur, onFocus: onFocus, onKeyDown: onKeyDown, onMouseDown: onMouseDown, onTouchStart: onTouchStart }) }));
|
|
52
48
|
};
|
|
53
|
-
exports.SelectionArea = SelectionArea;
|
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
-
const calculateFocusOutline_1 = require("../../../utils/calculateFocusOutline/calculateFocusOutline");
|
|
6
|
-
const HandlerIcon_1 = require("./HandlerIcon");
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { calculateFocusOutline } from '../../../utils/calculateFocusOutline/calculateFocusOutline';
|
|
3
|
+
import { HandlerIcon } from './HandlerIcon';
|
|
7
4
|
/**
|
|
8
5
|
* Default colors for zoom handlers
|
|
9
6
|
*/
|
|
@@ -42,11 +39,11 @@ const getHandlerStyles = (handlerConfig) => ({
|
|
|
42
39
|
/**
|
|
43
40
|
* Individual zoom handler with line, circle, and icon
|
|
44
41
|
*/
|
|
45
|
-
const ZoomHandler = ({ dataTestId, focusConfig, handlerConfig, height, isFocused, max, min, onBlur, onFocus, onKeyDown, onMouseDown, onTouchStart, screenReaderText, x, }) => {
|
|
42
|
+
export const ZoomHandler = ({ dataTestId, focusConfig, handlerConfig, height, isFocused, max, min, onBlur, onFocus, onKeyDown, onMouseDown, onTouchStart, screenReaderText, x, }) => {
|
|
46
43
|
const centerY = height / 2;
|
|
47
44
|
const styles = getHandlerStyles(handlerConfig);
|
|
48
45
|
// Calculate focus ring dimensions using the new util
|
|
49
|
-
const focusOutline =
|
|
46
|
+
const focusOutline = calculateFocusOutline({
|
|
50
47
|
elementHeight: styles.radius * 2,
|
|
51
48
|
elementPosition: { x, y: centerY },
|
|
52
49
|
elementStrokeWidth: typeof styles.strokeWidth === 'number'
|
|
@@ -58,6 +55,5 @@ const ZoomHandler = ({ dataTestId, focusConfig, handlerConfig, height, isFocused
|
|
|
58
55
|
innerStrokeWidth: focusConfig.innerStrokeWidth,
|
|
59
56
|
outlineStrokeWidth: focusConfig.outlineStrokeWidth,
|
|
60
57
|
});
|
|
61
|
-
return ((
|
|
58
|
+
return (_jsxs("g", { "data-testid": `${dataTestId}-group`, children: [_jsx("line", { pointerEvents: "none", stroke: styles.verticalLineStroke, strokeWidth: styles.verticalLineStrokeWidth, x1: x, x2: x, y1: 0, y2: height }), _jsx("circle", { "aria-label": screenReaderText, "aria-valuemax": max, "aria-valuemin": min, "aria-valuetext": screenReaderText, cursor: "ew-resize", cx: x, cy: centerY, "data-testid": dataTestId, fill: styles.fill, r: styles.radius, role: "slider", stroke: styles.stroke, strokeWidth: styles.strokeWidth, style: { outline: 'none' }, tabIndex: 0, onBlur: onBlur, onFocus: onFocus, onKeyDown: onKeyDown, onMouseDown: onMouseDown, onTouchStart: onTouchStart }), _jsx(HandlerIcon, { fill: styles.iconColor, x: x, y: centerY }), isFocused && focusOutline.type === 'circle' && (_jsxs("g", { pointerEvents: "none", children: [_jsx("circle", { cx: focusOutline.outer.cx, cy: focusOutline.outer.cy, fill: "none", r: focusOutline.outer.r, stroke: focusConfig.outlineColor, strokeWidth: focusConfig.outlineStrokeWidth }), _jsx("circle", { cx: focusOutline.inner.cx, cy: focusOutline.inner.cy, fill: "none", r: focusOutline.inner.r, stroke: focusConfig.innerColor, strokeWidth: focusConfig.innerStrokeWidth })] }))] }));
|
|
62
59
|
};
|
|
63
|
-
exports.ZoomHandler = ZoomHandler;
|
|
@@ -1,12 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
Object.defineProperty(exports, "HandlerIcon", { enumerable: true, get: function () { return HandlerIcon_1.HandlerIcon; } });
|
|
6
|
-
var LineRenderer_1 = require("./LineRenderer");
|
|
7
|
-
Object.defineProperty(exports, "LineRenderer", { enumerable: true, get: function () { return LineRenderer_1.LineRenderer; } });
|
|
8
|
-
var SelectionArea_1 = require("./SelectionArea");
|
|
9
|
-
Object.defineProperty(exports, "SelectionArea", { enumerable: true, get: function () { return SelectionArea_1.SelectionArea; } });
|
|
10
|
-
Object.defineProperty(exports, "SelectionAreaFocusRing", { enumerable: true, get: function () { return SelectionArea_1.SelectionAreaFocusRing; } });
|
|
11
|
-
var ZoomHandler_1 = require("./ZoomHandler");
|
|
12
|
-
Object.defineProperty(exports, "ZoomHandler", { enumerable: true, get: function () { return ZoomHandler_1.ZoomHandler; } });
|
|
1
|
+
export { HandlerIcon } from './HandlerIcon';
|
|
2
|
+
export { LineRenderer } from './LineRenderer';
|
|
3
|
+
export { SelectionArea, SelectionAreaFocusRing } from './SelectionArea';
|
|
4
|
+
export { ZoomHandler } from './ZoomHandler';
|
|
@@ -1,13 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
var useKeyboardNavigation_1 = require("./useKeyboardNavigation");
|
|
7
|
-
Object.defineProperty(exports, "useKeyboardNavigation", { enumerable: true, get: function () { return useKeyboardNavigation_1.useKeyboardNavigation; } });
|
|
8
|
-
var useResponsiveCanvas_1 = require("./useResponsiveCanvas");
|
|
9
|
-
Object.defineProperty(exports, "useResponsiveCanvas", { enumerable: true, get: function () { return useResponsiveCanvas_1.useResponsiveCanvas; } });
|
|
10
|
-
var useZoomAreaFocus_1 = require("./useZoomAreaFocus");
|
|
11
|
-
Object.defineProperty(exports, "useZoomAreaFocus", { enumerable: true, get: function () { return useZoomAreaFocus_1.useZoomAreaFocus; } });
|
|
12
|
-
var useZoomData_1 = require("./useZoomData");
|
|
13
|
-
Object.defineProperty(exports, "useZoomData", { enumerable: true, get: function () { return useZoomData_1.useZoomData; } });
|
|
1
|
+
export { useDragInteraction } from './useDragInteraction';
|
|
2
|
+
export { useKeyboardNavigation } from './useKeyboardNavigation';
|
|
3
|
+
export { useResponsiveCanvas } from './useResponsiveCanvas';
|
|
4
|
+
export { useZoomAreaFocus } from './useZoomAreaFocus';
|
|
5
|
+
export { useZoomData } from './useZoomData';
|
|
@@ -1,21 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const react_1 = require("react");
|
|
5
|
-
const rangeAndPositions_1 = require("../utils/rangeAndPositions");
|
|
6
|
-
const zoomArea_type_1 = require("../zoomArea.type");
|
|
1
|
+
import { useCallback, useEffect, useRef, useState } from 'react';
|
|
2
|
+
import { clampRange, mouseToDataIndex } from '../utils/rangeAndPositions';
|
|
3
|
+
import { ZoomAreaElements } from '../zoomArea.type';
|
|
7
4
|
/**
|
|
8
5
|
* Calculate new range based on drag type and pointer position
|
|
9
6
|
*/
|
|
10
7
|
const calculateNewRange = (dragType, currentRange, dataIndex, dataLength, interactionConfig) => {
|
|
11
8
|
const newRange = { ...currentRange };
|
|
12
|
-
if (dragType ===
|
|
9
|
+
if (dragType === ZoomAreaElements.START_HANDLER) {
|
|
13
10
|
newRange.start = Math.max(0, Math.min(dataIndex, currentRange.end - interactionConfig.minHandlerDistance));
|
|
14
11
|
}
|
|
15
|
-
else if (dragType ===
|
|
12
|
+
else if (dragType === ZoomAreaElements.END_HANDLER) {
|
|
16
13
|
newRange.end = Math.min(dataLength - 1, Math.max(dataIndex, currentRange.start + interactionConfig.minHandlerDistance));
|
|
17
14
|
}
|
|
18
|
-
else if (dragType ===
|
|
15
|
+
else if (dragType === ZoomAreaElements.SELECTION_AREA) {
|
|
19
16
|
// Moving entire selection
|
|
20
17
|
const selectionWidth = currentRange.end - currentRange.start;
|
|
21
18
|
const newStart = Math.max(0, Math.min(dataLength - 1 - selectionWidth, dataIndex - selectionWidth / 2));
|
|
@@ -34,22 +31,22 @@ const calculateNewRange = (dragType, currentRange, dataIndex, dataLength, intera
|
|
|
34
31
|
* @param params - Configuration parameters for drag functionality
|
|
35
32
|
* @returns Object with drag handlers and state
|
|
36
33
|
*/
|
|
37
|
-
const useDragInteraction = (params) => {
|
|
34
|
+
export const useDragInteraction = (params) => {
|
|
38
35
|
const { currentRange, dataLength, interactionConfig, onRangeChange, width } = params;
|
|
39
|
-
const groupRef =
|
|
40
|
-
const [isDragging, setIsDragging] =
|
|
41
|
-
const handleMouseDown =
|
|
36
|
+
const groupRef = useRef(null);
|
|
37
|
+
const [isDragging, setIsDragging] = useState(null);
|
|
38
|
+
const handleMouseDown = useCallback((target) => {
|
|
42
39
|
return () => {
|
|
43
40
|
setIsDragging(target);
|
|
44
41
|
};
|
|
45
42
|
}, []);
|
|
46
|
-
const handleTouchStart =
|
|
43
|
+
const handleTouchStart = useCallback((target) => {
|
|
47
44
|
return () => {
|
|
48
45
|
setIsDragging(target);
|
|
49
46
|
};
|
|
50
47
|
}, []);
|
|
51
48
|
// Common logic for handling pointer movement (mouse or touch)
|
|
52
|
-
const handlePointerMove =
|
|
49
|
+
const handlePointerMove = useCallback((clientX) => {
|
|
53
50
|
if (!isDragging || !groupRef.current) {
|
|
54
51
|
return;
|
|
55
52
|
}
|
|
@@ -62,15 +59,15 @@ const useDragInteraction = (params) => {
|
|
|
62
59
|
const rect = svgElement.getBoundingClientRect();
|
|
63
60
|
const pointerX = clientX - rect.left;
|
|
64
61
|
// Convert pointer X to data index (0 to dataLength-1)
|
|
65
|
-
const dataIndex =
|
|
62
|
+
const dataIndex = mouseToDataIndex(pointerX, width, dataLength);
|
|
66
63
|
const newRange = calculateNewRange(isDragging, currentRange, dataIndex, dataLength, interactionConfig);
|
|
67
|
-
const clampedRange =
|
|
64
|
+
const clampedRange = clampRange(newRange, dataLength, interactionConfig.minHandlerDistance);
|
|
68
65
|
onRangeChange(clampedRange);
|
|
69
66
|
}, [isDragging, width, dataLength, currentRange, onRangeChange, interactionConfig]);
|
|
70
|
-
const handleMouseMove =
|
|
67
|
+
const handleMouseMove = useCallback((event) => {
|
|
71
68
|
handlePointerMove(event.clientX);
|
|
72
69
|
}, [handlePointerMove]);
|
|
73
|
-
const handleTouchMove =
|
|
70
|
+
const handleTouchMove = useCallback((event) => {
|
|
74
71
|
if (event.touches.length === 0) {
|
|
75
72
|
return;
|
|
76
73
|
}
|
|
@@ -78,14 +75,14 @@ const useDragInteraction = (params) => {
|
|
|
78
75
|
event.preventDefault();
|
|
79
76
|
handlePointerMove(event.touches[0].clientX);
|
|
80
77
|
}, [handlePointerMove]);
|
|
81
|
-
const handleMouseUp =
|
|
78
|
+
const handleMouseUp = useCallback(() => {
|
|
82
79
|
setIsDragging(null);
|
|
83
80
|
}, []);
|
|
84
|
-
const handleTouchEnd =
|
|
81
|
+
const handleTouchEnd = useCallback(() => {
|
|
85
82
|
setIsDragging(null);
|
|
86
83
|
}, []);
|
|
87
84
|
// Set up global mouse and touch events when dragging
|
|
88
|
-
|
|
85
|
+
useEffect(() => {
|
|
89
86
|
if (isDragging) {
|
|
90
87
|
// Mouse events
|
|
91
88
|
document.addEventListener('mousemove', handleMouseMove);
|
|
@@ -111,4 +108,3 @@ const useDragInteraction = (params) => {
|
|
|
111
108
|
isDragging,
|
|
112
109
|
};
|
|
113
110
|
};
|
|
114
|
-
exports.useDragInteraction = useDragInteraction;
|
|
@@ -1,21 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const react_1 = require("react");
|
|
5
|
-
const rangeAndPositions_1 = require("../utils/rangeAndPositions");
|
|
6
|
-
const zoomArea_type_1 = require("../zoomArea.type");
|
|
1
|
+
import { useCallback } from 'react';
|
|
2
|
+
import { clampRange } from '../utils/rangeAndPositions';
|
|
3
|
+
import { ZoomAreaElements } from '../zoomArea.type';
|
|
7
4
|
/**
|
|
8
5
|
* Handle left arrow and down arrow key movement (decrease values)
|
|
9
6
|
*/
|
|
10
7
|
const handleArrowLeft = (target, currentRange, step, interactionConfig) => {
|
|
11
8
|
const newRange = { ...currentRange };
|
|
12
|
-
if (target ===
|
|
9
|
+
if (target === ZoomAreaElements.START_HANDLER) {
|
|
13
10
|
newRange.start = Math.max(0, currentRange.start - step);
|
|
14
11
|
}
|
|
15
|
-
else if (target ===
|
|
12
|
+
else if (target === ZoomAreaElements.END_HANDLER) {
|
|
16
13
|
newRange.end = Math.max(currentRange.start + interactionConfig.minHandlerDistance, currentRange.end - step);
|
|
17
14
|
}
|
|
18
|
-
else if (target ===
|
|
15
|
+
else if (target === ZoomAreaElements.SELECTION_AREA) {
|
|
19
16
|
// Move entire selection left
|
|
20
17
|
const selectionWidth = currentRange.end - currentRange.start;
|
|
21
18
|
const newStart = Math.max(0, currentRange.start - step);
|
|
@@ -29,13 +26,13 @@ const handleArrowLeft = (target, currentRange, step, interactionConfig) => {
|
|
|
29
26
|
*/
|
|
30
27
|
const handleArrowRight = (target, currentRange, step, dataLength, interactionConfig) => {
|
|
31
28
|
const newRange = { ...currentRange };
|
|
32
|
-
if (target ===
|
|
29
|
+
if (target === ZoomAreaElements.START_HANDLER) {
|
|
33
30
|
newRange.start = Math.min(currentRange.end - interactionConfig.minHandlerDistance, currentRange.start + step);
|
|
34
31
|
}
|
|
35
|
-
else if (target ===
|
|
32
|
+
else if (target === ZoomAreaElements.END_HANDLER) {
|
|
36
33
|
newRange.end = Math.min(dataLength - 1, currentRange.end + step);
|
|
37
34
|
}
|
|
38
|
-
else if (target ===
|
|
35
|
+
else if (target === ZoomAreaElements.SELECTION_AREA) {
|
|
39
36
|
// Move entire selection right
|
|
40
37
|
const selectionWidth = currentRange.end - currentRange.start;
|
|
41
38
|
const newStart = Math.min(dataLength - 1 - selectionWidth, currentRange.start + step);
|
|
@@ -49,13 +46,13 @@ const handleArrowRight = (target, currentRange, step, dataLength, interactionCon
|
|
|
49
46
|
*/
|
|
50
47
|
const handleHome = (target, currentRange, dataLength) => {
|
|
51
48
|
const newRange = { ...currentRange };
|
|
52
|
-
if (target ===
|
|
49
|
+
if (target === ZoomAreaElements.START_HANDLER) {
|
|
53
50
|
newRange.start = 0;
|
|
54
51
|
}
|
|
55
|
-
else if (target ===
|
|
52
|
+
else if (target === ZoomAreaElements.END_HANDLER) {
|
|
56
53
|
newRange.end = dataLength - 1;
|
|
57
54
|
}
|
|
58
|
-
else if (target ===
|
|
55
|
+
else if (target === ZoomAreaElements.SELECTION_AREA) {
|
|
59
56
|
const selectionWidth = currentRange.end - currentRange.start;
|
|
60
57
|
newRange.start = 0;
|
|
61
58
|
newRange.end = selectionWidth;
|
|
@@ -67,13 +64,13 @@ const handleHome = (target, currentRange, dataLength) => {
|
|
|
67
64
|
*/
|
|
68
65
|
const handleEnd = (target, currentRange, dataLength, interactionConfig) => {
|
|
69
66
|
const newRange = { ...currentRange };
|
|
70
|
-
if (target ===
|
|
67
|
+
if (target === ZoomAreaElements.START_HANDLER) {
|
|
71
68
|
newRange.start = currentRange.end - interactionConfig.minHandlerDistance;
|
|
72
69
|
}
|
|
73
|
-
else if (target ===
|
|
70
|
+
else if (target === ZoomAreaElements.END_HANDLER) {
|
|
74
71
|
newRange.end = dataLength - 1;
|
|
75
72
|
}
|
|
76
|
-
else if (target ===
|
|
73
|
+
else if (target === ZoomAreaElements.SELECTION_AREA) {
|
|
77
74
|
const selectionWidth = currentRange.end - currentRange.start;
|
|
78
75
|
newRange.start = dataLength - 1 - selectionWidth;
|
|
79
76
|
newRange.end = dataLength - 1;
|
|
@@ -86,9 +83,9 @@ const handleEnd = (target, currentRange, dataLength, interactionConfig) => {
|
|
|
86
83
|
* @param params - Configuration parameters for keyboard navigation
|
|
87
84
|
* @returns Object with keyboard event handlers
|
|
88
85
|
*/
|
|
89
|
-
const useKeyboardNavigation = (params) => {
|
|
86
|
+
export const useKeyboardNavigation = (params) => {
|
|
90
87
|
const { currentRange, dataLength, interactionConfig, onRangeChange } = params;
|
|
91
|
-
const handleKeyDown =
|
|
88
|
+
const handleKeyDown = useCallback((target) => {
|
|
92
89
|
return (event) => {
|
|
93
90
|
// Shift key = fast navigation, normal keys = precise control
|
|
94
91
|
const step = event.shiftKey
|
|
@@ -117,10 +114,9 @@ const useKeyboardNavigation = (params) => {
|
|
|
117
114
|
default:
|
|
118
115
|
return; // Don't handle other keys
|
|
119
116
|
}
|
|
120
|
-
const clampedRange =
|
|
117
|
+
const clampedRange = clampRange(newRange, dataLength, interactionConfig.minHandlerDistance);
|
|
121
118
|
onRangeChange(clampedRange);
|
|
122
119
|
};
|
|
123
120
|
}, [currentRange, dataLength, onRangeChange, interactionConfig]);
|
|
124
121
|
return { handleKeyDown };
|
|
125
122
|
};
|
|
126
|
-
exports.useKeyboardNavigation = useKeyboardNavigation;
|
|
@@ -1,18 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const
|
|
6
|
-
const getCanvasDimensions_1 = require("../../../utils/getCanvasDimensions/getCanvasDimensions");
|
|
7
|
-
const parseStringToNumberPx_1 = require("../../../utils/parseStringToNumberPx.ts/parseStringToNumberPx");
|
|
8
|
-
const useResponsiveCanvas = ({ canvasConfig, dataTestId, extraSpace = 0, height, width, }) => {
|
|
1
|
+
import { useEffect, useMemo, useState } from 'react';
|
|
2
|
+
import { buildViewBox } from '../../../components/svgContainer/utils/buildViewBox/buildViewBox';
|
|
3
|
+
import { getCanvasDimensions } from '../../../utils/getCanvasDimensions/getCanvasDimensions';
|
|
4
|
+
import { parseStringToNumberPx } from '../../../utils/parseStringToNumberPx.ts/parseStringToNumberPx';
|
|
5
|
+
export const useResponsiveCanvas = ({ canvasConfig, dataTestId, extraSpace = 0, height, width, }) => {
|
|
9
6
|
// State for parsed/calculated dimensions
|
|
10
|
-
const [parsedCanvas, setParsedCanvas] =
|
|
7
|
+
const [parsedCanvas, setParsedCanvas] = useState({
|
|
11
8
|
height: 0,
|
|
12
9
|
width: 0,
|
|
13
10
|
});
|
|
14
11
|
// Determine effective configuration (legacy vs modern API)
|
|
15
|
-
const effectiveCanvasConfig =
|
|
12
|
+
const effectiveCanvasConfig = useMemo(() => {
|
|
16
13
|
if (canvasConfig) {
|
|
17
14
|
// Legacy mode: use provided canvasConfig
|
|
18
15
|
return canvasConfig;
|
|
@@ -27,17 +24,17 @@ const useResponsiveCanvas = ({ canvasConfig, dataTestId, extraSpace = 0, height,
|
|
|
27
24
|
// Extract and parse canvas configuration
|
|
28
25
|
const { extraSpace: canvasExtraSpace, height: canvasHeight, width: canvasWidth, } = effectiveCanvasConfig;
|
|
29
26
|
const parsedCanvasExtraSpace = canvasExtraSpace
|
|
30
|
-
?
|
|
27
|
+
? parseStringToNumberPx(canvasExtraSpace)
|
|
31
28
|
: undefined;
|
|
32
29
|
// Set up responsive dimensions with ResizeObserver
|
|
33
|
-
|
|
30
|
+
useEffect(() => {
|
|
34
31
|
// Find the SVG element for this specific component instance
|
|
35
32
|
const svgElement = document.querySelector(`[data-testid="${dataTestId}"]`);
|
|
36
33
|
if (!svgElement) {
|
|
37
34
|
return;
|
|
38
35
|
}
|
|
39
36
|
const calculateDimensions = () => {
|
|
40
|
-
const { parsedCanvasHeight, parsedCanvasWidth } =
|
|
37
|
+
const { parsedCanvasHeight, parsedCanvasWidth } = getCanvasDimensions({
|
|
41
38
|
canvasHeight,
|
|
42
39
|
canvasWidth,
|
|
43
40
|
svgElement,
|
|
@@ -62,8 +59,8 @@ const useResponsiveCanvas = ({ canvasConfig, dataTestId, extraSpace = 0, height,
|
|
|
62
59
|
};
|
|
63
60
|
}, [canvasWidth, canvasHeight, dataTestId]);
|
|
64
61
|
// Calculate viewBox based on parsed dimensions
|
|
65
|
-
const viewBox =
|
|
66
|
-
const calculatedViewBox =
|
|
62
|
+
const viewBox = useMemo(() => {
|
|
63
|
+
const calculatedViewBox = buildViewBox(parsedCanvas.width, parsedCanvas.height, parsedCanvasExtraSpace);
|
|
67
64
|
return calculatedViewBox;
|
|
68
65
|
}, [parsedCanvas.width, parsedCanvas.height, parsedCanvasExtraSpace]);
|
|
69
66
|
return {
|
|
@@ -71,4 +68,3 @@ const useResponsiveCanvas = ({ canvasConfig, dataTestId, extraSpace = 0, height,
|
|
|
71
68
|
viewBox,
|
|
72
69
|
};
|
|
73
70
|
};
|
|
74
|
-
exports.useResponsiveCanvas = useResponsiveCanvas;
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.useZoomAreaFocus = void 0;
|
|
4
|
-
const react_1 = require("react");
|
|
1
|
+
import { useCallback, useState } from 'react';
|
|
5
2
|
/**
|
|
6
3
|
* Custom hook for managing focus state of zoom area elements.
|
|
7
4
|
*
|
|
@@ -11,16 +8,16 @@ const react_1 = require("react");
|
|
|
11
8
|
* @param params - Configuration parameters for the hook
|
|
12
9
|
* @returns Object with focus handlers and utilities
|
|
13
10
|
*/
|
|
14
|
-
const useZoomAreaFocus = () => {
|
|
15
|
-
const [focusedElement, setFocusedElement] =
|
|
16
|
-
const handleFocus =
|
|
11
|
+
export const useZoomAreaFocus = () => {
|
|
12
|
+
const [focusedElement, setFocusedElement] = useState(null);
|
|
13
|
+
const handleFocus = useCallback((target) => {
|
|
17
14
|
return () => setFocusedElement(target);
|
|
18
15
|
}, []);
|
|
19
|
-
const handleBlur =
|
|
16
|
+
const handleBlur = useCallback(() => {
|
|
20
17
|
setFocusedElement(null);
|
|
21
18
|
}, []);
|
|
22
19
|
// Helper function to check focus state
|
|
23
|
-
const isFocused =
|
|
20
|
+
const isFocused = useCallback((target) => {
|
|
24
21
|
return focusedElement === target;
|
|
25
22
|
}, [focusedElement]);
|
|
26
23
|
return {
|
|
@@ -29,4 +26,3 @@ const useZoomAreaFocus = () => {
|
|
|
29
26
|
isFocused,
|
|
30
27
|
};
|
|
31
28
|
};
|
|
32
|
-
exports.useZoomAreaFocus = useZoomAreaFocus;
|
|
@@ -1,20 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
const indexRounding_1 = require("../utils/indexRounding");
|
|
6
|
-
const rangeAndPositions_1 = require("../utils/rangeAndPositions");
|
|
7
|
-
const useZoomData = ({ data, initialRange, onDataChange, }) => {
|
|
1
|
+
import { useEffect, useState } from 'react';
|
|
2
|
+
import { getRangeIndices } from '../utils/indexRounding';
|
|
3
|
+
import { createDefaultRange } from '../utils/rangeAndPositions';
|
|
4
|
+
export const useZoomData = ({ data, initialRange, onDataChange, }) => {
|
|
8
5
|
// Initialize range state
|
|
9
|
-
const defaultRange = initialRange ||
|
|
10
|
-
const [currentRange, setCurrentRange] =
|
|
6
|
+
const defaultRange = initialRange || createDefaultRange(data.length);
|
|
7
|
+
const [currentRange, setCurrentRange] = useState(defaultRange);
|
|
11
8
|
// Filter data based on current range and emit changes
|
|
12
9
|
const filterData = (range) => {
|
|
13
10
|
if (!onDataChange || data.length === 0) {
|
|
14
11
|
return;
|
|
15
12
|
}
|
|
16
13
|
// Use centralized rounding logic to ensure consistency with accessibility labels
|
|
17
|
-
const { endIndex, startIndex } =
|
|
14
|
+
const { endIndex, startIndex } = getRangeIndices(range, data.length);
|
|
18
15
|
const filteredData = data.slice(startIndex, endIndex + 1);
|
|
19
16
|
onDataChange(filteredData);
|
|
20
17
|
};
|
|
@@ -24,7 +21,7 @@ const useZoomData = ({ data, initialRange, onDataChange, }) => {
|
|
|
24
21
|
filterData(newRange);
|
|
25
22
|
};
|
|
26
23
|
// Emit initial filtered data on mount
|
|
27
|
-
|
|
24
|
+
useEffect(() => {
|
|
28
25
|
filterData(currentRange);
|
|
29
26
|
}, []);
|
|
30
27
|
return {
|
|
@@ -32,4 +29,3 @@ const useZoomData = ({ data, initialRange, onDataChange, }) => {
|
|
|
32
29
|
handleRangeChange,
|
|
33
30
|
};
|
|
34
31
|
};
|
|
35
|
-
exports.useZoomData = useZoomData;
|
|
@@ -1,21 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./components"), exports);
|
|
18
|
-
__exportStar(require("./hooks"), exports);
|
|
19
|
-
__exportStar(require("./utils"), exports);
|
|
20
|
-
__exportStar(require("./zoomArea"), exports);
|
|
21
|
-
__exportStar(require("./zoomArea.type"), exports);
|
|
1
|
+
export * from './components';
|
|
2
|
+
export * from './hooks';
|
|
3
|
+
export * from './utils';
|
|
4
|
+
export * from './zoomArea';
|
|
5
|
+
export * from './zoomArea.type';
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.generateAccessibilityLabels = exports.getXAxisValue = void 0;
|
|
4
|
-
const indexRounding_1 = require("./indexRounding");
|
|
1
|
+
import { getRangeIndices } from './indexRounding';
|
|
5
2
|
// Template keys for accessibility labels
|
|
6
3
|
const ACCESSIBILITY_START_VALUE_KEY = '{{startValue}}';
|
|
7
4
|
const ACCESSIBILITY_END_VALUE_KEY = '{{endValue}}';
|
|
@@ -13,11 +10,10 @@ const ACCESSIBILITY_END_VALUE_KEY = '{{endValue}}';
|
|
|
13
10
|
* @param index - Integer index (should be pre-rounded using indexRounding utils)
|
|
14
11
|
* @returns String representation of the X-axis value, or fallback to string index
|
|
15
12
|
*/
|
|
16
|
-
const getXAxisValue = (data, xKey, index) => {
|
|
13
|
+
export const getXAxisValue = (data, xKey, index) => {
|
|
17
14
|
// Index should already be rounded and clamped by getRangeIndices()
|
|
18
15
|
return data[index]?.[xKey]?.toString() || `${index}`;
|
|
19
16
|
};
|
|
20
|
-
exports.getXAxisValue = getXAxisValue;
|
|
21
17
|
/**
|
|
22
18
|
* Builds screen reader text by replacing template keys with actual values
|
|
23
19
|
*
|
|
@@ -46,11 +42,11 @@ const buildScreenReaderText = (template, startValue, endValue) => {
|
|
|
46
42
|
* @param config - Optional configuration for custom label templates
|
|
47
43
|
* @returns Object with formatted accessibility labels for UI components
|
|
48
44
|
*/
|
|
49
|
-
const generateAccessibilityLabels = (data, xKey, currentRange, config) => {
|
|
45
|
+
export const generateAccessibilityLabels = (data, xKey, currentRange, config) => {
|
|
50
46
|
// Use EXACT same indexing logic as useZoomData.filterData() via shared utilities
|
|
51
|
-
const { endIndex, startIndex } =
|
|
52
|
-
const startValue =
|
|
53
|
-
const endValue =
|
|
47
|
+
const { endIndex, startIndex } = getRangeIndices(currentRange, data.length);
|
|
48
|
+
const startValue = getXAxisValue(data, xKey, startIndex);
|
|
49
|
+
const endValue = getXAxisValue(data, xKey, endIndex);
|
|
54
50
|
// Use custom templates or fall back to simple defaults (just the values)
|
|
55
51
|
const startHandler = buildScreenReaderText(config?.startHandler, startValue, endValue) ?? startValue;
|
|
56
52
|
const endHandler = buildScreenReaderText(config?.endHandler, startValue, endValue) ?? endValue;
|
|
@@ -62,4 +58,3 @@ const generateAccessibilityLabels = (data, xKey, currentRange, config) => {
|
|
|
62
58
|
startHandler,
|
|
63
59
|
};
|
|
64
60
|
};
|
|
65
|
-
exports.generateAccessibilityLabels = generateAccessibilityLabels;
|