@scality/core-ui 0.170.0 → 0.172.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 (89) hide show
  1. package/__mocks__/uuid.js +11 -0
  2. package/dist/components/barchartv2/Barchart.component.d.ts.map +1 -1
  3. package/dist/components/barchartv2/Barchart.component.js +4 -4
  4. package/dist/components/barchartv2/BarchartTooltip.d.ts +11 -0
  5. package/dist/components/barchartv2/BarchartTooltip.d.ts.map +1 -0
  6. package/dist/components/barchartv2/BarchartTooltip.js +27 -0
  7. package/dist/components/chartlegend/ChartLegend.d.ts +3 -1
  8. package/dist/components/chartlegend/ChartLegend.d.ts.map +1 -1
  9. package/dist/components/chartlegend/ChartLegend.js +2 -2
  10. package/dist/components/chartlegend/ChartLegendWrapper.d.ts +3 -1
  11. package/dist/components/chartlegend/ChartLegendWrapper.d.ts.map +1 -1
  12. package/dist/components/chartlegend/ChartLegendWrapper.js +43 -9
  13. package/dist/components/charttooltip/ChartTooltip.d.ts +13 -0
  14. package/dist/components/charttooltip/ChartTooltip.d.ts.map +1 -0
  15. package/dist/components/charttooltip/ChartTooltip.js +49 -0
  16. package/dist/components/globalhealthbar/GlobalHealthBar.component.d.ts +4 -0
  17. package/dist/components/globalhealthbar/GlobalHealthBar.component.d.ts.map +1 -1
  18. package/dist/components/globalhealthbar/GlobalHealthBar.component.js +4 -0
  19. package/dist/components/globalhealthbar/GlobalHealthBarRecharts.component.d.ts +10 -0
  20. package/dist/components/globalhealthbar/GlobalHealthBarRecharts.component.d.ts.map +1 -0
  21. package/dist/components/globalhealthbar/GlobalHealthBarRecharts.component.js +78 -0
  22. package/dist/components/globalhealthbar/components/GlobalHealthBarTooltip.d.ts +18 -0
  23. package/dist/components/globalhealthbar/components/GlobalHealthBarTooltip.d.ts.map +1 -0
  24. package/dist/components/globalhealthbar/components/GlobalHealthBarTooltip.js +95 -0
  25. package/dist/components/globalhealthbar/components/HealthBarXAxis.d.ts +7 -0
  26. package/dist/components/globalhealthbar/components/HealthBarXAxis.d.ts.map +1 -0
  27. package/dist/components/globalhealthbar/components/HealthBarXAxis.js +25 -0
  28. package/dist/components/globalhealthbar/healthBarUtils.d.ts +77 -0
  29. package/dist/components/globalhealthbar/healthBarUtils.d.ts.map +1 -0
  30. package/dist/components/globalhealthbar/healthBarUtils.js +196 -0
  31. package/dist/components/globalhealthbar/healthBarUtils.spec.d.ts +2 -0
  32. package/dist/components/globalhealthbar/healthBarUtils.spec.d.ts.map +1 -0
  33. package/dist/components/globalhealthbar/healthBarUtils.spec.js +391 -0
  34. package/dist/components/globalhealthbar/useHealthBarData.d.ts +18 -0
  35. package/dist/components/globalhealthbar/useHealthBarData.d.ts.map +1 -0
  36. package/dist/components/globalhealthbar/useHealthBarData.js +46 -0
  37. package/dist/components/globalhealthbar/useHealthBarData.spec.d.ts +2 -0
  38. package/dist/components/globalhealthbar/useHealthBarData.spec.d.ts.map +1 -0
  39. package/dist/components/globalhealthbar/useHealthBarData.spec.js +207 -0
  40. package/dist/components/icon/Icon.component.d.ts +2 -0
  41. package/dist/components/icon/Icon.component.d.ts.map +1 -1
  42. package/dist/components/icon/Icon.component.js +2 -0
  43. package/dist/components/linetemporalchart/ChartUtil.d.ts.map +1 -1
  44. package/dist/components/linetemporalchart/ChartUtil.js +12 -0
  45. package/dist/components/linetimeseriechart/linetimeseriechart.component.d.ts +8 -5
  46. package/dist/components/linetimeseriechart/linetimeseriechart.component.d.ts.map +1 -1
  47. package/dist/components/linetimeseriechart/linetimeseriechart.component.js +95 -100
  48. package/dist/components/sparkline/sparkline.component.d.ts +16 -0
  49. package/dist/components/sparkline/sparkline.component.d.ts.map +1 -0
  50. package/dist/components/sparkline/sparkline.component.js +20 -0
  51. package/dist/components/text/Text.component.d.ts +2 -1
  52. package/dist/components/text/Text.component.d.ts.map +1 -1
  53. package/dist/components/text/Text.component.js +6 -1
  54. package/dist/next.d.ts +4 -2
  55. package/dist/next.d.ts.map +1 -1
  56. package/dist/next.js +4 -2
  57. package/package.json +4 -2
  58. package/src/lib/components/barchartv2/Barchart.component.tsx +5 -4
  59. package/src/lib/components/barchartv2/{ChartTooltip.test.tsx → BarchartTooltip.test.tsx} +35 -12
  60. package/src/lib/components/barchartv2/BarchartTooltip.tsx +89 -0
  61. package/src/lib/components/chartlegend/ChartLegend.tsx +4 -2
  62. package/src/lib/components/chartlegend/ChartLegendWrapper.test.tsx +197 -0
  63. package/src/lib/components/chartlegend/ChartLegendWrapper.tsx +65 -9
  64. package/src/lib/components/charttooltip/ChartTooltip.tsx +83 -0
  65. package/src/lib/components/globalhealthbar/GlobalHealthBar.component.tsx +4 -1
  66. package/src/lib/components/globalhealthbar/GlobalHealthBarRecharts.component.tsx +203 -0
  67. package/src/lib/components/globalhealthbar/components/GlobalHealthBarTooltip.tsx +173 -0
  68. package/src/lib/components/globalhealthbar/components/HealthBarXAxis.tsx +94 -0
  69. package/src/lib/components/globalhealthbar/healthBarUtils.spec.ts +701 -0
  70. package/src/lib/components/globalhealthbar/healthBarUtils.ts +311 -0
  71. package/src/lib/components/globalhealthbar/useHealthBarData.spec.tsx +487 -0
  72. package/src/lib/components/globalhealthbar/useHealthBarData.ts +74 -0
  73. package/src/lib/components/icon/Icon.component.tsx +2 -0
  74. package/src/lib/components/linetemporalchart/ChartUtil.ts +26 -0
  75. package/src/lib/components/linetimeseriechart/linetimeseriechart.component.tsx +272 -229
  76. package/src/lib/components/sparkline/sparkline.component.tsx +54 -0
  77. package/src/lib/components/text/Text.component.tsx +15 -2
  78. package/src/lib/next.ts +12 -2
  79. package/stories/BarChart/barchart.stories.tsx +7 -1
  80. package/stories/GlobalHealthBar/globalhealthbarRecharts.stories.tsx +145 -0
  81. package/stories/GlobalHealthBar/globalheathbarrecharts.guideline.mdx +5 -0
  82. package/stories/InlineInput/InlineInput.stories.tsx +7 -1
  83. package/stories/globalhealthbar.stories.tsx +25 -5
  84. package/stories/linetimeseriechart.stories.tsx +217 -1
  85. package/stories/sparkline.stories.tsx +168 -0
  86. package/dist/components/barchartv2/ChartTooltip.d.ts +0 -14
  87. package/dist/components/barchartv2/ChartTooltip.d.ts.map +0 -1
  88. package/dist/components/barchartv2/ChartTooltip.js +0 -41
  89. package/src/lib/components/barchartv2/ChartTooltip.tsx +0 -106
@@ -0,0 +1,77 @@
1
+ export declare const CHART_CONFIG: {
2
+ readonly RADIUS_SIZE: 4;
3
+ readonly EDGE_THRESHOLD: 8;
4
+ readonly CHART_HEIGHT: 50;
5
+ readonly BAR_SIZE: 8;
6
+ readonly TICK_SIZE: 4;
7
+ readonly TOOLTIP_OFFSET: 24;
8
+ readonly FONT_SIZE: string;
9
+ readonly TEXT_DY_OFFSET: 12;
10
+ readonly TICK_INTERVAL: 0;
11
+ readonly MARGINS: {
12
+ readonly left: 28;
13
+ readonly right: 28;
14
+ readonly bottom: 4;
15
+ readonly top: 4;
16
+ };
17
+ };
18
+ export declare const TIME_CONSTANTS: {
19
+ readonly ONE_HOUR: number;
20
+ readonly ONE_DAY: number;
21
+ readonly ONE_WEEK: number;
22
+ readonly MARGIN_HOURS: 6;
23
+ readonly FIFTEEN_MINUTES: number;
24
+ readonly SIX_HOURS: number;
25
+ };
26
+ export declare const LABEL_CONFIG: {
27
+ readonly MIN_SPACE_PER_TICK: 80;
28
+ readonly MODULO_CONFIG: {
29
+ readonly [x: number]: 2 | 3;
30
+ };
31
+ };
32
+ export declare const calculateSevenDayTicks: (endTimestamp: number) => number[];
33
+ export declare const calculateDayTicks: (endTimestamp: number) => number[];
34
+ export declare const calculateHourTicks: (endTimestamp: number) => number[];
35
+ export declare const getEdgeMargin: (index: number, totalTicks: number, isDaySpan: boolean) => number;
36
+ export declare const getTicks: (startTimestamp: number, endTimestamp: number) => number[];
37
+ export interface LabelVisibilityConfig {
38
+ hasEnoughSpace: boolean;
39
+ timeSpan: number;
40
+ tickIndex: number;
41
+ totalTicks: number;
42
+ }
43
+ export declare const calculateLabelVisibility: (chartWidth: number, totalTicks: number, span: number, index: number, endTimestamp: number) => boolean;
44
+ /**
45
+ * Core calculation for alert positioning within a time range
46
+ */
47
+ export declare const calculateAlertPosition: (alertStartTimestamp: number, alertEndTimestamp: number, chartStartTimestamp: number, chartEndTimestamp: number, availableWidth: number, baseX?: number) => {
48
+ startX: number;
49
+ width: number;
50
+ relativeSize: number;
51
+ };
52
+ export type NavigationAction = 'previous' | 'next' | 'first' | 'last' | 'escape';
53
+ export interface NavigationState {
54
+ newIndex: number;
55
+ selectedAlert: any | null;
56
+ shouldActivateKeyboard: boolean;
57
+ }
58
+ /**
59
+ * Maps keyboard events to navigation actions
60
+ */
61
+ export declare const getNavigationAction: (key: string) => NavigationAction | null;
62
+ /**
63
+ * Calculates new index based on navigation action
64
+ */
65
+ export declare const calculateNavigationIndex: (action: NavigationAction, currentIndex: number, arrayLength: number) => number;
66
+ /**
67
+ * Gets complete navigation state update for a given action
68
+ */
69
+ export declare const getNavigationStateUpdate: <T>(action: NavigationAction, currentIndex: number, alerts: T[]) => NavigationState;
70
+ /**
71
+ * Calculates tooltip position for an alert based on its time range
72
+ */
73
+ export declare const getTooltipPosition: (alert: {
74
+ startsAt: string;
75
+ endsAt: string;
76
+ }, startTimestamp: number, endTimestamp: number, chartUsableWidth: number) => number;
77
+ //# sourceMappingURL=healthBarUtils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"healthBarUtils.d.ts","sourceRoot":"","sources":["../../../src/lib/components/globalhealthbar/healthBarUtils.ts"],"names":[],"mappings":"AAMA,eAAO,MAAM,YAAY;;;;;;;;;;;;;;;;CAWf,CAAC;AAEX,eAAO,MAAM,cAAc;;;;;;;CAOjB,CAAC;AAEX,eAAO,MAAM,YAAY;;;;;CAOf,CAAC;AA4BX,eAAO,MAAM,sBAAsB,iBAAkB,MAAM,KAAG,MAAM,EAInE,CAAC;AAEF,eAAO,MAAM,iBAAiB,iBAAkB,MAAM,KAAG,MAAM,EAM9D,CAAC;AAEF,eAAO,MAAM,kBAAkB,iBAAkB,MAAM,KAAG,M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AAC"}
@@ -0,0 +1,196 @@
1
+ import { fontSize } from '../../style/theme';
2
+ // =============================================================================
3
+ // CONSTANTS
4
+ // =============================================================================
5
+ export const CHART_CONFIG = {
6
+ RADIUS_SIZE: 4,
7
+ EDGE_THRESHOLD: 8,
8
+ CHART_HEIGHT: 50,
9
+ BAR_SIZE: 8,
10
+ TICK_SIZE: 4,
11
+ TOOLTIP_OFFSET: 24,
12
+ FONT_SIZE: fontSize.smaller,
13
+ TEXT_DY_OFFSET: 12,
14
+ TICK_INTERVAL: 0,
15
+ MARGINS: { left: 28, right: 28, bottom: 4, top: 4 },
16
+ };
17
+ export const TIME_CONSTANTS = {
18
+ ONE_HOUR: 60 * 60 * 1000,
19
+ ONE_DAY: 24 * 60 * 60 * 1000,
20
+ ONE_WEEK: 7 * 24 * 60 * 60 * 1000,
21
+ MARGIN_HOURS: 6,
22
+ FIFTEEN_MINUTES: 15 * 60 * 1000,
23
+ SIX_HOURS: 6 * 60 * 60 * 1000,
24
+ };
25
+ export const LABEL_CONFIG = {
26
+ MIN_SPACE_PER_TICK: 80,
27
+ MODULO_CONFIG: {
28
+ [TIME_CONSTANTS.ONE_WEEK]: 2,
29
+ [TIME_CONSTANTS.ONE_DAY]: 3,
30
+ [TIME_CONSTANTS.ONE_HOUR]: 3,
31
+ },
32
+ };
33
+ // =============================================================================
34
+ // TICK CALCULATIONS
35
+ // =============================================================================
36
+ const { ONE_HOUR, ONE_DAY, MARGIN_HOURS, FIFTEEN_MINUTES, SIX_HOURS } = TIME_CONSTANTS;
37
+ const generateTickArray = (endTimestamp, count, interval) => {
38
+ return Array.from({ length: count }, (_, i) => endTimestamp - i * interval);
39
+ };
40
+ const roundToNearestHalfDay = (timestamp) => {
41
+ const date = new Date(timestamp);
42
+ const hours = date.getHours();
43
+ if (hours <= 12) {
44
+ return new Date(timestamp).setHours(0, 0, 0, 0);
45
+ }
46
+ else {
47
+ return new Date(timestamp).setHours(12, 0, 0, 0);
48
+ }
49
+ };
50
+ export const calculateSevenDayTicks = (endTimestamp) => {
51
+ const marginedEnd = endTimestamp - MARGIN_HOURS * ONE_HOUR;
52
+ const roundedEnd = roundToNearestHalfDay(marginedEnd);
53
+ return generateTickArray(roundedEnd, 7, ONE_DAY);
54
+ };
55
+ export const calculateDayTicks = (endTimestamp) => {
56
+ const is6HourTick = endTimestamp % SIX_HOURS === 0;
57
+ const closest6Hours = Math.floor(endTimestamp / SIX_HOURS) * SIX_HOURS;
58
+ const tickCount = is6HourTick ? 5 : 4;
59
+ return generateTickArray(closest6Hours, tickCount, SIX_HOURS);
60
+ };
61
+ export const calculateHourTicks = (endTimestamp) => {
62
+ const is15MinuteTick = endTimestamp % FIFTEEN_MINUTES === 0;
63
+ const closest15Minutes = Math.floor(endTimestamp / FIFTEEN_MINUTES) * FIFTEEN_MINUTES;
64
+ const tickCount = is15MinuteTick ? 5 : 4;
65
+ return generateTickArray(closest15Minutes, tickCount, FIFTEEN_MINUTES);
66
+ };
67
+ export const getEdgeMargin = (index, totalTicks, isDaySpan) => {
68
+ if (isDaySpan && totalTicks === 5) {
69
+ return index === 0 ? -8 : index === totalTicks - 1 ? 8 : 0;
70
+ }
71
+ return 0;
72
+ };
73
+ export const getTicks = (startTimestamp, endTimestamp) => {
74
+ const span = endTimestamp - startTimestamp;
75
+ if (span === 7 * ONE_DAY) {
76
+ return calculateSevenDayTicks(endTimestamp);
77
+ }
78
+ else if (span === 24 * ONE_HOUR) {
79
+ return calculateDayTicks(endTimestamp);
80
+ }
81
+ else if (span === ONE_HOUR) {
82
+ return calculateHourTicks(endTimestamp);
83
+ }
84
+ return [];
85
+ };
86
+ export const calculateLabelVisibility = (chartWidth, totalTicks, span, index, endTimestamp) => {
87
+ const hasEnoughSpace = chartWidth / totalTicks > LABEL_CONFIG.MIN_SPACE_PER_TICK;
88
+ // If enough space, show all labels
89
+ if (hasEnoughSpace)
90
+ return true;
91
+ // Apply specific rules for each time range
92
+ if (span === TIME_CONSTANTS.ONE_WEEK) {
93
+ return index % 2 === 0;
94
+ }
95
+ if (span === TIME_CONSTANTS.ONE_DAY) {
96
+ const isRoundHour = endTimestamp % (60 * 60 * 1000) === 0;
97
+ const roundHourInterval = index % 2 === 0;
98
+ const defaultInterval = index % 3 === 0;
99
+ const result = isRoundHour ? roundHourInterval : defaultInterval;
100
+ return result;
101
+ }
102
+ if (span === TIME_CONSTANTS.ONE_HOUR) {
103
+ const isRound15Minute = endTimestamp % (15 * 60 * 1000) === 0;
104
+ const round15MinuteInterval = index % 2 === 0;
105
+ const defaultInterval = index % 3 === 0;
106
+ const result = isRound15Minute ? round15MinuteInterval : defaultInterval;
107
+ return result;
108
+ }
109
+ return false;
110
+ };
111
+ // =============================================================================
112
+ // RECTANGLE PROPERTIES
113
+ // =============================================================================
114
+ /**
115
+ * Core calculation for alert positioning within a time range
116
+ */
117
+ export const calculateAlertPosition = (alertStartTimestamp, alertEndTimestamp, chartStartTimestamp, chartEndTimestamp, availableWidth, baseX = 0) => {
118
+ const start = Math.max(alertStartTimestamp, chartStartTimestamp);
119
+ const end = Math.min(alertEndTimestamp, chartEndTimestamp);
120
+ const totalTimeSpan = chartEndTimestamp - chartStartTimestamp;
121
+ const relativeSize = (end - start) / totalTimeSpan;
122
+ // Calculate start position relative to baseX
123
+ let startX = baseX;
124
+ if (alertStartTimestamp > chartStartTimestamp) {
125
+ const alertStartRelative = (alertStartTimestamp - chartStartTimestamp) / totalTimeSpan;
126
+ startX = baseX + alertStartRelative * availableWidth;
127
+ }
128
+ const width = relativeSize * availableWidth;
129
+ return { startX, width, relativeSize };
130
+ };
131
+ /**
132
+ * Maps keyboard events to navigation actions
133
+ */
134
+ export const getNavigationAction = (key) => {
135
+ switch (key) {
136
+ case 'ArrowLeft':
137
+ case 'ArrowUp':
138
+ return 'previous';
139
+ case 'ArrowRight':
140
+ case 'ArrowDown':
141
+ return 'next';
142
+ case 'Home':
143
+ return 'first';
144
+ case 'End':
145
+ return 'last';
146
+ case 'Escape':
147
+ return 'escape';
148
+ default:
149
+ return null;
150
+ }
151
+ };
152
+ /**
153
+ * Calculates new index based on navigation action
154
+ */
155
+ export const calculateNavigationIndex = (action, currentIndex, arrayLength) => {
156
+ if (arrayLength === 0)
157
+ return -1;
158
+ switch (action) {
159
+ case 'previous':
160
+ return currentIndex <= 0 ? arrayLength - 1 : currentIndex - 1;
161
+ case 'next':
162
+ return currentIndex >= arrayLength - 1 ? 0 : currentIndex + 1;
163
+ case 'first':
164
+ return 0;
165
+ case 'last':
166
+ return arrayLength - 1;
167
+ case 'escape':
168
+ return -1;
169
+ default:
170
+ return currentIndex;
171
+ }
172
+ };
173
+ /**
174
+ * Gets complete navigation state update for a given action
175
+ */
176
+ export const getNavigationStateUpdate = (action, currentIndex, alerts) => {
177
+ const newIndex = calculateNavigationIndex(action, currentIndex, alerts.length);
178
+ return {
179
+ newIndex,
180
+ selectedAlert: newIndex >= 0 ? alerts[newIndex] : null,
181
+ shouldActivateKeyboard: action !== 'escape',
182
+ };
183
+ };
184
+ // =============================================================================
185
+ // TOOLTIP UTILS
186
+ // =============================================================================
187
+ /**
188
+ * Calculates tooltip position for an alert based on its time range
189
+ */
190
+ export const getTooltipPosition = (alert, startTimestamp, endTimestamp, chartUsableWidth) => {
191
+ const alertStart = new Date(alert.startsAt).getTime();
192
+ const alertEnd = new Date(alert.endsAt).getTime();
193
+ const { startX, width } = calculateAlertPosition(alertStart, alertEnd, startTimestamp, endTimestamp, chartUsableWidth, CHART_CONFIG.MARGINS.left);
194
+ // Return center position of the alert
195
+ return startX + width / 2;
196
+ };
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=healthBarUtils.spec.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"healthBarUtils.spec.d.ts","sourceRoot":"","sources":["../../../src/lib/components/globalhealthbar/healthBarUtils.spec.ts"],"names":[],"mappings":""}