@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,34 +1,31 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
const
|
|
11
|
-
const pickCustomAttributes_1 = require("../../../utils/pickCustomAttributes/pickCustomAttributes");
|
|
12
|
-
const lineChartContext_1 = require("../context/lineChartContext");
|
|
13
|
-
const LineChartYAxis = ({ ariaLabel, position = position_enum_1.Positions.LEFT, tickLine, tickText, valueFormatter = (value) => value,
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useContext } from 'react';
|
|
3
|
+
import { YAxis } from '../../../components/axisChart/yAxis/yAxis';
|
|
4
|
+
import { TickDataUtils } from '../../../components/tick/tick.types';
|
|
5
|
+
import { Positions } from '../../../types/position.enum';
|
|
6
|
+
import { ajustedTextSpace } from '../../../utils/ajustedTextSpace/ajustedTextSpace';
|
|
7
|
+
import { getTickTextXCoordinate } from '../../../utils/getTickTextCoordinate/getTickTextCoordinates';
|
|
8
|
+
import { pickCustomAttributes } from '../../../utils/pickCustomAttributes/pickCustomAttributes';
|
|
9
|
+
import { LineChartContext } from '../context/lineChartContext';
|
|
10
|
+
export const LineChartYAxis = ({ ariaLabel, position = Positions.LEFT, tickLine, tickText, valueFormatter = (value) => value,
|
|
14
11
|
// NOTE: tickValues prop is destructured but NOT USED - see TODO in lineChart.type.ts
|
|
15
12
|
...props }) => {
|
|
16
|
-
const { yAxisCoordinates: { coordinates, tickValues: contextTickValues }, yCursor, ...context } =
|
|
13
|
+
const { yAxisCoordinates: { coordinates, tickValues: contextTickValues }, yCursor, ...context } = useContext(LineChartContext);
|
|
17
14
|
// TODO: Currently ignoring props.tickValues and using contextTickValues instead
|
|
18
15
|
// This means custom tickValues prop has no effect. Implementation needed to:
|
|
19
16
|
// 1. Check if props.tickValues exists
|
|
20
17
|
// 2. Use custom tick values instead of context values when provided
|
|
21
18
|
// 3. Update buildLineContextValue to handle custom Y-axis tick values
|
|
22
19
|
const textAnchor = tickText?.textAnchor || 'middle';
|
|
23
|
-
const addSpace = position ===
|
|
20
|
+
const addSpace = position === Positions.RIGHT ? tickText?.right : tickText?.left;
|
|
24
21
|
const ajustedSpace = addSpace ?? 0;
|
|
25
|
-
const ajustedText =
|
|
26
|
-
const xTickText =
|
|
22
|
+
const ajustedText = ajustedTextSpace(textAnchor, context.yAxisText, ajustedSpace);
|
|
23
|
+
const xTickText = getTickTextXCoordinate(position, coordinates.x1, ajustedText);
|
|
27
24
|
const tickValues = tickText
|
|
28
|
-
?
|
|
25
|
+
? TickDataUtils.formatTicksValues(contextTickValues, valueFormatter)
|
|
29
26
|
: undefined;
|
|
30
27
|
// Extract custom attributes (aria-*, data-*) and handle deprecated ariaLabel
|
|
31
|
-
const customAttributes =
|
|
28
|
+
const customAttributes = pickCustomAttributes(props);
|
|
32
29
|
const finalAriaLabel = ariaLabel || props['aria-label'];
|
|
33
30
|
// Merge all props including custom attributes and ariaLabel precedence
|
|
34
31
|
const mergedProps = {
|
|
@@ -36,10 +33,9 @@ const LineChartYAxis = ({ ariaLabel, position = position_enum_1.Positions.LEFT,
|
|
|
36
33
|
...customAttributes,
|
|
37
34
|
...(finalAriaLabel && { 'aria-label': finalAriaLabel }),
|
|
38
35
|
};
|
|
39
|
-
return ((
|
|
36
|
+
return (_jsx(YAxis, { ...coordinates, ...mergedProps, canvasHeight: Number(context.canvasHeight), canvasWidth: Number(context.canvasWidth), cursor: yCursor, dataTestId: `${context.dataTestId}yAxis`, tickLine: {
|
|
40
37
|
...tickLine,
|
|
41
38
|
x1: context.extraSpaceLeftX,
|
|
42
39
|
x2: Number(context.canvasWidth) - context.extraSpaceRightX,
|
|
43
40
|
}, tickText: { ...tickText, x: xTickText }, tickValues: tickValues }));
|
|
44
41
|
};
|
|
45
|
-
exports.LineChartYAxis = LineChartYAxis;
|
|
@@ -1,9 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
var useAutoClick_1 = require("./useAutoClick");
|
|
5
|
-
Object.defineProperty(exports, "useAutoClick", { enumerable: true, get: function () { return useAutoClick_1.useAutoClick; } });
|
|
6
|
-
var useHover_1 = require("./useHover");
|
|
7
|
-
Object.defineProperty(exports, "useHover", { enumerable: true, get: function () { return useHover_1.useHover; } });
|
|
8
|
-
var useIndicator_1 = require("./useIndicator");
|
|
9
|
-
Object.defineProperty(exports, "useIndicator", { enumerable: true, get: function () { return useIndicator_1.useIndicator; } });
|
|
1
|
+
export { useAutoClick } from './useAutoClick';
|
|
2
|
+
export { useHover } from './useHover';
|
|
3
|
+
export { useIndicator } from './useIndicator';
|
|
@@ -1,15 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
const autoClick = (0, react_1.useRef)(false);
|
|
7
|
-
const innerRef = (0, react_1.useRef)(null);
|
|
8
|
-
(0, react_1.useImperativeHandle)(ref, () => innerRef.current, []);
|
|
1
|
+
import { useEffect, useImperativeHandle, useRef } from 'react';
|
|
2
|
+
export const useAutoClick = (ref) => {
|
|
3
|
+
const autoClick = useRef(false);
|
|
4
|
+
const innerRef = useRef(null);
|
|
5
|
+
useImperativeHandle(ref, () => innerRef.current, []);
|
|
9
6
|
const handleClick = (e) => {
|
|
10
7
|
autoClick.current = !!e.autoClick;
|
|
11
8
|
};
|
|
12
|
-
|
|
9
|
+
useEffect(() => {
|
|
13
10
|
if (!innerRef.current) {
|
|
14
11
|
return;
|
|
15
12
|
}
|
|
@@ -20,4 +17,3 @@ const useAutoClick = (ref) => {
|
|
|
20
17
|
}, []);
|
|
21
18
|
return [innerRef, autoClick];
|
|
22
19
|
};
|
|
23
|
-
exports.useAutoClick = useAutoClick;
|
|
@@ -1,11 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.useHover = void 0;
|
|
4
|
-
const react_1 = require("react");
|
|
1
|
+
import { useCallback, useState } from 'react';
|
|
5
2
|
const outRange = -Infinity;
|
|
6
|
-
const useHover = ({ canvasHeight, canvasWidth }) => {
|
|
7
|
-
const [[xCursor, yCursor], setCursor] =
|
|
8
|
-
const getCursor =
|
|
3
|
+
export const useHover = ({ canvasHeight, canvasWidth }) => {
|
|
4
|
+
const [[xCursor, yCursor], setCursor] = useState([outRange, outRange]);
|
|
5
|
+
const getCursor = useCallback((e, node) => {
|
|
9
6
|
const { height, left, top, width } = node.getBoundingClientRect();
|
|
10
7
|
// get the x and y position of the mouse
|
|
11
8
|
const x = e.clientX - left;
|
|
@@ -19,7 +16,7 @@ const useHover = ({ canvasHeight, canvasWidth }) => {
|
|
|
19
16
|
const startTouch = (e) => {
|
|
20
17
|
e.preventDefault();
|
|
21
18
|
};
|
|
22
|
-
const svgRef =
|
|
19
|
+
const svgRef = useCallback((node) => {
|
|
23
20
|
if (node) {
|
|
24
21
|
node.addEventListener('touchstart', startTouch);
|
|
25
22
|
node.addEventListener('touchmove', e => getCursor(e.touches[0], node));
|
|
@@ -31,4 +28,3 @@ const useHover = ({ canvasHeight, canvasWidth }) => {
|
|
|
31
28
|
}, [canvasHeight, canvasWidth]);
|
|
32
29
|
return { svgRef, xCursor, yCursor };
|
|
33
30
|
};
|
|
34
|
-
exports.useHover = useHover;
|
|
@@ -1,11 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
const pathRef = (0, react_1.useRef)(null);
|
|
7
|
-
const indicatorRef = (0, react_1.useRef)(null);
|
|
8
|
-
(0, react_1.useEffect)(() => {
|
|
1
|
+
import { useEffect, useRef } from 'react';
|
|
2
|
+
export const useIndicator = (xPosition, implement) => {
|
|
3
|
+
const pathRef = useRef(null);
|
|
4
|
+
const indicatorRef = useRef(null);
|
|
5
|
+
useEffect(() => {
|
|
9
6
|
if (!implement || !pathRef.current || !indicatorRef.current) {
|
|
10
7
|
return;
|
|
11
8
|
}
|
|
@@ -32,4 +29,3 @@ const useIndicator = (xPosition, implement) => {
|
|
|
32
29
|
}, [xPosition]);
|
|
33
30
|
return { indicatorRef, pathRef };
|
|
34
31
|
};
|
|
35
|
-
exports.useIndicator = useIndicator;
|
|
@@ -1,17 +1 @@
|
|
|
1
|
-
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
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("./lineChart"), exports);
|
|
1
|
+
export * from './lineChart';
|
|
@@ -1,30 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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
|
-
exports.LineChart = void 0;
|
|
18
|
-
const lineChartPath_1 = require("./fragments/lineChartPath");
|
|
19
|
-
const lineChartSeparator_1 = require("./fragments/lineChartSeparator");
|
|
20
|
-
const lineChartXAxis_1 = require("./fragments/lineChartXAxis");
|
|
21
|
-
const lineChartYAxis_1 = require("./fragments/lineChartYAxis");
|
|
22
|
-
const lineChartStructure_1 = require("./lineChartStructure");
|
|
23
|
-
const LineChart = Object.assign(lineChartStructure_1.LineChartStructure, {
|
|
24
|
-
Path: lineChartPath_1.LineChartPath,
|
|
25
|
-
Separator: lineChartSeparator_1.LineChartSeparator,
|
|
26
|
-
XAxis: lineChartXAxis_1.LineChartXAxis,
|
|
27
|
-
YAxis: lineChartYAxis_1.LineChartYAxis,
|
|
1
|
+
import { LineChartPath } from './fragments/lineChartPath';
|
|
2
|
+
import { LineChartSeparator } from './fragments/lineChartSeparator';
|
|
3
|
+
import { LineChartXAxis } from './fragments/lineChartXAxis';
|
|
4
|
+
import { LineChartYAxis } from './fragments/lineChartYAxis';
|
|
5
|
+
import { LineChartStructure } from './lineChartStructure';
|
|
6
|
+
const LineChart = Object.assign(LineChartStructure, {
|
|
7
|
+
Path: LineChartPath,
|
|
8
|
+
Separator: LineChartSeparator,
|
|
9
|
+
XAxis: LineChartXAxis,
|
|
10
|
+
YAxis: LineChartYAxis,
|
|
28
11
|
});
|
|
29
|
-
|
|
30
|
-
|
|
12
|
+
export { LineChart };
|
|
13
|
+
export * from './lineChart.type';
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
export {};
|
|
@@ -1,21 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
const lineChartXAxis_1 = require("./fragments/lineChartXAxis");
|
|
17
|
-
const lineChartYAxis_1 = require("./fragments/lineChartYAxis");
|
|
18
|
-
const useHover_1 = require("./hook/useHover");
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { Children, useEffect, useMemo, useState } from 'react';
|
|
3
|
+
import { SvgContainer } from '../../components/svgContainer/svgContainer';
|
|
4
|
+
import { buildViewBox } from '../../components/svgContainer/utils/buildViewBox/buildViewBox';
|
|
5
|
+
import { DefaultCanvasConfig } from '../../types/canvas.type';
|
|
6
|
+
import { ErrorType } from '../../types/errors.type';
|
|
7
|
+
import { getCanvasDimensions } from '../../utils/getCanvasDimensions/getCanvasDimensions';
|
|
8
|
+
import { getChildrenAttr } from '../../utils/getChildrenAttr/getChildrenAttr';
|
|
9
|
+
import { getDataFingerprint } from '../../utils/getDataFingerprint/getDataFingerprint';
|
|
10
|
+
import { parseStringToNumberPx } from '../../utils/parseStringToNumberPx.ts/parseStringToNumberPx';
|
|
11
|
+
import { buildLineContextValue } from './context/buildLineContextValue';
|
|
12
|
+
import { LineChartContext } from './context/lineChartContext';
|
|
13
|
+
import { LineChartXAxis } from './fragments/lineChartXAxis';
|
|
14
|
+
import { LineChartYAxis } from './fragments/lineChartYAxis';
|
|
15
|
+
import { useHover } from './hook/useHover';
|
|
19
16
|
/**
|
|
20
17
|
* Renders a line chart component.
|
|
21
18
|
*
|
|
@@ -45,39 +42,39 @@ const useHover_1 = require("./hook/useHover");
|
|
|
45
42
|
*
|
|
46
43
|
* @returns The rendered LineChart component.
|
|
47
44
|
*/
|
|
48
|
-
const LineChartStructure = ({ ariaHidden, ariaLabel, canvasConfig =
|
|
45
|
+
export const LineChartStructure = ({ ariaHidden, ariaLabel, canvasConfig = DefaultCanvasConfig, caption, children, classNames, data, dataTestId = 'line-chart', getPathArea, height = '100%', onErrors, role, tabIndex, width = '100%', xKey, ...props }) => {
|
|
49
46
|
const { extraSpace: canvasExtraSpace, height: canvasHeight, width: canvasWidth } = canvasConfig;
|
|
50
|
-
const [childrenYKeys, setChildrenYKey] =
|
|
51
|
-
const [parsedCanvas, setParsedCanvas] =
|
|
47
|
+
const [childrenYKeys, setChildrenYKey] = useState('');
|
|
48
|
+
const [parsedCanvas, setParsedCanvas] = useState({
|
|
52
49
|
height: 0,
|
|
53
50
|
width: 0,
|
|
54
51
|
});
|
|
55
52
|
const parsedCanvasExtraSpace = canvasExtraSpace
|
|
56
|
-
?
|
|
53
|
+
? parseStringToNumberPx(canvasExtraSpace)
|
|
57
54
|
: undefined;
|
|
58
|
-
const viewBox =
|
|
55
|
+
const viewBox = buildViewBox(parsedCanvas.width, parsedCanvas.height, parsedCanvasExtraSpace);
|
|
59
56
|
// Set the default axis for the chart
|
|
60
57
|
const defaultAxis = [
|
|
61
|
-
(
|
|
62
|
-
(
|
|
58
|
+
_jsx(LineChartXAxis, {}, "default-x-axis"),
|
|
59
|
+
_jsx(LineChartYAxis, {}, "default-y-axis"),
|
|
63
60
|
];
|
|
64
|
-
const arrayChildren = (
|
|
61
|
+
const arrayChildren = (Children.toArray(children) || []);
|
|
65
62
|
const chidrenWithDefaultAxis = defaultAxis.concat(arrayChildren);
|
|
66
63
|
const maxValue = Math.max(parsedCanvas.width, parsedCanvas.height, parsedCanvasExtraSpace ?? 0);
|
|
67
64
|
const ajustedX = isNaN(parsedCanvas.width / maxValue) ? 0 : parsedCanvas.width / maxValue;
|
|
68
65
|
const ajustedY = isNaN(parsedCanvas.height / maxValue) ? 0 : parsedCanvas.height / maxValue;
|
|
69
66
|
// watch the Y childs keys
|
|
70
|
-
|
|
67
|
+
getChildrenAttr({
|
|
71
68
|
attrName: 'dataKey',
|
|
72
69
|
children: chidrenWithDefaultAxis,
|
|
73
70
|
originalValue: childrenYKeys,
|
|
74
71
|
updateValue: setChildrenYKey,
|
|
75
72
|
});
|
|
76
73
|
// Create a fingerprint of the data to avoid unnecessary contextValue updates
|
|
77
|
-
const dataFingerprint =
|
|
74
|
+
const dataFingerprint = getDataFingerprint(data);
|
|
78
75
|
// Build the context value
|
|
79
|
-
const contextValue =
|
|
80
|
-
return
|
|
76
|
+
const contextValue = useMemo(() => {
|
|
77
|
+
return buildLineContextValue({
|
|
81
78
|
ajustedX,
|
|
82
79
|
ajustedY,
|
|
83
80
|
canvasHeight: parsedCanvas.height,
|
|
@@ -88,23 +85,23 @@ const LineChartStructure = ({ ariaHidden, ariaLabel, canvasConfig = canvas_type_
|
|
|
88
85
|
xKey,
|
|
89
86
|
});
|
|
90
87
|
}, [parsedCanvas.width, parsedCanvas.height, dataFingerprint, xKey, childrenYKeys]);
|
|
91
|
-
|
|
88
|
+
useEffect(() => {
|
|
92
89
|
if (contextValue.error && onErrors) {
|
|
93
90
|
onErrors({
|
|
94
|
-
[
|
|
91
|
+
[ErrorType.GENERIC]: contextValue.error,
|
|
95
92
|
});
|
|
96
93
|
}
|
|
97
94
|
}, [contextValue.error, onErrors]);
|
|
98
|
-
const { svgRef, xCursor, yCursor } =
|
|
95
|
+
const { svgRef, xCursor, yCursor } = useHover({
|
|
99
96
|
canvasHeight: parsedCanvas.height,
|
|
100
97
|
canvasWidth: parsedCanvas.width,
|
|
101
98
|
});
|
|
102
|
-
|
|
99
|
+
useEffect(() => {
|
|
103
100
|
const svgElement = document.querySelector('[data-kbt-svg]');
|
|
104
101
|
if (!svgElement) {
|
|
105
102
|
return;
|
|
106
103
|
}
|
|
107
|
-
const { parsedCanvasHeight, parsedCanvasWidth } =
|
|
104
|
+
const { parsedCanvasHeight, parsedCanvasWidth } = getCanvasDimensions({
|
|
108
105
|
canvasHeight,
|
|
109
106
|
canvasWidth,
|
|
110
107
|
svgElement,
|
|
@@ -114,7 +111,7 @@ const LineChartStructure = ({ ariaHidden, ariaLabel, canvasConfig = canvas_type_
|
|
|
114
111
|
width: parsedCanvasWidth,
|
|
115
112
|
});
|
|
116
113
|
}, [canvasWidth, canvasHeight]);
|
|
117
|
-
|
|
114
|
+
useEffect(() => {
|
|
118
115
|
getPathArea?.({
|
|
119
116
|
x1: contextValue.extraSpaceLeftX,
|
|
120
117
|
x2: parsedCanvas.width - contextValue.extraSpaceRightX,
|
|
@@ -122,7 +119,7 @@ const LineChartStructure = ({ ariaHidden, ariaLabel, canvasConfig = canvas_type_
|
|
|
122
119
|
y2: parsedCanvas.height - contextValue.extraSpaceBottomY,
|
|
123
120
|
});
|
|
124
121
|
}, [parsedCanvas.width, parsedCanvas.height]);
|
|
125
|
-
return ((
|
|
122
|
+
return (_jsx(SvgContainer, { ref: svgRef, ariaHidden: ariaHidden, ariaLabel: ariaLabel, caption: caption, className: classNames, "data-kbt-svg": true, dataTestId: dataTestId, height: height, role: role, tabIndex: tabIndex, viewBox: viewBox, width: width, ...props, children: _jsx(LineChartContext.Provider, { value: {
|
|
126
123
|
...contextValue,
|
|
127
124
|
canvasExtraSpace: parsedCanvasExtraSpace,
|
|
128
125
|
canvasHeight: parsedCanvas.height,
|
|
@@ -134,4 +131,3 @@ const LineChartStructure = ({ ariaHidden, ariaLabel, canvasConfig = canvas_type_
|
|
|
134
131
|
yCursor,
|
|
135
132
|
}, children: children }) }));
|
|
136
133
|
};
|
|
137
|
-
exports.LineChartStructure = LineChartStructure;
|
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.processAccessibilityTemplate = exports.TEMPLATE_KEYS = void 0;
|
|
4
1
|
// Template keys for accessibility labels
|
|
5
|
-
|
|
2
|
+
export const TEMPLATE_KEYS = {
|
|
6
3
|
DATA_KEY: '{{dataKey}}',
|
|
7
4
|
INDEX: '{{index}}',
|
|
8
5
|
X_VALUE: '{{xValue}}',
|
|
@@ -34,17 +31,17 @@ const extractValuesFromDataPoint = (dataPoint, nodeData) => {
|
|
|
34
31
|
const replaceTemplatePlaceholders = (template, nodeData, xValue, yValue) => {
|
|
35
32
|
let result = template;
|
|
36
33
|
if (nodeData.dataKey !== undefined) {
|
|
37
|
-
result = result.replace(new RegExp(
|
|
34
|
+
result = result.replace(new RegExp(TEMPLATE_KEYS.DATA_KEY, 'g'), nodeData.dataKey);
|
|
38
35
|
}
|
|
39
36
|
// Always replace xValue and yValue placeholders, even with empty strings
|
|
40
|
-
result = result.replace(new RegExp(
|
|
41
|
-
result = result.replace(new RegExp(
|
|
37
|
+
result = result.replace(new RegExp(TEMPLATE_KEYS.X_VALUE, 'g'), xValue);
|
|
38
|
+
result = result.replace(new RegExp(TEMPLATE_KEYS.Y_VALUE, 'g'), yValue);
|
|
42
39
|
if (nodeData.index !== undefined) {
|
|
43
|
-
result = result.replace(new RegExp(
|
|
40
|
+
result = result.replace(new RegExp(TEMPLATE_KEYS.INDEX, 'g'), (nodeData.index + 1).toString());
|
|
44
41
|
}
|
|
45
42
|
return result;
|
|
46
43
|
};
|
|
47
|
-
const processAccessibilityTemplate = (template, nodeData, dataValue) => {
|
|
44
|
+
export const processAccessibilityTemplate = (template, nodeData, dataValue) => {
|
|
48
45
|
if (!template) {
|
|
49
46
|
return undefined;
|
|
50
47
|
}
|
|
@@ -57,4 +54,3 @@ const processAccessibilityTemplate = (template, nodeData, dataValue) => {
|
|
|
57
54
|
// Replace template placeholders
|
|
58
55
|
return replaceTemplatePlaceholders(template, nodeData, xValue, yValue);
|
|
59
56
|
};
|
|
60
|
-
exports.processAccessibilityTemplate = processAccessibilityTemplate;
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.findClosestNumber = exports.findSurroundingNumber = void 0;
|
|
4
|
-
const findSurroundingNumber = (points, xPosition) => {
|
|
1
|
+
export const findSurroundingNumber = (points, xPosition) => {
|
|
5
2
|
let idx = 0;
|
|
6
3
|
let match = false;
|
|
7
4
|
// TODO: performance the init and last point
|
|
@@ -14,8 +11,7 @@ const findSurroundingNumber = (points, xPosition) => {
|
|
|
14
11
|
}
|
|
15
12
|
return { idx, match };
|
|
16
13
|
};
|
|
17
|
-
|
|
18
|
-
const findClosestNumber = (points, xPosition) => {
|
|
14
|
+
export const findClosestNumber = (points, xPosition) => {
|
|
19
15
|
let closest = 0;
|
|
20
16
|
let minDiff = Math.abs(points[0] - xPosition);
|
|
21
17
|
for (let i = 1; i < points.length; i++) {
|
|
@@ -27,4 +23,3 @@ const findClosestNumber = (points, xPosition) => {
|
|
|
27
23
|
}
|
|
28
24
|
return closest;
|
|
29
25
|
};
|
|
30
|
-
exports.findClosestNumber = findClosestNumber;
|
|
@@ -1,12 +1,9 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getDataValues = void 0;
|
|
4
1
|
/**
|
|
5
2
|
* Retrieves the data values from the given TickValuesAxisProps object.
|
|
6
3
|
* @param data - The TickValuesAxisProps object containing the data values.
|
|
7
4
|
* @returns An array of string values representing the data, or undefined if the data is invalid.
|
|
8
5
|
*/
|
|
9
|
-
const getDataValues = (data) => {
|
|
6
|
+
export const getDataValues = (data) => {
|
|
10
7
|
if (data.custom) {
|
|
11
8
|
return data.custom?.values;
|
|
12
9
|
}
|
|
@@ -25,4 +22,3 @@ const getDataValues = (data) => {
|
|
|
25
22
|
}
|
|
26
23
|
return undefined;
|
|
27
24
|
};
|
|
28
|
-
exports.getDataValues = getDataValues;
|
|
@@ -1,22 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
const lineChartYAxis_1 = require("../fragments/lineChartYAxis");
|
|
10
|
-
const getDataValues_1 = require("./getDataValues");
|
|
11
|
-
const getRoundedMaxValue_1 = require("./getRoundedMaxValue");
|
|
1
|
+
import { Children, isValidElement } from 'react';
|
|
2
|
+
import { Positions } from '../../../types/position.enum';
|
|
3
|
+
import { buildTickValues } from '../../../utils/buildTickValues/buildTickValues';
|
|
4
|
+
import { textBound } from '../../../utils/textBound/textBound';
|
|
5
|
+
import { LineChartXAxis } from '../fragments/lineChartXAxis';
|
|
6
|
+
import { LineChartYAxis } from '../fragments/lineChartYAxis';
|
|
7
|
+
import { getDataValues } from './getDataValues';
|
|
8
|
+
import { getYKeyRoundMaxValue } from './getRoundedMaxValue';
|
|
12
9
|
const handleLineChartXAxis = (child, data, xKey, ajustedX, viewBox, canvasHeight, canvasWidth) => {
|
|
13
10
|
const { position, tickText, tickValues, valueFormatter } = child.props;
|
|
14
11
|
const fontSize = tickText?.fontSize ?? 0;
|
|
15
12
|
const spaceFontSize = fontSize * ajustedX;
|
|
16
|
-
const xData = tickValues ?
|
|
13
|
+
const xData = tickValues ? getDataValues(tickValues) : data.map(d => d[xKey]);
|
|
17
14
|
// Apply the valueFormatter if provided to get the actual rendered text width
|
|
18
15
|
const formattedXData = valueFormatter ? xData.map(valueFormatter) : xData;
|
|
19
|
-
const securityXSpace =
|
|
16
|
+
const securityXSpace = textBound({
|
|
20
17
|
bound: 'width',
|
|
21
18
|
data: formattedXData,
|
|
22
19
|
fontSize,
|
|
@@ -24,11 +21,11 @@ const handleLineChartXAxis = (child, data, xKey, ajustedX, viewBox, canvasHeight
|
|
|
24
21
|
svgWidth: `${canvasWidth}`,
|
|
25
22
|
viewBox,
|
|
26
23
|
});
|
|
27
|
-
const isBottomPosition = position ===
|
|
28
|
-
const isTopPosition = position ===
|
|
24
|
+
const isBottomPosition = position === Positions.BOTTOM;
|
|
25
|
+
const isTopPosition = position === Positions.TOP;
|
|
29
26
|
const extraSpaceBottomY = isBottomPosition ? spaceFontSize + (tickText?.top ?? 0) : 0;
|
|
30
27
|
const extraSpaceTopY = isTopPosition ? spaceFontSize + (tickText?.bottom ?? 0) : 0;
|
|
31
|
-
const lineChartXPosition = (() => position ||
|
|
28
|
+
const lineChartXPosition = (() => position || Positions.BOTTOM)();
|
|
32
29
|
const getBreakAxis = () => {
|
|
33
30
|
if (tickValues?.numeric) {
|
|
34
31
|
return tickValues.numeric.breakAxis ?? 0;
|
|
@@ -50,11 +47,11 @@ const handleLineChartYAxis = (child, data, xKey, ajustedY, viewBox, canvasHeight
|
|
|
50
47
|
const fontSize = tickText?.fontSize ?? '0';
|
|
51
48
|
const spaceFontSize = fontSize * ajustedY;
|
|
52
49
|
const dataValues = tickValues ||
|
|
53
|
-
|
|
54
|
-
const yData =
|
|
50
|
+
buildTickValues([...new Set(getYKeyRoundMaxValue(data, xKey))]);
|
|
51
|
+
const yData = getDataValues(dataValues);
|
|
55
52
|
// Apply the valueFormatter if provided to get the actual rendered text width
|
|
56
53
|
const formattedYData = valueFormatter ? yData.map(valueFormatter) : yData;
|
|
57
|
-
const yAxisText =
|
|
54
|
+
const yAxisText = textBound({
|
|
58
55
|
bound: 'width',
|
|
59
56
|
data: formattedYData,
|
|
60
57
|
fontSize: fontSize,
|
|
@@ -63,11 +60,11 @@ const handleLineChartYAxis = (child, data, xKey, ajustedY, viewBox, canvasHeight
|
|
|
63
60
|
viewBox,
|
|
64
61
|
});
|
|
65
62
|
const securityYSpace = spaceFontSize;
|
|
66
|
-
const isLeftPosition = position ===
|
|
67
|
-
const isRightPosition = position ===
|
|
63
|
+
const isLeftPosition = position === Positions.LEFT;
|
|
64
|
+
const isRightPosition = position === Positions.RIGHT;
|
|
68
65
|
const extraSpaceLeftX = isLeftPosition ? yAxisText + (tickText?.right ?? 0) : 0;
|
|
69
66
|
const extraSpaceRightX = isRightPosition ? yAxisText + (tickText?.left ?? 0) : 0;
|
|
70
|
-
const lineChartYPosition = position ||
|
|
67
|
+
const lineChartYPosition = position || Positions.LEFT;
|
|
71
68
|
const getBreakAxis = () => {
|
|
72
69
|
if (tickValues?.numeric) {
|
|
73
70
|
return tickValues.numeric.breakAxis ?? 0;
|
|
@@ -90,14 +87,14 @@ const handleLineChartYAxis = (child, data, xKey, ajustedY, viewBox, canvasHeight
|
|
|
90
87
|
* @param {GetExtraSpacing} options - The options for calculating extra spacing.
|
|
91
88
|
* @returns {LineChartExtraSpacings} - The calculated extra spacings for the line chart.
|
|
92
89
|
*/
|
|
93
|
-
const getExtraSpacing = ({ ajustedX, ajustedY, canvasHeight, canvasWidth, children, data, viewBox, xKey, }) => {
|
|
90
|
+
export const getExtraSpacing = ({ ajustedX, ajustedY, canvasHeight, canvasWidth, children, data, viewBox, xKey, }) => {
|
|
94
91
|
let result = {
|
|
95
92
|
extraSpaceBottomY: 0,
|
|
96
93
|
extraSpaceLeftX: 0,
|
|
97
94
|
extraSpaceRightX: 0,
|
|
98
95
|
extraSpaceTopY: 0,
|
|
99
|
-
lineChartXPosition:
|
|
100
|
-
lineChartYPosition:
|
|
96
|
+
lineChartXPosition: Positions.BOTTOM,
|
|
97
|
+
lineChartYPosition: Positions.LEFT,
|
|
101
98
|
securityXSpace: 0,
|
|
102
99
|
securityYSpace: 0,
|
|
103
100
|
xAxisText: 0,
|
|
@@ -107,15 +104,15 @@ const getExtraSpacing = ({ ajustedX, ajustedY, canvasHeight, canvasWidth, childr
|
|
|
107
104
|
yBreakAxis: 0,
|
|
108
105
|
yData: [],
|
|
109
106
|
};
|
|
110
|
-
|
|
111
|
-
if (
|
|
112
|
-
if (child.type ===
|
|
107
|
+
Children.forEach(children, (child) => {
|
|
108
|
+
if (isValidElement(child)) {
|
|
109
|
+
if (child.type === LineChartXAxis) {
|
|
113
110
|
result = {
|
|
114
111
|
...result,
|
|
115
112
|
...handleLineChartXAxis(child, data, xKey, ajustedX, viewBox, canvasHeight, canvasWidth),
|
|
116
113
|
};
|
|
117
114
|
}
|
|
118
|
-
else if (child.type ===
|
|
115
|
+
else if (child.type === LineChartYAxis) {
|
|
119
116
|
result = {
|
|
120
117
|
...result,
|
|
121
118
|
...handleLineChartYAxis(child, data, xKey, ajustedY, viewBox, canvasHeight, canvasWidth),
|
|
@@ -125,4 +122,3 @@ const getExtraSpacing = ({ ajustedX, ajustedY, canvasHeight, canvasWidth, childr
|
|
|
125
122
|
});
|
|
126
123
|
return result;
|
|
127
124
|
};
|
|
128
|
-
exports.getExtraSpacing = getExtraSpacing;
|
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getPathData = void 0;
|
|
4
1
|
/**
|
|
5
2
|
* Generates SVG path data from an array of points.
|
|
6
3
|
* @param points - An array of points, where each point is an array of two numbers representing the x and y coordinates.
|
|
@@ -10,7 +7,7 @@ exports.getPathData = void 0;
|
|
|
10
7
|
* @param extendToBottom - A boolean indicating whether the path should extend to the bottom of the SVG container. Defaults to false.
|
|
11
8
|
* @returns The SVG path data as a string.
|
|
12
9
|
*/
|
|
13
|
-
const getPathData = ({ curved = false, extendToBottom = false, points, svgHeight, }) => {
|
|
10
|
+
export const getPathData = ({ curved = false, extendToBottom = false, points, svgHeight, }) => {
|
|
14
11
|
if (points.length === 0) {
|
|
15
12
|
return '';
|
|
16
13
|
}
|
|
@@ -34,4 +31,3 @@ const getPathData = ({ curved = false, extendToBottom = false, points, svgHeight
|
|
|
34
31
|
}
|
|
35
32
|
return pathData;
|
|
36
33
|
};
|
|
37
|
-
exports.getPathData = getPathData;
|
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getProjection = void 0;
|
|
4
1
|
const addXProjection = (point, projection) => {
|
|
5
2
|
if (!projection) {
|
|
6
3
|
return point;
|
|
@@ -31,7 +28,7 @@ const addYProjection = (point, svgHeight, projection) => {
|
|
|
31
28
|
* @param {ProjectionType} [params.lowerProjection] - The lower projection data.
|
|
32
29
|
* @returns {GetProjectionReturnType} The generated SVG path data.
|
|
33
30
|
*/
|
|
34
|
-
const getProjection = ({ curved, lowerProjection, points, svgHeight, upperProjection, }) => {
|
|
31
|
+
export const getProjection = ({ curved, lowerProjection, points, svgHeight, upperProjection, }) => {
|
|
35
32
|
const hasProjections = upperProjection || lowerProjection;
|
|
36
33
|
if (points.length === 0 && !hasProjections) {
|
|
37
34
|
return { shapePath: '' };
|
|
@@ -106,4 +103,3 @@ const getProjection = ({ curved, lowerProjection, points, svgHeight, upperProjec
|
|
|
106
103
|
}
|
|
107
104
|
return { downPath, shapePath, upPath };
|
|
108
105
|
};
|
|
109
|
-
exports.getProjection = getProjection;
|