@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
package/README.md
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
# Kubit React Charts
|
|
2
2
|
|
|
3
3
|
<p align="center">
|
|
4
|
-
<
|
|
4
|
+
<a href="https://kubit-ui.com">
|
|
5
|
+
<picture>
|
|
6
|
+
<source media="(prefers-color-scheme: dark)" srcset="https://github.com/kubit-ui/kubit-react-charts/raw/cms/assets/readme_logo.png">
|
|
7
|
+
<img src="hhttps://github.com/kubit-ui/kubit-react-charts/raw/cms/assets/readme_logo.png" width="70%">
|
|
8
|
+
</picture>
|
|
9
|
+
</a>
|
|
5
10
|
</p>
|
|
6
11
|
|
|
7
12
|
<p align="center">
|
|
@@ -10,9 +15,10 @@
|
|
|
10
15
|
</p>
|
|
11
16
|
|
|
12
17
|
<p align="center">
|
|
18
|
+
<img src="https://img.shields.io/npm/v/@kubit-ui-web/react-charts" alt="Version" />
|
|
13
19
|
<img src="https://img.shields.io/badge/React-18.3.1-blue?logo=react" alt="React version" />
|
|
14
20
|
<img src="https://img.shields.io/badge/TypeScript-5.9.2-blue?logo=typescript" alt="TypeScript version" />
|
|
15
|
-
<img src="https://img.shields.io/badge/license-
|
|
21
|
+
<img src="https://img.shields.io/badge/license-Apache%202.0-blue" alt="License" />
|
|
16
22
|
</p>
|
|
17
23
|
|
|
18
24
|
---
|
|
@@ -39,6 +45,8 @@
|
|
|
39
45
|
|
|
40
46
|
# For Library Users
|
|
41
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
|
+
|
|
42
50
|
## Features
|
|
43
51
|
|
|
44
52
|
**Composable**: Modular architecture where each chart is composed of specialized elements
|
|
@@ -84,26 +92,24 @@ yarn add react react-dom
|
|
|
84
92
|
|
|
85
93
|
```typescript
|
|
86
94
|
// Import complete charts
|
|
87
|
-
import { BarChart, LineChart, PieChart } from
|
|
88
|
-
|
|
95
|
+
import { BarChart, LineChart, PieChart } from '@kubit-ui-web/react-charts';
|
|
89
96
|
// Import specific components
|
|
90
|
-
import {
|
|
91
|
-
|
|
97
|
+
import { Node, Path, Plot } from '@kubit-ui-web/react-charts/components';
|
|
92
98
|
// Import types
|
|
93
|
-
import type {
|
|
99
|
+
import type { BarOrientation, ChartData } from '@kubit-ui-web/react-charts/types';
|
|
94
100
|
```
|
|
95
101
|
|
|
96
102
|
### LineChart Example
|
|
97
103
|
|
|
98
104
|
```tsx
|
|
99
|
-
import
|
|
100
|
-
import
|
|
105
|
+
import { LineChart } from '@kubit-ui-web/react-charts';
|
|
106
|
+
import React from 'react';
|
|
101
107
|
|
|
102
108
|
const data = [
|
|
103
|
-
{ year:
|
|
104
|
-
{ year:
|
|
105
|
-
{ year:
|
|
106
|
-
{ year:
|
|
109
|
+
{ year: '2020', sales: 100, profit: 20 },
|
|
110
|
+
{ year: '2021', sales: 150, profit: 35 },
|
|
111
|
+
{ year: '2022', sales: 180, profit: 45 },
|
|
112
|
+
{ year: '2023', sales: 200, profit: 60 },
|
|
107
113
|
];
|
|
108
114
|
|
|
109
115
|
function MyLineChart() {
|
|
@@ -112,7 +118,7 @@ function MyLineChart() {
|
|
|
112
118
|
<LineChart.Path dataKey="sales" stroke="#0078D4" strokeWidth={2} />
|
|
113
119
|
<LineChart.Path dataKey="profit" stroke="#FF6B35" strokeWidth={2} />
|
|
114
120
|
<LineChart.XAxis position="BOTTOM" showTickLines />
|
|
115
|
-
<LineChart.YAxis position="LEFT" valueFormatter={
|
|
121
|
+
<LineChart.YAxis position="LEFT" valueFormatter={val => `$${val}k`} />
|
|
116
122
|
</LineChart>
|
|
117
123
|
);
|
|
118
124
|
}
|
|
@@ -121,14 +127,14 @@ function MyLineChart() {
|
|
|
121
127
|
### BarChart Example
|
|
122
128
|
|
|
123
129
|
```tsx
|
|
124
|
-
import
|
|
125
|
-
import
|
|
130
|
+
import { BarChart, BarOrientation } from '@kubit-ui-web/react-charts';
|
|
131
|
+
import React from 'react';
|
|
126
132
|
|
|
127
133
|
const data = [
|
|
128
|
-
{ category:
|
|
129
|
-
{ category:
|
|
130
|
-
{ category:
|
|
131
|
-
{ category:
|
|
134
|
+
{ category: 'A', value: 30 },
|
|
135
|
+
{ category: 'B', value: 45 },
|
|
136
|
+
{ category: 'C', value: 25 },
|
|
137
|
+
{ category: 'D', value: 60 },
|
|
132
138
|
];
|
|
133
139
|
|
|
134
140
|
function MyBarChart() {
|
|
@@ -146,7 +152,7 @@ function MyBarChart() {
|
|
|
146
152
|
dataIdx={0}
|
|
147
153
|
barConfig={{
|
|
148
154
|
barWidth: 40,
|
|
149
|
-
singleConfig: [{ color:
|
|
155
|
+
singleConfig: [{ color: '#0078D4', coverage: 100 }],
|
|
150
156
|
}}
|
|
151
157
|
/>
|
|
152
158
|
<BarChart.XAxis position="BOTTOM" />
|
|
@@ -322,7 +328,7 @@ yarn test-storybook
|
|
|
322
328
|
yarn eslint --fix
|
|
323
329
|
```
|
|
324
330
|
|
|
325
|
-
## Contributing
|
|
331
|
+
## Contributing
|
|
326
332
|
|
|
327
333
|
### Code Standards
|
|
328
334
|
|
|
@@ -333,18 +339,7 @@ yarn eslint --fix
|
|
|
333
339
|
|
|
334
340
|
### Contribution Workflow
|
|
335
341
|
|
|
336
|
-
|
|
337
|
-
2. Develop following project conventions
|
|
338
|
-
3. Write tests for new features
|
|
339
|
-
4. Run `yarn test` to verify
|
|
340
|
-
5. Create Pull Request
|
|
341
|
-
|
|
342
|
-
### Conventions
|
|
343
|
-
|
|
344
|
-
- **Commits**: Use conventional commits
|
|
345
|
-
- **Components**: Follow existing composition pattern
|
|
346
|
-
- **Tests**: One test file per component
|
|
347
|
-
- **Stories**: Document all use cases
|
|
342
|
+
See our [CONTRIBUTING](./CONTRIBUTING.md) for coding conventions, commit message guidelines, and pull request processes.
|
|
348
343
|
|
|
349
344
|
### Component Development Guidelines
|
|
350
345
|
|
|
@@ -359,10 +354,10 @@ Please refer to our [development instructions](./.github/copilot-instructions.md
|
|
|
359
354
|
|
|
360
355
|
## License
|
|
361
356
|
|
|
362
|
-
This project is licensed under the
|
|
357
|
+
This project is licensed under the Apache License 2.0 - see the [LICENSE](./LICENSE) file for details.
|
|
363
358
|
|
|
364
359
|
---
|
|
365
360
|
|
|
366
361
|
<p align="center">
|
|
367
|
-
Made with ❤️ by the <strong>Kubit</strong> team <img src="
|
|
362
|
+
Made with ❤️ by the <strong>Kubit</strong> team <img src="https://github.com/kubit-ui/kubit-react-charts/raw/cms/assets/kubito.png" alt="Kubito" width="15" height="15" />
|
|
368
363
|
</p>
|
|
@@ -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;
|