@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.
- package/dist/components/barchartv2/Barchart.component.d.ts +3 -4
- package/dist/components/barchartv2/Barchart.component.d.ts.map +1 -1
- package/dist/components/barchartv2/Barchart.component.js +13 -21
- package/dist/components/barchartv2/BarchartTooltip.d.ts +1 -1
- package/dist/components/barchartv2/BarchartTooltip.d.ts.map +1 -1
- package/dist/components/barchartv2/BarchartTooltip.js +6 -6
- package/dist/components/barchartv2/utils.d.ts.map +1 -1
- package/dist/components/chartlegend/ChartLegendWrapper.js +1 -1
- package/dist/components/charttooltip/ChartTooltip.d.ts +6 -0
- package/dist/components/charttooltip/ChartTooltip.d.ts.map +1 -1
- package/dist/components/charttooltip/ChartTooltip.js +22 -0
- package/dist/components/date/FormattedDateTime.d.ts +23 -8
- package/dist/components/date/FormattedDateTime.d.ts.map +1 -1
- package/dist/components/date/FormattedDateTime.js +51 -7
- package/dist/components/linetimeseriechart/linetimeseriechart.component.d.ts +2 -1
- package/dist/components/linetimeseriechart/linetimeseriechart.component.d.ts.map +1 -1
- package/dist/components/linetimeseriechart/linetimeseriechart.component.js +15 -13
- package/dist/components/linetimeseriechart/utils.d.ts +1 -1
- package/dist/components/linetimeseriechart/utils.d.ts.map +1 -1
- package/dist/components/linetimeseriechart/utils.js +13 -13
- package/package.json +1 -1
- package/src/lib/components/barchartv2/Barchart.component.test.tsx +23 -25
- package/src/lib/components/barchartv2/Barchart.component.tsx +22 -27
- package/src/lib/components/barchartv2/BarchartTooltip.test.tsx +3 -3
- package/src/lib/components/barchartv2/BarchartTooltip.tsx +14 -18
- package/src/lib/components/barchartv2/utils.ts +1 -5
- package/src/lib/components/chartlegend/ChartLegendWrapper.tsx +1 -1
- package/src/lib/components/charttooltip/ChartTooltip.tsx +40 -0
- package/src/lib/components/date/FormattedDateTime.tsx +73 -8
- package/src/lib/components/linetimeseriechart/linetimeseriechart.component.tsx +34 -27
- package/src/lib/components/linetimeseriechart/utils.test.ts +30 -68
- package/src/lib/components/linetimeseriechart/utils.ts +14 -18
- package/stories/formattedate.stories.tsx +2 -0
- 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('
|
|
12
|
-
it('should format timestamp with
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
|
|
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('
|
|
23
|
-
it('should
|
|
24
|
-
const
|
|
25
|
-
const
|
|
26
|
-
|
|
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
|
-
|
|
42
|
-
|
|
43
|
-
|
|
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('
|
|
67
|
-
it('should handle
|
|
68
|
-
const
|
|
69
|
-
|
|
70
|
-
|
|
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
|
|
76
|
-
const
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
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
|
-
|
|
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
|
-
|
|
3
|
-
|
|
4
|
-
|
|
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
|
-
|
|
26
|
-
chartData: ChartDataPoint[] = [],
|
|
25
|
+
duration: number,
|
|
27
26
|
): string => {
|
|
28
27
|
const date = new Date(timestamp);
|
|
29
|
-
if (
|
|
30
|
-
return
|
|
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
|
};
|