@scality/core-ui 0.186.0 → 0.187.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 +73 -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 +180 -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
@@ -1,391 +0,0 @@
1
- import { TIME_CONSTANTS, calculateSevenDayTicks, calculateDayTicks, calculateHourTicks, getTicks, getEdgeMargin, calculateLabelVisibility, calculateAlertPosition, getNavigationAction, calculateNavigationIndex, getNavigationStateUpdate, } from './healthBarUtils';
2
- describe('Health Bar Utils', () => {
3
- describe('Tick Calculations', () => {
4
- describe('calculateSevenDayTicks', () => {
5
- it('should calculate 7 ticks for a week span with proper spacing', () => {
6
- const endTimestamp = new Date('2023-12-07T12:00:00Z').getTime();
7
- const ticks = calculateSevenDayTicks(endTimestamp);
8
- expect(ticks).toHaveLength(7);
9
- // Check that ticks are spaced by one day
10
- for (let i = 1; i < ticks.length; i++) {
11
- expect(ticks[i - 1] - ticks[i]).toBe(TIME_CONSTANTS.ONE_DAY);
12
- }
13
- });
14
- it('should apply margin hours offset', () => {
15
- const endTimestamp = new Date('2023-12-07T12:00:00Z').getTime();
16
- const ticks = calculateSevenDayTicks(endTimestamp);
17
- // First tick should be less than endTimestamp due to margin
18
- expect(ticks[0]).toBeLessThan(endTimestamp);
19
- // The difference should account for margin hours
20
- const expectedMargin = TIME_CONSTANTS.MARGIN_HOURS * TIME_CONSTANTS.ONE_HOUR;
21
- expect(endTimestamp - ticks[0]).toBeGreaterThan(expectedMargin);
22
- });
23
- it('should round to nearest half day', () => {
24
- const endTimestamp = new Date('2023-12-07T15:30:45Z').getTime();
25
- const ticks = calculateSevenDayTicks(endTimestamp);
26
- const firstTickDate = new Date(ticks[0]);
27
- // Should be rounded to either 00:00 or 12:00
28
- expect([0, 12]).toContain(firstTickDate.getUTCHours());
29
- expect(firstTickDate.getUTCMinutes()).toBe(0);
30
- expect(firstTickDate.getUTCSeconds()).toBe(0);
31
- });
32
- });
33
- describe('calculateDayTicks', () => {
34
- it('should calculate 5 ticks when end timestamp aligns with 6-hour boundary', () => {
35
- const endTimestamp = new Date('2023-12-07T12:00:00Z').getTime();
36
- const ticks = calculateDayTicks(endTimestamp);
37
- expect(ticks).toHaveLength(5);
38
- });
39
- it('should calculate 4 ticks when end timestamp does not align with 6-hour boundary', () => {
40
- const endTimestamp = new Date('2023-12-07T13:30:00Z').getTime();
41
- const ticks = calculateDayTicks(endTimestamp);
42
- expect(ticks).toHaveLength(4);
43
- });
44
- it('should space ticks by 6 hours', () => {
45
- const endTimestamp = new Date('2023-12-07T12:00:00Z').getTime();
46
- const ticks = calculateDayTicks(endTimestamp);
47
- for (let i = 1; i < ticks.length; i++) {
48
- expect(ticks[i - 1] - ticks[i]).toBe(TIME_CONSTANTS.SIX_HOURS);
49
- }
50
- });
51
- it('should start from closest 6-hour boundary', () => {
52
- const endTimestamp = new Date('2023-12-07T14:30:00Z').getTime();
53
- const ticks = calculateDayTicks(endTimestamp);
54
- const firstTickDate = new Date(ticks[0]);
55
- expect(firstTickDate.getUTCHours() % 6).toBe(0);
56
- expect(firstTickDate.getUTCMinutes()).toBe(0);
57
- expect(firstTickDate.getUTCSeconds()).toBe(0);
58
- });
59
- });
60
- describe('calculateHourTicks', () => {
61
- it('should calculate 5 ticks when end timestamp aligns with 15-minute boundary', () => {
62
- const endTimestamp = new Date('2023-12-07T12:15:00Z').getTime();
63
- const ticks = calculateHourTicks(endTimestamp);
64
- expect(ticks).toHaveLength(5);
65
- });
66
- it('should calculate 4 ticks when end timestamp does not align with 15-minute boundary', () => {
67
- const endTimestamp = new Date('2023-12-07T12:17:00Z').getTime();
68
- const ticks = calculateHourTicks(endTimestamp);
69
- expect(ticks).toHaveLength(4);
70
- });
71
- it('should space ticks by 15 minutes', () => {
72
- const endTimestamp = new Date('2023-12-07T12:15:00Z').getTime();
73
- const ticks = calculateHourTicks(endTimestamp);
74
- for (let i = 1; i < ticks.length; i++) {
75
- expect(ticks[i - 1] - ticks[i]).toBe(TIME_CONSTANTS.FIFTEEN_MINUTES);
76
- }
77
- });
78
- it('should start from closest 15-minute boundary', () => {
79
- const endTimestamp = new Date('2023-12-07T12:17:30Z').getTime();
80
- const ticks = calculateHourTicks(endTimestamp);
81
- const firstTickDate = new Date(ticks[0]);
82
- // Test time is 12:17 so the first tick should be 12:15
83
- expect(firstTickDate.getUTCHours()).toBe(12);
84
- expect(firstTickDate.getUTCMinutes()).toBe(15);
85
- expect(firstTickDate.getUTCSeconds()).toBe(0);
86
- });
87
- });
88
- describe('getTicks', () => {
89
- it('should return seven day ticks for week span', () => {
90
- const startTimestamp = new Date('2023-12-01T00:00:00Z').getTime();
91
- const endTimestamp = startTimestamp + 7 * TIME_CONSTANTS.ONE_DAY;
92
- const ticks = getTicks(startTimestamp, endTimestamp);
93
- expect(ticks).toHaveLength(7);
94
- });
95
- it('should return day ticks for 24-hour span', () => {
96
- const startTimestamp = new Date('2023-12-07T00:00:00Z').getTime();
97
- const endTimestamp = startTimestamp + 24 * TIME_CONSTANTS.ONE_HOUR;
98
- const ticks = getTicks(startTimestamp, endTimestamp);
99
- expect(ticks.length).toBe(5);
100
- });
101
- it('should return hour ticks for 1-hour span', () => {
102
- const startTimestamp = new Date('2023-12-07T12:00:00Z').getTime();
103
- const endTimestamp = startTimestamp + TIME_CONSTANTS.ONE_HOUR;
104
- const ticks = getTicks(startTimestamp, endTimestamp);
105
- expect(ticks.length).toBe(5);
106
- });
107
- it('should return empty array for unsupported time spans', () => {
108
- const startTimestamp = new Date('2023-12-07T12:00:00Z').getTime();
109
- const endTimestamp = startTimestamp + 2 * TIME_CONSTANTS.ONE_HOUR;
110
- const ticks = getTicks(startTimestamp, endTimestamp);
111
- expect(ticks).toEqual([]);
112
- });
113
- });
114
- });
115
- describe('Edge Margin Calculations', () => {
116
- describe('getEdgeMargin', () => {
117
- it('should return -8 for first tick in day span with 5 total ticks', () => {
118
- const margin = getEdgeMargin(0, 5, true);
119
- expect(margin).toBe(-8);
120
- });
121
- it('should return 8 for last tick in day span with 5 total ticks', () => {
122
- const margin = getEdgeMargin(4, 5, true);
123
- expect(margin).toBe(8);
124
- });
125
- it('should return 0 for middle ticks in day span with 5 total ticks', () => {
126
- const margin = getEdgeMargin(2, 5, true);
127
- expect(margin).toBe(0);
128
- });
129
- it('should return 0 for non-day spans', () => {
130
- const margin = getEdgeMargin(0, 5, false);
131
- expect(margin).toBe(0);
132
- });
133
- it('should return 0 for day span with non-5 total ticks', () => {
134
- const margin = getEdgeMargin(0, 4, true);
135
- expect(margin).toBe(0);
136
- });
137
- });
138
- });
139
- describe('Label Visibility', () => {
140
- describe('calculateLabelVisibility', () => {
141
- it('should return true when chart has enough space per tick', () => {
142
- const chartWidth = 500;
143
- const totalTicks = 5;
144
- const span = TIME_CONSTANTS.ONE_DAY;
145
- const index = 0;
146
- const endTimestamp = Date.now();
147
- const visible = calculateLabelVisibility(chartWidth, totalTicks, span, index, endTimestamp);
148
- expect(visible).toBe(true);
149
- });
150
- it('should apply week span rules when space is limited', () => {
151
- const chartWidth = 200;
152
- const totalTicks = 7;
153
- const span = TIME_CONSTANTS.ONE_WEEK;
154
- const endTimestamp = Date.now();
155
- expect(calculateLabelVisibility(chartWidth, totalTicks, span, 0, endTimestamp)).toBe(true);
156
- expect(calculateLabelVisibility(chartWidth, totalTicks, span, 1, endTimestamp)).toBe(false);
157
- expect(calculateLabelVisibility(chartWidth, totalTicks, span, 2, endTimestamp)).toBe(true);
158
- });
159
- it('should apply day span rules when space is limited', () => {
160
- const chartWidth = 200;
161
- const totalTicks = 4;
162
- const span = TIME_CONSTANTS.ONE_DAY;
163
- const endTimestamp = new Date('2023-12-07T12:10:00Z').getTime();
164
- expect(calculateLabelVisibility(chartWidth, totalTicks, span, 0, endTimestamp)).toBe(true);
165
- expect(calculateLabelVisibility(chartWidth, totalTicks, span, 1, endTimestamp)).toBe(false);
166
- expect(calculateLabelVisibility(chartWidth, totalTicks, span, 2, endTimestamp)).toBe(false);
167
- expect(calculateLabelVisibility(chartWidth, totalTicks, span, 3, endTimestamp)).toBe(true);
168
- });
169
- it('should handle special cases for day span with hour-aligned end timestamp', () => {
170
- const chartWidth = 200;
171
- const totalTicks = 5;
172
- const span = TIME_CONSTANTS.ONE_DAY;
173
- const endTimestamp = new Date('2023-12-07T12:00:00Z').getTime();
174
- expect(calculateLabelVisibility(chartWidth, totalTicks, span, 0, endTimestamp)).toBe(true);
175
- expect(calculateLabelVisibility(chartWidth, totalTicks, span, 2, endTimestamp)).toBe(true);
176
- expect(calculateLabelVisibility(chartWidth, totalTicks, span, 4, endTimestamp)).toBe(true);
177
- expect(calculateLabelVisibility(chartWidth, totalTicks, span, 3, endTimestamp)).toBe(false);
178
- });
179
- it('should apply day span rules when space is limited for non-round hour', () => {
180
- const chartWidth = 200;
181
- const totalTicks = 4;
182
- const span = TIME_CONSTANTS.ONE_DAY;
183
- const endTimestamp = new Date('2023-12-07T12:10:00Z').getTime();
184
- expect(calculateLabelVisibility(chartWidth, totalTicks, span, 0, endTimestamp)).toBe(true);
185
- expect(calculateLabelVisibility(chartWidth, totalTicks, span, 1, endTimestamp)).toBe(false);
186
- expect(calculateLabelVisibility(chartWidth, totalTicks, span, 2, endTimestamp)).toBe(false);
187
- expect(calculateLabelVisibility(chartWidth, totalTicks, span, 3, endTimestamp)).toBe(true);
188
- });
189
- it('should handle special cases for hour span with 15-minute aligned end timestamp', () => {
190
- const chartWidth = 200;
191
- const totalTicks = 5;
192
- const span = TIME_CONSTANTS.ONE_HOUR;
193
- const endTimestamp = new Date('2023-12-07T12:15:00Z').getTime();
194
- expect(calculateLabelVisibility(chartWidth, totalTicks, span, 0, endTimestamp)).toBe(true);
195
- expect(calculateLabelVisibility(chartWidth, totalTicks, span, 2, endTimestamp)).toBe(true);
196
- expect(calculateLabelVisibility(chartWidth, totalTicks, span, 4, endTimestamp)).toBe(true);
197
- expect(calculateLabelVisibility(chartWidth, totalTicks, span, 3, endTimestamp)).toBe(false);
198
- });
199
- it('should return false for unsupported time spans when space is limited', () => {
200
- const chartWidth = 200;
201
- const totalTicks = 5;
202
- const span = 123456;
203
- const index = 0;
204
- const endTimestamp = Date.now();
205
- const visible = calculateLabelVisibility(chartWidth, totalTicks, span, index, endTimestamp);
206
- expect(visible).toBe(false);
207
- });
208
- });
209
- });
210
- describe('Alert Position Calculations', () => {
211
- describe('calculateAlertPosition', () => {
212
- it('should calculate position for alert within time range', () => {
213
- const alertStartTimestamp = 2000;
214
- const alertEndTimestamp = 3000;
215
- const chartStartTimestamp = 1000;
216
- const chartEndTimestamp = 5000;
217
- const availableWidth = 200;
218
- const baseX = 50;
219
- const result = calculateAlertPosition(alertStartTimestamp, alertEndTimestamp, chartStartTimestamp, chartEndTimestamp, availableWidth, baseX);
220
- const expectedRelativeSize = (3000 - 2000) / (5000 - 1000);
221
- const expectedWidth = expectedRelativeSize * 200;
222
- const expectedStartX = 50 + ((2000 - 1000) / (5000 - 1000)) * 200;
223
- expect(result.width).toBe(expectedWidth);
224
- expect(result.startX).toBe(expectedStartX);
225
- expect(result.relativeSize).toBe(expectedRelativeSize);
226
- });
227
- it('should handle alert starting before time range', () => {
228
- const alertStartTimestamp = 1000;
229
- const alertEndTimestamp = 3000;
230
- const chartStartTimestamp = 2000;
231
- const chartEndTimestamp = 5000;
232
- const availableWidth = 200;
233
- const baseX = 50;
234
- const result = calculateAlertPosition(alertStartTimestamp, alertEndTimestamp, chartStartTimestamp, chartEndTimestamp, availableWidth, baseX);
235
- const expectedRelativeSize = (3000 - 2000) / (5000 - 2000);
236
- const expectedWidth = expectedRelativeSize * 200;
237
- const expectedStartX = 50; // baseX since alert starts before chart range
238
- expect(result.width).toBe(expectedWidth);
239
- expect(result.startX).toBe(expectedStartX);
240
- expect(result.relativeSize).toBe(expectedRelativeSize);
241
- });
242
- it('should handle alert ending after time range', () => {
243
- const alertStartTimestamp = 2500;
244
- const alertEndTimestamp = 6000;
245
- const chartStartTimestamp = 1000;
246
- const chartEndTimestamp = 4000;
247
- const availableWidth = 200;
248
- const baseX = 50;
249
- const result = calculateAlertPosition(alertStartTimestamp, alertEndTimestamp, chartStartTimestamp, chartEndTimestamp, availableWidth, baseX);
250
- const expectedRelativeSize = (4000 - 2500) / (4000 - 1000);
251
- const expectedWidth = expectedRelativeSize * 200;
252
- const expectedStartX = 50 + ((2500 - 1000) / (4000 - 1000)) * 200;
253
- expect(result.width).toBe(expectedWidth);
254
- expect(result.startX).toBe(expectedStartX);
255
- expect(result.relativeSize).toBe(expectedRelativeSize);
256
- });
257
- it('should handle alert spanning entire time range', () => {
258
- const alertStartTimestamp = 1000;
259
- const alertEndTimestamp = 5000;
260
- const chartStartTimestamp = 2000;
261
- const chartEndTimestamp = 4000;
262
- const availableWidth = 200;
263
- const baseX = 50;
264
- const result = calculateAlertPosition(alertStartTimestamp, alertEndTimestamp, chartStartTimestamp, chartEndTimestamp, availableWidth, baseX);
265
- const expectedStartX = 50; // baseX since alert starts before chart range
266
- expect(result.width).toBe(200);
267
- expect(result.startX).toBe(expectedStartX);
268
- expect(result.relativeSize).toBe(1);
269
- });
270
- it('should work with default baseX of 0', () => {
271
- const alertStartTimestamp = 2000;
272
- const alertEndTimestamp = 3000;
273
- const chartStartTimestamp = 1000;
274
- const chartEndTimestamp = 5000;
275
- const availableWidth = 200;
276
- const result = calculateAlertPosition(alertStartTimestamp, alertEndTimestamp, chartStartTimestamp, chartEndTimestamp, availableWidth);
277
- const expectedRelativeSize = (3000 - 2000) / (5000 - 1000);
278
- const expectedWidth = expectedRelativeSize * 200;
279
- const expectedStartX = 0 + ((2000 - 1000) / (5000 - 1000)) * 200;
280
- expect(result.width).toBe(expectedWidth);
281
- expect(result.startX).toBe(expectedStartX);
282
- expect(result.relativeSize).toBe(expectedRelativeSize);
283
- });
284
- });
285
- });
286
- describe('Keyboard Navigation Utils', () => {
287
- describe('getNavigationAction', () => {
288
- it('should map arrow keys to navigation actions', () => {
289
- expect(getNavigationAction('ArrowLeft')).toBe('previous');
290
- expect(getNavigationAction('ArrowUp')).toBe('previous');
291
- expect(getNavigationAction('ArrowRight')).toBe('next');
292
- expect(getNavigationAction('ArrowDown')).toBe('next');
293
- });
294
- it('should map Home and End keys', () => {
295
- expect(getNavigationAction('Home')).toBe('first');
296
- expect(getNavigationAction('End')).toBe('last');
297
- });
298
- it('should map Escape key', () => {
299
- expect(getNavigationAction('Escape')).toBe('escape');
300
- });
301
- it('should return null for unmapped keys', () => {
302
- expect(getNavigationAction('Enter')).toBe(null);
303
- expect(getNavigationAction('Space')).toBe(null);
304
- expect(getNavigationAction('Tab')).toBe(null);
305
- });
306
- });
307
- describe('calculateNavigationIndex', () => {
308
- const arrayLength = 5;
309
- it('should handle previous navigation', () => {
310
- expect(calculateNavigationIndex('previous', 2, arrayLength)).toBe(1);
311
- expect(calculateNavigationIndex('previous', 0, arrayLength)).toBe(4); // wraps to end
312
- });
313
- it('should handle next navigation', () => {
314
- expect(calculateNavigationIndex('next', 2, arrayLength)).toBe(3);
315
- expect(calculateNavigationIndex('next', 4, arrayLength)).toBe(0); // wraps to start
316
- });
317
- it('should handle first navigation', () => {
318
- expect(calculateNavigationIndex('first', 3, arrayLength)).toBe(0);
319
- });
320
- it('should handle last navigation', () => {
321
- expect(calculateNavigationIndex('last', 1, arrayLength)).toBe(4);
322
- });
323
- it('should handle escape navigation', () => {
324
- expect(calculateNavigationIndex('escape', 2, arrayLength)).toBe(-1);
325
- });
326
- it('should return -1 for empty array', () => {
327
- expect(calculateNavigationIndex('next', 0, 0)).toBe(-1);
328
- expect(calculateNavigationIndex('previous', 0, 0)).toBe(-1);
329
- });
330
- it('should handle single item array', () => {
331
- expect(calculateNavigationIndex('next', 0, 1)).toBe(0);
332
- expect(calculateNavigationIndex('previous', 0, 1)).toBe(0);
333
- expect(calculateNavigationIndex('first', 0, 1)).toBe(0);
334
- expect(calculateNavigationIndex('last', 0, 1)).toBe(0);
335
- });
336
- });
337
- describe('getNavigationStateUpdate', () => {
338
- const mockAlerts = [
339
- { id: 1, name: 'Alert 1' },
340
- { id: 2, name: 'Alert 2' },
341
- { id: 3, name: 'Alert 3' },
342
- ];
343
- it('should return correct state for next navigation', () => {
344
- const result = getNavigationStateUpdate('next', 0, mockAlerts);
345
- expect(result.newIndex).toBe(1);
346
- expect(result.selectedAlert).toEqual(mockAlerts[1]);
347
- expect(result.shouldActivateKeyboard).toBe(true);
348
- });
349
- it('should return correct state for previous navigation', () => {
350
- const result = getNavigationStateUpdate('previous', 2, mockAlerts);
351
- expect(result.newIndex).toBe(1);
352
- expect(result.selectedAlert).toEqual(mockAlerts[1]);
353
- expect(result.shouldActivateKeyboard).toBe(true);
354
- });
355
- it('should return correct state for first navigation', () => {
356
- const result = getNavigationStateUpdate('first', 2, mockAlerts);
357
- expect(result.newIndex).toBe(0);
358
- expect(result.selectedAlert).toEqual(mockAlerts[0]);
359
- expect(result.shouldActivateKeyboard).toBe(true);
360
- });
361
- it('should return correct state for last navigation', () => {
362
- const result = getNavigationStateUpdate('last', 0, mockAlerts);
363
- expect(result.newIndex).toBe(2);
364
- expect(result.selectedAlert).toEqual(mockAlerts[2]);
365
- expect(result.shouldActivateKeyboard).toBe(true);
366
- });
367
- it('should return correct state for escape navigation', () => {
368
- const result = getNavigationStateUpdate('escape', 1, mockAlerts);
369
- expect(result.newIndex).toBe(-1);
370
- expect(result.selectedAlert).toBe(null);
371
- expect(result.shouldActivateKeyboard).toBe(false);
372
- });
373
- it('should handle empty array', () => {
374
- const result = getNavigationStateUpdate('next', 0, []);
375
- expect(result.newIndex).toBe(-1);
376
- expect(result.selectedAlert).toBe(null);
377
- expect(result.shouldActivateKeyboard).toBe(true);
378
- });
379
- it('should handle wrapping navigation', () => {
380
- // Next from last index should wrap to first
381
- const nextResult = getNavigationStateUpdate('next', 2, mockAlerts);
382
- expect(nextResult.newIndex).toBe(0);
383
- expect(nextResult.selectedAlert).toEqual(mockAlerts[0]);
384
- // Previous from first index should wrap to last
385
- const prevResult = getNavigationStateUpdate('previous', 0, mockAlerts);
386
- expect(prevResult.newIndex).toBe(2);
387
- expect(prevResult.selectedAlert).toEqual(mockAlerts[2]);
388
- });
389
- });
390
- });
391
- });
@@ -1,8 +0,0 @@
1
- /**
2
- * Format the value to be shown in the tooltip.
3
- *
4
- * @param value The value to show in the tooltip.
5
- * @param valueToHtml Function to convert a single cell value to an HTML string
6
- */
7
- export declare function formatValue(): (value: any, valueToHtml: (value: any) => string, maxDepth: number) => string;
8
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/lib/components/globalhealthbar/tooltip/index.ts"],"names":[],"mappings":"AAIA;;;;;GAKG;AACH,wBAAgB,WAAW,YAEhB,GAAG,eACG,CAAC,KAAK,EAAE,GAAG,KAAK,MAAM,YACzB,MAAM,KACf,MAAM,CAwDV"}
@@ -1,55 +0,0 @@
1
- // @ts-nocheck
2
- import { stringify } from 'vega-lite';
3
- import { isArray, isObject, isString } from 'vega-util';
4
- /**
5
- * Format the value to be shown in the tooltip.
6
- *
7
- * @param value The value to show in the tooltip.
8
- * @param valueToHtml Function to convert a single cell value to an HTML string
9
- */
10
- export function formatValue() {
11
- return (value, valueToHtml, maxDepth) => {
12
- if (isArray(value)) {
13
- return `[${value
14
- .map((v) => valueToHtml(isString(v) ? v : stringify(v, maxDepth)))
15
- .join(', ')}]`;
16
- }
17
- if (isObject(value)) {
18
- let content = '';
19
- const { title, image, ...rest } = value;
20
- if (title) {
21
- content += `<h2 style="text-align: center;">${valueToHtml(title)}</h2>`;
22
- }
23
- if (image) {
24
- content += `<img src="${valueToHtml(image)}">`;
25
- }
26
- const keys = Object.keys(rest);
27
- if (keys.length > 0) {
28
- content += '<table>';
29
- for (const key of keys) {
30
- let val = rest[key];
31
- // ignore undefined properties
32
- if (val === undefined) {
33
- continue;
34
- }
35
- if (isObject(val)) {
36
- val = stringify(val, maxDepth);
37
- }
38
- if (val && val !== 'undefined' && val !== 'null') {
39
- content += `<tr>
40
- <td class="key" style="text-align: left;">
41
- ${valueToHtml(key)}:
42
- </td>
43
- <td class="value" style="text-align: right;">
44
- ${valueToHtml(val)}
45
- </td>
46
- </tr>`;
47
- }
48
- }
49
- content += `</table>`;
50
- }
51
- return content || '{}'; // show empty object if there are no properties
52
- }
53
- return valueToHtml(value);
54
- };
55
- }
@@ -1 +0,0 @@
1
- {"version":3,"file":"useHealthBarData.d.ts","sourceRoot":"","sources":["../../../src/lib/components/globalhealthbar/useHealthBarData.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,KAAK;IACpB,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,SAAS,GAAG,UAAU,GAAG,aAAa,CAAC;IACjD,GAAG,EAAE,MAAM,CAAC;CACb;AAED,eAAO,MAAM,gBAAgB,WACnB,KAAK,EAAE,kBACC,MAAM,gBACR,MAAM,MAChB,MAAM;;;;;;;;;;CA6DX,CAAC"}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=useHealthBarData.spec.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useHealthBarData.spec.d.ts","sourceRoot":"","sources":["../../../src/lib/components/globalhealthbar/useHealthBarData.spec.tsx"],"names":[],"mappings":""}