@kubit-ui-web/react-charts 1.1.0 → 1.2.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.
Files changed (196) hide show
  1. package/dist/cjs/charts/barChart/barChart.type.d.ts +4 -0
  2. package/dist/cjs/charts/barChart/barChart.type.d.ts.map +1 -1
  3. package/dist/cjs/charts/barChart/barChartStructure.d.ts.map +1 -1
  4. package/dist/cjs/charts/barChart/barChartStructure.js +9 -2
  5. package/dist/cjs/charts/barChart/context/buildBarContextValues.d.ts +3 -1
  6. package/dist/cjs/charts/barChart/context/buildBarContextValues.d.ts.map +1 -1
  7. package/dist/cjs/charts/barChart/context/buildBarContextValues.js +177 -16
  8. package/dist/cjs/charts/barChart/fragments/barChartPath.d.ts +6 -0
  9. package/dist/cjs/charts/barChart/fragments/barChartPath.d.ts.map +1 -1
  10. package/dist/cjs/charts/barChart/fragments/barChartPath.js +38 -4
  11. package/dist/cjs/charts/barChart/fragments/barChartSeparator.d.ts.map +1 -1
  12. package/dist/cjs/charts/barChart/fragments/barChartSeparator.js +52 -2
  13. package/dist/cjs/charts/barChart/fragments/barChartXAxis.d.ts.map +1 -1
  14. package/dist/cjs/charts/barChart/fragments/barChartXAxis.js +2 -1
  15. package/dist/cjs/charts/barChart/fragments/barChartYAxis.d.ts.map +1 -1
  16. package/dist/cjs/charts/barChart/fragments/barChartYAxis.js +2 -1
  17. package/dist/cjs/charts/barChart/fragments/fixture/barContextData.d.ts.map +1 -1
  18. package/dist/cjs/charts/barChart/fragments/fixture/barContextData.js +1 -0
  19. package/dist/cjs/charts/barChart/utils/getBarDataValue.d.ts.map +1 -1
  20. package/dist/cjs/charts/barChart/utils/getBarDataValue.js +5 -0
  21. package/dist/cjs/charts/constants/chartDefaults.d.ts +77 -0
  22. package/dist/cjs/charts/constants/chartDefaults.d.ts.map +1 -0
  23. package/dist/cjs/charts/constants/chartDefaults.js +76 -0
  24. package/dist/cjs/charts/lineChart/context/buildLineContextValue.d.ts +3 -1
  25. package/dist/cjs/charts/lineChart/context/buildLineContextValue.d.ts.map +1 -1
  26. package/dist/cjs/charts/lineChart/context/buildLineContextValue.js +162 -46
  27. package/dist/cjs/charts/lineChart/fragments/fixture/contextData.d.ts +1 -0
  28. package/dist/cjs/charts/lineChart/fragments/fixture/contextData.d.ts.map +1 -1
  29. package/dist/cjs/charts/lineChart/fragments/fixture/contextData.js +1 -0
  30. package/dist/cjs/charts/lineChart/fragments/lineChartPath.d.ts.map +1 -1
  31. package/dist/cjs/charts/lineChart/fragments/lineChartPath.js +34 -1
  32. package/dist/cjs/charts/lineChart/fragments/lineChartProjection.d.ts +1 -1
  33. package/dist/cjs/charts/lineChart/fragments/lineChartProjection.d.ts.map +1 -1
  34. package/dist/cjs/charts/lineChart/fragments/lineChartProjection.js +44 -0
  35. package/dist/cjs/charts/lineChart/fragments/lineChartSeparator.d.ts.map +1 -1
  36. package/dist/cjs/charts/lineChart/fragments/lineChartSeparator.js +52 -2
  37. package/dist/cjs/charts/lineChart/lineChart.type.d.ts +2 -1
  38. package/dist/cjs/charts/lineChart/lineChart.type.d.ts.map +1 -1
  39. package/dist/cjs/charts/lineChart/lineChartStructure.d.ts.map +1 -1
  40. package/dist/cjs/charts/lineChart/lineChartStructure.js +15 -11
  41. package/dist/cjs/types/errors.type.d.ts +14 -1
  42. package/dist/cjs/types/errors.type.d.ts.map +1 -1
  43. package/dist/cjs/types/errors.type.js +18 -0
  44. package/dist/cjs/utils/buildErrors/buildErrors.d.ts +63 -0
  45. package/dist/cjs/utils/buildErrors/buildErrors.d.ts.map +1 -1
  46. package/dist/cjs/utils/buildErrors/buildErrors.js +32 -0
  47. package/dist/cjs/utils/buildErrors/charts/buildBarChartErrors.d.ts +17 -0
  48. package/dist/cjs/utils/buildErrors/charts/buildBarChartErrors.d.ts.map +1 -0
  49. package/dist/cjs/utils/buildErrors/charts/buildBarChartErrors.js +16 -0
  50. package/dist/cjs/utils/buildErrors/charts/buildLineChartErrors.d.ts +13 -0
  51. package/dist/cjs/utils/buildErrors/charts/buildLineChartErrors.d.ts.map +1 -0
  52. package/dist/cjs/utils/buildErrors/charts/buildLineChartErrors.js +12 -0
  53. package/dist/cjs/utils/buildErrors/constants/errorMessages/barChartErrorMessages.d.ts +19 -0
  54. package/dist/cjs/utils/buildErrors/constants/errorMessages/barChartErrorMessages.d.ts.map +1 -0
  55. package/dist/cjs/utils/buildErrors/constants/errorMessages/barChartErrorMessages.js +23 -0
  56. package/dist/cjs/utils/buildErrors/constants/errorMessages/lineChartErrorMessages.d.ts +25 -0
  57. package/dist/cjs/utils/buildErrors/constants/errorMessages/lineChartErrorMessages.d.ts.map +1 -0
  58. package/dist/cjs/utils/buildErrors/constants/errorMessages/lineChartErrorMessages.js +29 -0
  59. package/dist/cjs/utils/buildErrors/constants/errors/barChartErrors.d.ts +20 -0
  60. package/dist/cjs/utils/buildErrors/constants/errors/barChartErrors.d.ts.map +1 -0
  61. package/dist/cjs/utils/buildErrors/constants/errors/barChartErrors.js +28 -0
  62. package/dist/cjs/utils/buildErrors/constants/errors/lineChartErrors.d.ts +26 -0
  63. package/dist/cjs/utils/buildErrors/constants/errors/lineChartErrors.d.ts.map +1 -0
  64. package/dist/cjs/utils/buildErrors/constants/errors/lineChartErrors.js +34 -0
  65. package/dist/cjs/utils/buildErrors/index.d.ts +2 -0
  66. package/dist/cjs/utils/buildErrors/index.d.ts.map +1 -0
  67. package/dist/cjs/utils/buildErrors/index.js +2 -0
  68. package/dist/cjs/utils/createErrorAccumulator/createErrorAccumulator.d.ts +7 -0
  69. package/dist/cjs/utils/createErrorAccumulator/createErrorAccumulator.d.ts.map +1 -0
  70. package/dist/cjs/utils/createErrorAccumulator/createErrorAccumulator.js +54 -0
  71. package/dist/cjs/utils/createErrorAccumulator/index.d.ts +2 -0
  72. package/dist/cjs/utils/createErrorAccumulator/index.d.ts.map +1 -0
  73. package/dist/cjs/utils/createErrorAccumulator/index.js +1 -0
  74. package/dist/esm/charts/barChart/barChart.type.d.ts +4 -0
  75. package/dist/esm/charts/barChart/barChart.type.d.ts.map +1 -1
  76. package/dist/esm/charts/barChart/barChartStructure.d.ts.map +1 -1
  77. package/dist/esm/charts/barChart/barChartStructure.js +9 -2
  78. package/dist/esm/charts/barChart/context/buildBarContextValues.d.ts +3 -1
  79. package/dist/esm/charts/barChart/context/buildBarContextValues.d.ts.map +1 -1
  80. package/dist/esm/charts/barChart/context/buildBarContextValues.js +177 -16
  81. package/dist/esm/charts/barChart/fragments/barChartPath.d.ts +6 -0
  82. package/dist/esm/charts/barChart/fragments/barChartPath.d.ts.map +1 -1
  83. package/dist/esm/charts/barChart/fragments/barChartPath.js +38 -4
  84. package/dist/esm/charts/barChart/fragments/barChartSeparator.d.ts.map +1 -1
  85. package/dist/esm/charts/barChart/fragments/barChartSeparator.js +52 -2
  86. package/dist/esm/charts/barChart/fragments/barChartXAxis.d.ts.map +1 -1
  87. package/dist/esm/charts/barChart/fragments/barChartXAxis.js +2 -1
  88. package/dist/esm/charts/barChart/fragments/barChartYAxis.d.ts.map +1 -1
  89. package/dist/esm/charts/barChart/fragments/barChartYAxis.js +2 -1
  90. package/dist/esm/charts/barChart/fragments/fixture/barContextData.d.ts.map +1 -1
  91. package/dist/esm/charts/barChart/fragments/fixture/barContextData.js +1 -0
  92. package/dist/esm/charts/barChart/utils/getBarDataValue.d.ts.map +1 -1
  93. package/dist/esm/charts/barChart/utils/getBarDataValue.js +5 -0
  94. package/dist/esm/charts/constants/chartDefaults.d.ts +77 -0
  95. package/dist/esm/charts/constants/chartDefaults.d.ts.map +1 -0
  96. package/dist/esm/charts/constants/chartDefaults.js +76 -0
  97. package/dist/esm/charts/lineChart/context/buildLineContextValue.d.ts +3 -1
  98. package/dist/esm/charts/lineChart/context/buildLineContextValue.d.ts.map +1 -1
  99. package/dist/esm/charts/lineChart/context/buildLineContextValue.js +162 -46
  100. package/dist/esm/charts/lineChart/fragments/fixture/contextData.d.ts +1 -0
  101. package/dist/esm/charts/lineChart/fragments/fixture/contextData.d.ts.map +1 -1
  102. package/dist/esm/charts/lineChart/fragments/fixture/contextData.js +1 -0
  103. package/dist/esm/charts/lineChart/fragments/lineChartPath.d.ts.map +1 -1
  104. package/dist/esm/charts/lineChart/fragments/lineChartPath.js +34 -1
  105. package/dist/esm/charts/lineChart/fragments/lineChartProjection.d.ts +1 -1
  106. package/dist/esm/charts/lineChart/fragments/lineChartProjection.d.ts.map +1 -1
  107. package/dist/esm/charts/lineChart/fragments/lineChartProjection.js +44 -0
  108. package/dist/esm/charts/lineChart/fragments/lineChartSeparator.d.ts.map +1 -1
  109. package/dist/esm/charts/lineChart/fragments/lineChartSeparator.js +52 -2
  110. package/dist/esm/charts/lineChart/lineChart.type.d.ts +2 -1
  111. package/dist/esm/charts/lineChart/lineChart.type.d.ts.map +1 -1
  112. package/dist/esm/charts/lineChart/lineChartStructure.d.ts.map +1 -1
  113. package/dist/esm/charts/lineChart/lineChartStructure.js +15 -11
  114. package/dist/esm/types/errors.type.d.ts +14 -1
  115. package/dist/esm/types/errors.type.d.ts.map +1 -1
  116. package/dist/esm/types/errors.type.js +18 -0
  117. package/dist/esm/utils/buildErrors/buildErrors.d.ts +63 -0
  118. package/dist/esm/utils/buildErrors/buildErrors.d.ts.map +1 -1
  119. package/dist/esm/utils/buildErrors/buildErrors.js +32 -0
  120. package/dist/esm/utils/buildErrors/charts/buildBarChartErrors.d.ts +17 -0
  121. package/dist/esm/utils/buildErrors/charts/buildBarChartErrors.d.ts.map +1 -0
  122. package/dist/esm/utils/buildErrors/charts/buildBarChartErrors.js +16 -0
  123. package/dist/esm/utils/buildErrors/charts/buildLineChartErrors.d.ts +13 -0
  124. package/dist/esm/utils/buildErrors/charts/buildLineChartErrors.d.ts.map +1 -0
  125. package/dist/esm/utils/buildErrors/charts/buildLineChartErrors.js +12 -0
  126. package/dist/esm/utils/buildErrors/constants/errorMessages/barChartErrorMessages.d.ts +19 -0
  127. package/dist/esm/utils/buildErrors/constants/errorMessages/barChartErrorMessages.d.ts.map +1 -0
  128. package/dist/esm/utils/buildErrors/constants/errorMessages/barChartErrorMessages.js +23 -0
  129. package/dist/esm/utils/buildErrors/constants/errorMessages/lineChartErrorMessages.d.ts +25 -0
  130. package/dist/esm/utils/buildErrors/constants/errorMessages/lineChartErrorMessages.d.ts.map +1 -0
  131. package/dist/esm/utils/buildErrors/constants/errorMessages/lineChartErrorMessages.js +29 -0
  132. package/dist/esm/utils/buildErrors/constants/errors/barChartErrors.d.ts +20 -0
  133. package/dist/esm/utils/buildErrors/constants/errors/barChartErrors.d.ts.map +1 -0
  134. package/dist/esm/utils/buildErrors/constants/errors/barChartErrors.js +28 -0
  135. package/dist/esm/utils/buildErrors/constants/errors/lineChartErrors.d.ts +26 -0
  136. package/dist/esm/utils/buildErrors/constants/errors/lineChartErrors.d.ts.map +1 -0
  137. package/dist/esm/utils/buildErrors/constants/errors/lineChartErrors.js +34 -0
  138. package/dist/esm/utils/buildErrors/index.d.ts +2 -0
  139. package/dist/esm/utils/buildErrors/index.d.ts.map +1 -0
  140. package/dist/esm/utils/buildErrors/index.js +2 -0
  141. package/dist/esm/utils/createErrorAccumulator/createErrorAccumulator.d.ts +7 -0
  142. package/dist/esm/utils/createErrorAccumulator/createErrorAccumulator.d.ts.map +1 -0
  143. package/dist/esm/utils/createErrorAccumulator/createErrorAccumulator.js +54 -0
  144. package/dist/esm/utils/createErrorAccumulator/index.d.ts +2 -0
  145. package/dist/esm/utils/createErrorAccumulator/index.d.ts.map +1 -0
  146. package/dist/esm/utils/createErrorAccumulator/index.js +1 -0
  147. package/dist/kubit-ui-web-react-charts.cjs.js +1 -1
  148. package/dist/kubit-ui-web-react-charts.es.js +1 -1
  149. package/dist/kubit-ui-web-react-charts.umd.js +1 -1
  150. package/dist/types/charts/barChart/barChart.type.d.ts +4 -0
  151. package/dist/types/charts/barChart/barChart.type.d.ts.map +1 -1
  152. package/dist/types/charts/barChart/barChartStructure.d.ts.map +1 -1
  153. package/dist/types/charts/barChart/context/buildBarContextValues.d.ts +3 -1
  154. package/dist/types/charts/barChart/context/buildBarContextValues.d.ts.map +1 -1
  155. package/dist/types/charts/barChart/fragments/barChartPath.d.ts +6 -0
  156. package/dist/types/charts/barChart/fragments/barChartPath.d.ts.map +1 -1
  157. package/dist/types/charts/barChart/fragments/barChartSeparator.d.ts.map +1 -1
  158. package/dist/types/charts/barChart/fragments/barChartXAxis.d.ts.map +1 -1
  159. package/dist/types/charts/barChart/fragments/barChartYAxis.d.ts.map +1 -1
  160. package/dist/types/charts/barChart/fragments/fixture/barContextData.d.ts.map +1 -1
  161. package/dist/types/charts/barChart/utils/getBarDataValue.d.ts.map +1 -1
  162. package/dist/types/charts/constants/chartDefaults.d.ts +77 -0
  163. package/dist/types/charts/constants/chartDefaults.d.ts.map +1 -0
  164. package/dist/types/charts/lineChart/context/buildLineContextValue.d.ts +3 -1
  165. package/dist/types/charts/lineChart/context/buildLineContextValue.d.ts.map +1 -1
  166. package/dist/types/charts/lineChart/fragments/fixture/contextData.d.ts +1 -0
  167. package/dist/types/charts/lineChart/fragments/fixture/contextData.d.ts.map +1 -1
  168. package/dist/types/charts/lineChart/fragments/lineChartPath.d.ts.map +1 -1
  169. package/dist/types/charts/lineChart/fragments/lineChartProjection.d.ts.map +1 -1
  170. package/dist/types/charts/lineChart/fragments/lineChartSeparator.d.ts.map +1 -1
  171. package/dist/types/charts/lineChart/lineChart.type.d.ts +2 -1
  172. package/dist/types/charts/lineChart/lineChart.type.d.ts.map +1 -1
  173. package/dist/types/charts/lineChart/lineChartStructure.d.ts.map +1 -1
  174. package/dist/types/types/errors.type.d.ts +14 -1
  175. package/dist/types/types/errors.type.d.ts.map +1 -1
  176. package/dist/types/utils/buildErrors/buildErrors.d.ts +63 -0
  177. package/dist/types/utils/buildErrors/buildErrors.d.ts.map +1 -1
  178. package/dist/types/utils/buildErrors/charts/buildBarChartErrors.d.ts +17 -0
  179. package/dist/types/utils/buildErrors/charts/buildBarChartErrors.d.ts.map +1 -0
  180. package/dist/types/utils/buildErrors/charts/buildLineChartErrors.d.ts +13 -0
  181. package/dist/types/utils/buildErrors/charts/buildLineChartErrors.d.ts.map +1 -0
  182. package/dist/types/utils/buildErrors/constants/errorMessages/barChartErrorMessages.d.ts +19 -0
  183. package/dist/types/utils/buildErrors/constants/errorMessages/barChartErrorMessages.d.ts.map +1 -0
  184. package/dist/types/utils/buildErrors/constants/errorMessages/lineChartErrorMessages.d.ts +25 -0
  185. package/dist/types/utils/buildErrors/constants/errorMessages/lineChartErrorMessages.d.ts.map +1 -0
  186. package/dist/types/utils/buildErrors/constants/errors/barChartErrors.d.ts +20 -0
  187. package/dist/types/utils/buildErrors/constants/errors/barChartErrors.d.ts.map +1 -0
  188. package/dist/types/utils/buildErrors/constants/errors/lineChartErrors.d.ts +26 -0
  189. package/dist/types/utils/buildErrors/constants/errors/lineChartErrors.d.ts.map +1 -0
  190. package/dist/types/utils/buildErrors/index.d.ts +2 -0
  191. package/dist/types/utils/buildErrors/index.d.ts.map +1 -0
  192. package/dist/types/utils/createErrorAccumulator/createErrorAccumulator.d.ts +7 -0
  193. package/dist/types/utils/createErrorAccumulator/createErrorAccumulator.d.ts.map +1 -0
  194. package/dist/types/utils/createErrorAccumulator/index.d.ts +2 -0
  195. package/dist/types/utils/createErrorAccumulator/index.d.ts.map +1 -0
  196. package/package.json +1 -1
@@ -0,0 +1,77 @@
1
+ /**
2
+ * Shared default configuration constants for chart components.
3
+ *
4
+ * These constants provide standardized default values that are common across
5
+ * different chart types, as well as type-specific constants with clear naming.
6
+ */
7
+ /**
8
+ * Default canvas dimensions used as fallback when invalid dimensions are provided
9
+ */
10
+ export declare const CHART_CANVAS_DEFAULTS: {
11
+ /** Default canvas height when invalid height is provided */
12
+ readonly SAFE_HEIGHT: 100;
13
+ /** Default canvas width when invalid width is provided */
14
+ readonly SAFE_WIDTH: 100;
15
+ };
16
+ /**
17
+ * Axis validation constants for tick values and positioning
18
+ */
19
+ export declare const AXIS_VALIDATION: {
20
+ /** Minimum number of tick values required for a valid axis */
21
+ readonly MIN_TICK_COUNT: 2;
22
+ /** Number used to detect when all tick values are identical */
23
+ readonly UNIQUE_VALUE_THRESHOLD: 1;
24
+ };
25
+ /**
26
+ * Default spacing and positioning values
27
+ */
28
+ export declare const CHART_SPACING_DEFAULTS: {
29
+ /** Default spacing value when no spacing is specified */
30
+ readonly DEFAULT_SPACE: 0;
31
+ };
32
+ /**
33
+ * Break axis default values
34
+ */
35
+ export declare const BREAK_AXIS_DEFAULTS: {
36
+ /** Default value when no custom break axis is specified */
37
+ readonly DEFAULT_BREAK_VALUE: 0;
38
+ };
39
+ /**
40
+ * Shared fallback data points used across different chart types
41
+ */
42
+ export declare const SHARED_FALLBACK_DATA: {
43
+ /** First fallback primary key value (used for axis labels) */
44
+ readonly FALLBACK_PKEY_FIRST: "0";
45
+ /** Second fallback primary key value (used for axis labels) */
46
+ readonly FALLBACK_PKEY_SECOND: "1";
47
+ };
48
+ /**
49
+ * Bar Chart specific default configuration values
50
+ */
51
+ export declare const BAR_CHART_DEFAULTS: {
52
+ /** Default width for bar elements when not specified */
53
+ readonly BAR_WIDTH: 20;
54
+ };
55
+ /**
56
+ * Bar Chart specific fallback data points used when bar chart data is invalid or empty
57
+ */
58
+ export declare const BAR_CHART_FALLBACK_DATA: {
59
+ /** Default x value for fallback data points */
60
+ readonly DEFAULT_X_VALUE: 0;
61
+ /** Generic secondary key for fallback data when dataKey is needed */
62
+ readonly FALLBACK_SECONDARY_KEY: "fallbackData";
63
+ };
64
+ /**
65
+ * Line Chart specific fallback data points used when line chart data is invalid or empty
66
+ */
67
+ export declare const LINE_CHART_FALLBACK_DATA: {
68
+ /** First X value for line chart fallback data */
69
+ readonly FALLBACK_X_FIRST: "0";
70
+ /** Second X value for line chart fallback data */
71
+ readonly FALLBACK_X_SECOND: "1";
72
+ /** First Y value for line chart fallback data */
73
+ readonly FALLBACK_Y_FIRST: 0;
74
+ /** Second Y value for line chart fallback data */
75
+ readonly FALLBACK_Y_SECOND: 1;
76
+ };
77
+ //# sourceMappingURL=chartDefaults.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"chartDefaults.d.ts","sourceRoot":"","sources":["../../../../src/charts/constants/chartDefaults.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH;;GAEG;AACH,eAAO,MAAM,qBAAqB;IAChC,4DAA4D;;IAE5D,0DAA0D;;CAElD,CAAC;AAEX;;GAEG;AACH,eAAO,MAAM,eAAe;IAC1B,8DAA8D;;IAE9D,+DAA+D;;CAEvD,CAAC;AAEX;;GAEG;AACH,eAAO,MAAM,sBAAsB;IACjC,yDAAyD;;CAEjD,CAAC;AAEX;;GAEG;AACH,eAAO,MAAM,mBAAmB;IAC9B,2DAA2D;;CAEnD,CAAC;AAEX;;GAEG;AACH,eAAO,MAAM,oBAAoB;IAC/B,8DAA8D;;IAE9D,+DAA+D;;CAEvD,CAAC;AAEX;;GAEG;AACH,eAAO,MAAM,kBAAkB;IAC7B,wDAAwD;;CAEhD,CAAC;AAEX;;GAEG;AACH,eAAO,MAAM,uBAAuB;IAClC,+CAA+C;;IAE/C,qEAAqE;;CAE7D,CAAC;AAEX;;GAEG;AACH,eAAO,MAAM,wBAAwB;IACnC,iDAAiD;;IAEjD,kDAAkD;;IAElD,iDAAiD;;IAEjD,kDAAkD;;CAE1C,CAAC"}
@@ -0,0 +1,76 @@
1
+ /**
2
+ * Shared default configuration constants for chart components.
3
+ *
4
+ * These constants provide standardized default values that are common across
5
+ * different chart types, as well as type-specific constants with clear naming.
6
+ */
7
+ /**
8
+ * Default canvas dimensions used as fallback when invalid dimensions are provided
9
+ */
10
+ export const CHART_CANVAS_DEFAULTS = {
11
+ /** Default canvas height when invalid height is provided */
12
+ SAFE_HEIGHT: 100,
13
+ /** Default canvas width when invalid width is provided */
14
+ SAFE_WIDTH: 100,
15
+ };
16
+ /**
17
+ * Axis validation constants for tick values and positioning
18
+ */
19
+ export const AXIS_VALIDATION = {
20
+ /** Minimum number of tick values required for a valid axis */
21
+ MIN_TICK_COUNT: 2,
22
+ /** Number used to detect when all tick values are identical */
23
+ UNIQUE_VALUE_THRESHOLD: 1,
24
+ };
25
+ /**
26
+ * Default spacing and positioning values
27
+ */
28
+ export const CHART_SPACING_DEFAULTS = {
29
+ /** Default spacing value when no spacing is specified */
30
+ DEFAULT_SPACE: 0,
31
+ };
32
+ /**
33
+ * Break axis default values
34
+ */
35
+ export const BREAK_AXIS_DEFAULTS = {
36
+ /** Default value when no custom break axis is specified */
37
+ DEFAULT_BREAK_VALUE: 0,
38
+ };
39
+ /**
40
+ * Shared fallback data points used across different chart types
41
+ */
42
+ export const SHARED_FALLBACK_DATA = {
43
+ /** First fallback primary key value (used for axis labels) */
44
+ FALLBACK_PKEY_FIRST: '0',
45
+ /** Second fallback primary key value (used for axis labels) */
46
+ FALLBACK_PKEY_SECOND: '1',
47
+ };
48
+ /**
49
+ * Bar Chart specific default configuration values
50
+ */
51
+ export const BAR_CHART_DEFAULTS = {
52
+ /** Default width for bar elements when not specified */
53
+ BAR_WIDTH: 20,
54
+ };
55
+ /**
56
+ * Bar Chart specific fallback data points used when bar chart data is invalid or empty
57
+ */
58
+ export const BAR_CHART_FALLBACK_DATA = {
59
+ /** Default x value for fallback data points */
60
+ DEFAULT_X_VALUE: 0,
61
+ /** Generic secondary key for fallback data when dataKey is needed */
62
+ FALLBACK_SECONDARY_KEY: 'fallbackData',
63
+ };
64
+ /**
65
+ * Line Chart specific fallback data points used when line chart data is invalid or empty
66
+ */
67
+ export const LINE_CHART_FALLBACK_DATA = {
68
+ /** First X value for line chart fallback data */
69
+ FALLBACK_X_FIRST: '0',
70
+ /** Second X value for line chart fallback data */
71
+ FALLBACK_X_SECOND: '1',
72
+ /** First Y value for line chart fallback data */
73
+ FALLBACK_Y_FIRST: 0,
74
+ /** Second Y value for line chart fallback data */
75
+ FALLBACK_Y_SECOND: 1,
76
+ };
@@ -1,3 +1,4 @@
1
+ import { type ChartError, ErrorType } from '../../../types/errors.type';
1
2
  import type { ChildrenType, IDataPoint, LineChartContextType } from '../lineChart.type';
2
3
  interface BuildContextValue {
3
4
  children: ChildrenType;
@@ -8,6 +9,7 @@ interface BuildContextValue {
8
9
  canvasHeight: number;
9
10
  canvasWidth: number;
10
11
  viewBox: string;
12
+ addError?: (errorType: keyof typeof ErrorType, error: Omit<ChartError, 'type'>) => void;
11
13
  }
12
14
  type OmitProps = 'data' | 'xKey' | 'canvasHeight' | 'canvasWidth' | 'canvasExtraSpace' | 'xBreakAxis' | 'yBreakAxis' | 'xCursor' | 'yCursor';
13
15
  /**
@@ -16,6 +18,6 @@ type OmitProps = 'data' | 'xKey' | 'canvasHeight' | 'canvasWidth' | 'canvasExtra
16
18
  * @param {BuildContextValue} options - The options for building the context value.
17
19
  * @returns {LineContextValue} - The built context value.
18
20
  */
19
- export declare const buildLineContextValue: ({ ajustedX, ajustedY, canvasHeight, canvasWidth, children, data, viewBox, xKey, }: BuildContextValue) => Omit<LineChartContextType, OmitProps>;
21
+ export declare const buildLineContextValue: ({ addError, ajustedX, ajustedY, canvasHeight, canvasWidth, children, data, viewBox, xKey, }: BuildContextValue) => Omit<LineChartContextType, OmitProps>;
20
22
  export {};
21
23
  //# sourceMappingURL=buildLineContextValue.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"buildLineContextValue.d.ts","sourceRoot":"","sources":["../../../../../src/charts/lineChart/context/buildLineContextValue.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,YAAY,EAAE,UAAU,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AAGxF,UAAU,iBAAiB;IACzB,QAAQ,EAAE,YAAY,CAAC;IACvB,IAAI,EAAE,UAAU,EAAE,CAAC;IACnB,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,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,KAAK,SAAS,GACV,MAAM,GACN,MAAM,GACN,cAAc,GACd,aAAa,GACb,kBAAkB,GAClB,YAAY,GACZ,YAAY,GACZ,SAAS,GACT,SAAS,CAAC;AAEd;;;;;GAKG;AACH,eAAO,MAAM,qBAAqB,GAAI,mFASnC,iBAAiB,KAAG,IAAI,CAAC,oBAAoB,EAAE,SAAS,CA+I1D,CAAC"}
1
+ {"version":3,"file":"buildLineContextValue.d.ts","sourceRoot":"","sources":["../../../../../src/charts/lineChart/context/buildLineContextValue.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,UAAU,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAkBjE,OAAO,KAAK,EAAE,YAAY,EAAE,UAAU,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AAGxF,UAAU,iBAAiB;IACzB,QAAQ,EAAE,YAAY,CAAC;IACvB,IAAI,EAAE,UAAU,EAAE,CAAC;IACnB,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,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,CAAC;AAEd;;;;;GAKG;AACH,eAAO,MAAM,qBAAqB,GAAI,6FAUnC,iBAAiB,KAAG,IAAI,CAAC,oBAAoB,EAAE,SAAS,CAoR1D,CAAC"}
@@ -1,8 +1,10 @@
1
+ import { ErrorType } from '../../../types/errors.type';
1
2
  import { Positions } from '../../../types/position.enum';
2
- import { BuildError, buildError } from '../../../utils/buildErrors/buildErrors';
3
+ import { BuildError, buildCanvasDimensionsError, buildError, } from '../../../utils/buildErrors/buildErrors';
3
4
  import { getXCoordinates, getYCoordinates } from '../../../utils/getCoordinates/getCoordinates';
4
5
  import { getPoints } from '../../../utils/getPoints/getPoints';
5
6
  import { getXTicks, getYTicks } from '../../../utils/getTicks/getTicks';
7
+ import { AXIS_VALIDATION, BREAK_AXIS_DEFAULTS, CHART_CANVAS_DEFAULTS, LINE_CHART_FALLBACK_DATA, SHARED_FALLBACK_DATA, } from '../../constants/chartDefaults';
6
8
  import { getExtraSpacing } from '../utils/getExtraSpacing';
7
9
  /**
8
10
  * Builds the context value for the line chart.
@@ -10,18 +12,56 @@ import { getExtraSpacing } from '../utils/getExtraSpacing';
10
12
  * @param {BuildContextValue} options - The options for building the context value.
11
13
  * @returns {LineContextValue} - The built context value.
12
14
  */
13
- export const buildLineContextValue = ({ ajustedX, ajustedY, canvasHeight, canvasWidth, children, data, viewBox, xKey, }) => {
15
+ export const buildLineContextValue = ({ addError, ajustedX, ajustedY, canvasHeight, canvasWidth, children, data, viewBox, xKey, }) => {
14
16
  let error = undefined;
17
+ // 1. Validate data exists
18
+ if (!data || data.length === 0) {
19
+ const dataError = {
20
+ error: buildError(BuildError.LINE_CHART_NO_DATA),
21
+ };
22
+ addError?.('LINE_CHART_CONTEXT_ERROR', dataError);
23
+ error = dataError;
24
+ }
25
+ if (data && data.length === 1) {
26
+ const singlePointError = {
27
+ error: buildError(BuildError.LINE_CHART_SINGLE_POINT),
28
+ };
29
+ addError?.('LINE_CHART_CONTEXT_ERROR', singlePointError);
30
+ error = singlePointError;
31
+ }
32
+ // 2. Validate canvas dimensions
33
+ if (canvasWidth <= 0 || canvasHeight <= 0) {
34
+ const canvasError = {
35
+ error: buildCanvasDimensionsError(canvasWidth, canvasHeight),
36
+ };
37
+ addError?.('LINE_CHART_CONTEXT_ERROR', canvasError);
38
+ error = canvasError;
39
+ }
40
+ // Use safe defaults for data processing if there are critical errors
41
+ const safeData = data && data.length > 0
42
+ ? data
43
+ : [
44
+ {
45
+ [xKey]: LINE_CHART_FALLBACK_DATA.FALLBACK_X_FIRST,
46
+ y: LINE_CHART_FALLBACK_DATA.FALLBACK_Y_FIRST,
47
+ },
48
+ {
49
+ [xKey]: LINE_CHART_FALLBACK_DATA.FALLBACK_X_SECOND,
50
+ y: LINE_CHART_FALLBACK_DATA.FALLBACK_Y_SECOND,
51
+ },
52
+ ];
53
+ const safeCanvasWidth = canvasWidth > 0 ? canvasWidth : CHART_CANVAS_DEFAULTS.SAFE_WIDTH;
54
+ const safeCanvasHeight = canvasHeight > 0 ? canvasHeight : CHART_CANVAS_DEFAULTS.SAFE_HEIGHT;
15
55
  /**
16
56
  * Get the extra spacings for the line chart.
17
57
  */
18
58
  const { extraSpaceBottomY, extraSpaceLeftX, extraSpaceRightX, extraSpaceTopY, lineChartXPosition, lineChartYPosition, securityXSpace, securityYSpace, xAxisText, xBreakAxis, xData, yAxisText, yBreakAxis, yData, } = getExtraSpacing({
19
59
  ajustedX,
20
60
  ajustedY,
21
- canvasHeight,
22
- canvasWidth,
61
+ canvasHeight: safeCanvasHeight,
62
+ canvasWidth: safeCanvasWidth,
23
63
  children,
24
- data,
64
+ data: safeData,
25
65
  viewBox,
26
66
  xKey,
27
67
  });
@@ -32,15 +72,41 @@ export const buildLineContextValue = ({ ajustedX, ajustedY, canvasHeight, canvas
32
72
  const yAxisSpace = extraSpaceLeftX + extraSpaceRightX;
33
73
  const xTickValues = getXTicks({
34
74
  initPos: extraSpaceLeftX,
35
- maxSpaceAvailable: canvasWidth,
75
+ maxSpaceAvailable: safeCanvasWidth,
36
76
  otherAxisSpace: yAxisSpace,
37
77
  securitySpace: securityXSpace,
38
78
  tickValues: xData,
39
79
  });
40
80
  if ((xTickValues ?? []).some(({ position }) => isNaN(position))) {
41
- error = {
81
+ const xTickError = {
42
82
  error: buildError(BuildError.INVALID_X_TICK),
43
83
  };
84
+ addError?.('LINE_CHART_CONTEXT_ERROR', xTickError);
85
+ error = xTickError;
86
+ }
87
+ // Validate X-axis tick values
88
+ if (xTickValues) {
89
+ const hasInsufficientTicks = xTickValues.length < AXIS_VALIDATION.MIN_TICK_COUNT;
90
+ const hasIdenticalValues = xTickValues.length >= AXIS_VALIDATION.MIN_TICK_COUNT &&
91
+ new Set(xTickValues.map(tick => tick.value)).size === AXIS_VALIDATION.UNIQUE_VALUE_THRESHOLD;
92
+ if (hasInsufficientTicks) {
93
+ const xAxisError = {
94
+ error: buildError(BuildError.LINE_CHART_X_AXIS_INSUFFICIENT_TICKS),
95
+ };
96
+ addError?.('LINE_CHART_X_AXIS_ERROR', xAxisError);
97
+ if (!error) {
98
+ error = xAxisError;
99
+ }
100
+ }
101
+ if (hasIdenticalValues) {
102
+ const xAxisError = {
103
+ error: buildError(BuildError.LINE_CHART_X_AXIS_IDENTICAL_VALUES),
104
+ };
105
+ addError?.('LINE_CHART_X_AXIS_ERROR', xAxisError);
106
+ if (!error) {
107
+ error = xAxisError;
108
+ }
109
+ }
44
110
  }
45
111
  /**
46
112
  * Calculate the tick values for the Y Axis.
@@ -48,23 +114,51 @@ export const buildLineContextValue = ({ ajustedX, ajustedY, canvasHeight, canvas
48
114
  const crossYAxis = lineChartYPosition !== Positions.LEFT && lineChartYPosition !== Positions.RIGHT;
49
115
  const otherAxisSpace = extraSpaceTopY + extraSpaceBottomY;
50
116
  const yTickValues = getYTicks({
51
- initPos: canvasHeight - extraSpaceBottomY,
52
- maxSpaceAvailable: canvasHeight,
117
+ initPos: safeCanvasHeight - extraSpaceBottomY,
118
+ maxSpaceAvailable: safeCanvasHeight,
53
119
  otherAxisSpace,
54
120
  securitySpace: securityYSpace,
55
121
  tickValues: yData,
56
122
  });
123
+ // Validate Y-axis tick values
124
+ if (yTickValues) {
125
+ const hasInsufficientTicks = yTickValues.length < AXIS_VALIDATION.MIN_TICK_COUNT;
126
+ const hasIdenticalValues = yTickValues.length >= AXIS_VALIDATION.MIN_TICK_COUNT &&
127
+ new Set(yTickValues.map(tick => tick.value)).size === AXIS_VALIDATION.UNIQUE_VALUE_THRESHOLD;
128
+ if (hasInsufficientTicks) {
129
+ const yAxisError = {
130
+ error: buildError(BuildError.LINE_CHART_Y_AXIS_INSUFFICIENT_TICKS),
131
+ };
132
+ addError?.('LINE_CHART_Y_AXIS_ERROR', yAxisError);
133
+ if (!error) {
134
+ error = yAxisError;
135
+ }
136
+ }
137
+ if (hasIdenticalValues) {
138
+ const yAxisError = {
139
+ error: buildError(BuildError.LINE_CHART_Y_AXIS_IDENTICAL_VALUES),
140
+ };
141
+ addError?.('LINE_CHART_Y_AXIS_ERROR', yAxisError);
142
+ if (!error) {
143
+ error = yAxisError;
144
+ }
145
+ }
146
+ }
57
147
  /**
58
148
  * Calculate the custom breakAxis for the X and Y Axis.
59
149
  */
60
- const customBreakXAxis = crossXAxis ? getPoints(yTickValues || [], [String(xBreakAxis)])[0] : 0;
61
- const customBreakYAxis = crossYAxis ? getPoints(xTickValues || [], [String(yBreakAxis)])[0] : 0;
150
+ const customBreakXAxis = crossXAxis
151
+ ? getPoints(yTickValues || [], [String(xBreakAxis)])[0]
152
+ : BREAK_AXIS_DEFAULTS.DEFAULT_BREAK_VALUE;
153
+ const customBreakYAxis = crossYAxis
154
+ ? getPoints(xTickValues || [], [String(yBreakAxis)])[0]
155
+ : BREAK_AXIS_DEFAULTS.DEFAULT_BREAK_VALUE;
62
156
  /**
63
157
  * Calculate the X coordinates for the line chart.
64
158
  */
65
159
  const xCoordinates = getXCoordinates({
66
- canvasHeight,
67
- canvasWidth,
160
+ canvasHeight: safeCanvasHeight,
161
+ canvasWidth: safeCanvasWidth,
68
162
  customBreakAxis: Number(customBreakXAxis),
69
163
  extraSpaceBottomY,
70
164
  extraSpaceLeftX,
@@ -77,8 +171,8 @@ export const buildLineContextValue = ({ ajustedX, ajustedY, canvasHeight, canvas
77
171
  * Calculate the Y coordinates for the line chart.
78
172
  */
79
173
  const yCoordinates = getYCoordinates({
80
- canvasHeight,
81
- canvasWidth,
174
+ canvasHeight: safeCanvasHeight,
175
+ canvasWidth: safeCanvasWidth,
82
176
  customBreakAxis: Number(customBreakYAxis),
83
177
  extraSpaceBottomY,
84
178
  extraSpaceLeftX,
@@ -87,37 +181,27 @@ export const buildLineContextValue = ({ ajustedX, ajustedY, canvasHeight, canvas
87
181
  position: lineChartYPosition,
88
182
  securityYSpace,
89
183
  });
90
- if (error) {
91
- // return fallback context value with error
92
- return {
93
- crossXAxis,
94
- crossYAxis,
95
- error,
96
- extraSpaceBottomY,
97
- extraSpaceLeftX,
98
- extraSpaceRightX,
99
- extraSpaceTopY,
100
- securityXSpace,
101
- securityYSpace,
102
- xAxisCoordinates: {
103
- coordinates: xCoordinates,
104
- tickValues: [
105
- { position: 0, value: '0' },
106
- { position: canvasWidth, value: '1' },
107
- ],
108
- },
109
- xAxisText,
110
- yAxisCoordinates: {
111
- coordinates: yCoordinates,
112
- tickValues: [
113
- { position: canvasHeight, value: '0' },
114
- { position: 0, value: '1' },
115
- ],
116
- },
117
- yAxisText,
184
+ // Validate axis coordinates for zero-length axes
185
+ if (xCoordinates.x1 === xCoordinates.x2) {
186
+ const xAxisError = {
187
+ error: buildError(BuildError.LINE_CHART_X_AXIS_ZERO_LENGTH),
188
+ };
189
+ addError?.('LINE_CHART_X_AXIS_ERROR', xAxisError);
190
+ if (!error) {
191
+ error = xAxisError;
192
+ }
193
+ }
194
+ if (yCoordinates.y1 === yCoordinates.y2) {
195
+ const yAxisError = {
196
+ error: buildError(BuildError.LINE_CHART_Y_AXIS_ZERO_LENGTH),
118
197
  };
198
+ addError?.('LINE_CHART_Y_AXIS_ERROR', yAxisError);
199
+ if (!error) {
200
+ error = yAxisError;
201
+ }
119
202
  }
120
- return {
203
+ const baseContext = {
204
+ addError,
121
205
  crossXAxis,
122
206
  crossYAxis,
123
207
  extraSpaceBottomY,
@@ -126,9 +210,41 @@ export const buildLineContextValue = ({ ajustedX, ajustedY, canvasHeight, canvas
126
210
  extraSpaceTopY,
127
211
  securityXSpace,
128
212
  securityYSpace,
129
- xAxisCoordinates: { coordinates: xCoordinates, tickValues: xTickValues },
213
+ xAxisCoordinates: {
214
+ coordinates: xCoordinates,
215
+ tickValues: xTickValues ||
216
+ (error
217
+ ? [
218
+ {
219
+ position: BREAK_AXIS_DEFAULTS.DEFAULT_BREAK_VALUE,
220
+ value: LINE_CHART_FALLBACK_DATA.FALLBACK_X_FIRST,
221
+ },
222
+ { position: safeCanvasWidth, value: LINE_CHART_FALLBACK_DATA.FALLBACK_X_SECOND },
223
+ ]
224
+ : []),
225
+ },
130
226
  xAxisText,
131
- yAxisCoordinates: { coordinates: yCoordinates, tickValues: yTickValues },
227
+ yAxisCoordinates: {
228
+ coordinates: yCoordinates,
229
+ tickValues: yTickValues ||
230
+ (error
231
+ ? [
232
+ { position: safeCanvasHeight, value: SHARED_FALLBACK_DATA.FALLBACK_PKEY_FIRST },
233
+ {
234
+ position: BREAK_AXIS_DEFAULTS.DEFAULT_BREAK_VALUE,
235
+ value: SHARED_FALLBACK_DATA.FALLBACK_PKEY_SECOND,
236
+ },
237
+ ]
238
+ : []),
239
+ },
132
240
  yAxisText,
133
241
  };
242
+ // Add error only if it exists
243
+ if (error) {
244
+ return {
245
+ ...baseContext,
246
+ error: { ...error, type: ErrorType.LINE_CHART_CONTEXT_ERROR },
247
+ };
248
+ }
249
+ return baseContext;
134
250
  };
@@ -1,5 +1,6 @@
1
1
  import type { TickData } from '../../../../components/tick/tick.types';
2
2
  export declare const CONTEXT: {
3
+ addError: undefined;
3
4
  canvasExtraSpace: number;
4
5
  canvasHeight: number;
5
6
  canvasWidth: number;
@@ -1 +1 @@
1
- {"version":3,"file":"contextData.d.ts","sourceRoot":"","sources":["../../../../../../src/charts/lineChart/fragments/fixture/contextData.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,8BAA8B,CAAC;AAE7D,eAAO,MAAM,OAAO;;;;;;;;;;;;;;;;;;;;;;;;oBAwBA,QAAQ,EAAE;;;;;;;;;;;;oBAWV,QAAQ,EAAE;;;;CAI7B,CAAC"}
1
+ {"version":3,"file":"contextData.d.ts","sourceRoot":"","sources":["../../../../../../src/charts/lineChart/fragments/fixture/contextData.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,8BAA8B,CAAC;AAE7D,eAAO,MAAM,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;oBAyBA,QAAQ,EAAE;;;;;;;;;;;;oBAWV,QAAQ,EAAE;;;;CAI7B,CAAC"}
@@ -1,4 +1,5 @@
1
1
  export const CONTEXT = {
2
+ addError: undefined,
2
3
  canvasExtraSpace: 0,
3
4
  canvasHeight: 500,
4
5
  canvasWidth: 500,
@@ -1 +1 @@
1
- {"version":3,"file":"lineChartPath.d.ts","sourceRoot":"","sources":["../../../../../src/charts/lineChart/fragments/lineChartPath.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,EAAoD,MAAM,OAAO,CAAC;AAUlF,OAAO,KAAK,EAAc,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAIxE,OAAO,qBAAqB,CAAC;AAO7B,eAAO,MAAM,aAAa,EAAE,EAAE,CAAC,kBAAkB,CAiJhD,CAAC"}
1
+ {"version":3,"file":"lineChartPath.d.ts","sourceRoot":"","sources":["../../../../../src/charts/lineChart/fragments/lineChartPath.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,EAAoD,MAAM,OAAO,CAAC;AAWlF,OAAO,KAAK,EAAc,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAIxE,OAAO,qBAAqB,CAAC;AAO7B,eAAO,MAAM,aAAa,EAAE,EAAE,CAAC,kBAAkB,CAwLhD,CAAC"}
@@ -3,6 +3,7 @@ import { useContext, useEffect, useRef } from 'react';
3
3
  import { Line } from '../../../components/line/line';
4
4
  import { Node } from '../../../components/node/node';
5
5
  import { Path } from '../../../components/path/path';
6
+ import { BuildError, buildDataKeyNotFoundError, buildError } from '../../../utils/buildErrors/buildErrors';
6
7
  import { getPoints } from '../../../utils/getPoints/getPoints';
7
8
  import { pickCustomAttributes } from '../../../utils/pickCustomAttributes/pickCustomAttributes';
8
9
  import { LineChartContext } from '../context/lineChartContext';
@@ -17,7 +18,39 @@ const getAxisData = (data, key) => {
17
18
  };
18
19
  export const LineChartPath = ({ ariaLabel, closestClick, curved, getNodeFocusInfo, getNodesCoords, indicatorConfig, lineProjection, onClick, ...props }) => {
19
20
  // recovery the context values
20
- const { xAxisCoordinates, yAxisCoordinates, ...context } = useContext(LineChartContext);
21
+ const { addError, xAxisCoordinates, yAxisCoordinates, ...context } = useContext(LineChartContext);
22
+ // Path error validations
23
+ useEffect(() => {
24
+ // Invalid dataKey validation
25
+ if (!props.dataKey || typeof props.dataKey !== 'string') {
26
+ addError?.('LINE_CHART_PATH_ERROR', {
27
+ error: buildError(BuildError.LINE_CHART_PATH_INVALID_DATAKEY),
28
+ });
29
+ return;
30
+ }
31
+ // Check if dataKey exists in dataset
32
+ if (context.data.length > 0 &&
33
+ !Object.prototype.hasOwnProperty.call(context.data[0], props.dataKey)) {
34
+ addError?.('LINE_CHART_PATH_ERROR', {
35
+ error: buildDataKeyNotFoundError(props.dataKey),
36
+ });
37
+ return;
38
+ }
39
+ // Curved path calculation errors
40
+ if (curved && context.data.length < 2) {
41
+ addError?.('LINE_CHART_PATH_ERROR', {
42
+ error: buildError(BuildError.LINE_CHART_PATH_INSUFFICIENT_POINTS),
43
+ });
44
+ return;
45
+ }
46
+ // Path rendering errors - validate coordinates
47
+ const yData = getAxisData(context.data, props.dataKey);
48
+ if (yData.length > 0 && yData.every(val => val === null || val === undefined)) {
49
+ addError?.('LINE_CHART_PATH_ERROR', {
50
+ error: buildError(BuildError.LINE_CHART_PATH_ALL_VALUES_NULL),
51
+ });
52
+ }
53
+ }, [props.dataKey, curved, context.data, addError]);
21
54
  // the node indicator logic
22
55
  const { indicatorRef, pathRef } = useIndicator(context.xCursor, !!indicatorConfig);
23
56
  const showIndicator = !!indicatorConfig && context.xCursor !== -Infinity;
@@ -1,4 +1,4 @@
1
- import type { FC } from 'react';
1
+ import { type FC } from 'react';
2
2
  import type { LineChartProjectionProps } from '../lineChart.type';
3
3
  import './lineChartPath.css';
4
4
  export declare const LineChartProjection: FC<LineChartProjectionProps>;
@@ -1 +1 @@
1
- {"version":3,"file":"lineChartProjection.d.ts","sourceRoot":"","sources":["../../../../../src/charts/lineChart/fragments/lineChartProjection.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC;AAEhC,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,mBAAmB,CAAC;AAElE,OAAO,qBAAqB,CAAC;AAE7B,eAAO,MAAM,mBAAmB,EAAE,EAAE,CAAC,wBAAwB,CA2B5D,CAAC"}
1
+ {"version":3,"file":"lineChartProjection.d.ts","sourceRoot":"","sources":["../../../../../src/charts/lineChart/fragments/lineChartProjection.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,EAAyB,MAAM,OAAO,CAAC;AASvD,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,mBAAmB,CAAC;AAElE,OAAO,qBAAqB,CAAC;AAE7B,eAAO,MAAM,mBAAmB,EAAE,EAAE,CAAC,wBAAwB,CA4E5D,CAAC"}
@@ -1,12 +1,56 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useContext, useEffect } from 'react';
3
+ import { buildProjectionBoundsError, buildProjectionXOutOfRangeError, buildProjectionYOutOfRangeError, } from '../../../utils/buildErrors/charts/buildLineChartErrors';
4
+ import { LineChartContext } from '../context/lineChartContext';
2
5
  import { getProjection } from '../utils/getProjection';
3
6
  import './lineChartPath.css';
4
7
  export const LineChartProjection = ({ curved, lineProjection, points, svgHeight, }) => {
8
+ const { addError } = useContext(LineChartContext);
5
9
  const { lower, shapeColor, upper } = lineProjection;
6
10
  const { xProjection: xUp, yProjection: yUp, ...upperProps } = upper || {};
7
11
  const { xProjection: xDw, yProjection: yDw, ...lowerProps } = lower || {};
8
12
  const upperProjection = xUp || yUp ? { x: xUp, y: yUp } : undefined;
9
13
  const lowerProjection = xDw || yDw ? { x: xDw, y: yDw } : undefined;
14
+ // Projection error validations
15
+ useEffect(() => {
16
+ // Invalid projection bounds - upper/lower overlap
17
+ if (upperProjection && lowerProjection) {
18
+ const upperY = upperProjection.y || 0;
19
+ const lowerY = lowerProjection.y || 0;
20
+ if (upperY >= lowerY) {
21
+ addError?.('LINE_CHART_PROJECTION_ERROR', {
22
+ error: buildProjectionBoundsError(upperY, lowerY),
23
+ });
24
+ }
25
+ }
26
+ // Projection coordinates outside chart area
27
+ if (upperProjection) {
28
+ const { x: upperX, y: upperY } = upperProjection;
29
+ if (upperX !== undefined && (upperX < 0 || upperX > 100)) {
30
+ addError?.('LINE_CHART_PROJECTION_ERROR', {
31
+ error: buildProjectionXOutOfRangeError(upperX, true),
32
+ });
33
+ }
34
+ if (upperY !== undefined && (upperY < 0 || upperY > svgHeight)) {
35
+ addError?.('LINE_CHART_PROJECTION_ERROR', {
36
+ error: buildProjectionYOutOfRangeError(upperY, svgHeight, true),
37
+ });
38
+ }
39
+ }
40
+ if (lowerProjection) {
41
+ const { x: lowerX, y: lowerY } = lowerProjection;
42
+ if (lowerX !== undefined && (lowerX < 0 || lowerX > 100)) {
43
+ addError?.('LINE_CHART_PROJECTION_ERROR', {
44
+ error: buildProjectionXOutOfRangeError(lowerX, false),
45
+ });
46
+ }
47
+ if (lowerY !== undefined && (lowerY < 0 || lowerY > svgHeight)) {
48
+ addError?.('LINE_CHART_PROJECTION_ERROR', {
49
+ error: buildProjectionYOutOfRangeError(lowerY, svgHeight, false),
50
+ });
51
+ }
52
+ }
53
+ }, [upperProjection, lowerProjection, svgHeight, addError]);
10
54
  const { downPath, shapePath, upPath } = getProjection({
11
55
  curved,
12
56
  lowerProjection,
@@ -1 +1 @@
1
- {"version":3,"file":"lineChartSeparator.d.ts","sourceRoot":"","sources":["../../../../../src/charts/lineChart/fragments/lineChartSeparator.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,EAAiC,MAAM,OAAO,CAAC;AAK/D,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,mBAAmB,CAAC;AAEjE,eAAO,MAAM,kBAAkB,EAAE,EAAE,CAAC,uBAAuB,CAoC1D,CAAC"}
1
+ {"version":3,"file":"lineChartSeparator.d.ts","sourceRoot":"","sources":["../../../../../src/charts/lineChart/fragments/lineChartSeparator.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,EAA4C,MAAM,OAAO,CAAC;AAa1E,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,mBAAmB,CAAC;AAEjE,eAAO,MAAM,kBAAkB,EAAE,EAAE,CAAC,uBAAuB,CA0F1D,CAAC"}