@kubit-ui-web/react-charts 1.1.0 → 1.3.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 +96 -0
- package/dist/cjs/charts/barChart/barChart.type.d.ts +4 -0
- package/dist/cjs/charts/barChart/barChart.type.d.ts.map +1 -1
- package/dist/cjs/charts/barChart/barChartStructure.d.ts.map +1 -1
- package/dist/cjs/charts/barChart/barChartStructure.js +9 -2
- package/dist/cjs/charts/barChart/context/buildBarContextValues.d.ts +3 -1
- package/dist/cjs/charts/barChart/context/buildBarContextValues.d.ts.map +1 -1
- package/dist/cjs/charts/barChart/context/buildBarContextValues.js +177 -16
- package/dist/cjs/charts/barChart/fragments/barChartPath.d.ts +6 -0
- package/dist/cjs/charts/barChart/fragments/barChartPath.d.ts.map +1 -1
- package/dist/cjs/charts/barChart/fragments/barChartPath.js +38 -4
- package/dist/cjs/charts/barChart/fragments/barChartSeparator.d.ts.map +1 -1
- package/dist/cjs/charts/barChart/fragments/barChartSeparator.js +52 -2
- package/dist/cjs/charts/barChart/fragments/barChartXAxis.d.ts.map +1 -1
- package/dist/cjs/charts/barChart/fragments/barChartXAxis.js +2 -1
- package/dist/cjs/charts/barChart/fragments/barChartYAxis.d.ts.map +1 -1
- package/dist/cjs/charts/barChart/fragments/barChartYAxis.js +2 -1
- package/dist/cjs/charts/barChart/fragments/fixture/barContextData.d.ts.map +1 -1
- package/dist/cjs/charts/barChart/fragments/fixture/barContextData.js +1 -0
- package/dist/cjs/charts/barChart/utils/getBarDataValue.d.ts.map +1 -1
- package/dist/cjs/charts/barChart/utils/getBarDataValue.js +5 -0
- package/dist/cjs/charts/constants/chartDefaults.d.ts +77 -0
- package/dist/cjs/charts/constants/chartDefaults.d.ts.map +1 -0
- package/dist/cjs/charts/constants/chartDefaults.js +76 -0
- package/dist/cjs/charts/lineChart/context/buildLineContextValue.d.ts +3 -1
- package/dist/cjs/charts/lineChart/context/buildLineContextValue.d.ts.map +1 -1
- package/dist/cjs/charts/lineChart/context/buildLineContextValue.js +162 -46
- package/dist/cjs/charts/lineChart/fragments/fixture/contextData.d.ts +1 -0
- package/dist/cjs/charts/lineChart/fragments/fixture/contextData.d.ts.map +1 -1
- package/dist/cjs/charts/lineChart/fragments/fixture/contextData.js +1 -0
- package/dist/cjs/charts/lineChart/fragments/lineChartPath.d.ts.map +1 -1
- package/dist/cjs/charts/lineChart/fragments/lineChartPath.js +34 -1
- package/dist/cjs/charts/lineChart/fragments/lineChartProjection.d.ts +1 -1
- package/dist/cjs/charts/lineChart/fragments/lineChartProjection.d.ts.map +1 -1
- package/dist/cjs/charts/lineChart/fragments/lineChartProjection.js +44 -0
- package/dist/cjs/charts/lineChart/fragments/lineChartSeparator.d.ts.map +1 -1
- package/dist/cjs/charts/lineChart/fragments/lineChartSeparator.js +52 -2
- package/dist/cjs/charts/lineChart/lineChart.type.d.ts +2 -1
- package/dist/cjs/charts/lineChart/lineChart.type.d.ts.map +1 -1
- package/dist/cjs/charts/lineChart/lineChartStructure.d.ts.map +1 -1
- package/dist/cjs/charts/lineChart/lineChartStructure.js +15 -11
- package/dist/cjs/components/zoomArea/hooks/useResponsiveCanvas.d.ts.map +1 -1
- package/dist/cjs/components/zoomArea/hooks/useResponsiveCanvas.js +6 -1
- package/dist/cjs/types/errors.type.d.ts +14 -1
- package/dist/cjs/types/errors.type.d.ts.map +1 -1
- package/dist/cjs/types/errors.type.js +18 -0
- package/dist/cjs/utils/buildErrors/buildErrors.d.ts +63 -0
- package/dist/cjs/utils/buildErrors/buildErrors.d.ts.map +1 -1
- package/dist/cjs/utils/buildErrors/buildErrors.js +32 -0
- package/dist/cjs/utils/buildErrors/charts/buildBarChartErrors.d.ts +17 -0
- package/dist/cjs/utils/buildErrors/charts/buildBarChartErrors.d.ts.map +1 -0
- package/dist/cjs/utils/buildErrors/charts/buildBarChartErrors.js +16 -0
- package/dist/cjs/utils/buildErrors/charts/buildLineChartErrors.d.ts +13 -0
- package/dist/cjs/utils/buildErrors/charts/buildLineChartErrors.d.ts.map +1 -0
- package/dist/cjs/utils/buildErrors/charts/buildLineChartErrors.js +12 -0
- package/dist/cjs/utils/buildErrors/constants/errorMessages/barChartErrorMessages.d.ts +19 -0
- package/dist/cjs/utils/buildErrors/constants/errorMessages/barChartErrorMessages.d.ts.map +1 -0
- package/dist/cjs/utils/buildErrors/constants/errorMessages/barChartErrorMessages.js +23 -0
- package/dist/cjs/utils/buildErrors/constants/errorMessages/lineChartErrorMessages.d.ts +25 -0
- package/dist/cjs/utils/buildErrors/constants/errorMessages/lineChartErrorMessages.d.ts.map +1 -0
- package/dist/cjs/utils/buildErrors/constants/errorMessages/lineChartErrorMessages.js +29 -0
- package/dist/cjs/utils/buildErrors/constants/errors/barChartErrors.d.ts +20 -0
- package/dist/cjs/utils/buildErrors/constants/errors/barChartErrors.d.ts.map +1 -0
- package/dist/cjs/utils/buildErrors/constants/errors/barChartErrors.js +28 -0
- package/dist/cjs/utils/buildErrors/constants/errors/lineChartErrors.d.ts +26 -0
- package/dist/cjs/utils/buildErrors/constants/errors/lineChartErrors.d.ts.map +1 -0
- package/dist/cjs/utils/buildErrors/constants/errors/lineChartErrors.js +34 -0
- package/dist/cjs/utils/buildErrors/index.d.ts +2 -0
- package/dist/cjs/utils/buildErrors/index.d.ts.map +1 -0
- package/dist/cjs/utils/buildErrors/index.js +2 -0
- package/dist/cjs/utils/createErrorAccumulator/createErrorAccumulator.d.ts +7 -0
- package/dist/cjs/utils/createErrorAccumulator/createErrorAccumulator.d.ts.map +1 -0
- package/dist/cjs/utils/createErrorAccumulator/createErrorAccumulator.js +54 -0
- package/dist/cjs/utils/createErrorAccumulator/index.d.ts +2 -0
- package/dist/cjs/utils/createErrorAccumulator/index.d.ts.map +1 -0
- package/dist/cjs/utils/createErrorAccumulator/index.js +1 -0
- package/dist/cjs/utils/cssGradientToSvg/cssGradientToSvg.d.ts.map +1 -1
- package/dist/cjs/utils/cssGradientToSvg/cssGradientToSvg.js +2 -2
- package/dist/cjs/utils/getCanvasDimensions/getCanvasDimensions.d.ts.map +1 -1
- package/dist/cjs/utils/getCanvasDimensions/getCanvasDimensions.js +13 -2
- package/dist/cjs/utils/index.d.ts +2 -0
- package/dist/cjs/utils/index.d.ts.map +1 -1
- package/dist/cjs/utils/index.js +2 -0
- package/dist/cjs/utils/logger/index.d.ts +2 -0
- package/dist/cjs/utils/logger/index.d.ts.map +1 -0
- package/dist/cjs/utils/logger/index.js +1 -0
- package/dist/cjs/utils/logger/logger.d.ts +45 -0
- package/dist/cjs/utils/logger/logger.d.ts.map +1 -0
- package/dist/cjs/utils/logger/logger.js +140 -0
- package/dist/cjs/utils/ssr/index.d.ts +2 -0
- package/dist/cjs/utils/ssr/index.d.ts.map +1 -0
- package/dist/cjs/utils/ssr/index.js +1 -0
- package/dist/cjs/utils/ssr/ssr.d.ts +80 -0
- package/dist/cjs/utils/ssr/ssr.d.ts.map +1 -0
- package/dist/cjs/utils/ssr/ssr.js +117 -0
- package/dist/cjs/utils/textBound/textBound.d.ts.map +1 -1
- package/dist/cjs/utils/textBound/textBound.js +17 -5
- package/dist/esm/charts/barChart/barChart.type.d.ts +4 -0
- package/dist/esm/charts/barChart/barChart.type.d.ts.map +1 -1
- package/dist/esm/charts/barChart/barChartStructure.d.ts.map +1 -1
- package/dist/esm/charts/barChart/barChartStructure.js +9 -2
- package/dist/esm/charts/barChart/context/buildBarContextValues.d.ts +3 -1
- package/dist/esm/charts/barChart/context/buildBarContextValues.d.ts.map +1 -1
- package/dist/esm/charts/barChart/context/buildBarContextValues.js +177 -16
- package/dist/esm/charts/barChart/fragments/barChartPath.d.ts +6 -0
- package/dist/esm/charts/barChart/fragments/barChartPath.d.ts.map +1 -1
- package/dist/esm/charts/barChart/fragments/barChartPath.js +38 -4
- package/dist/esm/charts/barChart/fragments/barChartSeparator.d.ts.map +1 -1
- package/dist/esm/charts/barChart/fragments/barChartSeparator.js +52 -2
- package/dist/esm/charts/barChart/fragments/barChartXAxis.d.ts.map +1 -1
- package/dist/esm/charts/barChart/fragments/barChartXAxis.js +2 -1
- package/dist/esm/charts/barChart/fragments/barChartYAxis.d.ts.map +1 -1
- package/dist/esm/charts/barChart/fragments/barChartYAxis.js +2 -1
- package/dist/esm/charts/barChart/fragments/fixture/barContextData.d.ts.map +1 -1
- package/dist/esm/charts/barChart/fragments/fixture/barContextData.js +1 -0
- package/dist/esm/charts/barChart/utils/getBarDataValue.d.ts.map +1 -1
- package/dist/esm/charts/barChart/utils/getBarDataValue.js +5 -0
- package/dist/esm/charts/constants/chartDefaults.d.ts +77 -0
- package/dist/esm/charts/constants/chartDefaults.d.ts.map +1 -0
- package/dist/esm/charts/constants/chartDefaults.js +76 -0
- package/dist/esm/charts/lineChart/context/buildLineContextValue.d.ts +3 -1
- package/dist/esm/charts/lineChart/context/buildLineContextValue.d.ts.map +1 -1
- package/dist/esm/charts/lineChart/context/buildLineContextValue.js +162 -46
- package/dist/esm/charts/lineChart/fragments/fixture/contextData.d.ts +1 -0
- package/dist/esm/charts/lineChart/fragments/fixture/contextData.d.ts.map +1 -1
- package/dist/esm/charts/lineChart/fragments/fixture/contextData.js +1 -0
- package/dist/esm/charts/lineChart/fragments/lineChartPath.d.ts.map +1 -1
- package/dist/esm/charts/lineChart/fragments/lineChartPath.js +34 -1
- package/dist/esm/charts/lineChart/fragments/lineChartProjection.d.ts +1 -1
- package/dist/esm/charts/lineChart/fragments/lineChartProjection.d.ts.map +1 -1
- package/dist/esm/charts/lineChart/fragments/lineChartProjection.js +44 -0
- package/dist/esm/charts/lineChart/fragments/lineChartSeparator.d.ts.map +1 -1
- package/dist/esm/charts/lineChart/fragments/lineChartSeparator.js +52 -2
- package/dist/esm/charts/lineChart/lineChart.type.d.ts +2 -1
- package/dist/esm/charts/lineChart/lineChart.type.d.ts.map +1 -1
- package/dist/esm/charts/lineChart/lineChartStructure.d.ts.map +1 -1
- package/dist/esm/charts/lineChart/lineChartStructure.js +15 -11
- package/dist/esm/components/zoomArea/hooks/useResponsiveCanvas.d.ts.map +1 -1
- package/dist/esm/components/zoomArea/hooks/useResponsiveCanvas.js +6 -1
- package/dist/esm/types/errors.type.d.ts +14 -1
- package/dist/esm/types/errors.type.d.ts.map +1 -1
- package/dist/esm/types/errors.type.js +18 -0
- package/dist/esm/utils/buildErrors/buildErrors.d.ts +63 -0
- package/dist/esm/utils/buildErrors/buildErrors.d.ts.map +1 -1
- package/dist/esm/utils/buildErrors/buildErrors.js +32 -0
- package/dist/esm/utils/buildErrors/charts/buildBarChartErrors.d.ts +17 -0
- package/dist/esm/utils/buildErrors/charts/buildBarChartErrors.d.ts.map +1 -0
- package/dist/esm/utils/buildErrors/charts/buildBarChartErrors.js +16 -0
- package/dist/esm/utils/buildErrors/charts/buildLineChartErrors.d.ts +13 -0
- package/dist/esm/utils/buildErrors/charts/buildLineChartErrors.d.ts.map +1 -0
- package/dist/esm/utils/buildErrors/charts/buildLineChartErrors.js +12 -0
- package/dist/esm/utils/buildErrors/constants/errorMessages/barChartErrorMessages.d.ts +19 -0
- package/dist/esm/utils/buildErrors/constants/errorMessages/barChartErrorMessages.d.ts.map +1 -0
- package/dist/esm/utils/buildErrors/constants/errorMessages/barChartErrorMessages.js +23 -0
- package/dist/esm/utils/buildErrors/constants/errorMessages/lineChartErrorMessages.d.ts +25 -0
- package/dist/esm/utils/buildErrors/constants/errorMessages/lineChartErrorMessages.d.ts.map +1 -0
- package/dist/esm/utils/buildErrors/constants/errorMessages/lineChartErrorMessages.js +29 -0
- package/dist/esm/utils/buildErrors/constants/errors/barChartErrors.d.ts +20 -0
- package/dist/esm/utils/buildErrors/constants/errors/barChartErrors.d.ts.map +1 -0
- package/dist/esm/utils/buildErrors/constants/errors/barChartErrors.js +28 -0
- package/dist/esm/utils/buildErrors/constants/errors/lineChartErrors.d.ts +26 -0
- package/dist/esm/utils/buildErrors/constants/errors/lineChartErrors.d.ts.map +1 -0
- package/dist/esm/utils/buildErrors/constants/errors/lineChartErrors.js +34 -0
- package/dist/esm/utils/buildErrors/index.d.ts +2 -0
- package/dist/esm/utils/buildErrors/index.d.ts.map +1 -0
- package/dist/esm/utils/buildErrors/index.js +2 -0
- package/dist/esm/utils/createErrorAccumulator/createErrorAccumulator.d.ts +7 -0
- package/dist/esm/utils/createErrorAccumulator/createErrorAccumulator.d.ts.map +1 -0
- package/dist/esm/utils/createErrorAccumulator/createErrorAccumulator.js +54 -0
- package/dist/esm/utils/createErrorAccumulator/index.d.ts +2 -0
- package/dist/esm/utils/createErrorAccumulator/index.d.ts.map +1 -0
- package/dist/esm/utils/createErrorAccumulator/index.js +1 -0
- package/dist/esm/utils/cssGradientToSvg/cssGradientToSvg.d.ts.map +1 -1
- package/dist/esm/utils/cssGradientToSvg/cssGradientToSvg.js +2 -2
- package/dist/esm/utils/getCanvasDimensions/getCanvasDimensions.d.ts.map +1 -1
- package/dist/esm/utils/getCanvasDimensions/getCanvasDimensions.js +13 -2
- package/dist/esm/utils/index.d.ts +2 -0
- package/dist/esm/utils/index.d.ts.map +1 -1
- package/dist/esm/utils/index.js +2 -0
- package/dist/esm/utils/logger/index.d.ts +2 -0
- package/dist/esm/utils/logger/index.d.ts.map +1 -0
- package/dist/esm/utils/logger/index.js +1 -0
- package/dist/esm/utils/logger/logger.d.ts +45 -0
- package/dist/esm/utils/logger/logger.d.ts.map +1 -0
- package/dist/esm/utils/logger/logger.js +140 -0
- package/dist/esm/utils/ssr/index.d.ts +2 -0
- package/dist/esm/utils/ssr/index.d.ts.map +1 -0
- package/dist/esm/utils/ssr/index.js +1 -0
- package/dist/esm/utils/ssr/ssr.d.ts +80 -0
- package/dist/esm/utils/ssr/ssr.d.ts.map +1 -0
- package/dist/esm/utils/ssr/ssr.js +117 -0
- package/dist/esm/utils/textBound/textBound.d.ts.map +1 -1
- package/dist/esm/utils/textBound/textBound.js +17 -5
- package/dist/kubit-ui-web-react-charts.cjs.js +1 -1
- package/dist/kubit-ui-web-react-charts.es.js +1 -1
- package/dist/kubit-ui-web-react-charts.umd.js +1 -1
- package/dist/types/charts/barChart/barChart.type.d.ts +4 -0
- package/dist/types/charts/barChart/barChart.type.d.ts.map +1 -1
- package/dist/types/charts/barChart/barChartStructure.d.ts.map +1 -1
- package/dist/types/charts/barChart/context/buildBarContextValues.d.ts +3 -1
- package/dist/types/charts/barChart/context/buildBarContextValues.d.ts.map +1 -1
- package/dist/types/charts/barChart/fragments/barChartPath.d.ts +6 -0
- package/dist/types/charts/barChart/fragments/barChartPath.d.ts.map +1 -1
- package/dist/types/charts/barChart/fragments/barChartSeparator.d.ts.map +1 -1
- package/dist/types/charts/barChart/fragments/barChartXAxis.d.ts.map +1 -1
- package/dist/types/charts/barChart/fragments/barChartYAxis.d.ts.map +1 -1
- package/dist/types/charts/barChart/fragments/fixture/barContextData.d.ts.map +1 -1
- package/dist/types/charts/barChart/utils/getBarDataValue.d.ts.map +1 -1
- package/dist/types/charts/constants/chartDefaults.d.ts +77 -0
- package/dist/types/charts/constants/chartDefaults.d.ts.map +1 -0
- package/dist/types/charts/lineChart/context/buildLineContextValue.d.ts +3 -1
- package/dist/types/charts/lineChart/context/buildLineContextValue.d.ts.map +1 -1
- package/dist/types/charts/lineChart/fragments/fixture/contextData.d.ts +1 -0
- package/dist/types/charts/lineChart/fragments/fixture/contextData.d.ts.map +1 -1
- package/dist/types/charts/lineChart/fragments/lineChartPath.d.ts.map +1 -1
- package/dist/types/charts/lineChart/fragments/lineChartProjection.d.ts.map +1 -1
- package/dist/types/charts/lineChart/fragments/lineChartSeparator.d.ts.map +1 -1
- package/dist/types/charts/lineChart/lineChart.type.d.ts +2 -1
- package/dist/types/charts/lineChart/lineChart.type.d.ts.map +1 -1
- package/dist/types/charts/lineChart/lineChartStructure.d.ts.map +1 -1
- package/dist/types/components/zoomArea/hooks/useResponsiveCanvas.d.ts.map +1 -1
- package/dist/types/types/errors.type.d.ts +14 -1
- package/dist/types/types/errors.type.d.ts.map +1 -1
- package/dist/types/utils/buildErrors/buildErrors.d.ts +63 -0
- package/dist/types/utils/buildErrors/buildErrors.d.ts.map +1 -1
- package/dist/types/utils/buildErrors/charts/buildBarChartErrors.d.ts +17 -0
- package/dist/types/utils/buildErrors/charts/buildBarChartErrors.d.ts.map +1 -0
- package/dist/types/utils/buildErrors/charts/buildLineChartErrors.d.ts +13 -0
- package/dist/types/utils/buildErrors/charts/buildLineChartErrors.d.ts.map +1 -0
- package/dist/types/utils/buildErrors/constants/errorMessages/barChartErrorMessages.d.ts +19 -0
- package/dist/types/utils/buildErrors/constants/errorMessages/barChartErrorMessages.d.ts.map +1 -0
- package/dist/types/utils/buildErrors/constants/errorMessages/lineChartErrorMessages.d.ts +25 -0
- package/dist/types/utils/buildErrors/constants/errorMessages/lineChartErrorMessages.d.ts.map +1 -0
- package/dist/types/utils/buildErrors/constants/errors/barChartErrors.d.ts +20 -0
- package/dist/types/utils/buildErrors/constants/errors/barChartErrors.d.ts.map +1 -0
- package/dist/types/utils/buildErrors/constants/errors/lineChartErrors.d.ts +26 -0
- package/dist/types/utils/buildErrors/constants/errors/lineChartErrors.d.ts.map +1 -0
- package/dist/types/utils/buildErrors/index.d.ts +2 -0
- package/dist/types/utils/buildErrors/index.d.ts.map +1 -0
- package/dist/types/utils/createErrorAccumulator/createErrorAccumulator.d.ts +7 -0
- package/dist/types/utils/createErrorAccumulator/createErrorAccumulator.d.ts.map +1 -0
- package/dist/types/utils/createErrorAccumulator/index.d.ts +2 -0
- package/dist/types/utils/createErrorAccumulator/index.d.ts.map +1 -0
- package/dist/types/utils/cssGradientToSvg/cssGradientToSvg.d.ts.map +1 -1
- package/dist/types/utils/getCanvasDimensions/getCanvasDimensions.d.ts.map +1 -1
- package/dist/types/utils/index.d.ts +2 -0
- package/dist/types/utils/index.d.ts.map +1 -1
- package/dist/types/utils/logger/index.d.ts +2 -0
- package/dist/types/utils/logger/index.d.ts.map +1 -0
- package/dist/types/utils/logger/logger.d.ts +45 -0
- package/dist/types/utils/logger/logger.d.ts.map +1 -0
- package/dist/types/utils/ssr/index.d.ts +2 -0
- package/dist/types/utils/ssr/index.d.ts.map +1 -0
- package/dist/types/utils/ssr/ssr.d.ts +80 -0
- package/dist/types/utils/ssr/ssr.d.ts.map +1 -0
- package/dist/types/utils/textBound/textBound.d.ts.map +1 -1
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -55,6 +55,9 @@
|
|
|
55
55
|
**Customizable**: Flexible styling and granular configurations
|
|
56
56
|
**Responsive**: Adaptable to different screen sizes
|
|
57
57
|
**TypeScript**: Fully typed for better developer experience
|
|
58
|
+
**SSR Ready**: Complete Server-Side Rendering support for Next.js, Remix, Gatsby, and more
|
|
59
|
+
**Error Handling**: Advanced centralized error management system with detailed debugging
|
|
60
|
+
**Production Safe**: Built-in logging system that's automatically optimized for production builds
|
|
58
61
|
**Tested**: Complete coverage with Vitest and Testing Library
|
|
59
62
|
|
|
60
63
|
## Installation
|
|
@@ -86,6 +89,22 @@ yarn add react react-dom
|
|
|
86
89
|
- React: ^18.3.1
|
|
87
90
|
- React DOM: ^18.3.1
|
|
88
91
|
|
|
92
|
+
### Tree-Shaking Support
|
|
93
|
+
|
|
94
|
+
The library supports granular imports for optimal bundle size:
|
|
95
|
+
|
|
96
|
+
```typescript
|
|
97
|
+
// Import specific charts only
|
|
98
|
+
import { BarChart } from '@kubit-ui-web/react-charts/charts/barChart';
|
|
99
|
+
import { LineChart } from '@kubit-ui-web/react-charts/charts/lineChart';
|
|
100
|
+
// Import specific components only
|
|
101
|
+
import { Node } from '@kubit-ui-web/react-charts/components/node';
|
|
102
|
+
import { Path } from '@kubit-ui-web/react-charts/components/path';
|
|
103
|
+
// Import specific utilities only
|
|
104
|
+
import { logger } from '@kubit-ui-web/react-charts/utils/logger';
|
|
105
|
+
import { isBrowser } from '@kubit-ui-web/react-charts/utils/ssr';
|
|
106
|
+
```
|
|
107
|
+
|
|
89
108
|
## Quick Start
|
|
90
109
|
|
|
91
110
|
### Importing Components
|
|
@@ -97,6 +116,9 @@ import { BarChart, LineChart, PieChart } from '@kubit-ui-web/react-charts';
|
|
|
97
116
|
import { Node, Path, Plot } from '@kubit-ui-web/react-charts/components';
|
|
98
117
|
// Import types
|
|
99
118
|
import type { BarOrientation, ChartData } from '@kubit-ui-web/react-charts/types';
|
|
119
|
+
// Import utilities
|
|
120
|
+
import { configureLogger, logger } from '@kubit-ui-web/react-charts/utils';
|
|
121
|
+
import { createSVGElement, isBrowser, safeWindow } from '@kubit-ui-web/react-charts/utils';
|
|
100
122
|
```
|
|
101
123
|
|
|
102
124
|
### LineChart Example
|
|
@@ -162,6 +184,67 @@ function MyBarChart() {
|
|
|
162
184
|
}
|
|
163
185
|
```
|
|
164
186
|
|
|
187
|
+
### Error Handling Example
|
|
188
|
+
|
|
189
|
+
```tsx
|
|
190
|
+
import { LineChart } from '@kubit-ui-web/react-charts';
|
|
191
|
+
import type { ChartErrorCollection } from '@kubit-ui-web/react-charts/types';
|
|
192
|
+
import React from 'react';
|
|
193
|
+
|
|
194
|
+
function ChartWithErrorHandling() {
|
|
195
|
+
const handleErrors = (errors: ChartErrorCollection) => {
|
|
196
|
+
// Centralized error handling
|
|
197
|
+
console.warn('Chart errors:', errors);
|
|
198
|
+
// Display user-friendly messages or retry logic
|
|
199
|
+
};
|
|
200
|
+
|
|
201
|
+
return (
|
|
202
|
+
<LineChart data={data} xKey="year" onErrors={handleErrors} width="100%" height="400px">
|
|
203
|
+
<LineChart.Path dataKey="sales" stroke="#0078D4" />
|
|
204
|
+
<LineChart.XAxis position="BOTTOM" />
|
|
205
|
+
<LineChart.YAxis position="LEFT" />
|
|
206
|
+
</LineChart>
|
|
207
|
+
);
|
|
208
|
+
}
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
### SSR (Server-Side Rendering) Support
|
|
212
|
+
|
|
213
|
+
```tsx
|
|
214
|
+
import { LineChart, isBrowser, safeWindow } from '@kubit-ui-web/react-charts';
|
|
215
|
+
import React from 'react';
|
|
216
|
+
|
|
217
|
+
function SSRCompatibleChart() {
|
|
218
|
+
// Safe browser API access
|
|
219
|
+
const windowWidth = isBrowser() ? safeWindow()?.innerWidth || 800 : 800;
|
|
220
|
+
|
|
221
|
+
return (
|
|
222
|
+
<LineChart data={data} xKey="year" width={windowWidth} height="400px">
|
|
223
|
+
<LineChart.Path dataKey="sales" stroke="#0078D4" />
|
|
224
|
+
</LineChart>
|
|
225
|
+
);
|
|
226
|
+
}
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
### Logger Configuration
|
|
230
|
+
|
|
231
|
+
```tsx
|
|
232
|
+
import { configureLogger, logger } from '@kubit-ui-web/react-charts';
|
|
233
|
+
|
|
234
|
+
// Configure logger for development
|
|
235
|
+
configureLogger({
|
|
236
|
+
enabled: true,
|
|
237
|
+
minLevel: 'debug',
|
|
238
|
+
prefix: '[MyApp Charts]',
|
|
239
|
+
});
|
|
240
|
+
|
|
241
|
+
// Use logger in your components
|
|
242
|
+
function MyComponent() {
|
|
243
|
+
logger.info('Chart rendering started');
|
|
244
|
+
// Chart implementation
|
|
245
|
+
}
|
|
246
|
+
```
|
|
247
|
+
|
|
165
248
|
## Available Components
|
|
166
249
|
|
|
167
250
|
### Main Charts
|
|
@@ -190,6 +273,19 @@ function MyBarChart() {
|
|
|
190
273
|
| **`useFocus`** | Focus state management for accessibility |
|
|
191
274
|
| **`useHover`** | Hover detection with callbacks |
|
|
192
275
|
|
|
276
|
+
### Utility Functions
|
|
277
|
+
|
|
278
|
+
| Utility | Description |
|
|
279
|
+
| ---------------------------- | -------------------------------------------------- |
|
|
280
|
+
| **`logger`** | Production-safe logging with configurable levels |
|
|
281
|
+
| **`configureLogger`** | Logger configuration for development/debugging |
|
|
282
|
+
| **`isBrowser`** | Environment detection for browser vs SSR |
|
|
283
|
+
| **`isServer`** | Check if running in server-side environment |
|
|
284
|
+
| **`safeWindow`** | Safe access to window object in SSR environments |
|
|
285
|
+
| **`safeDocument`** | Safe access to document object in SSR environments |
|
|
286
|
+
| **`createSVGElement`** | SSR-compatible SVG element creation |
|
|
287
|
+
| **`createErrorAccumulator`** | Advanced error management for chart components |
|
|
288
|
+
|
|
193
289
|
## API Reference
|
|
194
290
|
|
|
195
291
|
For detailed API documentation, component props, and advanced examples, please refer to our individual component READMEs:
|
|
@@ -5,6 +5,7 @@ import type { BarChartStyles, BarOrientation } from '../../components/bar/bar.ty
|
|
|
5
5
|
import type { PathProps, StyleProps } from '../../components/path/path.types';
|
|
6
6
|
import type { TickData } from '../../components/tick/tick.types';
|
|
7
7
|
import type { CanvasConfig } from '../../types/canvas.type';
|
|
8
|
+
import type { ChartError, ChartErrorCollection, ErrorType } from '../../types/errors.type';
|
|
8
9
|
import type { Positions } from '../../types/position.enum';
|
|
9
10
|
export type BarChartChildrenType = ReactNode | ReactElement<PathProps | XAxisProps | YAxisProps>;
|
|
10
11
|
export interface BarChartIDataPoint {
|
|
@@ -51,6 +52,8 @@ export type BarChartContextType = Omit<BarChartExtraSpacings, OmitLineProps> & {
|
|
|
51
52
|
barChildrenCount: number;
|
|
52
53
|
gapBetweenBars?: number;
|
|
53
54
|
orientation: (typeof BarOrientation)[keyof typeof BarOrientation];
|
|
55
|
+
error?: ChartError;
|
|
56
|
+
addError?: (errorType: keyof typeof ErrorType, error: Omit<ChartError, 'type'>) => void;
|
|
54
57
|
};
|
|
55
58
|
export interface BarChartProps {
|
|
56
59
|
children: BarChartChildrenType;
|
|
@@ -74,6 +77,7 @@ export interface BarChartProps {
|
|
|
74
77
|
onBlur?: (event: React.FocusEvent<SVGElement>) => void;
|
|
75
78
|
onKeyDown?: (event: React.KeyboardEvent<SVGSVGElement>) => void;
|
|
76
79
|
onKeyUp?: (event: React.KeyboardEvent<SVGSVGElement>) => void;
|
|
80
|
+
onErrors?: (errors: ChartErrorCollection) => void;
|
|
77
81
|
}
|
|
78
82
|
export interface BarChartTickNumeric {
|
|
79
83
|
max: number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"barChart.type.d.ts","sourceRoot":"","sources":["../../../../src/charts/barChart/barChart.type.ts"],"names":[],"mapp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,CAAC,EAAE,MAAM,CAAC;CACrB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"barChartStructure.d.ts","sourceRoot":"","sources":["../../../../src/charts/barChart/barChartStructure.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"barChartStructure.d.ts","sourceRoot":"","sources":["../../../../src/charts/barChart/barChartStructure.tsx"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAOrD,eAAO,MAAM,iBAAiB,EAAE,KAAK,CAAC,EAAE,CAAC,aAAa,CAoGrD,CAAC"}
|
|
@@ -3,6 +3,7 @@ import { Children, useMemo } from 'react';
|
|
|
3
3
|
import { SvgContainer } from '../../components/svgContainer/svgContainer';
|
|
4
4
|
import { buildViewBox } from '../../components/svgContainer/utils/buildViewBox/buildViewBox';
|
|
5
5
|
import { DefaultCanvasConfig } from '../../types/canvas.type';
|
|
6
|
+
import { createErrorAccumulator } from '../../utils/createErrorAccumulator';
|
|
6
7
|
import { getDataFingerprint } from '../../utils/getDataFingerprint/getDataFingerprint';
|
|
7
8
|
import { parseStringToNumberPx } from '../../utils/parseStringToNumberPx.ts/parseStringToNumberPx';
|
|
8
9
|
import { BarChartContext } from './context/barChartContext';
|
|
@@ -10,7 +11,7 @@ import { buildBarContextValue } from './context/buildBarContextValues';
|
|
|
10
11
|
import { BarChartXAxis } from './fragments/barChartXAxis';
|
|
11
12
|
import { BarChartYAxis } from './fragments/barChartYAxis';
|
|
12
13
|
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 }) => {
|
|
14
|
+
export const BarChartStructure = ({ canvasConfig = DefaultCanvasConfig, caption, children, classNames, data, dataTestId, gapBetweenBars = 0, height = '100%', onErrors, orientation, pKey, role, tabIndex, width = '100%', ...props }) => {
|
|
14
15
|
// Extracts and sets default values for canvas configuration
|
|
15
16
|
const { extraSpace: canvasExtraSpace, height: canvasHeight, width: canvasWidth } = canvasConfig;
|
|
16
17
|
const parsedCanvasWidth = parseStringToNumberPx(canvasWidth);
|
|
@@ -32,11 +33,17 @@ export const BarChartStructure = ({ canvasConfig = DefaultCanvasConfig, caption,
|
|
|
32
33
|
const maxValue = Math.max(parsedCanvasWidth, parsedCanvasHeight, parsedCanvasExtraSpace ?? 0);
|
|
33
34
|
const ajustedX = parsedCanvasWidth / maxValue;
|
|
34
35
|
const ajustedY = parsedCanvasHeight / maxValue;
|
|
36
|
+
const errorAccumulator = useMemo(() => createErrorAccumulator(onErrors), [onErrors]);
|
|
35
37
|
// Create a fingerprint of the data to avoid unnecessary contextValue updates
|
|
36
38
|
const dataFingerprint = getDataFingerprint(data);
|
|
37
39
|
// Build the context value
|
|
38
40
|
const contextValue = useMemo(() => {
|
|
41
|
+
// Clear previous errors before building new context
|
|
42
|
+
errorAccumulator.clearErrors();
|
|
39
43
|
return buildBarContextValue({
|
|
44
|
+
addError: (errorType, error) => {
|
|
45
|
+
errorAccumulator.addError(errorType, error);
|
|
46
|
+
},
|
|
40
47
|
ajustedX,
|
|
41
48
|
ajustedY,
|
|
42
49
|
canvasHeight: parsedCanvasHeight,
|
|
@@ -48,7 +55,7 @@ export const BarChartStructure = ({ canvasConfig = DefaultCanvasConfig, caption,
|
|
|
48
55
|
pKey,
|
|
49
56
|
viewBox,
|
|
50
57
|
});
|
|
51
|
-
}, [canvasHeight, canvasWidth, dataFingerprint, pKey, orientation]);
|
|
58
|
+
}, [canvasHeight, canvasWidth, dataFingerprint, pKey, orientation, errorAccumulator.addError]);
|
|
52
59
|
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: {
|
|
53
60
|
...contextValue,
|
|
54
61
|
barChildrenCount,
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { BarOrientation } from '../../../components/bar/bar.type';
|
|
2
|
+
import { type ChartError, ErrorType } from '../../../types/errors.type';
|
|
2
3
|
import type { BarChartChildrenType, BarChartContextType, BarChartIDataPoint } from '../barChart.type';
|
|
3
4
|
interface BuildContextValue {
|
|
4
5
|
children: BarChartChildrenType;
|
|
@@ -11,6 +12,7 @@ interface BuildContextValue {
|
|
|
11
12
|
gapBetweenBars: number;
|
|
12
13
|
orientation: (typeof BarOrientation)[keyof typeof BarOrientation];
|
|
13
14
|
viewBox: string;
|
|
15
|
+
addError?: (errorType: keyof typeof ErrorType, error: Omit<ChartError, 'type'>) => void;
|
|
14
16
|
}
|
|
15
17
|
type OmitProps = 'data' | 'pKey' | 'canvasHeight' | 'canvasWidth' | 'canvasExtraSpace' | 'xBreakAxis' | 'yBreakAxis' | 'xCursor' | 'yCursor' | 'barChildrenCount' | 'orientation';
|
|
16
18
|
/**
|
|
@@ -19,6 +21,6 @@ type OmitProps = 'data' | 'pKey' | 'canvasHeight' | 'canvasWidth' | 'canvasExtra
|
|
|
19
21
|
* @param {BuildContextValue} options - The options for building the context value.
|
|
20
22
|
* @returns {LineContextValue} - The built context value.
|
|
21
23
|
*/
|
|
22
|
-
export declare const buildBarContextValue: ({ ajustedX, ajustedY, canvasHeight, canvasWidth, children, data, gapBetweenBars, orientation, pKey, viewBox, }: BuildContextValue) => Omit<BarChartContextType, OmitProps>;
|
|
24
|
+
export declare const buildBarContextValue: ({ addError, ajustedX, ajustedY, canvasHeight, canvasWidth, children, data, gapBetweenBars, orientation, pKey, viewBox, }: BuildContextValue) => Omit<BarChartContextType, OmitProps>;
|
|
23
25
|
export {};
|
|
24
26
|
//# sourceMappingURL=buildBarContextValues.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"buildBarContextValues.d.ts","sourceRoot":"","sources":["../../../../../src/charts/barChart/context/buildBarContextValues.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;
|
|
1
|
+
{"version":3,"file":"buildBarContextValues.d.ts","sourceRoot":"","sources":["../../../../../src/charts/barChart/context/buildBarContextValues.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAC3D,OAAO,EAAE,KAAK,UAAU,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAoBjE,OAAO,KAAK,EACV,oBAAoB,EACpB,mBAAmB,EACnB,kBAAkB,EACnB,MAAM,kBAAkB,CAAC;AAI1B,UAAU,iBAAiB;IACzB,QAAQ,EAAE,oBAAoB,CAAC;IAC/B,IAAI,EAAE,kBAAkB,EAAE,CAAC;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,MAAM,CAAC;IACrB,WAAW,EAAE,MAAM,CAAC;IACpB,cAAc,EAAE,MAAM,CAAC;IACvB,WAAW,EAAE,CAAC,OAAO,cAAc,CAAC,CAAC,MAAM,OAAO,cAAc,CAAC,CAAC;IAClE,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,CAAC,SAAS,EAAE,MAAM,OAAO,SAAS,EAAE,KAAK,EAAE,IAAI,CAAC,UAAU,EAAE,MAAM,CAAC,KAAK,IAAI,CAAC;CACzF;AAED,KAAK,SAAS,GACV,MAAM,GACN,MAAM,GACN,cAAc,GACd,aAAa,GACb,kBAAkB,GAClB,YAAY,GACZ,YAAY,GACZ,SAAS,GACT,SAAS,GACT,kBAAkB,GAClB,aAAa,CAAC;AAElB;;;;;GAKG;AACH,eAAO,MAAM,oBAAoB,GAAI,0HAYlC,iBAAiB,KAAG,IAAI,CAAC,mBAAmB,EAAE,SAAS,CAkSzD,CAAC"}
|
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
import { BarOrientation } from '../../../components/bar/bar.type';
|
|
2
|
+
import { ErrorType } from '../../../types/errors.type';
|
|
2
3
|
import { Positions } from '../../../types/position.enum';
|
|
4
|
+
import { BuildError, buildBarDistributionError, buildCanvasDimensionsError, buildError, } from '../../../utils/buildErrors/buildErrors';
|
|
3
5
|
import { getXCoordinates, getYCoordinates } from '../../../utils/getCoordinates/getCoordinates';
|
|
4
6
|
import { getPoints } from '../../../utils/getPoints/getPoints';
|
|
5
7
|
import { getXTicks, getYTicks } from '../../../utils/getTicks/getTicks';
|
|
8
|
+
import { AXIS_VALIDATION, BAR_CHART_DEFAULTS, BAR_CHART_FALLBACK_DATA, BREAK_AXIS_DEFAULTS, CHART_CANVAS_DEFAULTS, SHARED_FALLBACK_DATA, } from '../../constants/chartDefaults';
|
|
9
|
+
import { countBarChildren } from '../utils/countBarChildren';
|
|
6
10
|
import { getAxisExtraSpacing } from '../utils/getAxisExtraSpacing';
|
|
7
11
|
/**
|
|
8
12
|
* Builds the context value for the line chart.
|
|
@@ -10,17 +14,62 @@ import { getAxisExtraSpacing } from '../utils/getAxisExtraSpacing';
|
|
|
10
14
|
* @param {BuildContextValue} options - The options for building the context value.
|
|
11
15
|
* @returns {LineContextValue} - The built context value.
|
|
12
16
|
*/
|
|
13
|
-
export const buildBarContextValue = ({ ajustedX, ajustedY, canvasHeight, canvasWidth, children, data, gapBetweenBars, orientation, pKey, viewBox, }) => {
|
|
17
|
+
export const buildBarContextValue = ({ addError, ajustedX, ajustedY, canvasHeight, canvasWidth, children, data, gapBetweenBars, orientation, pKey, viewBox, }) => {
|
|
18
|
+
let error = undefined;
|
|
19
|
+
// 1. Validate data exists
|
|
20
|
+
if (!data || data.length === 0) {
|
|
21
|
+
const dataError = {
|
|
22
|
+
error: buildError(BuildError.BAR_CHART_NO_DATA),
|
|
23
|
+
};
|
|
24
|
+
addError?.('BAR_CHART_CONTEXT_ERROR', dataError);
|
|
25
|
+
error = dataError;
|
|
26
|
+
}
|
|
27
|
+
// 2. Validate canvas dimensions
|
|
28
|
+
if (canvasWidth <= 0 || canvasHeight <= 0) {
|
|
29
|
+
const canvasError = {
|
|
30
|
+
error: buildCanvasDimensionsError(canvasWidth, canvasHeight),
|
|
31
|
+
};
|
|
32
|
+
addError?.('BAR_CHART_CONTEXT_ERROR', canvasError);
|
|
33
|
+
error = canvasError;
|
|
34
|
+
}
|
|
35
|
+
// 3. Validate bar spacing and distribution
|
|
36
|
+
const barChildrenCount = countBarChildren(children);
|
|
37
|
+
const defaultBarWidth = BAR_CHART_DEFAULTS.BAR_WIDTH; // Default width used in BarChartPath
|
|
38
|
+
const requiredSpace = barChildrenCount * defaultBarWidth;
|
|
39
|
+
const totalGapSpace = (barChildrenCount - 1) * gapBetweenBars;
|
|
40
|
+
const availableSpace = orientation === BarOrientation.VERTICAL ? canvasWidth : canvasHeight;
|
|
41
|
+
if (requiredSpace + totalGapSpace > availableSpace) {
|
|
42
|
+
const distributionError = {
|
|
43
|
+
error: buildBarDistributionError('all', `Insufficient space: requires ${requiredSpace + totalGapSpace}px but only ${availableSpace}px available`),
|
|
44
|
+
};
|
|
45
|
+
addError?.('BAR_CHART_CONTEXT_ERROR', distributionError);
|
|
46
|
+
error = distributionError;
|
|
47
|
+
}
|
|
48
|
+
// Use safe defaults for data processing if there are critical errors
|
|
49
|
+
const safeData = data && data.length > 0
|
|
50
|
+
? data
|
|
51
|
+
: [
|
|
52
|
+
{
|
|
53
|
+
[BAR_CHART_FALLBACK_DATA.FALLBACK_SECONDARY_KEY]: BAR_CHART_FALLBACK_DATA.DEFAULT_X_VALUE,
|
|
54
|
+
[pKey]: SHARED_FALLBACK_DATA.FALLBACK_PKEY_FIRST,
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
[BAR_CHART_FALLBACK_DATA.FALLBACK_SECONDARY_KEY]: BAR_CHART_FALLBACK_DATA.DEFAULT_X_VALUE,
|
|
58
|
+
[pKey]: SHARED_FALLBACK_DATA.FALLBACK_PKEY_SECOND,
|
|
59
|
+
},
|
|
60
|
+
];
|
|
61
|
+
const safeCanvasWidth = canvasWidth > 0 ? canvasWidth : CHART_CANVAS_DEFAULTS.SAFE_WIDTH;
|
|
62
|
+
const safeCanvasHeight = canvasHeight > 0 ? canvasHeight : CHART_CANVAS_DEFAULTS.SAFE_HEIGHT;
|
|
14
63
|
/**
|
|
15
64
|
* Get the extra spacings for the line chart.
|
|
16
65
|
*/
|
|
17
66
|
const { barChartXPosition, barChartYPosition, extraSpaceBottomY, extraSpaceLeftX, extraSpaceRightX, extraSpaceTopY, securityXSpace, securityYSpace, xAxisText, xBreakAxis, xData, yAxisText, yBreakAxis, yData, } = getAxisExtraSpacing({
|
|
18
67
|
ajustedX,
|
|
19
68
|
ajustedY,
|
|
20
|
-
canvasHeight,
|
|
21
|
-
canvasWidth,
|
|
69
|
+
canvasHeight: safeCanvasHeight,
|
|
70
|
+
canvasWidth: safeCanvasWidth,
|
|
22
71
|
children,
|
|
23
|
-
data,
|
|
72
|
+
data: safeData,
|
|
24
73
|
gapBetweenBars,
|
|
25
74
|
orientation,
|
|
26
75
|
pKey,
|
|
@@ -33,35 +82,94 @@ export const buildBarContextValue = ({ ajustedX, ajustedY, canvasHeight, canvasW
|
|
|
33
82
|
const yAxisSpace = extraSpaceLeftX + extraSpaceRightX;
|
|
34
83
|
const xTickValue = getXTicks({
|
|
35
84
|
initPos: extraSpaceLeftX,
|
|
36
|
-
maxSpaceAvailable:
|
|
85
|
+
maxSpaceAvailable: safeCanvasWidth,
|
|
37
86
|
otherAxisSpace: yAxisSpace,
|
|
38
87
|
securitySpace: securityXSpace,
|
|
39
88
|
tickValues: xData,
|
|
40
89
|
});
|
|
90
|
+
if ((xTickValue ?? []).some(({ position }) => isNaN(position))) {
|
|
91
|
+
const xTickError = {
|
|
92
|
+
error: buildError(BuildError.INVALID_X_TICK),
|
|
93
|
+
};
|
|
94
|
+
addError?.('BAR_CHART_CONTEXT_ERROR', xTickError);
|
|
95
|
+
error = xTickError;
|
|
96
|
+
}
|
|
97
|
+
// Validate X-axis tick values
|
|
98
|
+
if (xTickValue) {
|
|
99
|
+
const hasInsufficientTicks = xTickValue.length < AXIS_VALIDATION.MIN_TICK_COUNT;
|
|
100
|
+
const hasIdenticalValues = xTickValue.length >= AXIS_VALIDATION.MIN_TICK_COUNT &&
|
|
101
|
+
new Set(xTickValue.map(tick => tick.value)).size === AXIS_VALIDATION.UNIQUE_VALUE_THRESHOLD;
|
|
102
|
+
if (hasInsufficientTicks) {
|
|
103
|
+
const xAxisError = {
|
|
104
|
+
error: buildError(BuildError.LINE_CHART_X_AXIS_INSUFFICIENT_TICKS),
|
|
105
|
+
};
|
|
106
|
+
addError?.('BAR_CHART_X_AXIS_ERROR', xAxisError);
|
|
107
|
+
if (!error) {
|
|
108
|
+
error = xAxisError;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
if (hasIdenticalValues) {
|
|
112
|
+
const xAxisError = {
|
|
113
|
+
error: buildError(BuildError.LINE_CHART_X_AXIS_IDENTICAL_VALUES),
|
|
114
|
+
};
|
|
115
|
+
addError?.('BAR_CHART_X_AXIS_ERROR', xAxisError);
|
|
116
|
+
if (!error) {
|
|
117
|
+
error = xAxisError;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
41
121
|
/**
|
|
42
122
|
* Calculate the tick values for the Y Axis.
|
|
43
123
|
*/
|
|
44
124
|
const crossYAxis = barChartYPosition !== Positions.LEFT && barChartYPosition !== Positions.RIGHT;
|
|
45
125
|
const otherAxisSpace = extraSpaceTopY + extraSpaceBottomY;
|
|
46
126
|
const yTickValue = getYTicks({
|
|
47
|
-
initPos:
|
|
48
|
-
maxSpaceAvailable:
|
|
127
|
+
initPos: safeCanvasHeight - extraSpaceBottomY,
|
|
128
|
+
maxSpaceAvailable: safeCanvasHeight,
|
|
49
129
|
needAjusted: orientation === BarOrientation.HORIZONTAL,
|
|
50
130
|
otherAxisSpace,
|
|
51
131
|
securitySpace: securityYSpace,
|
|
52
132
|
tickValues: yData,
|
|
53
133
|
});
|
|
134
|
+
// Validate Y-axis tick values
|
|
135
|
+
if (yTickValue) {
|
|
136
|
+
const hasInsufficientTicks = yTickValue.length < AXIS_VALIDATION.MIN_TICK_COUNT;
|
|
137
|
+
const hasIdenticalValues = yTickValue.length >= AXIS_VALIDATION.MIN_TICK_COUNT &&
|
|
138
|
+
new Set(yTickValue.map(tick => tick.value)).size === AXIS_VALIDATION.UNIQUE_VALUE_THRESHOLD;
|
|
139
|
+
if (hasInsufficientTicks) {
|
|
140
|
+
const yAxisError = {
|
|
141
|
+
error: buildError(BuildError.LINE_CHART_Y_AXIS_INSUFFICIENT_TICKS),
|
|
142
|
+
};
|
|
143
|
+
addError?.('BAR_CHART_Y_AXIS_ERROR', yAxisError);
|
|
144
|
+
if (!error) {
|
|
145
|
+
error = yAxisError;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
if (hasIdenticalValues) {
|
|
149
|
+
const yAxisError = {
|
|
150
|
+
error: buildError(BuildError.LINE_CHART_Y_AXIS_IDENTICAL_VALUES),
|
|
151
|
+
};
|
|
152
|
+
addError?.('BAR_CHART_Y_AXIS_ERROR', yAxisError);
|
|
153
|
+
if (!error) {
|
|
154
|
+
error = yAxisError;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
54
158
|
/**
|
|
55
159
|
* Calculate the custom breakAxis for the X and Y Axis.
|
|
56
160
|
*/
|
|
57
|
-
const customBreakXAxis = crossXAxis
|
|
58
|
-
|
|
161
|
+
const customBreakXAxis = crossXAxis
|
|
162
|
+
? getPoints(yTickValue || [], [String(xBreakAxis)])[0]
|
|
163
|
+
: BREAK_AXIS_DEFAULTS.DEFAULT_BREAK_VALUE;
|
|
164
|
+
const customBreakYAxis = crossYAxis
|
|
165
|
+
? getPoints(xTickValue || [], [String(yBreakAxis)])[0]
|
|
166
|
+
: BREAK_AXIS_DEFAULTS.DEFAULT_BREAK_VALUE;
|
|
59
167
|
/**
|
|
60
168
|
* Calculate the X coordinates for the line chart.
|
|
61
169
|
*/
|
|
62
170
|
const xCoordinates = getXCoordinates({
|
|
63
|
-
canvasHeight,
|
|
64
|
-
canvasWidth,
|
|
171
|
+
canvasHeight: safeCanvasHeight,
|
|
172
|
+
canvasWidth: safeCanvasWidth,
|
|
65
173
|
customBreakAxis: Number(customBreakXAxis),
|
|
66
174
|
extraSpaceBottomY,
|
|
67
175
|
extraSpaceLeftX,
|
|
@@ -74,8 +182,8 @@ export const buildBarContextValue = ({ ajustedX, ajustedY, canvasHeight, canvasW
|
|
|
74
182
|
* Calculate the Y coordinates for the line chart.
|
|
75
183
|
*/
|
|
76
184
|
const yCoordinates = getYCoordinates({
|
|
77
|
-
canvasHeight,
|
|
78
|
-
canvasWidth,
|
|
185
|
+
canvasHeight: safeCanvasHeight,
|
|
186
|
+
canvasWidth: safeCanvasWidth,
|
|
79
187
|
customBreakAxis: Number(customBreakYAxis),
|
|
80
188
|
extraSpaceBottomY,
|
|
81
189
|
extraSpaceLeftX,
|
|
@@ -84,18 +192,71 @@ export const buildBarContextValue = ({ ajustedX, ajustedY, canvasHeight, canvasW
|
|
|
84
192
|
position: barChartYPosition,
|
|
85
193
|
securityYSpace,
|
|
86
194
|
});
|
|
87
|
-
|
|
195
|
+
// Validate axis coordinates for zero-length axes
|
|
196
|
+
if (xCoordinates.x1 === xCoordinates.x2) {
|
|
197
|
+
const xAxisError = {
|
|
198
|
+
error: buildError(BuildError.LINE_CHART_X_AXIS_ZERO_LENGTH),
|
|
199
|
+
};
|
|
200
|
+
addError?.('BAR_CHART_X_AXIS_ERROR', xAxisError);
|
|
201
|
+
if (!error) {
|
|
202
|
+
error = xAxisError;
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
if (yCoordinates.y1 === yCoordinates.y2) {
|
|
206
|
+
const yAxisError = {
|
|
207
|
+
error: buildError(BuildError.LINE_CHART_Y_AXIS_ZERO_LENGTH),
|
|
208
|
+
};
|
|
209
|
+
addError?.('BAR_CHART_Y_AXIS_ERROR', yAxisError);
|
|
210
|
+
if (!error) {
|
|
211
|
+
error = yAxisError;
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
const baseContext = {
|
|
215
|
+
addError,
|
|
88
216
|
crossXAxis,
|
|
89
217
|
crossYAxis,
|
|
218
|
+
data: safeData,
|
|
90
219
|
extraSpaceBottomY,
|
|
91
220
|
extraSpaceLeftX,
|
|
92
221
|
extraSpaceRightX,
|
|
93
222
|
extraSpaceTopY,
|
|
94
223
|
securityXSpace,
|
|
95
224
|
securityYSpace,
|
|
96
|
-
xAxisCoordinates: {
|
|
225
|
+
xAxisCoordinates: {
|
|
226
|
+
coordinates: xCoordinates,
|
|
227
|
+
tickValues: xTickValue ||
|
|
228
|
+
(error
|
|
229
|
+
? [
|
|
230
|
+
{
|
|
231
|
+
position: BREAK_AXIS_DEFAULTS.DEFAULT_BREAK_VALUE,
|
|
232
|
+
value: SHARED_FALLBACK_DATA.FALLBACK_PKEY_FIRST,
|
|
233
|
+
},
|
|
234
|
+
{ position: safeCanvasWidth, value: SHARED_FALLBACK_DATA.FALLBACK_PKEY_SECOND },
|
|
235
|
+
]
|
|
236
|
+
: []),
|
|
237
|
+
},
|
|
97
238
|
xAxisText,
|
|
98
|
-
yAxisCoordinates: {
|
|
239
|
+
yAxisCoordinates: {
|
|
240
|
+
coordinates: yCoordinates,
|
|
241
|
+
tickValues: yTickValue ||
|
|
242
|
+
(error
|
|
243
|
+
? [
|
|
244
|
+
{ position: safeCanvasHeight, value: SHARED_FALLBACK_DATA.FALLBACK_PKEY_FIRST },
|
|
245
|
+
{
|
|
246
|
+
position: BREAK_AXIS_DEFAULTS.DEFAULT_BREAK_VALUE,
|
|
247
|
+
value: SHARED_FALLBACK_DATA.FALLBACK_PKEY_SECOND,
|
|
248
|
+
},
|
|
249
|
+
]
|
|
250
|
+
: []),
|
|
251
|
+
},
|
|
99
252
|
yAxisText,
|
|
100
253
|
};
|
|
254
|
+
// Add error only if it exists
|
|
255
|
+
if (error) {
|
|
256
|
+
return {
|
|
257
|
+
...baseContext,
|
|
258
|
+
error: { ...error, type: ErrorType.BAR_CHART_CONTEXT_ERROR },
|
|
259
|
+
};
|
|
260
|
+
}
|
|
261
|
+
return baseContext;
|
|
101
262
|
};
|
|
@@ -1,3 +1,9 @@
|
|
|
1
1
|
import type { BarChartPathProps } from '../barChart.type';
|
|
2
|
+
/**
|
|
3
|
+
* Extracts the values for a specific key from the dataset
|
|
4
|
+
* @param data Array of data points
|
|
5
|
+
* @param key Key to extract values from
|
|
6
|
+
* @returns Array of values for the given key
|
|
7
|
+
*/
|
|
2
8
|
export declare const BarChartPath: React.FC<BarChartPathProps>;
|
|
3
9
|
//# sourceMappingURL=barChartPath.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"barChartPath.d.ts","sourceRoot":"","sources":["../../../../../src/charts/barChart/fragments/barChartPath.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"barChartPath.d.ts","sourceRoot":"","sources":["../../../../../src/charts/barChart/fragments/barChartPath.tsx"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAG1D;;;;;GAKG;AAEH,eAAO,MAAM,YAAY,EAAE,KAAK,CAAC,EAAE,CAAC,iBAAiB,CA8EpD,CAAC"}
|
|
@@ -1,18 +1,52 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import { useContext } from 'react';
|
|
2
|
+
import { useContext, useEffect } from 'react';
|
|
3
3
|
import { Bar } from '../../../components/bar/bar';
|
|
4
4
|
import { BarOrientation } from '../../../components/bar/bar.type';
|
|
5
|
+
import { buildBarNegativeValueError, buildBarValueError, buildDataKeyNotFoundError, } from '../../../utils/buildErrors/buildErrors';
|
|
5
6
|
import { getPoints } from '../../../utils/getPoints/getPoints';
|
|
6
7
|
import { BarChartContext } from '../context/barChartContext';
|
|
8
|
+
/**
|
|
9
|
+
* Extracts the values for a specific key from the dataset
|
|
10
|
+
* @param data Array of data points
|
|
11
|
+
* @param key Key to extract values from
|
|
12
|
+
* @returns Array of values for the given key
|
|
13
|
+
*/
|
|
7
14
|
export const BarChartPath = ({ barConfig, dataIdx, dataKey, order, ...props }) => {
|
|
8
|
-
const { xAxisCoordinates, yAxisCoordinates, ...context } = useContext(BarChartContext);
|
|
15
|
+
const { addError, xAxisCoordinates, yAxisCoordinates, ...context } = useContext(BarChartContext);
|
|
9
16
|
const { coordinates: xACoord, tickValues: xTickValues } = xAxisCoordinates;
|
|
10
17
|
const { coordinates: yACoord, tickValues: yTickValues } = yAxisCoordinates;
|
|
11
18
|
const isVertical = context.orientation === BarOrientation.VERTICAL;
|
|
12
19
|
const xKey = isVertical ? context.pKey : dataKey;
|
|
13
20
|
const yKey = isVertical ? dataKey : context.pKey;
|
|
14
|
-
|
|
15
|
-
const
|
|
21
|
+
// Safe data access
|
|
22
|
+
const dataItem = context.data[dataIdx];
|
|
23
|
+
const xData = dataItem?.[xKey];
|
|
24
|
+
const yData = dataItem?.[yKey];
|
|
25
|
+
// Path error validations - only validates the data for this specific bar
|
|
26
|
+
useEffect(() => {
|
|
27
|
+
// Validate dataKey exists in dataset
|
|
28
|
+
if (context.data.length > 0 &&
|
|
29
|
+
!Object.prototype.hasOwnProperty.call(context.data[0], dataKey)) {
|
|
30
|
+
addError?.('BAR_CHART_PATH_ERROR', {
|
|
31
|
+
error: buildDataKeyNotFoundError(dataKey),
|
|
32
|
+
});
|
|
33
|
+
return; // Stop validation if dataKey doesn't exist
|
|
34
|
+
}
|
|
35
|
+
// Validate bar value is numeric
|
|
36
|
+
const numericValue = Number(yData);
|
|
37
|
+
if (isNaN(numericValue)) {
|
|
38
|
+
addError?.('BAR_CHART_PATH_ERROR', {
|
|
39
|
+
error: buildBarValueError(yData, dataKey),
|
|
40
|
+
});
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
// Validate negative values
|
|
44
|
+
if (numericValue < 0) {
|
|
45
|
+
addError?.('BAR_CHART_PATH_ERROR', {
|
|
46
|
+
error: buildBarNegativeValueError(numericValue, dataKey),
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
}, [addError, context.data, dataKey, yData]);
|
|
16
50
|
const xPoint = getPoints(xTickValues, [String(xData)], true)[0];
|
|
17
51
|
const yPoint = getPoints(yTickValues, [String(yData)])[0];
|
|
18
52
|
const points = isVertical
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"barChartSeparator.d.ts","sourceRoot":"","sources":["../../../../../src/charts/barChart/fragments/barChartSeparator.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"barChartSeparator.d.ts","sourceRoot":"","sources":["../../../../../src/charts/barChart/fragments/barChartSeparator.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,EAA4C,MAAM,OAAO,CAAC;AAY1E,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,kBAAkB,CAAC;AAG/D,eAAO,MAAM,iBAAiB,EAAE,EAAE,CAAC,sBAAsB,CA0FxD,CAAC"}
|