@scality/core-ui 0.186.0 → 0.188.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 (171) hide show
  1. package/dist/components/{linetemporalchart/MetricTimespanProvider.d.ts → charts/MetricsTimeSpanProvider.d.ts} +1 -1
  2. package/dist/components/charts/MetricsTimeSpanProvider.d.ts.map +1 -0
  3. package/dist/components/{barchartv2/Barchart.component.d.ts → charts/barchart/Barchart.d.ts} +2 -33
  4. package/dist/components/charts/barchart/Barchart.d.ts.map +1 -0
  5. package/dist/components/charts/barchart/Barchart.js +56 -0
  6. package/dist/components/{barchartv2/utils.d.ts → charts/barchart/Barchart.utils.d.ts} +8 -35
  7. package/dist/components/charts/barchart/Barchart.utils.d.ts.map +1 -0
  8. package/dist/components/{barchartv2/utils.js → charts/barchart/Barchart.utils.js} +7 -88
  9. package/dist/components/{barchartv2 → charts/barchart}/BarchartTooltip.d.ts +2 -1
  10. package/dist/components/charts/barchart/BarchartTooltip.d.ts.map +1 -0
  11. package/dist/components/{barchartv2 → charts/barchart}/BarchartTooltip.js +3 -3
  12. package/dist/components/{charttooltip → charts/common}/ChartTooltip.d.ts +9 -2
  13. package/dist/components/charts/common/ChartTooltip.d.ts.map +1 -0
  14. package/dist/components/{charttooltip → charts/common}/ChartTooltip.js +11 -15
  15. package/dist/components/charts/common/SharedComponents.d.ts +47 -0
  16. package/dist/components/charts/common/SharedComponents.d.ts.map +1 -0
  17. package/dist/components/charts/common/SharedComponents.js +83 -0
  18. package/dist/components/charts/common/chartUtils.d.ts +91 -0
  19. package/dist/components/charts/common/chartUtils.d.ts.map +1 -0
  20. package/dist/components/charts/common/chartUtils.js +243 -0
  21. package/dist/components/{globalhealthbar/GlobalHealthBarRecharts.component.d.ts → charts/globalhealthbar/GlobalHealthBar.d.ts} +2 -2
  22. package/dist/components/charts/globalhealthbar/GlobalHealthBar.d.ts.map +1 -0
  23. package/dist/components/{globalhealthbar/useHealthBarData.d.ts → charts/globalhealthbar/GlobalHealthBar.hooks.d.ts} +1 -1
  24. package/dist/components/charts/globalhealthbar/GlobalHealthBar.hooks.d.ts.map +1 -0
  25. package/dist/components/{globalhealthbar/GlobalHealthBarRecharts.component.js → charts/globalhealthbar/GlobalHealthBar.js} +4 -4
  26. package/dist/components/{globalhealthbar/healthBarUtils.d.ts → charts/globalhealthbar/GlobalHealthBar.utils.d.ts} +1 -1
  27. package/dist/components/charts/globalhealthbar/GlobalHealthBar.utils.d.ts.map +1 -0
  28. package/dist/components/{globalhealthbar/healthBarUtils.js → charts/globalhealthbar/GlobalHealthBar.utils.js} +1 -1
  29. package/dist/components/{globalhealthbar/components → charts/globalhealthbar}/GlobalHealthBarTooltip.d.ts +1 -1
  30. package/dist/components/charts/globalhealthbar/GlobalHealthBarTooltip.d.ts.map +1 -0
  31. package/dist/components/{globalhealthbar/components → charts/globalhealthbar}/GlobalHealthBarTooltip.js +7 -3
  32. package/dist/components/charts/globalhealthbar/HealthBarXAxis.d.ts.map +1 -0
  33. package/dist/components/{globalhealthbar/components → charts/globalhealthbar}/HealthBarXAxis.js +1 -1
  34. package/dist/components/charts/index.d.ts +16 -0
  35. package/dist/components/charts/index.d.ts.map +1 -0
  36. package/dist/components/charts/index.js +15 -0
  37. package/dist/components/{chartlegend → charts/legend}/ChartLegend.d.ts +1 -1
  38. package/dist/components/charts/legend/ChartLegend.d.ts.map +1 -0
  39. package/dist/components/{chartlegend → charts/legend}/ChartLegend.js +2 -2
  40. package/dist/components/{chartlegend → charts/legend}/ChartLegendWrapper.d.ts +1 -1
  41. package/dist/components/charts/legend/ChartLegendWrapper.d.ts.map +1 -0
  42. package/dist/components/{linetimeseriechart/linetimeseriechart.component.d.ts → charts/linetimeseries/LineTimeSerieChart.d.ts} +12 -2
  43. package/dist/components/charts/linetimeseries/LineTimeSerieChart.d.ts.map +1 -0
  44. package/dist/components/{linetimeseriechart/linetimeseriechart.component.js → charts/linetimeseries/LineTimeSerieChart.js} +34 -35
  45. package/dist/components/charts/linetimeseries/LineTimeSerieChart.utils.d.ts +14 -0
  46. package/dist/components/charts/linetimeseries/LineTimeSerieChart.utils.d.ts.map +1 -0
  47. package/dist/components/{linetimeseriechart/utils.js → charts/linetimeseries/LineTimeSerieChart.utils.js} +4 -6
  48. package/dist/components/charts/sparkline/Sparkline.d.ts +23 -0
  49. package/dist/components/charts/sparkline/Sparkline.d.ts.map +1 -0
  50. package/dist/components/{sparkline/sparkline.component.js → charts/sparkline/Sparkline.js} +12 -6
  51. package/dist/components/charts/types.d.ts +34 -0
  52. package/dist/components/charts/types.d.ts.map +1 -0
  53. package/dist/components/charts/types.js +4 -0
  54. package/dist/components/icon/Icon.component.d.ts +1 -0
  55. package/dist/components/icon/Icon.component.d.ts.map +1 -1
  56. package/dist/components/icon/Icon.component.js +2 -2
  57. package/dist/components/textbadge/TextBadge.component.d.ts +1 -1
  58. package/dist/components/textbadge/TextBadge.component.d.ts.map +1 -1
  59. package/dist/index.d.ts +0 -2
  60. package/dist/index.d.ts.map +1 -1
  61. package/dist/index.js +4 -2
  62. package/dist/next.d.ts +3 -11
  63. package/dist/next.d.ts.map +1 -1
  64. package/dist/next.js +4 -11
  65. package/package.json +2 -6
  66. package/src/lib/components/{barchartv2/Barchart.component.test.tsx → charts/barchart/Barchart.test.tsx} +35 -10
  67. package/src/lib/components/{barchartv2/Barchart.component.tsx → charts/barchart/Barchart.tsx} +42 -207
  68. package/src/lib/components/{barchartv2/utils.test.ts → charts/barchart/Barchart.utils.test.ts} +2 -141
  69. package/src/lib/components/{barchartv2/utils.ts → charts/barchart/Barchart.utils.ts} +17 -143
  70. package/src/lib/components/{barchartv2 → charts/barchart}/BarchartTooltip.tsx +5 -9
  71. package/src/lib/components/{charttooltip → charts/common}/ChartTooltip.tsx +13 -20
  72. package/src/lib/components/charts/common/SharedComponents.tsx +193 -0
  73. package/src/lib/components/charts/common/chartUtils.test.ts +402 -0
  74. package/src/lib/components/charts/common/chartUtils.ts +334 -0
  75. package/src/lib/components/{globalhealthbar/useHealthBarData.spec.tsx → charts/globalhealthbar/GlobalHealthBar.hooks.test.tsx} +1 -1
  76. package/src/lib/components/{globalhealthbar/GlobalHealthBarRecharts.component.tsx → charts/globalhealthbar/GlobalHealthBar.tsx} +4 -4
  77. package/src/lib/components/{globalhealthbar/healthBarUtils.spec.ts → charts/globalhealthbar/GlobalHealthBar.utils.test.ts} +1 -1
  78. package/src/lib/components/{globalhealthbar/healthBarUtils.ts → charts/globalhealthbar/GlobalHealthBar.utils.ts} +1 -1
  79. package/src/lib/components/{globalhealthbar/components → charts/globalhealthbar}/GlobalHealthBarTooltip.tsx +8 -4
  80. package/src/lib/components/{globalhealthbar/components → charts/globalhealthbar}/HealthBarXAxis.tsx +1 -1
  81. package/src/lib/components/charts/index.ts +59 -0
  82. package/src/lib/components/{chartlegend → charts/legend}/ChartLegend.tsx +2 -2
  83. package/src/lib/components/{chartlegend → charts/legend}/ChartLegendWrapper.tsx +1 -1
  84. package/src/lib/components/{linetimeseriechart/linetimeseriechart.test.tsx → charts/linetimeseries/LineTimeSerieChart.test.tsx} +3 -6
  85. package/src/lib/components/{linetimeseriechart/linetimeseriechart.component.tsx → charts/linetimeseries/LineTimeSerieChart.tsx} +48 -44
  86. package/src/lib/components/{linetimeseriechart/utils.test.ts → charts/linetimeseries/LineTimeSerieChart.utils.test.ts} +1 -1
  87. package/src/lib/components/{linetimeseriechart/utils.ts → charts/linetimeseries/LineTimeSerieChart.utils.ts} +4 -6
  88. package/src/lib/components/charts/sparkline/Sparkline.tsx +80 -0
  89. package/src/lib/components/charts/types.ts +36 -0
  90. package/src/lib/components/icon/Icon.component.tsx +12 -8
  91. package/src/lib/components/textbadge/TextBadge.component.tsx +1 -1
  92. package/src/lib/index.ts +4 -2
  93. package/src/lib/next.ts +26 -13
  94. package/stories/BarChart/barchart.stories.tsx +10 -9
  95. package/stories/GlobalHealthBar/{globalhealthbarRecharts.stories.tsx → globalhealthbar.stories.tsx} +3 -21
  96. package/stories/GlobalHealthBar/globalheathbarrecharts.guideline.mdx +2 -2
  97. package/stories/guideline/chart-guideline.mdx +1 -38
  98. package/stories/linetimeseriechart.stories.tsx +4 -6
  99. package/stories/sparkline.stories.tsx +13 -11
  100. package/stories/textbadge.stories.tsx +15 -0
  101. package/dist/components/barchart/BarChart.component.d.ts +0 -17
  102. package/dist/components/barchart/BarChart.component.d.ts.map +0 -1
  103. package/dist/components/barchart/BarChart.component.js +0 -27
  104. package/dist/components/barchartv2/Barchart.component.d.ts.map +0 -1
  105. package/dist/components/barchartv2/Barchart.component.js +0 -122
  106. package/dist/components/barchartv2/BarchartTooltip.d.ts.map +0 -1
  107. package/dist/components/barchartv2/utils.d.ts.map +0 -1
  108. package/dist/components/chartlegend/ChartLegend.d.ts.map +0 -1
  109. package/dist/components/chartlegend/ChartLegendWrapper.d.ts.map +0 -1
  110. package/dist/components/charttooltip/ChartTooltip.d.ts.map +0 -1
  111. package/dist/components/globalhealthbar/GlobalHealthBar.component.d.ts +0 -23
  112. package/dist/components/globalhealthbar/GlobalHealthBar.component.d.ts.map +0 -1
  113. package/dist/components/globalhealthbar/GlobalHealthBar.component.js +0 -173
  114. package/dist/components/globalhealthbar/GlobalHealthBarRecharts.component.d.ts.map +0 -1
  115. package/dist/components/globalhealthbar/components/GlobalHealthBarTooltip.d.ts.map +0 -1
  116. package/dist/components/globalhealthbar/components/HealthBarXAxis.d.ts.map +0 -1
  117. package/dist/components/globalhealthbar/healthBarUtils.d.ts.map +0 -1
  118. package/dist/components/globalhealthbar/healthBarUtils.spec.d.ts +0 -2
  119. package/dist/components/globalhealthbar/healthBarUtils.spec.d.ts.map +0 -1
  120. package/dist/components/globalhealthbar/healthBarUtils.spec.js +0 -391
  121. package/dist/components/globalhealthbar/tooltip/index.d.ts +0 -8
  122. package/dist/components/globalhealthbar/tooltip/index.d.ts.map +0 -1
  123. package/dist/components/globalhealthbar/tooltip/index.js +0 -55
  124. package/dist/components/globalhealthbar/useHealthBarData.d.ts.map +0 -1
  125. package/dist/components/globalhealthbar/useHealthBarData.spec.d.ts +0 -2
  126. package/dist/components/globalhealthbar/useHealthBarData.spec.d.ts.map +0 -1
  127. package/dist/components/globalhealthbar/useHealthBarData.spec.js +0 -209
  128. package/dist/components/linetemporalchart/ChartUtil.d.ts +0 -41
  129. package/dist/components/linetemporalchart/ChartUtil.d.ts.map +0 -1
  130. package/dist/components/linetemporalchart/ChartUtil.js +0 -148
  131. package/dist/components/linetemporalchart/LineTemporalChart.component.d.ts +0 -46
  132. package/dist/components/linetemporalchart/LineTemporalChart.component.d.ts.map +0 -1
  133. package/dist/components/linetemporalchart/LineTemporalChart.component.js +0 -579
  134. package/dist/components/linetemporalchart/MetricTimespanProvider.d.ts.map +0 -1
  135. package/dist/components/linetemporalchart/tooltip/index.d.ts +0 -30
  136. package/dist/components/linetemporalchart/tooltip/index.d.ts.map +0 -1
  137. package/dist/components/linetemporalchart/tooltip/index.js +0 -104
  138. package/dist/components/linetimeseriechart/linetimeseriechart.component.d.ts.map +0 -1
  139. package/dist/components/linetimeseriechart/utils.d.ts +0 -16
  140. package/dist/components/linetimeseriechart/utils.d.ts.map +0 -1
  141. package/dist/components/sparkline/sparkline.component.d.ts +0 -17
  142. package/dist/components/sparkline/sparkline.component.d.ts.map +0 -1
  143. package/dist/components/vegachartv2/SyncedCursorCharts.d.ts +0 -12
  144. package/dist/components/vegachartv2/SyncedCursorCharts.d.ts.map +0 -1
  145. package/dist/components/vegachartv2/SyncedCursorCharts.js +0 -15
  146. package/dist/components/vegachartv2/VegaChartV2.component.d.ts +0 -15
  147. package/dist/components/vegachartv2/VegaChartV2.component.d.ts.map +0 -1
  148. package/dist/components/vegachartv2/VegaChartV2.component.js +0 -218
  149. package/src/lib/components/barchart/BarChart.component.tsx +0 -51
  150. package/src/lib/components/globalhealthbar/GlobalHealthBar.component.tsx +0 -204
  151. package/src/lib/components/globalhealthbar/tooltip/index.ts +0 -72
  152. package/src/lib/components/linetemporalchart/ChartUtil.test.ts +0 -250
  153. package/src/lib/components/linetemporalchart/ChartUtil.ts +0 -225
  154. package/src/lib/components/linetemporalchart/LineTemporalChart.component.tsx +0 -800
  155. package/src/lib/components/linetemporalchart/tooltip/index.ts +0 -178
  156. package/src/lib/components/sparkline/sparkline.component.tsx +0 -56
  157. package/src/lib/components/vegachartv2/SyncedCursorCharts.tsx +0 -28
  158. package/src/lib/components/vegachartv2/VegaChartV2.component.tsx +0 -276
  159. package/stories/barchart.stories.tsx +0 -142
  160. package/stories/globalhealthbar.stories.tsx +0 -191
  161. package/stories/guideline/mdxExampleComponents.tsx +0 -57
  162. package/stories/linecharttemporal.stories.tsx +0 -88
  163. /package/dist/components/{linetemporalchart/MetricTimespanProvider.js → charts/MetricsTimeSpanProvider.js} +0 -0
  164. /package/dist/components/{globalhealthbar/useHealthBarData.js → charts/globalhealthbar/GlobalHealthBar.hooks.js} +0 -0
  165. /package/dist/components/{globalhealthbar/components → charts/globalhealthbar}/HealthBarXAxis.d.ts +0 -0
  166. /package/dist/components/{chartlegend → charts/legend}/ChartLegendWrapper.js +0 -0
  167. /package/src/lib/components/{linetemporalchart/MetricTimespanProvider.tsx → charts/MetricsTimeSpanProvider.tsx} +0 -0
  168. /package/src/lib/components/{barchartv2 → charts/barchart}/BarchartTooltip.test.tsx +0 -0
  169. /package/src/lib/components/{globalhealthbar/useHealthBarData.ts → charts/globalhealthbar/GlobalHealthBar.hooks.ts} +0 -0
  170. /package/src/lib/components/{chartlegend → charts/legend}/ChartLegend.test.tsx +0 -0
  171. /package/src/lib/components/{chartlegend → charts/legend}/ChartLegendWrapper.test.tsx +0 -0
@@ -6,4 +6,4 @@ export declare const MetricsTimeSpanProvider: ({ children, location, }: {
6
6
  location?: ReturnType<typeof useLocation>;
7
7
  }) => import("react/jsx-runtime").JSX.Element;
8
8
  export declare const useMetricsTimeSpan: () => QueryTimeSpan;
9
- //# sourceMappingURL=MetricTimespanProvider.d.ts.map
9
+ //# sourceMappingURL=MetricsTimeSpanProvider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MetricsTimeSpanProvider.d.ts","sourceRoot":"","sources":["../../../src/lib/components/charts/MetricsTimeSpanProvider.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAuB,MAAM,cAAc,CAAC;AAClE,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAC3C,eAAO,MAAM,sBAAsB,+CAA4C,CAAC;AAChF,eAAO,MAAM,uBAAuB,4BAGjC;IACD,QAAQ,EAAE,GAAG,CAAC,OAAO,CAAC;IACtB,QAAQ,CAAC,EAAE,UAAU,CAAC,OAAO,WAAW,CAAC,CAAC;CAC3C,4CA4BA,CAAC;AACF,eAAO,MAAM,kBAAkB,QAAO,aAUrC,CAAC"}
@@ -1,16 +1,4 @@
1
- import { UnitRange } from './utils';
2
- export type TimeType = {
3
- type: 'time';
4
- timeRange: {
5
- startDate: Date;
6
- endDate: Date;
7
- interval: number;
8
- };
9
- };
10
- export type CategoryType = {
11
- type: 'category';
12
- gap?: number;
13
- };
1
+ import { TimeType, CategoryType, UnitRange } from '../types';
14
2
  export type Point = {
15
3
  key: string | number;
16
4
  values: {
@@ -61,24 +49,5 @@ export type BarchartProps<T extends BarchartBars> = {
61
49
  isLoading?: boolean;
62
50
  isError?: boolean;
63
51
  };
64
- interface CustomTickProps {
65
- x: number;
66
- y: number;
67
- payload: {
68
- value: number;
69
- };
70
- visibleTicksCount: number;
71
- width: number;
72
- type: TimeType;
73
- }
74
- /**
75
- * Get the format of the date based on the duration
76
- * @param duration - Duration in seconds
77
- * @returns Formatted string
78
- */
79
- export declare const formatDate: (duration: number) => "time" | "day-month-abbreviated" | "chart-long-term-date";
80
- export declare const CustomTick: ({ x, y, payload, visibleTicksCount, width, type, }: CustomTickProps) => import("react/jsx-runtime").JSX.Element;
81
- export declare const StyledResponsiveContainer: import("styled-components").StyledComponent<import("react").ForwardRefExoticComponent<import("recharts").ResponsiveContainerProps & import("react").RefAttributes<HTMLDivElement>>, import("styled-components").DefaultTheme, {}, never>;
82
52
  export declare const Barchart: <T extends BarchartBars>(props: BarchartProps<T>) => import("react/jsx-runtime").JSX.Element;
83
- export {};
84
- //# sourceMappingURL=Barchart.component.d.ts.map
53
+ //# sourceMappingURL=Barchart.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Barchart.d.ts","sourceRoot":"","sources":["../../../../src/lib/components/charts/barchart/Barchart.tsx"],"names":[],"mappings":"AAwBA,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAiB7D,MAAM,MAAM,KAAK,GAAG;IAClB,GAAG,EAAE,MAAM,GAAG,MAAM,CAAC;IACrB,MAAM,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;CAC5C,CAAC;AAEF,MAAM,MAAM,YAAY,GAAG,SAAS;IAClC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB;;;OAGG;IACH,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC,SAAS,CAAC,MAAM,GAAG,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC,CAAC,EAAE,CAAC;CACvE,EAAE,CAAC;AAEJ,MAAM,MAAM,iBAAiB,CAAC,CAAC,SAAS,YAAY,IAAI,CAAC,YAAY,EAAE;IACrE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAAC;IAC1B,MAAM,EAAE;QAAE,KAAK,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,CAAC;QAAC,KAAK,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,OAAO,CAAA;KAAE,EAAE,CAAC;CAC5E,KAAK,KAAK,CAAC,SAAS,CAAC;AAEtB,MAAM,MAAM,cAAc,CAAC,CAAC,SAAS,YAAY,IAAI,CACnD,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC,GAAG;IAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAAA;CAAE,EAC1E,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC,GAAG;IAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAAA;CAAE,KACvE,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC;AAEhB,MAAM,MAAM,aAAa,CAAC,CAAC,SAAS,YAAY,IAAI;IAClD,IAAI,EAAE,YAAY,GAAG,QAAQ,CAAC;IAC9B,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,CAAC,CAAC;IACT,OAAO,CAAC,EAAE,iBAAiB,CAAC,CAAC,CAAC,CAAC;IAC/B,WAAW,CAAC,EAAE,cAAc,CAAC,CAAC,CAAC,CAAC;IAChC,SAAS,CAAC,EAAE,SAAS,CAAC;IACtB,WAAW,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IAC9B,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB;;;;;OAKG;IACH,cAAc,CAAC,EAAE,SAAS,GAAG,QAAQ,CAAC;IACtC,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,UAAU,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IAC7B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB,CAAC;AAIF,eAAO,MAAM,QAAQ,GAAI,CAAC,SAAS,YAAY,SAAS,aAAa,CAAC,CAAC,CAAC,4CA4JvE,CAAC"}
@@ -0,0 +1,56 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useState, useRef } from 'react';
3
+ import { Bar, BarChart as RechartsBarChart, CartesianGrid, Tooltip, XAxis, YAxis, } from 'recharts';
4
+ import { useTheme } from 'styled-components';
5
+ import { Stack } from '../../../spacing';
6
+ import { chartColors, fontSize } from '../../../style/theme';
7
+ import { useChartLegend } from '../legend/ChartLegendWrapper';
8
+ import { BarchartTooltip } from './BarchartTooltip';
9
+ import { formatToISONumber, getTicks } from '../common/chartUtils';
10
+ import { useChartData } from './Barchart.utils';
11
+ import { ChartHeader, ChartError, ChartLoading, CustomTick, StyledResponsiveContainer, } from '../common/SharedComponents';
12
+ const CHART_CONSTANTS = {
13
+ TICK_WIDTH_OFFSET: 4,
14
+ BAR_SIZE: 12,
15
+ MIN_POINT_SIZE: 3,
16
+ DEFAULT_HEIGHT: 200,
17
+ CHART_MARGIN: {
18
+ left: 0,
19
+ right: -10,
20
+ top: 0,
21
+ bottom: 0,
22
+ },
23
+ };
24
+ /* ---------------------------------- MAIN COMPONENT ---------------------------------- */
25
+ export const Barchart = (props) => {
26
+ const theme = useTheme();
27
+ const { getColor } = useChartLegend();
28
+ const [hoveredValue, setHoveredValue] = useState();
29
+ const chartRef = useRef(null);
30
+ const { height = CHART_CONSTANTS.DEFAULT_HEIGHT, bars, type = { type: 'category' }, unitRange, stacked, stackedBarSort = 'default', defaultSort, tooltip, title, secondaryTitle, helpTooltip, rightTitle, isLoading, isError, } = props;
31
+ // Create colorSet from ChartLegendWrapper
32
+ const colorSet = bars === null || bars === void 0 ? void 0 : bars.reduce((acc, bar) => {
33
+ const color = getColor(bar.label);
34
+ if (color) {
35
+ acc[bar.label] = color;
36
+ }
37
+ return acc;
38
+ }, {});
39
+ const { rechartsBars, unitLabel, roundReferenceValue, rechartsData, topDomain, } = useChartData(bars || [], type, colorSet || {}, stacked, defaultSort, unitRange, stackedBarSort);
40
+ const titleWithUnit = unitLabel ? `${title} (${unitLabel})` : title;
41
+ return (_jsxs(Stack, { direction: "vertical", style: { gap: '0' }, children: [_jsx(ChartHeader, { title: titleWithUnit, secondaryTitle: secondaryTitle, helpTooltip: helpTooltip, rightTitle: rightTitle }), isError || (!bars && !isLoading) ? (_jsx(ChartError, { height: height })) : isLoading ? (_jsx(ChartLoading, { height: height })) : (_jsx(StyledResponsiveContainer, { ref: chartRef, width: "100%", height: height, children: _jsxs(RechartsBarChart, { data: rechartsData, accessibilityLayer: true, barSize: type.type === 'category'
42
+ ? type.gap === 0
43
+ ? undefined
44
+ : CHART_CONSTANTS.BAR_SIZE
45
+ : CHART_CONSTANTS.BAR_SIZE, height: height, margin: CHART_CONSTANTS.CHART_MARGIN, barCategoryGap: type.type === 'category' ? type.gap : undefined, children: [_jsx(CartesianGrid, { vertical: true, horizontal: true, verticalPoints: [0], horizontalPoints: [0], stroke: theme.border, fill: theme.backgroundLevel4, strokeWidth: 1 }), rechartsBars.map((bar) => {
46
+ const { fill, dataKey, stackId } = bar;
47
+ return (_jsx(Bar, { dataKey: dataKey, fill: chartColors[fill] || fill, minPointSize: stacked ? 0 : CHART_CONSTANTS.MIN_POINT_SIZE, stackId: stackId, isAnimationActive: false, onMouseOver: () => setHoveredValue(dataKey), onMouseLeave: () => setHoveredValue(undefined) }, dataKey));
48
+ }), _jsx(YAxis, { interval: 0, domain: [0, topDomain], ticks: getTicks(roundReferenceValue, false), tickFormatter: (value) => formatToISONumber(value), axisLine: { stroke: theme.border }, tick: {
49
+ fill: theme.textSecondary,
50
+ fontSize: fontSize.smaller,
51
+ }, orientation: "right" }), _jsx(XAxis, { dataKey: "category", tick: (props) => (_jsx(CustomTick, { ...props, type: type, tickWidthOffset: CHART_CONSTANTS.TICK_WIDTH_OFFSET })), type: "category", interval: 0, allowDataOverflow: true, tickLine: {
52
+ stroke: theme.border,
53
+ }, axisLine: {
54
+ stroke: theme.border,
55
+ } }), _jsx(Tooltip, { content: (props) => (_jsx(BarchartTooltip, { type: type, colorSet: colorSet, tooltipProps: props, hoveredValue: hoveredValue, tooltip: tooltip, unitLabel: unitLabel, chartContainerRef: chartRef })), cursor: false })] }) }))] }));
56
+ };
@@ -1,8 +1,7 @@
1
- import { BarchartProps, BarchartBars } from './Barchart.component';
1
+ import { BarchartProps, BarchartBars } from './Barchart';
2
2
  import { TooltipContentProps } from 'recharts';
3
- import { ChartColors } from '../../style/theme';
4
- export declare const getRoundReferenceValue: (value: number) => number;
5
- export declare const getTicks: (topValue: number, isSymmetrical: boolean) => number[];
3
+ import { ChartColors } from '../../../style/theme';
4
+ import { UnitRange } from '../types';
6
5
  export declare const getMaxBarValue: (data: {
7
6
  [key: string]: string | number;
8
7
  }[], stacked?: boolean) => number;
@@ -49,34 +48,6 @@ export declare const formatPrometheusDataToRechartsDataAndBars: <T extends Barch
49
48
  stackId?: string;
50
49
  }[];
51
50
  };
52
- export type UnitRange = {
53
- threshold: number;
54
- label: string;
55
- }[];
56
- export declare const computeUnitLabelAndRoundReferenceValue: (data: any, maxValue: number, unitRange: UnitRange | undefined) => {
57
- unitLabel: undefined;
58
- roundReferenceValue: number;
59
- rechartsData: any;
60
- topDomain: number;
61
- } | {
62
- unitLabel: string;
63
- roundReferenceValue: number;
64
- rechartsData: any;
65
- topDomain: number;
66
- };
67
- /**
68
- * Return the unit label base on the current dataset, and the valueBase which is used to convert the data
69
- * @param {any} unitRange
70
- * @param {any} maxValue the maximum value among the data set
71
- * @returns {any}
72
- */
73
- export declare function getUnitLabel(unitRange: {
74
- threshold: number;
75
- label: string;
76
- }[], maxValue: number): {
77
- valueBase: number;
78
- unitLabel: string;
79
- };
80
51
  export declare const sortStackedBars: (rechartsBars: {
81
52
  dataKey: string;
82
53
  fill: string;
@@ -118,9 +89,11 @@ export declare const useChartData: <T extends BarchartBars>(bars: T, type: Barch
118
89
  stackId?: string;
119
90
  }[];
120
91
  unitLabel: string | undefined;
121
- topDomain: number;
122
92
  roundReferenceValue: number;
123
- rechartsData: any;
93
+ rechartsData: {
94
+ [key: string]: string | number;
95
+ }[];
96
+ topDomain: number;
124
97
  };
125
98
  export declare const getCurrentPoint: <T extends BarchartBars>(props: TooltipContentProps<number, string>, hoveredValue: string | undefined) => {
126
99
  category: string | number;
@@ -130,4 +103,4 @@ export declare const getCurrentPoint: <T extends BarchartBars>(props: TooltipCon
130
103
  isHovered: boolean;
131
104
  }[];
132
105
  };
133
- //# sourceMappingURL=utils.d.ts.map
106
+ //# sourceMappingURL=Barchart.utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Barchart.utils.d.ts","sourceRoot":"","sources":["../../../../src/lib/components/charts/barchart/Barchart.utils.ts"],"names":[],"mappings":"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"}
@@ -1,40 +1,6 @@
1
- import { chartColors } from '../../style/theme';
2
- import { useChartLegend } from '../chartlegend/ChartLegendWrapper';
3
- export const getRoundReferenceValue = (value) => {
4
- if (value <= 0)
5
- return 1; // Default for zero or negative values
6
- // Buffer the value by 10% to avoid being too close to the edge of the chart
7
- const bufferedValue = value * 1.1;
8
- if (value >= 10) {
9
- const remainder = value % 10;
10
- const incremented = value + (10 - remainder);
11
- // If the remainder is less than 5, round down to the nearest 10
12
- if (remainder < 5) {
13
- return value - remainder;
14
- }
15
- // If incrementing would exceed the buffered max, also round down
16
- if (incremented > bufferedValue) {
17
- return value - remainder;
18
- }
19
- // Otherwise, round up to the next 10
20
- return incremented;
21
- }
22
- const magnitude = Math.pow(10, Math.floor(Math.log10(value)));
23
- const remainder = bufferedValue % magnitude;
24
- return remainder === 0 ? bufferedValue : bufferedValue - remainder;
25
- };
26
- export const getTicks = (topValue, isSymmetrical) => {
27
- const possibleTickNumbers = [4, 3];
28
- const numberOfTicks = possibleTickNumbers.find((number) => topValue % (number - 1) === 0) || 3; // Default to 2 ticks if no match
29
- const tickInterval = topValue / (numberOfTicks - 1);
30
- const ticks = Array.from({ length: numberOfTicks }, (_, index) => index * tickInterval);
31
- if (isSymmetrical) {
32
- // Create negative ticks in order without 0
33
- const negativeTicks = Array.from({ length: numberOfTicks - 1 }, (_, index) => -(numberOfTicks - 1 - index) * tickInterval);
34
- ticks.unshift(...negativeTicks);
35
- }
36
- return ticks;
37
- };
1
+ import { chartColors } from '../../../style/theme';
2
+ import { useChartLegend } from '../legend/ChartLegendWrapper';
3
+ import { normalizeChartDataWithUnits } from '../common/chartUtils';
38
4
  export const getMaxBarValue = (data, stacked) => {
39
5
  const values = data.map((item) => {
40
6
  // If stacked, we need to filter out category and sum the values in the same object
@@ -201,53 +167,6 @@ export const formatPrometheusDataToRechartsDataAndBars = (bars, type, colorSet,
201
167
  data,
202
168
  };
203
169
  };
204
- export const computeUnitLabelAndRoundReferenceValue = (data, maxValue, unitRange) => {
205
- if (!unitRange) {
206
- const roundReferenceValue = getRoundReferenceValue(maxValue);
207
- return { unitLabel: undefined, roundReferenceValue, rechartsData: data, topDomain: maxValue * 1.1 };
208
- }
209
- const { valueBase, unitLabel } = getUnitLabel(unitRange, maxValue);
210
- const topValue = maxValue / valueBase;
211
- const roundReferenceValue = getRoundReferenceValue(topValue);
212
- const rechartsData = data.map((dataPoint) => {
213
- const normalizedDataPoint = { ...dataPoint };
214
- Object.entries(dataPoint).forEach(([key, value]) => {
215
- if (key !== 'category' && typeof value === 'number') {
216
- normalizedDataPoint[key] = value / valueBase;
217
- }
218
- });
219
- return normalizedDataPoint;
220
- });
221
- return { unitLabel, roundReferenceValue, rechartsData, topDomain: topValue * 1.1 };
222
- };
223
- /**
224
- * Return the unit label base on the current dataset, and the valueBase which is used to convert the data
225
- * @param {any} unitRange
226
- * @param {any} maxValue the maximum value among the data set
227
- * @returns {any}
228
- */
229
- export function getUnitLabel(unitRange, maxValue) {
230
- // first sort the unitRange
231
- unitRange.sort((unitA, unitB) => {
232
- return unitA.threshold - unitB.threshold;
233
- });
234
- let index = unitRange.findIndex((range) => range.threshold > maxValue);
235
- // last unit
236
- if (index === -1) {
237
- index = unitRange.length;
238
- }
239
- if (index === 0) {
240
- return {
241
- valueBase: unitRange[index].threshold,
242
- unitLabel: unitRange[index].label,
243
- };
244
- }
245
- return {
246
- // if the threshold is 0, we use 1 as the value base to avoid division by 0
247
- valueBase: unitRange[index - 1].threshold || 1,
248
- unitLabel: unitRange[index - 1].label,
249
- };
250
- }
251
170
  // Sort stacked bars by their average values in descending order or by legend order
252
171
  // This ensures the largest bars appear at the bottom of the stack (default) or follow legend order
253
172
  export const sortStackedBars = (rechartsBars, data, stacked, legendOrder) => {
@@ -321,13 +240,13 @@ export const useChartData = (bars, type, colorSet, stacked, defaultSort, unitRan
321
240
  // Filter both data and bars to only include selected resources for accurate maxValue calculation
322
241
  const { filteredData, filteredRechartsBars } = filterChartDataAndBarsByLegendSelection(data, rechartsBars, selectedResources);
323
242
  const maxValue = getMaxBarValue(filteredData, stacked);
324
- const { unitLabel, roundReferenceValue, rechartsData, topDomain } = computeUnitLabelAndRoundReferenceValue(filteredData, maxValue, unitRange);
243
+ const { unitLabel, topValue, rechartsData, topDomain } = normalizeChartDataWithUnits(filteredData, maxValue, unitRange, 'category');
325
244
  return {
326
245
  rechartsBars: filteredRechartsBars,
327
- unitLabel,
328
- topDomain,
329
- roundReferenceValue,
246
+ unitLabel: unitLabel,
247
+ roundReferenceValue: topValue,
330
248
  rechartsData,
249
+ topDomain,
331
250
  };
332
251
  };
333
252
  export const getCurrentPoint = (props, hoveredValue) => {
@@ -1,5 +1,6 @@
1
1
  import { TooltipContentProps } from 'recharts';
2
- import { BarchartBars, BarchartTooltipFn, CategoryType, TimeType } from './Barchart.component';
2
+ import { BarchartBars, BarchartTooltipFn } from './Barchart';
3
+ import { CategoryType, TimeType } from '../types';
3
4
  export declare const BarchartTooltip: <T extends BarchartBars>({ type, tooltipProps, colorSet, hoveredValue, tooltip, unitLabel, chartContainerRef, }: {
4
5
  type: TimeType | CategoryType;
5
6
  tooltipProps: TooltipContentProps<number, string>;
@@ -0,0 +1 @@
1
+ {"version":3,"file":"BarchartTooltip.d.ts","sourceRoot":"","sources":["../../../../src/lib/components/charts/barchart/BarchartTooltip.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAC;AAS/C,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAC7D,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAGlD,eAAO,MAAM,eAAe,GAAI,CAAC,SAAS,YAAY,0FAQnD;IACD,IAAI,EAAE,QAAQ,GAAG,YAAY,CAAC;IAC9B,YAAY,EAAE,mBAAmB,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAClD,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAClC,YAAY,EAAE,MAAM,GAAG,SAAS,CAAC;IACjC,OAAO,CAAC,EAAE,iBAAiB,CAAC,CAAC,CAAC,CAAC;IAC/B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,iBAAiB,EAAE,KAAK,CAAC,SAAS,CAAC,cAAc,CAAC,CAAC;CACpD,mDAgEA,CAAC"}
@@ -1,7 +1,7 @@
1
1
  import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { LegendShape } from '../chartlegend/ChartLegend';
3
- import { ChartTooltipPortal, ChartTooltipHeader, ChartTooltipItem, ChartTooltipItemsContainer, TooltipHeader, } from '../charttooltip/ChartTooltip';
4
- import { getCurrentPoint } from './utils';
2
+ import { LegendShape } from '../legend/ChartLegend';
3
+ import { ChartTooltipPortal, ChartTooltipHeader, ChartTooltipItem, ChartTooltipItemsContainer, TooltipHeader, } from '../common/ChartTooltip';
4
+ import { getCurrentPoint } from './Barchart.utils';
5
5
  export const BarchartTooltip = ({ type, tooltipProps, colorSet, hoveredValue, tooltip, unitLabel, chartContainerRef, }) => {
6
6
  const { active, coordinate } = tooltipProps;
7
7
  if (!active) {
@@ -12,10 +12,17 @@ export declare const ChartTooltipHeader: import("styled-components").StyledCompo
12
12
  export declare const ChartTooltipItemsContainer: import("styled-components").StyledComponent<"div", import("styled-components").DefaultTheme, {}, never>;
13
13
  export declare const ChartTooltipSeparator: import("styled-components").StyledComponent<"div", import("styled-components").DefaultTheme, {}, never>;
14
14
  export type TooltipDateFormat = 'day-month-abbreviated-year-hour-minute' | 'day-month-abbreviated-hour-minute-second' | 'day-month-abbreviated-hour-minute';
15
- export declare const TooltipHeader: ({ duration, value, }: {
15
+ export type TooltipHeaderProps = {
16
16
  duration: number;
17
17
  value: string | number;
18
- }) => import("react/jsx-runtime").JSX.Element;
18
+ };
19
+ /**
20
+ * Tooltip header component
21
+ * @param duration - Duration in seconds
22
+ * @param value - Value to format
23
+ * @returns Formatted string type
24
+ */
25
+ export declare const TooltipHeader: ({ duration, value }: TooltipHeaderProps) => import("react/jsx-runtime").JSX.Element;
19
26
  export interface ChartTooltipPortalProps {
20
27
  children: React.ReactNode;
21
28
  coordinate?: {
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ChartTooltip.d.ts","sourceRoot":"","sources":["../../../../src/lib/components/charts/common/ChartTooltip.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAG1B,OAAO,EAML,UAAU,EACX,MAAM,oBAAoB,CAAC;AAO5B,eAAO,MAAM,qBAAqB,yGAWjC,CAAC;AA+BF,UAAU,qBAAqB;IAC7B,KAAK,EAAE,KAAK,CAAC,SAAS,CAAC;IACvB,KAAK,EAAE,KAAK,CAAC,SAAS,CAAC;IACvB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,UAAU,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;CAC9B;AAED,eAAO,MAAM,gBAAgB,EAAE,KAAK,CAAC,EAAE,CAAC,qBAAqB,CAe5D,CAAC;AAEF,eAAO,MAAM,kBAAkB,yGAK9B,CAAC;AAEF,eAAO,MAAM,0BAA0B,yGAKtC,CAAC;AAEF,eAAO,MAAM,qBAAqB,yGAKjC,CAAC;AAEF,MAAM,MAAM,iBAAiB,GACzB,wCAAwC,GACxC,0CAA0C,GAC1C,mCAAmC,CAAC;AAExC,MAAM,MAAM,kBAAkB,GAAG;IAC/B,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,MAAM,GAAG,MAAM,CAAC;CACxB,CAAC;AACF;;;;;GAKG;AACH,eAAO,MAAM,aAAa,wBAAyB,kBAAkB,4CAOpE,CAAC;AAEF,MAAM,WAAW,uBAAuB;IACtC,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;IAC1B,UAAU,CAAC,EAAE;QAAE,CAAC,EAAE,MAAM,CAAC;QAAC,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;IACtC,iBAAiB,EAAE,KAAK,CAAC,SAAS,CAAC,cAAc,CAAC,CAAC;IACnD,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,UAAU,CAAC,EAAE,UAAU,EAAE,CAAC;IAC1B,MAAM,CAAC,EAAE,MAAM,GAAG,CAAC,CAAC,EAAE,SAAS,EAAE,EAAE;QAAE,SAAS,EAAE,MAAM,CAAA;KAAE,KAAK,MAAM,CAAC,CAAC;IACrE,cAAc,CAAC,EAAE,CACf,SAAS,EAAE,OAAO,EAClB,UAAU,CAAC,EAAE;QAAE,CAAC,EAAE,MAAM,CAAC;QAAC,CAAC,EAAE,MAAM,CAAA;KAAE,KAClC;QAAE,CAAC,EAAE,MAAM,CAAC;QAAC,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;IAC9B,kBAAkB,CAAC,EAAE,KAAK,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC;CAC/C;AAED,eAAO,MAAM,kBAAkB,EAAE,KAAK,CAAC,EAAE,CAAC,uBAAuB,CA0GhE,CAAC"}
@@ -3,9 +3,10 @@ import { createPortal } from 'react-dom';
3
3
  import { useEffect, useState, useRef } from 'react';
4
4
  import { useFloating, autoUpdate, offset, flip, shift, } from '@floating-ui/react';
5
5
  import styled from 'styled-components';
6
- import { spacing } from '../../spacing';
7
- import { fontSize, fontWeight } from '../../style/theme';
8
- import { FormattedDateTime } from '../date/FormattedDateTime';
6
+ import { spacing } from '../../../spacing';
7
+ import { fontSize, fontWeight } from '../../../style/theme';
8
+ import { FormattedDateTime } from '../../date/FormattedDateTime';
9
+ import { getTooltipDateFormat } from './chartUtils';
9
10
  export const ChartTooltipContainer = styled.div `
10
11
  border: 1px solid ${({ theme }) => theme.border};
11
12
  background-color: ${({ theme }) => theme.backgroundLevel1};
@@ -58,18 +59,13 @@ export const ChartTooltipSeparator = styled.div `
58
59
  margin: ${spacing.r4} 0;
59
60
  width: 100%;
60
61
  `;
61
- const getTooltipDateFormat = (duration) => {
62
- if (duration <= 60 * 60) {
63
- return 'day-month-abbreviated-hour-minute-second';
64
- }
65
- else if (duration <= 7 * 24 * 60 * 60) {
66
- return 'day-month-abbreviated-hour-minute';
67
- }
68
- else {
69
- return 'day-month-abbreviated-year-hour-minute';
70
- }
71
- };
72
- export const TooltipHeader = ({ duration, value, }) => {
62
+ /**
63
+ * Tooltip header component
64
+ * @param duration - Duration in seconds
65
+ * @param value - Value to format
66
+ * @returns Formatted string type
67
+ */
68
+ export const TooltipHeader = ({ duration, value }) => {
73
69
  const timeFormat = getTooltipDateFormat(duration);
74
70
  return (_jsx(ChartTooltipHeader, { children: _jsx(FormattedDateTime, { format: timeFormat, value: new Date(value) }) }));
75
71
  };
@@ -0,0 +1,47 @@
1
+ import { TimeType } from '../types';
2
+ /**
3
+ * Styled ResponsiveContainer for charts
4
+ * Shared by Barchart and LineTimeSerieChart
5
+ * Ensures tooltip overflow is visible and removes outline
6
+ */
7
+ export declare const StyledResponsiveContainer: import("styled-components").StyledComponent<import("react").ForwardRefExoticComponent<import("recharts").ResponsiveContainerProps & import("react").RefAttributes<HTMLDivElement>>, import("styled-components").DefaultTheme, {}, never>;
8
+ interface ChartLoadingOrErrorProps {
9
+ height: number;
10
+ }
11
+ /**
12
+ * Error state component for charts
13
+ */
14
+ export declare const ChartError: ({ height }: ChartLoadingOrErrorProps) => import("react/jsx-runtime").JSX.Element;
15
+ /**
16
+ * Loading state component for charts
17
+ */
18
+ export declare const ChartLoading: ({ height }: ChartLoadingOrErrorProps) => import("react/jsx-runtime").JSX.Element;
19
+ interface ChartHeaderProps {
20
+ title?: string;
21
+ secondaryTitle?: string;
22
+ helpTooltip?: React.ReactNode;
23
+ rightTitle?: React.ReactNode;
24
+ }
25
+ /**
26
+ * Shared chart header component
27
+ * Used by Barchart and can be used by other charts
28
+ */
29
+ export declare const ChartHeader: ({ title, secondaryTitle, helpTooltip, rightTitle, }: ChartHeaderProps) => import("react/jsx-runtime").JSX.Element;
30
+ interface CustomTickProps {
31
+ x: number;
32
+ y: number;
33
+ payload: {
34
+ value: number;
35
+ };
36
+ visibleTicksCount: number;
37
+ width: number;
38
+ type: TimeType;
39
+ tickWidthOffset?: number;
40
+ }
41
+ /**
42
+ * Custom tick component for charts
43
+ * Used by Barchart for time-based x-axis ticks
44
+ */
45
+ export declare const CustomTick: ({ x, y, payload, visibleTicksCount, width, type, tickWidthOffset, }: CustomTickProps) => import("react/jsx-runtime").JSX.Element;
46
+ export {};
47
+ //# sourceMappingURL=SharedComponents.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SharedComponents.d.ts","sourceRoot":"","sources":["../../../../src/lib/components/charts/common/SharedComponents.tsx"],"names":[],"mappings":"AAUA,OAAO,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAEpC;;;;GAIG;AACH,eAAO,MAAM,yBAAyB,0OAMrC,CAAC;AAUF,UAAU,wBAAwB;IAChC,MAAM,EAAE,MAAM,CAAC;CAChB;AAED;;GAEG;AACH,eAAO,MAAM,UAAU,eAAgB,wBAAwB,4CAa9D,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,YAAY,eAAgB,wBAAwB,4CAahE,CAAC;AAEF,UAAU,gBAAgB;IACxB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,WAAW,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IAC9B,UAAU,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;CAC9B;AAED;;;GAGG;AACH,eAAO,MAAM,WAAW,wDAKrB,gBAAgB,4CA2BlB,CAAC;AAEF,UAAU,eAAe;IACvB,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IACV,OAAO,EAAE;QACP,KAAK,EAAE,MAAM,CAAC;KACf,CAAC;IACF,iBAAiB,EAAE,MAAM,CAAC;IAC1B,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,QAAQ,CAAC;IACf,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B;AAED;;;GAGG;AACH,eAAO,MAAM,UAAU,wEAQpB,eAAe,4CAkDjB,CAAC"}
@@ -0,0 +1,83 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { ResponsiveContainer } from 'recharts';
3
+ import styled, { useTheme } from 'styled-components';
4
+ import { spacing, Stack, Wrap } from '../../../spacing';
5
+ import { Box } from '../../box/Box';
6
+ import { IconHelp } from '../../iconhelper/IconHelper';
7
+ import { Loader } from '../../loader/Loader.component';
8
+ import { Text } from '../../text/Text.component';
9
+ import { ConstrainedText } from '../../constrainedtext/Constrainedtext.component';
10
+ import { FormattedDateTime } from '../../date/FormattedDateTime';
11
+ import { formatXAxisDate, maxWidthTooltip } from './chartUtils';
12
+ /**
13
+ * Styled ResponsiveContainer for charts
14
+ * Shared by Barchart and LineTimeSerieChart
15
+ * Ensures tooltip overflow is visible and removes outline
16
+ */
17
+ export const StyledResponsiveContainer = styled(ResponsiveContainer) `
18
+ // Avoid tooltip over constrained text to be cut off
19
+ & .recharts-surface {
20
+ outline: none;
21
+ overflow: visible;
22
+ }
23
+ `;
24
+ const TickContainer = styled.div `
25
+ width: 100%;
26
+ height: 100%;
27
+ display: flex;
28
+ align-items: center;
29
+ justify-content: center;
30
+ `;
31
+ /**
32
+ * Error state component for charts
33
+ */
34
+ export const ChartError = ({ height }) => {
35
+ return (_jsx(Box, { height: height, style: {
36
+ alignItems: 'center',
37
+ justifyContent: 'center',
38
+ display: 'flex',
39
+ }, children: _jsx(Text, { children: "Chart data is not available" }) }));
40
+ };
41
+ /**
42
+ * Loading state component for charts
43
+ */
44
+ export const ChartLoading = ({ height }) => {
45
+ return (_jsx(Box, { height: height, style: {
46
+ alignItems: 'center',
47
+ justifyContent: 'center',
48
+ display: 'flex',
49
+ }, children: _jsx(Loader, { size: "larger", children: _jsx(Text, { children: "Loading Chart Data..." }) }) }));
50
+ };
51
+ /**
52
+ * Shared chart header component
53
+ * Used by Barchart and can be used by other charts
54
+ */
55
+ export const ChartHeader = ({ title, secondaryTitle, helpTooltip, rightTitle, }) => {
56
+ return (_jsxs(Wrap, { children: [_jsxs(Stack, { gap: "r4", children: [_jsx(Text, { variant: "ChartTitle", children: title }), helpTooltip && (_jsx(IconHelp, { tooltipMessage: helpTooltip, overlayStyle: maxWidthTooltip })), secondaryTitle && (_jsx(Text, { color: "textSecondary", style: {
57
+ marginLeft: spacing.r8,
58
+ }, children: secondaryTitle }))] }), rightTitle && _jsx(Text, { children: rightTitle })] }));
59
+ };
60
+ /**
61
+ * Custom tick component for charts
62
+ * Used by Barchart for time-based x-axis ticks
63
+ */
64
+ export const CustomTick = ({ x, y, payload, visibleTicksCount, width, type, tickWidthOffset = 4, }) => {
65
+ const theme = useTheme();
66
+ const tickWidth = width / visibleTicksCount - tickWidthOffset;
67
+ const centerX = x - tickWidth / 2;
68
+ const duration = type.type === 'time'
69
+ ? (type.timeRange.endDate.getTime() -
70
+ type.timeRange.startDate.getTime()) /
71
+ 1000
72
+ : 0;
73
+ return (_jsx("foreignObject", { x: centerX, y: y - 10, width: tickWidth, height: 30, style: {
74
+ overflow: 'visible',
75
+ pointerEvents: 'none',
76
+ }, children: _jsx(TickContainer, { children: _jsx(ConstrainedText, { color: "textSecondary", text: _jsx(Text, { variant: "Smaller", children: type.type === 'time' ? (_jsx(FormattedDateTime, { format: formatXAxisDate(duration), value: new Date(payload.value) })) : (String(payload.value)) }), centered: true, tooltipStyle: {
77
+ backgroundColor: theme.backgroundLevel1,
78
+ padding: spacing.r10,
79
+ borderRadius: spacing.r8,
80
+ border: `1px solid ${theme.border}`,
81
+ position: 'absolute',
82
+ } }) }) }));
83
+ };
@@ -0,0 +1,91 @@
1
+ import { TooltipDateFormat } from './ChartTooltip';
2
+ import { UnitRange } from '../types';
3
+ export declare const maxWidthTooltip: {
4
+ maxWidth: string;
5
+ };
6
+ /**
7
+ * Round a value to a nice number for chart display
8
+ * Used by Barchart and LineTimeSerieChart for Y-axis scaling
9
+ */
10
+ export declare const getRoundReferenceValue: (value: number) => number;
11
+ /**
12
+ * Generate tick values for Y-axis
13
+ * Used by Barchart and LineTimeSerieChart
14
+ */
15
+ export declare const getTicks: (topValue: number, isSymmetrical: boolean) => number[];
16
+ /**
17
+ * Return the unit label based on the current dataset, and the valueBase which is used to convert the data
18
+ * Used by LineTimeSerieChart
19
+ * @param unitRange - Array of threshold and label pairs
20
+ * @param maxValue - The maximum value among the data set
21
+ * @returns Object with valueBase and unitLabel
22
+ */
23
+ export declare function getUnitLabel(unitRange: {
24
+ threshold: number;
25
+ label: string;
26
+ }[], maxValue: number): {
27
+ valueBase: number;
28
+ unitLabel: string | undefined;
29
+ };
30
+ /**
31
+ * Computes unit label and normalizes chart data based on unit range.
32
+ * This is shared logic used by both Barchart and LineTimeSerieChart.
33
+ *
34
+ * @param data - Chart data to normalize
35
+ * @param maxValue - Maximum value in the dataset
36
+ * @param unitRange - Optional unit range configuration for automatic scaling
37
+ * @param excludeKey - Key to exclude from normalization (e.g., 'category' for Barchart, 'timestamp' for LineTimeSerieChart)
38
+ * @returns Object containing unit label, top value for Y-axis, and normalized data
39
+ */
40
+ export declare const normalizeChartDataWithUnits: <T extends Record<string, any>>(data: T[], maxValue: number, unitRange: UnitRange | undefined, excludeKey: string) => {
41
+ unitLabel: string | undefined;
42
+ topValue: number;
43
+ rechartsData: T[];
44
+ topDomain: number;
45
+ };
46
+ /**
47
+ * This function manually adds the missing data points with `null` value caused by downtime of the VMs
48
+ * Missing data points are only added when the gap between consecutive data points is bigger than 2 intervals
49
+ * Used by LineTimeSerieChart and Sparkline
50
+ *
51
+ * @param orginalValues - The array of the data points are already sorted according to the time series
52
+ * @param startingTimeStamp - The starting timestamp in seconds
53
+ * @param sampleDuration - The time span value in seconds
54
+ * @param sampleInterval - The time difference between two data points in seconds
55
+ */
56
+ export declare function addMissingDataPoint(originalValues: [number, number | string | null][], startingTimeStamp?: number, sampleDuration?: number, sampleInterval?: number): [number, number | string | null][];
57
+ /**
58
+ * Date Format Reference Table
59
+ * ============================
60
+ *
61
+ * This table documents the date formatting logic used across charts:
62
+ * - X-Axis Format: Used for chart axis labels (formatXAxisDate + LineTimeSerieChart's formatXAxisLabel)
63
+ * - Tooltip Format: Used for tooltip headers (getTooltipDateFormat)
64
+ *
65
+ * ┌─────────────────┬──────────────┬────────────────────────┬──────────────────┬──────────────────────────────────────────┬───────────────────────────┐
66
+ * │ Interval │ Duration (s) │ X-axis format │ Example (X-axis) │ Tooltip format │ Example (Tooltip) │
67
+ * ├─────────────────┼──────────────┼────────────────────────┼──────────────────┼──────────────────────────────────────────┼───────────────────────────┤
68
+ * │ Last hour │ ≤ 3,600 │ HH:MM │ 14:05 │ DD MMM HH:MM:SS │ 01 Oct 00:15:00 │
69
+ * │ Last 24 hours │ ≤ 86,400 │ HH:MM │ 23:00 │ DD MMM HH:MM │ 01 Oct 00:15 │
70
+ * │ Last 7 days │ ≤ 604,800 │ DD MMM HH:MM │ 27 Sep 10:12 │ DD MMM HH:MM │ 01 Oct 00:15 │
71
+ * │ Long term │ > 604,800 │ DDMMMYY │ 15Sep25 │ DD MMM YYYY HH:MM │ 01 Oct 2025 00:15 │
72
+ * └─────────────────┴──────────────┴────────────────────────┴──────────────────┴──────────────────────────────────────────┴───────────────────────────┘
73
+ *
74
+ * Note: Duration is in seconds. Some intervals share the same format, which is why both functions only have 3 cases.
75
+ */
76
+ /**
77
+ * Get the format of the date based on the duration
78
+ * Used by Barchart CustomTick component
79
+ * @param duration - Duration in seconds
80
+ * @returns Formatted string type
81
+ */
82
+ export declare const formatXAxisDate: (duration: number) => "time" | "day-month-abbreviated" | "chart-long-term-date";
83
+ /**
84
+ * Get the format of the date based on the duration
85
+ * Used by TooltipHeader component
86
+ * @param duration - Duration in seconds
87
+ * @returns Formatted string type
88
+ */
89
+ export declare const getTooltipDateFormat: (duration: number) => TooltipDateFormat;
90
+ export declare const formatToISONumber: (value: number) => string;
91
+ //# sourceMappingURL=chartUtils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"chartUtils.d.ts","sourceRoot":"","sources":["../../../../src/lib/components/charts/common/chartUtils.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AACnD,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAMrC,eAAO,MAAM,eAAe;;CAAwB,CAAC;AAMrD;;;GAGG;AACH,eAAO,MAAM,sBAAsB,UAAW,MAAM,KAAG,MA+BtD,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,QAAQ,aAAc,MAAM,iBAAiB,OAAO,aAmBhE,CAAC;AAEF;;;;;;GAMG;AACH,wBAAgB,YAAY,CAC1B,SAAS,EAAE;IACT,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,MAAM,CAAC;CACf,EAAE,EACH,QAAQ,EAAE,MAAM,GACf;IACD,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,GAAG,SAAS,CAAC;CAC/B,CAyCA;AAED;;;;;;;;;GASG;AACH,eAAO,MAAM,2BAA2B,GAAI,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,QACjE,CAAC,EAAE,YACC,MAAM,aACL,SAAS,GAAG,SAAS,cACpB,MAAM,KACjB;IACD,SAAS,EAAE,MAAM,GAAG,SAAS,CAAC;IAC9B,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,CAAC,EAAE,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;CAgCnB,CAAC;AAEF;;;;;;;;;GASG;AACH,wBAAgB,mBAAmB,CACjC,cAAc,EAAE,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAAC,EAAE,EAClD,iBAAiB,CAAC,EAAE,MAAM,EAC1B,cAAc,CAAC,EAAE,MAAM,EACvB,cAAc,CAAC,EAAE,MAAM,GACtB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAAC,EAAE,CAoEpC;AACD;;;;;;;;;;;;;;;;;;GAkBG;AAEH;;;;;GAKG;AACH,eAAO,MAAM,eAAe,aAChB,MAAM,KACf,MAAM,GAAG,uBAAuB,GAAG,sBAQrC,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,oBAAoB,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,iBAUxD,CAAC;AAEF,eAAO,MAAM,iBAAiB,UAAW,MAAM,KAAG,MAKjD,CAAC"}