@kubit-ui-web/react-charts 1.0.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 +2 -0
- 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/package.json +31 -33
package/README.md
CHANGED
|
@@ -45,6 +45,8 @@
|
|
|
45
45
|
|
|
46
46
|
# For Library Users
|
|
47
47
|
|
|
48
|
+
> 💡 **Cross-platform**: Kubit Charts is also available for [Android](https://github.com/kubit-ui/kubit-android-charts) and [iOS](https://github.com/kubit-ui/kubit-ios-charts) platforms, enabling consistent chart experiences across all your applications.
|
|
49
|
+
|
|
48
50
|
## Features
|
|
49
51
|
|
|
50
52
|
**Composable**: Modular architecture where each chart is composed of specialized elements
|
|
@@ -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.BarChart = void 0;
|
|
18
|
-
const barChartStructure_1 = require("./barChartStructure");
|
|
19
|
-
const barChartPath_1 = require("./fragments/barChartPath");
|
|
20
|
-
const barChartSeparator_1 = require("./fragments/barChartSeparator");
|
|
21
|
-
const barChartXAxis_1 = require("./fragments/barChartXAxis");
|
|
22
|
-
const barChartYAxis_1 = require("./fragments/barChartYAxis");
|
|
23
|
-
const BarChart = Object.assign(barChartStructure_1.BarChartStructure, {
|
|
24
|
-
Path: barChartPath_1.BarChartPath,
|
|
25
|
-
Separator: barChartSeparator_1.BarChartSeparator,
|
|
26
|
-
XAxis: barChartXAxis_1.BarChartXAxis,
|
|
27
|
-
YAxis: barChartYAxis_1.BarChartYAxis,
|
|
1
|
+
import { BarChartStructure } from './barChartStructure';
|
|
2
|
+
import { BarChartPath } from './fragments/barChartPath';
|
|
3
|
+
import { BarChartSeparator } from './fragments/barChartSeparator';
|
|
4
|
+
import { BarChartXAxis } from './fragments/barChartXAxis';
|
|
5
|
+
import { BarChartYAxis } from './fragments/barChartYAxis';
|
|
6
|
+
const BarChart = Object.assign(BarChartStructure, {
|
|
7
|
+
Path: BarChartPath,
|
|
8
|
+
Separator: BarChartSeparator,
|
|
9
|
+
XAxis: BarChartXAxis,
|
|
10
|
+
YAxis: BarChartYAxis,
|
|
28
11
|
});
|
|
29
|
-
|
|
30
|
-
|
|
12
|
+
export { BarChart };
|
|
13
|
+
export * from './barChart.type';
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
export {};
|
|
@@ -1,45 +1,42 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
const
|
|
14
|
-
const barChartYAxis_1 = require("./fragments/barChartYAxis");
|
|
15
|
-
const countBarChildren_1 = require("./utils/countBarChildren");
|
|
16
|
-
const BarChartStructure = ({ canvasConfig = canvas_type_1.DefaultCanvasConfig, caption, children, classNames, data, dataTestId, gapBetweenBars = 0, height = '100%', orientation, pKey, role, tabIndex, width = '100%', ...props }) => {
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { Children, useMemo } 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 { getDataFingerprint } from '../../utils/getDataFingerprint/getDataFingerprint';
|
|
7
|
+
import { parseStringToNumberPx } from '../../utils/parseStringToNumberPx.ts/parseStringToNumberPx';
|
|
8
|
+
import { BarChartContext } from './context/barChartContext';
|
|
9
|
+
import { buildBarContextValue } from './context/buildBarContextValues';
|
|
10
|
+
import { BarChartXAxis } from './fragments/barChartXAxis';
|
|
11
|
+
import { BarChartYAxis } from './fragments/barChartYAxis';
|
|
12
|
+
import { countBarChildren } from './utils/countBarChildren';
|
|
13
|
+
export const BarChartStructure = ({ canvasConfig = DefaultCanvasConfig, caption, children, classNames, data, dataTestId, gapBetweenBars = 0, height = '100%', orientation, pKey, role, tabIndex, width = '100%', ...props }) => {
|
|
17
14
|
// Extracts and sets default values for canvas configuration
|
|
18
15
|
const { extraSpace: canvasExtraSpace, height: canvasHeight, width: canvasWidth } = canvasConfig;
|
|
19
|
-
const parsedCanvasWidth =
|
|
20
|
-
const parsedCanvasHeight =
|
|
16
|
+
const parsedCanvasWidth = parseStringToNumberPx(canvasWidth);
|
|
17
|
+
const parsedCanvasHeight = parseStringToNumberPx(canvasHeight);
|
|
21
18
|
const parsedCanvasExtraSpace = canvasExtraSpace
|
|
22
|
-
?
|
|
19
|
+
? parseStringToNumberPx(canvasExtraSpace)
|
|
23
20
|
: undefined;
|
|
24
|
-
const viewBox =
|
|
21
|
+
const viewBox = buildViewBox(parsedCanvasWidth, parsedCanvasHeight, parsedCanvasExtraSpace);
|
|
25
22
|
// count how many of bar children exists
|
|
26
|
-
const barChildrenCount =
|
|
23
|
+
const barChildrenCount = countBarChildren(children);
|
|
27
24
|
const secureGap = gapBetweenBars * 2;
|
|
28
25
|
// Set the default axis for the chart
|
|
29
26
|
const defaultAxis = [
|
|
30
|
-
(
|
|
31
|
-
(
|
|
27
|
+
_jsx(BarChartXAxis, {}, "default-x-axis"),
|
|
28
|
+
_jsx(BarChartYAxis, {}, "default-y-axis"),
|
|
32
29
|
];
|
|
33
|
-
const arrayChildren = (
|
|
30
|
+
const arrayChildren = (Children.toArray(children) || []);
|
|
34
31
|
const chidrenWithDefaultAxis = defaultAxis.concat(arrayChildren);
|
|
35
32
|
const maxValue = Math.max(parsedCanvasWidth, parsedCanvasHeight, parsedCanvasExtraSpace ?? 0);
|
|
36
33
|
const ajustedX = parsedCanvasWidth / maxValue;
|
|
37
34
|
const ajustedY = parsedCanvasHeight / maxValue;
|
|
38
35
|
// Create a fingerprint of the data to avoid unnecessary contextValue updates
|
|
39
|
-
const dataFingerprint =
|
|
36
|
+
const dataFingerprint = getDataFingerprint(data);
|
|
40
37
|
// Build the context value
|
|
41
|
-
const contextValue =
|
|
42
|
-
return
|
|
38
|
+
const contextValue = useMemo(() => {
|
|
39
|
+
return buildBarContextValue({
|
|
43
40
|
ajustedX,
|
|
44
41
|
ajustedY,
|
|
45
42
|
canvasHeight: parsedCanvasHeight,
|
|
@@ -52,7 +49,7 @@ const BarChartStructure = ({ canvasConfig = canvas_type_1.DefaultCanvasConfig, c
|
|
|
52
49
|
viewBox,
|
|
53
50
|
});
|
|
54
51
|
}, [canvasHeight, canvasWidth, dataFingerprint, pKey, orientation]);
|
|
55
|
-
return ((
|
|
52
|
+
return (_jsx(SvgContainer, { caption: caption, className: classNames, dataTestId: dataTestId, height: height, role: role, tabIndex: tabIndex, viewBox: viewBox, width: width, ...props, children: _jsx(BarChartContext.Provider, { value: {
|
|
56
53
|
...contextValue,
|
|
57
54
|
barChildrenCount,
|
|
58
55
|
canvasExtraSpace: parsedCanvasExtraSpace,
|
|
@@ -65,4 +62,3 @@ const BarChartStructure = ({ canvasConfig = canvas_type_1.DefaultCanvasConfig, c
|
|
|
65
62
|
pKey,
|
|
66
63
|
}, children: children }) }));
|
|
67
64
|
};
|
|
68
|
-
exports.BarChartStructure = BarChartStructure;
|
|
@@ -1,5 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.BarChartContext = void 0;
|
|
4
|
-
const react_1 = require("react");
|
|
5
|
-
exports.BarChartContext = (0, react_1.createContext)({});
|
|
1
|
+
import { createContext } from 'react';
|
|
2
|
+
export const BarChartContext = createContext({});
|
|
@@ -1,23 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const getPoints_1 = require("../../../utils/getPoints/getPoints");
|
|
8
|
-
const getTicks_1 = require("../../../utils/getTicks/getTicks");
|
|
9
|
-
const getAxisExtraSpacing_1 = require("../utils/getAxisExtraSpacing");
|
|
1
|
+
import { BarOrientation } from '../../../components/bar/bar.type';
|
|
2
|
+
import { Positions } from '../../../types/position.enum';
|
|
3
|
+
import { getXCoordinates, getYCoordinates } from '../../../utils/getCoordinates/getCoordinates';
|
|
4
|
+
import { getPoints } from '../../../utils/getPoints/getPoints';
|
|
5
|
+
import { getXTicks, getYTicks } from '../../../utils/getTicks/getTicks';
|
|
6
|
+
import { getAxisExtraSpacing } from '../utils/getAxisExtraSpacing';
|
|
10
7
|
/**
|
|
11
8
|
* Builds the context value for the line chart.
|
|
12
9
|
*
|
|
13
10
|
* @param {BuildContextValue} options - The options for building the context value.
|
|
14
11
|
* @returns {LineContextValue} - The built context value.
|
|
15
12
|
*/
|
|
16
|
-
const buildBarContextValue = ({ ajustedX, ajustedY, canvasHeight, canvasWidth, children, data, gapBetweenBars, orientation, pKey, viewBox, }) => {
|
|
13
|
+
export const buildBarContextValue = ({ ajustedX, ajustedY, canvasHeight, canvasWidth, children, data, gapBetweenBars, orientation, pKey, viewBox, }) => {
|
|
17
14
|
/**
|
|
18
15
|
* Get the extra spacings for the line chart.
|
|
19
16
|
*/
|
|
20
|
-
const { barChartXPosition, barChartYPosition, extraSpaceBottomY, extraSpaceLeftX, extraSpaceRightX, extraSpaceTopY, securityXSpace, securityYSpace, xAxisText, xBreakAxis, xData, yAxisText, yBreakAxis, yData, } =
|
|
17
|
+
const { barChartXPosition, barChartYPosition, extraSpaceBottomY, extraSpaceLeftX, extraSpaceRightX, extraSpaceTopY, securityXSpace, securityYSpace, xAxisText, xBreakAxis, xData, yAxisText, yBreakAxis, yData, } = getAxisExtraSpacing({
|
|
21
18
|
ajustedX,
|
|
22
19
|
ajustedY,
|
|
23
20
|
canvasHeight,
|
|
@@ -32,9 +29,9 @@ const buildBarContextValue = ({ ajustedX, ajustedY, canvasHeight, canvasWidth, c
|
|
|
32
29
|
/**
|
|
33
30
|
* Calculate the tick values for the X Axis.
|
|
34
31
|
*/
|
|
35
|
-
const crossXAxis = barChartXPosition !==
|
|
32
|
+
const crossXAxis = barChartXPosition !== Positions.TOP && barChartXPosition !== Positions.BOTTOM;
|
|
36
33
|
const yAxisSpace = extraSpaceLeftX + extraSpaceRightX;
|
|
37
|
-
const xTickValue =
|
|
34
|
+
const xTickValue = getXTicks({
|
|
38
35
|
initPos: extraSpaceLeftX,
|
|
39
36
|
maxSpaceAvailable: canvasWidth,
|
|
40
37
|
otherAxisSpace: yAxisSpace,
|
|
@@ -44,12 +41,12 @@ const buildBarContextValue = ({ ajustedX, ajustedY, canvasHeight, canvasWidth, c
|
|
|
44
41
|
/**
|
|
45
42
|
* Calculate the tick values for the Y Axis.
|
|
46
43
|
*/
|
|
47
|
-
const crossYAxis = barChartYPosition !==
|
|
44
|
+
const crossYAxis = barChartYPosition !== Positions.LEFT && barChartYPosition !== Positions.RIGHT;
|
|
48
45
|
const otherAxisSpace = extraSpaceTopY + extraSpaceBottomY;
|
|
49
|
-
const yTickValue =
|
|
46
|
+
const yTickValue = getYTicks({
|
|
50
47
|
initPos: canvasHeight - extraSpaceBottomY,
|
|
51
48
|
maxSpaceAvailable: canvasHeight,
|
|
52
|
-
needAjusted: orientation ===
|
|
49
|
+
needAjusted: orientation === BarOrientation.HORIZONTAL,
|
|
53
50
|
otherAxisSpace,
|
|
54
51
|
securitySpace: securityYSpace,
|
|
55
52
|
tickValues: yData,
|
|
@@ -57,12 +54,12 @@ const buildBarContextValue = ({ ajustedX, ajustedY, canvasHeight, canvasWidth, c
|
|
|
57
54
|
/**
|
|
58
55
|
* Calculate the custom breakAxis for the X and Y Axis.
|
|
59
56
|
*/
|
|
60
|
-
const customBreakXAxis = crossXAxis ?
|
|
61
|
-
const customBreakYAxis = crossYAxis ?
|
|
57
|
+
const customBreakXAxis = crossXAxis ? getPoints(yTickValue || [], [String(xBreakAxis)])[0] : 0;
|
|
58
|
+
const customBreakYAxis = crossYAxis ? getPoints(xTickValue || [], [String(yBreakAxis)])[0] : 0;
|
|
62
59
|
/**
|
|
63
60
|
* Calculate the X coordinates for the line chart.
|
|
64
61
|
*/
|
|
65
|
-
const xCoordinates =
|
|
62
|
+
const xCoordinates = getXCoordinates({
|
|
66
63
|
canvasHeight,
|
|
67
64
|
canvasWidth,
|
|
68
65
|
customBreakAxis: Number(customBreakXAxis),
|
|
@@ -76,7 +73,7 @@ const buildBarContextValue = ({ ajustedX, ajustedY, canvasHeight, canvasWidth, c
|
|
|
76
73
|
/**
|
|
77
74
|
* Calculate the Y coordinates for the line chart.
|
|
78
75
|
*/
|
|
79
|
-
const yCoordinates =
|
|
76
|
+
const yCoordinates = getYCoordinates({
|
|
80
77
|
canvasHeight,
|
|
81
78
|
canvasWidth,
|
|
82
79
|
customBreakAxis: Number(customBreakYAxis),
|
|
@@ -102,4 +99,3 @@ const buildBarContextValue = ({ ajustedX, ajustedY, canvasHeight, canvasWidth, c
|
|
|
102
99
|
yAxisText,
|
|
103
100
|
};
|
|
104
101
|
};
|
|
105
|
-
exports.buildBarContextValue = buildBarContextValue;
|
|
@@ -1,23 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const
|
|
8
|
-
const
|
|
9
|
-
const barChartContext_1 = require("../context/barChartContext");
|
|
10
|
-
const BarChartPath = ({ barConfig, dataIdx, dataKey, order, ...props }) => {
|
|
11
|
-
const { xAxisCoordinates, yAxisCoordinates, ...context } = (0, react_1.useContext)(barChartContext_1.BarChartContext);
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useContext } from 'react';
|
|
3
|
+
import { Bar } from '../../../components/bar/bar';
|
|
4
|
+
import { BarOrientation } from '../../../components/bar/bar.type';
|
|
5
|
+
import { getPoints } from '../../../utils/getPoints/getPoints';
|
|
6
|
+
import { BarChartContext } from '../context/barChartContext';
|
|
7
|
+
export const BarChartPath = ({ barConfig, dataIdx, dataKey, order, ...props }) => {
|
|
8
|
+
const { xAxisCoordinates, yAxisCoordinates, ...context } = useContext(BarChartContext);
|
|
12
9
|
const { coordinates: xACoord, tickValues: xTickValues } = xAxisCoordinates;
|
|
13
10
|
const { coordinates: yACoord, tickValues: yTickValues } = yAxisCoordinates;
|
|
14
|
-
const isVertical = context.orientation ===
|
|
11
|
+
const isVertical = context.orientation === BarOrientation.VERTICAL;
|
|
15
12
|
const xKey = isVertical ? context.pKey : dataKey;
|
|
16
13
|
const yKey = isVertical ? dataKey : context.pKey;
|
|
17
14
|
const xData = context.data[dataIdx][xKey];
|
|
18
15
|
const yData = context.data[dataIdx][yKey];
|
|
19
|
-
const xPoint =
|
|
20
|
-
const yPoint =
|
|
16
|
+
const xPoint = getPoints(xTickValues, [String(xData)], true)[0];
|
|
17
|
+
const yPoint = getPoints(yTickValues, [String(yData)])[0];
|
|
21
18
|
const points = isVertical
|
|
22
19
|
? {
|
|
23
20
|
x1: xPoint,
|
|
@@ -31,6 +28,5 @@ const BarChartPath = ({ barConfig, dataIdx, dataKey, order, ...props }) => {
|
|
|
31
28
|
y1: yPoint,
|
|
32
29
|
y2: yPoint,
|
|
33
30
|
};
|
|
34
|
-
return ((
|
|
31
|
+
return (_jsx(Bar, { barConfig: barConfig, currentBars: context.barChildrenCount, extraSpacing: context.gapBetweenBars, order: order, orientation: context.orientation, ...points, ...props }));
|
|
35
32
|
};
|
|
36
|
-
exports.BarChartPath = BarChartPath;
|
|
@@ -1,17 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
const barChartContext_1 = require("../context/barChartContext");
|
|
8
|
-
const BarChartSeparator = ({ areaSeparator, dataTestId, rightSeparator, topSeparator, xBreakAxis, yBreakAxis, }) => {
|
|
9
|
-
const { crossXAxis, crossYAxis, xAxisCoordinates, yAxisCoordinates } = (0, react_1.useContext)(barChartContext_1.BarChartContext);
|
|
1
|
+
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useContext } from 'react';
|
|
3
|
+
import { getPoints } from '../../../utils/getPoints/getPoints';
|
|
4
|
+
import { BarChartContext } from '../context/barChartContext';
|
|
5
|
+
export const BarChartSeparator = ({ areaSeparator, dataTestId, rightSeparator, topSeparator, xBreakAxis, yBreakAxis, }) => {
|
|
6
|
+
const { crossXAxis, crossYAxis, xAxisCoordinates, yAxisCoordinates } = useContext(BarChartContext);
|
|
10
7
|
if (!topSeparator && !rightSeparator && !areaSeparator) {
|
|
11
|
-
return (
|
|
8
|
+
return _jsx(_Fragment, {});
|
|
12
9
|
}
|
|
13
|
-
const customXEnd = xBreakAxis &&
|
|
14
|
-
const customYEnd = yBreakAxis &&
|
|
10
|
+
const customXEnd = xBreakAxis && getPoints(xAxisCoordinates.tickValues, [xBreakAxis], true)[0];
|
|
11
|
+
const customYEnd = yBreakAxis && getPoints(yAxisCoordinates.tickValues, [yBreakAxis])[0];
|
|
15
12
|
const autoXEnd = crossYAxis ? yAxisCoordinates.coordinates.x1 : xAxisCoordinates.coordinates.x2;
|
|
16
13
|
const autoYEnd = crossXAxis ? xAxisCoordinates.coordinates.y1 : yAxisCoordinates.coordinates.y1;
|
|
17
14
|
const xStart = xAxisCoordinates.coordinates.x1;
|
|
@@ -21,6 +18,5 @@ const BarChartSeparator = ({ areaSeparator, dataTestId, rightSeparator, topSepar
|
|
|
21
18
|
const squarePath = `M${xStart} ${yStart} H ${xEnd} V ${yEnd} H ${xStart} Z`;
|
|
22
19
|
const lineTop = `M${xStart} ${yEnd} H ${xEnd}`;
|
|
23
20
|
const lineRight = `M${xEnd} ${yStart} V ${yEnd}`;
|
|
24
|
-
return ((
|
|
21
|
+
return (_jsxs("g", { children: [_jsx("path", { d: squarePath, "data-testid": `${dataTestId}Area`, ...areaSeparator }), _jsx("path", { d: lineTop, "data-testid": `${dataTestId}Top`, ...topSeparator }), _jsx("path", { d: lineRight, "data-testid": `${dataTestId}Right`, ...rightSeparator })] }));
|
|
25
22
|
};
|
|
26
|
-
exports.BarChartSeparator = BarChartSeparator;
|
|
@@ -1,20 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const
|
|
8
|
-
const getTickTextCoordinates_1 = require("../../../utils/getTickTextCoordinate/getTickTextCoordinates");
|
|
9
|
-
const barChartContext_1 = require("../context/barChartContext");
|
|
10
|
-
const BarChartXAxis = ({ position = position_enum_1.Positions.BOTTOM, tickLine, tickText, ...props }) => {
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useContext } from 'react';
|
|
3
|
+
import { XAxis } from '../../../components/axisChart/xAxis/xAxis';
|
|
4
|
+
import { Positions } from '../../../types/position.enum';
|
|
5
|
+
import { getTickTextYCoordinate } from '../../../utils/getTickTextCoordinate/getTickTextCoordinates';
|
|
6
|
+
import { BarChartContext } from '../context/barChartContext';
|
|
7
|
+
export const BarChartXAxis = ({ position = Positions.BOTTOM, tickLine, tickText, ...props }) => {
|
|
11
8
|
const { xAxisCoordinates: { coordinates, tickValues },
|
|
12
9
|
// xCursor,
|
|
13
|
-
...context } =
|
|
14
|
-
const tickTextY =
|
|
10
|
+
...context } = useContext(BarChartContext);
|
|
11
|
+
const tickTextY = getTickTextYCoordinate(position, coordinates.y1, Number(tickText?.fontSize), tickText?.top ?? 0);
|
|
15
12
|
const y1 = context.extraSpaceTopY;
|
|
16
13
|
const y2 = Number(context.canvasHeight) - context.extraSpaceBottomY;
|
|
17
|
-
return ((
|
|
14
|
+
return (_jsx(XAxis, { ...coordinates, ...props, canvasHeight: Number(context.canvasHeight), canvasWidth: Number(context.canvasWidth),
|
|
18
15
|
// cursor={xCursor}
|
|
19
16
|
dataTestId: `${context.dataTestId}xAxis`, extraSpace: {
|
|
20
17
|
left: context.extraSpaceLeftX,
|
|
@@ -28,4 +25,3 @@ const BarChartXAxis = ({ position = position_enum_1.Positions.BOTTOM, tickLine,
|
|
|
28
25
|
y: tickTextY,
|
|
29
26
|
}, tickValues: tickText ? tickValues : undefined }));
|
|
30
27
|
};
|
|
31
|
-
exports.BarChartXAxis = BarChartXAxis;
|
|
@@ -1,24 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const
|
|
9
|
-
const
|
|
10
|
-
const barChartContext_1 = require("../context/barChartContext");
|
|
11
|
-
const BarChartYAxis = ({ position = position_enum_1.Positions.LEFT, tickLine, tickText, ...props }) => {
|
|
12
|
-
const { yAxisCoordinates: { coordinates, tickValues }, ...context } = (0, react_1.useContext)(barChartContext_1.BarChartContext);
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useContext } from 'react';
|
|
3
|
+
import { YAxis } from '../../../components/axisChart/yAxis/yAxis';
|
|
4
|
+
import { Positions } from '../../../types/position.enum';
|
|
5
|
+
import { ajustedTextSpace } from '../../../utils/ajustedTextSpace/ajustedTextSpace';
|
|
6
|
+
import { getTickTextXCoordinate } from '../../../utils/getTickTextCoordinate/getTickTextCoordinates';
|
|
7
|
+
import { BarChartContext } from '../context/barChartContext';
|
|
8
|
+
export const BarChartYAxis = ({ position = Positions.LEFT, tickLine, tickText, ...props }) => {
|
|
9
|
+
const { yAxisCoordinates: { coordinates, tickValues }, ...context } = useContext(BarChartContext);
|
|
13
10
|
const textAnchor = tickText?.textAnchor || 'middle';
|
|
14
|
-
const addSpace = position ===
|
|
11
|
+
const addSpace = position === Positions.RIGHT ? tickText?.right : tickText?.left;
|
|
15
12
|
const ajustedSpace = addSpace ?? 0;
|
|
16
|
-
const ajustedText =
|
|
17
|
-
const xTickText =
|
|
18
|
-
return ((
|
|
13
|
+
const ajustedText = ajustedTextSpace(textAnchor, context.yAxisText, ajustedSpace);
|
|
14
|
+
const xTickText = getTickTextXCoordinate(position, coordinates.x1, ajustedText);
|
|
15
|
+
return (_jsx(YAxis, { ...coordinates, ...props, canvasHeight: Number(context.canvasHeight), canvasWidth: Number(context.canvasWidth), dataTestId: `${context.dataTestId}yAxis`, tickLine: {
|
|
19
16
|
...tickLine,
|
|
20
17
|
x1: context.extraSpaceLeftX,
|
|
21
18
|
x2: Number(context.canvasWidth) - context.extraSpaceRightX,
|
|
22
19
|
}, tickText: { ...tickText, x: xTickText }, tickValues: tickText ? tickValues : undefined }));
|
|
23
20
|
};
|
|
24
|
-
exports.BarChartYAxis = BarChartYAxis;
|
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.CONTEXT = void 0;
|
|
4
|
-
const bar_type_1 = require("../../../../components/bar/bar.type");
|
|
5
|
-
exports.CONTEXT = {
|
|
1
|
+
import { BarOrientation } from '../../../../components/bar/bar.type';
|
|
2
|
+
export const CONTEXT = {
|
|
6
3
|
barChildrenCount: 3,
|
|
7
4
|
canvasExtraSpace: 0,
|
|
8
5
|
canvasHeight: 500,
|
|
@@ -19,7 +16,7 @@ exports.CONTEXT = {
|
|
|
19
16
|
extraSpaceLeftX: 0,
|
|
20
17
|
extraSpaceRightX: 0,
|
|
21
18
|
extraSpaceTopY: 0,
|
|
22
|
-
orientation:
|
|
19
|
+
orientation: BarOrientation.HORIZONTAL,
|
|
23
20
|
pKey: 'pKey',
|
|
24
21
|
securityXSpace: 0,
|
|
25
22
|
securityYSpace: 0,
|
|
@@ -1,5 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.CONTEXT = void 0;
|
|
4
|
-
var barContextData_1 = require("./barContextData");
|
|
5
|
-
Object.defineProperty(exports, "CONTEXT", { enumerable: true, get: function () { return barContextData_1.CONTEXT; } });
|
|
1
|
+
export { CONTEXT } from './barContextData';
|
|
@@ -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("./barChart"), exports);
|
|
1
|
+
export * from './barChart';
|
|
@@ -1,15 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const react_1 = require("react");
|
|
5
|
-
const barChartPath_1 = require("../fragments/barChartPath");
|
|
6
|
-
const countBarChildren = (children) => {
|
|
1
|
+
import { Children, isValidElement } from 'react';
|
|
2
|
+
import { BarChartPath } from '../fragments/barChartPath';
|
|
3
|
+
export const countBarChildren = (children) => {
|
|
7
4
|
let higherOrder = 0;
|
|
8
|
-
|
|
9
|
-
if (
|
|
5
|
+
Children.toArray(children).forEach(child => {
|
|
6
|
+
if (isValidElement(child) && child.type === BarChartPath && child.props.order > higherOrder) {
|
|
10
7
|
higherOrder = child.props.order;
|
|
11
8
|
}
|
|
12
9
|
});
|
|
13
10
|
return higherOrder;
|
|
14
11
|
};
|
|
15
|
-
exports.countBarChildren = countBarChildren;
|
|
@@ -1,24 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
const barChartYAxis_1 = require("../fragments/barChartYAxis");
|
|
12
|
-
const getBarDataValue_1 = require("./getBarDataValue");
|
|
13
|
-
const getRoundedBarMaxValue_1 = require("./getRoundedBarMaxValue");
|
|
1
|
+
import { Children, isValidElement } from 'react';
|
|
2
|
+
import { BarOrientation } from '../../../components/bar/bar.type';
|
|
3
|
+
import { Positions } from '../../../types/position.enum';
|
|
4
|
+
import { buildTickValues } from '../../../utils/buildTickValues/buildTickValues';
|
|
5
|
+
import { textBound } from '../../../utils/textBound/textBound';
|
|
6
|
+
import { BarChartPath } from '../fragments/barChartPath';
|
|
7
|
+
import { BarChartXAxis } from '../fragments/barChartXAxis';
|
|
8
|
+
import { BarChartYAxis } from '../fragments/barChartYAxis';
|
|
9
|
+
import { getBarDataValues } from './getBarDataValue';
|
|
10
|
+
import { getBarKeyRoundMaxValue } from './getRoundedBarMaxValue';
|
|
14
11
|
const handleBarChartXAxis = (child, data, pKey, ajustedX, barsSpacing, viewBox, canvasHeight, canvasWidth) => {
|
|
15
12
|
const { position, tickText, tickValues } = child.props;
|
|
16
13
|
const fontSize = tickText?.fontSize ?? 0;
|
|
17
14
|
const spaceFontSize = fontSize * ajustedX;
|
|
18
15
|
const xData = tickValues
|
|
19
|
-
?
|
|
16
|
+
? getBarDataValues(tickValues)
|
|
20
17
|
: data.map(d => d[pKey]);
|
|
21
|
-
const fontSpacing =
|
|
18
|
+
const fontSpacing = textBound({
|
|
22
19
|
bound: 'width',
|
|
23
20
|
data: xData,
|
|
24
21
|
fontSize,
|
|
@@ -27,9 +24,9 @@ const handleBarChartXAxis = (child, data, pKey, ajustedX, barsSpacing, viewBox,
|
|
|
27
24
|
viewBox,
|
|
28
25
|
});
|
|
29
26
|
const securityXSpace = (() => (barsSpacing > fontSpacing ? barsSpacing : fontSpacing))();
|
|
30
|
-
const extraSpaceBottomY = position ===
|
|
31
|
-
const extraSpaceTopY = position ===
|
|
32
|
-
const barChartXPosition = (() => position ||
|
|
27
|
+
const extraSpaceBottomY = position === Positions.BOTTOM ? spaceFontSize + (tickText?.top ?? 0) : 0;
|
|
28
|
+
const extraSpaceTopY = position === Positions.TOP ? spaceFontSize + (tickText?.bottom ?? 0) : 0;
|
|
29
|
+
const barChartXPosition = (() => position || Positions.BOTTOM)();
|
|
33
30
|
const xBreakAxis = tickValues?.numeric
|
|
34
31
|
? (tickValues.numeric.breakAxis ?? 0)
|
|
35
32
|
: (tickText?.custom?.breakAxis ?? 0);
|
|
@@ -47,10 +44,10 @@ const handleBarChartYAxis = (child, data, pKey, ajustedY, barSpacing, viewBox, c
|
|
|
47
44
|
const fontSize = tickText?.fontSize ?? 0;
|
|
48
45
|
const spaceFontSize = fontSize * ajustedY; //! review
|
|
49
46
|
const dataValues = tickValues ||
|
|
50
|
-
|
|
51
|
-
const yData =
|
|
47
|
+
buildTickValues([...new Set(getBarKeyRoundMaxValue(data, pKey))]);
|
|
48
|
+
const yData = getBarDataValues(dataValues);
|
|
52
49
|
const securityYSpace = (() => (barSpacing > spaceFontSize ? barSpacing : spaceFontSize))();
|
|
53
|
-
const textWidth =
|
|
50
|
+
const textWidth = textBound({
|
|
54
51
|
bound: 'width',
|
|
55
52
|
data: yData,
|
|
56
53
|
fontSize,
|
|
@@ -58,9 +55,9 @@ const handleBarChartYAxis = (child, data, pKey, ajustedY, barSpacing, viewBox, c
|
|
|
58
55
|
svgWidth: `${canvasWidth}`,
|
|
59
56
|
viewBox,
|
|
60
57
|
});
|
|
61
|
-
const extraSpaceLeftX = position ===
|
|
62
|
-
const extraSpaceRightX = position ===
|
|
63
|
-
const barChartYPosition = (() => position ||
|
|
58
|
+
const extraSpaceLeftX = position === Positions.LEFT ? textWidth + (tickText?.right ?? 0) : 0;
|
|
59
|
+
const extraSpaceRightX = position === Positions.RIGHT ? textWidth + (tickText?.left ?? 0) : 0;
|
|
60
|
+
const barChartYPosition = (() => position || Positions.LEFT)();
|
|
64
61
|
const yBreakAxis = tickValues?.numeric
|
|
65
62
|
? (tickValues.numeric.breakAxis ?? 0)
|
|
66
63
|
: (tickText?.custom?.breakAxis ?? 0);
|
|
@@ -74,10 +71,10 @@ const handleBarChartYAxis = (child, data, pKey, ajustedY, barSpacing, viewBox, c
|
|
|
74
71
|
yData,
|
|
75
72
|
};
|
|
76
73
|
};
|
|
77
|
-
const getAxisExtraSpacing = ({ ajustedX, ajustedY, canvasHeight, canvasWidth, children, data, gapBetweenBars, orientation, pKey, viewBox, }) => {
|
|
74
|
+
export const getAxisExtraSpacing = ({ ajustedX, ajustedY, canvasHeight, canvasWidth, children, data, gapBetweenBars, orientation, pKey, viewBox, }) => {
|
|
78
75
|
let result = {
|
|
79
|
-
barChartXPosition:
|
|
80
|
-
barChartYPosition:
|
|
76
|
+
barChartXPosition: Positions.BOTTOM,
|
|
77
|
+
barChartYPosition: Positions.LEFT,
|
|
81
78
|
extraSpaceBottomY: 0,
|
|
82
79
|
extraSpaceLeftX: 0,
|
|
83
80
|
extraSpaceRightX: 0,
|
|
@@ -93,21 +90,21 @@ const getAxisExtraSpacing = ({ ajustedX, ajustedY, canvasHeight, canvasWidth, ch
|
|
|
93
90
|
};
|
|
94
91
|
let barsSpacing = gapBetweenBars;
|
|
95
92
|
const reviews = [];
|
|
96
|
-
|
|
97
|
-
if (
|
|
98
|
-
if (child.type ===
|
|
93
|
+
Children.forEach(children, (child) => {
|
|
94
|
+
if (isValidElement(child)) {
|
|
95
|
+
if (child.type === BarChartPath && !reviews.includes(child.props.order)) {
|
|
99
96
|
reviews.push(child.props.order);
|
|
100
97
|
barsSpacing += child.props.barConfig.barWidth ?? 0;
|
|
101
98
|
}
|
|
102
|
-
if (child.type ===
|
|
103
|
-
const securitySpace = orientation ===
|
|
99
|
+
if (child.type === BarChartXAxis) {
|
|
100
|
+
const securitySpace = orientation === BarOrientation.VERTICAL ? barsSpacing : 0;
|
|
104
101
|
result = {
|
|
105
102
|
...result,
|
|
106
103
|
...handleBarChartXAxis(child, data, pKey, ajustedX, securitySpace, viewBox, canvasHeight, canvasWidth),
|
|
107
104
|
};
|
|
108
105
|
}
|
|
109
|
-
else if (child.type ===
|
|
110
|
-
const securitySpace = orientation ===
|
|
106
|
+
else if (child.type === BarChartYAxis) {
|
|
107
|
+
const securitySpace = orientation === BarOrientation.HORIZONTAL ? barsSpacing : 0;
|
|
111
108
|
result = {
|
|
112
109
|
...result,
|
|
113
110
|
...handleBarChartYAxis(child, data, pKey, ajustedY, securitySpace, viewBox, canvasHeight, canvasWidth),
|
|
@@ -117,4 +114,3 @@ const getAxisExtraSpacing = ({ ajustedX, ajustedY, canvasHeight, canvasWidth, ch
|
|
|
117
114
|
});
|
|
118
115
|
return result;
|
|
119
116
|
};
|
|
120
|
-
exports.getAxisExtraSpacing = getAxisExtraSpacing;
|
|
@@ -1,12 +1,9 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getBarDataValues = void 0;
|
|
4
1
|
/**
|
|
5
2
|
* Retrieves the data values from the given BarTickValuesAxisProps object.
|
|
6
3
|
* @param data - The BarTickValuesAxisProps 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 getBarDataValues = (data) => {
|
|
6
|
+
export const getBarDataValues = (data) => {
|
|
10
7
|
if (data.custom) {
|
|
11
8
|
return data.custom?.values;
|
|
12
9
|
}
|
|
@@ -20,4 +17,3 @@ const getBarDataValues = (data) => {
|
|
|
20
17
|
}
|
|
21
18
|
return undefined;
|
|
22
19
|
};
|
|
23
|
-
exports.getBarDataValues = getBarDataValues;
|