@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,168 @@
1
+ import type { Meta, StoryObj } from '@storybook/react';
2
+ import { Sparkline } from '../src/lib/components/sparkline/sparkline.component';
3
+ import { lineColor5, lineColor6 } from '../src/lib/style/theme';
4
+
5
+ const meta: Meta<typeof Sparkline> = {
6
+ title: 'Components/Data Display/Charts/Sparkline',
7
+ component: Sparkline,
8
+ parameters: {
9
+ layout: 'centered',
10
+ },
11
+ tags: ['autodocs'],
12
+ argTypes: {
13
+ serie: {
14
+ control: 'object',
15
+ description: 'Data series containing array of [timestamp, value] pairs'
16
+ },
17
+ startingTimeStamp: {
18
+ control: 'number',
19
+ description: 'Starting timestamp in seconds for the data series'
20
+ },
21
+ sampleDuration: {
22
+ control: 'number',
23
+ description: 'Total duration in seconds to cover in the sparkline'
24
+ },
25
+ sampleInterval: {
26
+ control: 'number',
27
+ description: 'Interval in seconds between data points'
28
+ },
29
+ },
30
+ decorators: [
31
+ (Story) => (
32
+ <div style={{ width: 200, height: 100 }}>
33
+ <Story />
34
+ </div>
35
+ ),
36
+ ],
37
+ };
38
+
39
+ export default meta;
40
+ type Story = StoryObj<typeof Sparkline>;
41
+
42
+ // Sample data for different scenarios
43
+ const volatileData: [number, number][] = [
44
+ [1740405600, 25.32],
45
+ [1740406320, 78.45],
46
+ [1740407040, 45.67],
47
+ [1740407760, 15.67],
48
+ [1740408480, 92.33],
49
+ [1740409200, 8.91],
50
+ [1740409920, 88.76],
51
+ [1740410640, 34.22],
52
+ [1740411360, 67.89],
53
+ [1740412080, 12.45],
54
+ [1740412800, 95.67],
55
+ ];
56
+
57
+ const trendingUpData: [number, number][] = [
58
+ [1740405600, 10.5],
59
+ [1740406320, 15.2],
60
+ [1740407040, 20.3],
61
+ [1740407760, 18.9],
62
+ [1740408480, 22.1],
63
+ [1740409200, 28.7],
64
+ [1740409920, 35.4],
65
+ [1740410640, 42.8],
66
+ [1740411360, 48.3],
67
+ [1740412080, 55.9],
68
+ [1740412800, 62.1],
69
+ ];
70
+
71
+ const trendingDownData: [number, number][] = [
72
+ [1740405600, 70.5],
73
+ [1740406320, 65.2],
74
+ [1740407040, 58.9],
75
+ [1740407760, 58.9],
76
+ [1740408480, 52.1],
77
+ [1740409200, 48.7],
78
+ [1740409920, 35.4],
79
+ [1740410640, 32.8],
80
+ [1740411360, 28.3],
81
+ [1740412080, 25.9],
82
+ [1740412800, 22.1],
83
+ ];
84
+
85
+ const flatData: [number, number|null][] = [
86
+ [1740405600, 50.0],
87
+ [1740406320, 50.0],
88
+ [1740407760, 50.0],
89
+ [1740409200, 50.0],
90
+ [1740409920, 50.0],
91
+ [1740410640, 50.0],
92
+ [1740412080, 50.0],
93
+ [1740412800, 50.0],
94
+ ];
95
+
96
+ export const Default: Story = {
97
+ args: {
98
+ serie: {
99
+ data: volatileData,
100
+ },
101
+ startingTimeStamp: 1740405600,
102
+ sampleDuration: 7200,
103
+ sampleInterval: 720,
104
+ },
105
+ parameters: {
106
+ docs: {
107
+ description: {
108
+ story: 'Sparkline displaying highly volatile data with frequent peaks and valleys.',
109
+ },
110
+ },
111
+ },
112
+ };
113
+
114
+ export const TrendingUp: Story = {
115
+ args: {
116
+ serie: {
117
+ data: trendingUpData,
118
+ color: lineColor5, // Optional custom color (green)
119
+ },
120
+ startingTimeStamp: 1740405600,
121
+ sampleDuration: 7200,
122
+ sampleInterval: 720,
123
+ },
124
+ parameters: {
125
+ docs: {
126
+ description: {
127
+ story: 'Sparkline showing a clear upward trend over time.',
128
+ },
129
+ },
130
+ },
131
+ };
132
+
133
+ export const TrendingDown: Story = {
134
+ args: {
135
+ serie: {
136
+ data: trendingDownData,
137
+ color: lineColor6,
138
+ },
139
+ startingTimeStamp: 1740405600,
140
+ sampleDuration: 7200,
141
+ sampleInterval: 720,
142
+ },
143
+ parameters: {
144
+ docs: {
145
+ description: {
146
+ story: 'Sparkline illustrating a downward trend over time.',
147
+ },
148
+ },
149
+ },
150
+ };
151
+
152
+ export const FlatWithMissingData: Story = {
153
+ args: {
154
+ serie: {
155
+ data: flatData,
156
+ },
157
+ startingTimeStamp: 1740405600,
158
+ sampleDuration: 7200,
159
+ sampleInterval: 720,
160
+ },
161
+ parameters: {
162
+ docs: {
163
+ description: {
164
+ story: 'Sparkline representing stable data with some missing values.',
165
+ },
166
+ },
167
+ },
168
+ };
@@ -1,14 +0,0 @@
1
- import { BarchartBars, BarchartTooltipFn, CategoryType, TimeType } from './Barchart.component';
2
- import { TooltipContentProps } from 'recharts';
3
- export declare const ChartTooltipContainer: import("styled-components").StyledComponent<"div", import("styled-components").DefaultTheme, {}, never>;
4
- export declare const ChartTooltipItem: import("styled-components").StyledComponent<"div", import("styled-components").DefaultTheme, {
5
- isHovered: boolean;
6
- }, never>;
7
- export declare const ChartTooltip: <T extends BarchartBars>({ type, tooltipProps, colorSet, hoveredValue, tooltip, }: {
8
- type: TimeType | CategoryType;
9
- tooltipProps: TooltipContentProps<number, string>;
10
- colorSet?: Record<string, string>;
11
- hoveredValue: string | undefined;
12
- tooltip?: BarchartTooltipFn<T>;
13
- }) => string | number | boolean | Iterable<import("react").ReactNode> | import("react/jsx-runtime").JSX.Element | null | undefined;
14
- //# sourceMappingURL=ChartTooltip.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ChartTooltip.d.ts","sourceRoot":"","sources":["../../../src/lib/components/barchartv2/ChartTooltip.tsx"],"names":[],"mappings":"AAGA,OAAO,EACL,YAAY,EACZ,iBAAiB,EACjB,YAAY,EACZ,QAAQ,EACT,MAAM,sBAAsB,CAAC;AAI9B,OAAO,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAC;AAG/C,eAAO,MAAM,qBAAqB,yGAYjC,CAAC;AAEF,eAAO,MAAM,gBAAgB;eAA2B,OAAO;SAM9D,CAAC;AAEF,eAAO,MAAM,YAAY,GAAI,CAAC,SAAS,YAAY,4DAMhD;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;CAChC,iIAwDA,CAAC"}
@@ -1,41 +0,0 @@
1
- import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
2
- import styled from 'styled-components';
3
- import { spacing, Stack, Wrap } from '../../spacing';
4
- import { Text } from '../text/Text.component';
5
- import { fontSize, fontWeight } from '../../style/theme';
6
- import { LegendShape } from '../chartlegend/ChartLegend';
7
- import { FormattedDateTime } from '../date/FormattedDateTime';
8
- import { getCurrentPoint } from './utils';
9
- export const ChartTooltipContainer = styled.div `
10
- background-color: ${({ theme }) => theme.backgroundLevel1};
11
- padding: ${spacing.r4} ${spacing.r8};
12
- border-radius: 4px;
13
- width: max-content;
14
- max-width: 40rem;
15
- border: 1px solid ${({ theme }) => theme.border};
16
- display: flex;
17
- font-size: ${fontSize.small};
18
- flex-direction: column;
19
- gap: 16px;
20
- align-items: center;
21
- `;
22
- export const ChartTooltipItem = styled.div `
23
- display: flex;
24
- align-items: center;
25
- gap: 8px;
26
- font-weight: ${({ isHovered }) => isHovered ? fontWeight.bold : fontWeight.base};
27
- `;
28
- export const ChartTooltip = ({ type, tooltipProps, colorSet, hoveredValue, tooltip, }) => {
29
- const { active } = tooltipProps;
30
- if (!active) {
31
- return null;
32
- }
33
- const currentPoint = getCurrentPoint(tooltipProps, hoveredValue);
34
- if (tooltip) {
35
- return tooltip(currentPoint);
36
- }
37
- return (_jsxs(ChartTooltipContainer, { children: [_jsx(Text, { isEmphazed: true, children: type.type === 'time' ? (_jsxs(_Fragment, { children: [_jsx(FormattedDateTime, { format: "long-date", value: new Date(currentPoint.category) }), ' ', type.type === 'time' &&
38
- type.timeRange.interval < 24 * 60 * 60 * 1000 && (_jsx(FormattedDateTime, { format: "time", value: new Date(currentPoint.category) }))] })) : (currentPoint.category) }), _jsx(Stack, { direction: "vertical", gap: "r8", style: { width: '100%' }, children: currentPoint.values.map((value) => {
39
- return (_jsxs(Wrap, { gap: spacing.r32, children: [_jsxs(ChartTooltipItem, { isHovered: value.isHovered, children: [colorSet && (_jsx(LegendShape, { color: colorSet[value.label], shape: "rectangle", chartColors: colorSet })), value.label] }), _jsx(ChartTooltipItem, { isHovered: value.isHovered, children: value.value })] }, value.label));
40
- }) })] }));
41
- };
@@ -1,106 +0,0 @@
1
- import styled from 'styled-components';
2
- import { spacing, Stack, Wrap } from '../../spacing';
3
- import { Text } from '../text/Text.component';
4
- import {
5
- BarchartBars,
6
- BarchartTooltipFn,
7
- CategoryType,
8
- TimeType,
9
- } from './Barchart.component';
10
- import { fontSize, fontWeight } from '../../style/theme';
11
- import { LegendShape } from '../chartlegend/ChartLegend';
12
- import { FormattedDateTime } from '../date/FormattedDateTime';
13
- import { TooltipContentProps } from 'recharts';
14
- import { getCurrentPoint } from './utils';
15
-
16
- export const ChartTooltipContainer = styled.div`
17
- background-color: ${({ theme }) => theme.backgroundLevel1};
18
- padding: ${spacing.r4} ${spacing.r8};
19
- border-radius: 4px;
20
- width: max-content;
21
- max-width: 40rem;
22
- border: 1px solid ${({ theme }) => theme.border};
23
- display: flex;
24
- font-size: ${fontSize.small};
25
- flex-direction: column;
26
- gap: 16px;
27
- align-items: center;
28
- `;
29
-
30
- export const ChartTooltipItem = styled.div<{ isHovered: boolean }>`
31
- display: flex;
32
- align-items: center;
33
- gap: 8px;
34
- font-weight: ${({ isHovered }) =>
35
- isHovered ? fontWeight.bold : fontWeight.base};
36
- `;
37
-
38
- export const ChartTooltip = <T extends BarchartBars>({
39
- type,
40
- tooltipProps,
41
- colorSet,
42
- hoveredValue,
43
- tooltip,
44
- }: {
45
- type: TimeType | CategoryType;
46
- tooltipProps: TooltipContentProps<number, string>;
47
- colorSet?: Record<string, string>;
48
- hoveredValue: string | undefined;
49
- tooltip?: BarchartTooltipFn<T>;
50
- }) => {
51
- const { active } = tooltipProps;
52
-
53
- if (!active) {
54
- return null;
55
- }
56
-
57
- const currentPoint = getCurrentPoint(tooltipProps, hoveredValue);
58
- if (tooltip) {
59
- return tooltip(currentPoint);
60
- }
61
-
62
- return (
63
- <ChartTooltipContainer>
64
- <Text isEmphazed>
65
- {type.type === 'time' ? (
66
- <>
67
- <FormattedDateTime
68
- format="long-date"
69
- value={new Date(currentPoint.category)}
70
- />{' '}
71
- {type.type === 'time' &&
72
- type.timeRange.interval < 24 * 60 * 60 * 1000 && (
73
- <FormattedDateTime
74
- format="time"
75
- value={new Date(currentPoint.category)}
76
- />
77
- )}
78
- </>
79
- ) : (
80
- currentPoint.category
81
- )}
82
- </Text>
83
- <Stack direction="vertical" gap="r8" style={{ width: '100%' }}>
84
- {currentPoint.values.map((value) => {
85
- return (
86
- <Wrap key={value.label} gap={spacing.r32}>
87
- <ChartTooltipItem isHovered={value.isHovered}>
88
- {colorSet && (
89
- <LegendShape
90
- color={colorSet[value.label as keyof typeof colorSet]}
91
- shape="rectangle"
92
- chartColors={colorSet}
93
- />
94
- )}
95
- {value.label}
96
- </ChartTooltipItem>
97
- <ChartTooltipItem isHovered={value.isHovered}>
98
- {value.value}
99
- </ChartTooltipItem>
100
- </Wrap>
101
- );
102
- })}
103
- </Stack>
104
- </ChartTooltipContainer>
105
- );
106
- };