@scality/core-ui 0.175.0 → 0.176.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 (34) hide show
  1. package/dist/components/barchartv2/Barchart.component.d.ts +3 -4
  2. package/dist/components/barchartv2/Barchart.component.d.ts.map +1 -1
  3. package/dist/components/barchartv2/Barchart.component.js +13 -21
  4. package/dist/components/barchartv2/BarchartTooltip.d.ts +1 -1
  5. package/dist/components/barchartv2/BarchartTooltip.d.ts.map +1 -1
  6. package/dist/components/barchartv2/BarchartTooltip.js +6 -6
  7. package/dist/components/barchartv2/utils.d.ts.map +1 -1
  8. package/dist/components/chartlegend/ChartLegendWrapper.js +1 -1
  9. package/dist/components/charttooltip/ChartTooltip.d.ts +6 -0
  10. package/dist/components/charttooltip/ChartTooltip.d.ts.map +1 -1
  11. package/dist/components/charttooltip/ChartTooltip.js +22 -0
  12. package/dist/components/date/FormattedDateTime.d.ts +23 -8
  13. package/dist/components/date/FormattedDateTime.d.ts.map +1 -1
  14. package/dist/components/date/FormattedDateTime.js +51 -7
  15. package/dist/components/linetimeseriechart/linetimeseriechart.component.d.ts +2 -1
  16. package/dist/components/linetimeseriechart/linetimeseriechart.component.d.ts.map +1 -1
  17. package/dist/components/linetimeseriechart/linetimeseriechart.component.js +15 -13
  18. package/dist/components/linetimeseriechart/utils.d.ts +1 -1
  19. package/dist/components/linetimeseriechart/utils.d.ts.map +1 -1
  20. package/dist/components/linetimeseriechart/utils.js +13 -13
  21. package/package.json +1 -1
  22. package/src/lib/components/barchartv2/Barchart.component.test.tsx +23 -25
  23. package/src/lib/components/barchartv2/Barchart.component.tsx +22 -27
  24. package/src/lib/components/barchartv2/BarchartTooltip.test.tsx +3 -3
  25. package/src/lib/components/barchartv2/BarchartTooltip.tsx +14 -18
  26. package/src/lib/components/barchartv2/utils.ts +1 -5
  27. package/src/lib/components/chartlegend/ChartLegendWrapper.tsx +1 -1
  28. package/src/lib/components/charttooltip/ChartTooltip.tsx +40 -0
  29. package/src/lib/components/date/FormattedDateTime.tsx +73 -8
  30. package/src/lib/components/linetimeseriechart/linetimeseriechart.component.tsx +34 -27
  31. package/src/lib/components/linetimeseriechart/utils.test.ts +30 -68
  32. package/src/lib/components/linetimeseriechart/utils.ts +14 -18
  33. package/stories/formattedate.stories.tsx +2 -0
  34. package/stories/linetimeseriechart.stories.tsx +1 -0
@@ -1,87 +1,49 @@
1
1
  import { formatXAxisLabel } from './utils';
2
2
 
3
- const createChartData = (startDate: Date, endDate: Date) => [
4
- { timestamp: startDate.getTime() },
5
- { timestamp: endDate.getTime() },
6
- ];
7
-
8
3
  describe('formatXAxisLabel', () => {
9
4
  const mockTimestamp = new Date('2025-09-15T14:30:00Z').getTime();
10
5
 
11
- describe('date-time format', () => {
12
- it('should format timestamp with day-month-abbreviated-hour-minute format', () => {
13
- const chartData = createChartData(
14
- new Date('2022-01-01'),
15
- new Date('2022-01-02'),
16
- );
17
- const result = formatXAxisLabel(mockTimestamp, 'date-time', chartData);
18
- expect(result).toBe('15 Sept 14:30');
6
+ describe('short duration (≤ 24 hours)', () => {
7
+ it('should format timestamp with time format', () => {
8
+ const duration = 12 * 60 * 60; // 12 hours
9
+ const result = formatXAxisLabel(mockTimestamp, duration);
10
+ expect(result).toBe('14:30');
19
11
  });
20
12
  });
21
13
 
22
- describe('date format', () => {
23
- it('should use YYYY-MM-DD format for time ranges greater than 1 year', () => {
24
- const startDate = new Date('2022-01-01');
25
- const endDate = new Date('2024-01-01'); // More than 1 year
26
- const chartData = createChartData(startDate, endDate);
27
-
28
- const result = formatXAxisLabel(mockTimestamp, 'date', chartData);
29
- expect(result).toBe('2025-09-15');
30
- });
31
-
32
- it('should use MM-DD format for time ranges less than 1 year', () => {
33
- const startDate = new Date('2023-09-01');
34
- const endDate = new Date('2023-12-01'); // Less than 1 year
35
- const chartData = createChartData(startDate, endDate);
36
-
37
- const result = formatXAxisLabel(mockTimestamp, 'date', chartData);
38
- expect(result).toBe('09-15');
14
+ describe('medium duration (≤ 7 days)', () => {
15
+ it('should format timestamp with day-month-abbreviated format', () => {
16
+ const duration = 3 * 24 * 60 * 60; // 3 days
17
+ const result = formatXAxisLabel(mockTimestamp, duration);
18
+ expect(result).toBe('15 Sep');
39
19
  });
20
+ });
40
21
 
41
- it('should use YYYY-MM-DD format when chartData is empty', () => {
42
- const result = formatXAxisLabel(mockTimestamp, 'date', []);
43
- expect(result).toBe('2025-09-15');
44
- });
45
-
46
- it('should handle edge case of exactly 1 year time range', () => {
47
- const startDate = new Date('2022-09-15');
48
- const endDate = new Date('2023-09-15'); // Exactly 1 year
49
- const chartData = createChartData(startDate, endDate);
50
-
51
- const result = formatXAxisLabel(mockTimestamp, 'date', chartData);
52
- expect(result).toBe('09-15');
53
- });
54
-
55
- it('should handle leap year calculation correctly', () => {
56
- const startDate = new Date('2023-01-01');
57
- const endDate = new Date('2024-01-02'); // Just over 1 year including leap year
58
- const chartData = createChartData(startDate, endDate);
59
-
60
- const result = formatXAxisLabel(mockTimestamp, 'date', chartData);
61
-
62
- expect(result).toBe('2025-09-15');
22
+ describe('long duration (> 7 days)', () => {
23
+ it('should format timestamp with day-month-abbreviated-year format', () => {
24
+ const duration = 30 * 24 * 60 * 60; // 30 days
25
+ const result = formatXAxisLabel(mockTimestamp, duration);
26
+ expect(result).toBe('15Sep25');
63
27
  });
64
28
  });
65
29
 
66
- describe('chartData with various scenarios', () => {
67
- it('should handle chartData with single data point', () => {
68
- const chartData = [{ timestamp: mockTimestamp }];
69
-
70
- const result = formatXAxisLabel(mockTimestamp, 'date', chartData);
71
-
72
- expect(result).toBe('09-15');
30
+ describe('edge cases', () => {
31
+ it('should handle exactly 24 hours duration', () => {
32
+ const duration = 24 * 60 * 60; // exactly 24 hours
33
+ const result = formatXAxisLabel(mockTimestamp, duration);
34
+ expect(result).toBe('14:30');
73
35
  });
74
36
 
75
- it('should handle chartData with mixed timestamp values', () => {
76
- const chartData = [
77
- { timestamp: new Date('2023-01-01').getTime() },
78
- { timestamp: new Date('2023-06-01').getTime() },
79
- { timestamp: new Date('2023-12-01').getTime() },
80
- ];
81
-
82
- const result = formatXAxisLabel(mockTimestamp, 'date', chartData);
37
+ it('should handle exactly 7 days duration', () => {
38
+ const duration = 7 * 24 * 60 * 60; // exactly 7 days
39
+ const result = formatXAxisLabel(mockTimestamp, duration);
40
+ expect(result).toBe('15 Sep');
41
+ });
83
42
 
84
- expect(result).toBe('09-15');
43
+ it('should handle just over 7 days duration', () => {
44
+ const duration = 8 * 24 * 60 * 60; // 8 days
45
+ const result = formatXAxisLabel(mockTimestamp, duration);
46
+ expect(result).toBe('15Sep25');
85
47
  });
86
48
  });
87
49
  });
@@ -1,7 +1,7 @@
1
1
  import {
2
- DAY_MONTH_ABBREVIATED_HOUR_MINUTE,
3
- YEAR_MONTH_DAY_FORMATTER,
4
- MONTH_DAY_FORMATTER,
2
+ TIME_FORMATER,
3
+ DAY_MONTH_ABBREVIATED,
4
+ DAY_MONTH_ABBREVIATED_YEAR,
5
5
  } from '../date/FormattedDateTime';
6
6
 
7
7
  export const ONE_YEAR_MILLISECONDS = 366 * 24 * 60 * 60 * 1000;
@@ -22,22 +22,18 @@ export type ChartDataPoint = {
22
22
  */
23
23
  export const formatXAxisLabel = (
24
24
  timestamp: number,
25
- timeFormat: 'date-time' | 'date' = 'date-time',
26
- chartData: ChartDataPoint[] = [],
25
+ duration: number,
27
26
  ): string => {
28
27
  const date = new Date(timestamp);
29
- if (!chartData.length) {
30
- return YEAR_MONTH_DAY_FORMATTER.format(date);
28
+ if (duration <= 24 * 60 * 60) {
29
+ return TIME_FORMATER.format(date);
30
+ } else if (duration <= 7 * 24 * 60 * 60) {
31
+ return DAY_MONTH_ABBREVIATED.format(date)
32
+ .replace(',', '')
33
+ .replace(/Sept/g, 'Sep');
34
+ } else {
35
+ return DAY_MONTH_ABBREVIATED_YEAR.format(date)
36
+ .replace(/[ ,]/g, '')
37
+ .replace(/Sept/g, 'Sep');
31
38
  }
32
- if (timeFormat === 'date-time') {
33
- return DAY_MONTH_ABBREVIATED_HOUR_MINUTE.format(date).replace(',', '');
34
- }
35
- const timestamps = chartData.map((d) => d.timestamp);
36
- const minTimestamp = Math.min(...timestamps);
37
- const maxTimestamp = Math.max(...timestamps);
38
- const timeRangeMilliseconds = maxTimestamp - minTimestamp;
39
-
40
- return timeRangeMilliseconds >= ONE_YEAR_MILLISECONDS
41
- ? YEAR_MONTH_DAY_FORMATTER.format(date)
42
- : MONTH_DAY_FORMATTER.format(date);
43
39
  };
@@ -31,6 +31,8 @@ export const FormattedDate = {
31
31
  'chart-date' as const,
32
32
  'year-month-day' as const,
33
33
  'month-day' as const,
34
+ 'day-month-abbreviated' as const,
35
+ 'chart-long-term-date' as const,
34
36
  ].map((format) => (
35
37
  <tr key={format}>
36
38
  <td>{format}</td>
@@ -837,6 +837,7 @@ export const DynamicColorSetExample: Story = {
837
837
  ]}
838
838
  title="Dynamic Chart 2"
839
839
  height={200}
840
+ unitRange={UNIT_RANGE_BS}
840
841
  startingTimeStamp={Number(prometheusData3[0][0])}
841
842
  isLoading={false}
842
843
  yAxisType={'percentage'}