@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
@@ -3,6 +3,14 @@ import { spacing } from '../../spacing';
3
3
  import { CoreUITheme } from '../../style/theme';
4
4
  import { FocusVisibleStyle } from '../buttonv2/Buttonv2.component';
5
5
 
6
+ export type TextVariant =
7
+ | 'ChartTitle'
8
+ | 'Basic'
9
+ | 'Smaller'
10
+ | 'Larger'
11
+ | 'Large'
12
+ | 'Small';
13
+
6
14
  type Status = 'unknown' | 'healthy' | 'warning' | 'critical';
7
15
  type Props = {
8
16
  children: React.ReactNode | string;
@@ -128,7 +136,7 @@ export const GentleEmphaseSecondaryText = styled(SecondaryText)<{
128
136
  `;
129
137
 
130
138
  export const Text = styled.span<{
131
- variant?: 'ChartTitle' | 'Basic' | 'Smaller' | 'Larger' | 'Large';
139
+ variant?: TextVariant;
132
140
  color?: keyof CoreUITheme;
133
141
  isEmphazed?: boolean;
134
142
  isGentleEmphazed?: boolean;
@@ -151,7 +159,12 @@ export const Text = styled.span<{
151
159
  line-height: 1.4;
152
160
  letter-spacing: 2%;// to be defined, percentage value is not valid
153
161
  `
154
- : `
162
+ : props.variant === 'Small'
163
+ ? `
164
+ font-size: 0.85rem;
165
+ line-height: 1.4;
166
+ `
167
+ : `
155
168
  font-size: 1rem;
156
169
  line-height: ${spacing.r24};
157
170
  `}
package/src/lib/next.ts CHANGED
@@ -21,8 +21,18 @@ export {
21
21
  BarchartSortFn,
22
22
  BarchartTooltipFn,
23
23
  } from './components/barchartv2/Barchart.component';
24
- export { ChartTooltip } from './components/barchartv2/ChartTooltip';
25
- export { ChartLegendWrapper } from './components/chartlegend/ChartLegendWrapper';
24
+ export { BarchartTooltip } from './components/barchartv2/BarchartTooltip';
25
+ export {
26
+ ChartLegendWrapper,
27
+ useChartId,
28
+ } from './components/chartlegend/ChartLegendWrapper';
26
29
  export { ChartLegend } from './components/chartlegend/ChartLegend';
27
30
  export { LineTimeSerieChart } from './components/linetimeseriechart/linetimeseriechart.component';
31
+ export {
32
+ ChartTooltipContainer,
33
+ ChartTooltipItem,
34
+ ChartTooltipHeader,
35
+ ChartTooltipItemsContainer,
36
+ } from './components/charttooltip/ChartTooltip';
28
37
  export { CoreUITheme } from './style/theme';
38
+ export { GlobalHealthBar } from './components/globalhealthbar/GlobalHealthBarRecharts.component';
@@ -987,7 +987,13 @@ export const StackedHistogram: Story = {
987
987
  ] as const;
988
988
  const theme = useTheme() as CoreUITheme;
989
989
  return (
990
- <div style={{ width: '50%', padding: spacing.r16 }}>
990
+ <div
991
+ style={{
992
+ width: '50%',
993
+ padding: spacing.r16,
994
+ backgroundColor: theme.backgroundLevel2,
995
+ }}
996
+ >
991
997
  <ChartLegendWrapper
992
998
  colorSet={{
993
999
  'Test 1': theme.statusHealthy,
@@ -0,0 +1,145 @@
1
+ import React, { useState } from 'react';
2
+ import { Meta, StoryObj } from '@storybook/react';
3
+ import {
4
+ Alert,
5
+ GlobalHealthBar,
6
+ GlobalHealthProps,
7
+ } from '../../src/lib/components/globalhealthbar/GlobalHealthBarRecharts.component';
8
+
9
+ import {
10
+ DATE_FORMATER,
11
+ TIME_SECOND_FORMATER,
12
+ } from '../../src/lib/components/date/FormattedDateTime';
13
+ import {
14
+ MetricsTimeSpanProvider,
15
+ useMetricsTimeSpan,
16
+ } from '../../src/lib/next';
17
+ import { Dropdown, Icon, Stack } from '../../src/lib';
18
+ import {
19
+ LAST_ONE_HOUR,
20
+ LAST_SEVEN_DAYS,
21
+ LAST_TWENTY_FOUR_HOURS,
22
+ SAMPLE_DURATION_LAST_ONE_HOUR,
23
+ SAMPLE_DURATION_LAST_SEVEN_DAYS,
24
+ SAMPLE_DURATION_LAST_TWENTY_FOUR_HOURS,
25
+ } from '../../src/lib/components/constants';
26
+
27
+ type Story = StoryObj<GlobalHealthProps>;
28
+
29
+ const meta: Meta<GlobalHealthProps> = {
30
+ title: 'Components/GlobalHealthBarRecharts',
31
+ component: GlobalHealthBar,
32
+ };
33
+ export default meta;
34
+
35
+ const start = '2021-01-30T23:00:00Z'; // UTC time
36
+ const end = '2021-02-06T23:00:00Z';
37
+ const start2 = '2021-01-29T14:00:00Z';
38
+ const end2 = '2021-02-05T14:00:00Z';
39
+ const startLast24h = '2021-02-01T00:00:00Z';
40
+ const endLast24h = '2021-02-02T00:00:00Z';
41
+ const startLastHour = '2021-02-01T00:00:00Z';
42
+ const endLastHour = '2021-02-01T01:00:00Z';
43
+
44
+ const alerts = [
45
+ {
46
+ id: '0',
47
+ severity: 'unavailable',
48
+ startsAt: '2021-02-01T00:00:00Z',
49
+ endsAt: '2021-02-01T01:00:00Z',
50
+ description: 'Global health unavailable',
51
+ },
52
+ {
53
+ id: '1',
54
+ severity: 'critical',
55
+ startsAt: '2021-02-01T11:00:00Z',
56
+ endsAt: '2021-02-02T11:00:00Z',
57
+ description: 'Global health critical',
58
+ },
59
+ {
60
+ id: '2',
61
+ severity: 'warning',
62
+ startsAt: '2021-02-01T23:00:00Z',
63
+ endsAt: '2021-02-02T22:00:00Z',
64
+ description: 'Global health warning',
65
+ },
66
+ {
67
+ severity: 'critical',
68
+ startsAt: '2021-02-03T00:00:00Z',
69
+ endsAt: '2021-02-04T00:00:00Z',
70
+ description:
71
+ 'Global health critical Long descritpion so it takes more space. Add more text to see how it wraps.',
72
+ },
73
+ {
74
+ id: '4',
75
+ severity: 'warning',
76
+ startsAt: '2021-02-04T10:00:00Z',
77
+ endsAt: '2021-02-06T00:00:00Z',
78
+ description:
79
+ 'Global health warning Long descritpion so it takes more space. Add more text to see how it wraps.',
80
+ },
81
+ {
82
+ id: '5',
83
+ severity: 'warning',
84
+ startsAt: '2021-02-06T12:00:00Z',
85
+ endsAt: '2021-02-07T00:00:00Z',
86
+ description:
87
+ 'Global health warning Long descritpion so it takes more space. Add more text to see how it wraps.',
88
+ },
89
+ {
90
+ id: '6',
91
+ severity: 'warning',
92
+ startsAt: '2021-01-30T22:00:00Z',
93
+ endsAt: '2021-01-30T23:00:00Z',
94
+ description:
95
+ 'Global health warning Long descritpion so it takes more space. Add more text to see how it wraps.',
96
+ },
97
+ {
98
+ id: '7',
99
+ severity: 'warning',
100
+ startsAt: '2021-02-01T00:47:30Z',
101
+ endsAt: '2021-02-01T01:30:00Z',
102
+ description:
103
+ 'Global health warning Long descritpion so it takes more space. Add more text to see how it wraps.',
104
+ },
105
+ ];
106
+
107
+ export const Default: Story = {
108
+ args: {
109
+ start: new Date(start),
110
+ end: new Date(end),
111
+ alerts: alerts as Alert[],
112
+ },
113
+ };
114
+
115
+ export const Last24Hours: Story = {
116
+ render: () => {
117
+ return (
118
+ <div style={{ width: '350px', height: '1000px', overflow: 'hidden' }}>
119
+ <div style={{ width: '500px', height: '400px' }} />
120
+ <GlobalHealthBar
121
+ start={new Date(startLast24h)}
122
+ end={new Date(endLast24h)}
123
+ alerts={alerts as Alert[]}
124
+ id="1"
125
+ />
126
+ </div>
127
+ );
128
+ },
129
+ };
130
+
131
+ export const LastHour: Story = {
132
+ render: () => {
133
+ return (
134
+ <div style={{ width: '250px', height: '1000px', overflow: 'hidden' }}>
135
+ <div style={{ width: '400px', height: '400px' }} />
136
+ <GlobalHealthBar
137
+ start={new Date(startLastHour)}
138
+ end={new Date(endLastHour)}
139
+ alerts={alerts as Alert[]}
140
+ id="1"
141
+ />
142
+ </div>
143
+ );
144
+ },
145
+ };
@@ -0,0 +1,5 @@
1
+ import { Meta } from '@storybook/blocks';
2
+ import { GlobalHealthBar } from '../../src/lib/components/globalhealthbar/GlobalHealthBarRecharts.component';
3
+ import * as GlobalHealthBarStories from './globalhealthbarRecharts.stories';
4
+
5
+ <Meta name="Guideline" of={GlobalHealthBarStories} />
@@ -26,7 +26,13 @@ export default {
26
26
  });
27
27
  },
28
28
  });
29
- return <InlineInput {...args} changeMutation={changeMutation} />;
29
+ return (
30
+ <InlineInput
31
+ id="inline-input-story"
32
+ {...args}
33
+ changeMutation={changeMutation}
34
+ />
35
+ );
30
36
  },
31
37
  };
32
38
 
@@ -1,7 +1,9 @@
1
1
  import React from 'react';
2
- import { GlobalHealthBar } from '../src/lib/components/globalhealthbar/GlobalHealthBar.component';
2
+ import { GlobalHealthBar } from '../src/lib/components/globalhealthbar/GlobalHealthBarRecharts.component';
3
+ import { GlobalHealthBar as VegaGlobalHealthBar } from '../src/lib/components/globalhealthbar/GlobalHealthBar.component';
3
4
  import { SyncedCursorCharts } from '../src/lib/components/vegachartv2/SyncedCursorCharts';
4
5
  import { Wrapper } from './common';
6
+ import { Stack } from '../src/lib/spacing';
5
7
  const alerts = [
6
8
  {
7
9
  id: '1',
@@ -34,10 +36,17 @@ const alerts = [
34
36
  {
35
37
  id: '5',
36
38
  severity: 'warning',
37
- startsAt: '2021-02-06T12:00:00Z',
39
+ startsAt: '2021-02-06T10:00:00Z',
38
40
  endsAt: '2021-02-06T20:00:00Z',
39
41
  description: 'Global health warning',
40
42
  },
43
+ {
44
+ id: '6',
45
+ severity: 'warning',
46
+ startsAt: '2021-02-06T12:00:00Z',
47
+ endsAt: '2021-02-06T22:30:00Z',
48
+ description: 'Global health warning',
49
+ },
41
50
  ];
42
51
  const alertsLast24h = [
43
52
  {
@@ -75,7 +84,7 @@ const alertRetrieveBefore = [
75
84
  id: '2',
76
85
  severity: 'critical',
77
86
  startsAt: '2021-02-05T23:00:00Z',
78
- endsAt: '2021-02-06T21:00:00Z',
87
+ endsAt: '2021-02-07T00:00:00Z',
79
88
  description: 'Global health warning',
80
89
  },
81
90
  ];
@@ -105,13 +114,18 @@ const endNotFirstDay = '2021-03-01T23:00:00Z';
105
114
 
106
115
  export default {
107
116
  title: 'Components/Data Display/Charts/GlobalHealthBar',
108
- component: GlobalHealthBar,
117
+ component: (props) => (
118
+ <Stack direction="vertical">
119
+ <GlobalHealthBar {...props} />
120
+ <VegaGlobalHealthBar {...props} />
121
+ </Stack>
122
+ ),
109
123
  decorators: [
110
124
  (story) => (
111
125
  <Wrapper
112
126
  style={{ minHeight: '50vh', display: 'flex', alignItems: 'center' }}
113
127
  >
114
- <div style={{ width: '500px' }}>
128
+ <div style={{ width: '500px', height: '400px' }}>
115
129
  <SyncedCursorCharts>{story()}</SyncedCursorCharts>
116
130
  </div>
117
131
  </Wrapper>
@@ -120,6 +134,7 @@ export default {
120
134
  args: {
121
135
  start,
122
136
  end,
137
+ width: 500,
123
138
  },
124
139
  argTypes: {
125
140
  start: {
@@ -135,6 +150,7 @@ export const GlobalHealthComponentDemo = {
135
150
  args: {
136
151
  id: 'vis_globalhealth',
137
152
  alerts,
153
+ width: 500,
138
154
  },
139
155
  };
140
156
 
@@ -144,12 +160,14 @@ export const GlobalHealthLast24Hours = {
144
160
  alerts: alertsLast24h,
145
161
  start: startLast24h,
146
162
  end: endLast24h,
163
+ width: 500,
147
164
  },
148
165
  };
149
166
  export const GlobalHealthEmpty = {
150
167
  args: {
151
168
  id: 'vis_globalhealth_empty',
152
169
  alerts: emptyAlert,
170
+ width: 500,
153
171
  },
154
172
  };
155
173
 
@@ -157,6 +175,7 @@ export const AlertTriggeredEarlierThanTheStartingTime = {
157
175
  args: {
158
176
  id: 'vis_globalhealth_alert_retrieve_before',
159
177
  alerts: alertRetrieveBefore,
178
+ width: 500,
160
179
  },
161
180
  };
162
181
 
@@ -167,5 +186,6 @@ export const FirstLabel = {
167
186
  alerts: alertTriggerNotFirstDay,
168
187
  start: startNotFirstDay,
169
188
  end: endNotFirstDay,
189
+ width: 500,
170
190
  },
171
191
  };
@@ -1,13 +1,22 @@
1
1
  import React from 'react';
2
2
  import { Meta, StoryObj } from '@storybook/react';
3
- import { LineTimeSerieChart } from '../src/lib/components/linetimeseriechart/linetimeseriechart.component';
3
+ import {
4
+ LineTimeSerieChart,
5
+ Serie,
6
+ } from '../src/lib/components/linetimeseriechart/linetimeseriechart.component';
4
7
  import { ChartLegendWrapper } from '../src/lib/components/chartlegend/ChartLegendWrapper';
5
8
  import { lineTimeSeriesColorRange } from '../src/lib/style/theme';
6
9
  import { ChartLegend } from '../src/lib/components/chartlegend/ChartLegend';
10
+ import {
11
+ useChartId,
12
+ useChartLegend,
13
+ } from '../src/lib/components/chartlegend/ChartLegendWrapper';
14
+ import { useEffect } from 'react';
7
15
  import {
8
16
  SAMPLE_DURATION_LAST_TWENTY_FOUR_HOURS,
9
17
  SAMPLE_FREQUENCY_LAST_TWENTY_FOUR_HOURS,
10
18
  } from '../src/lib/components/constants';
19
+ import { Button } from '../src/lib/components/buttonv2/Buttonv2.component';
11
20
 
12
21
  const ChartWithProviders = (props) => {
13
22
  return (
@@ -634,3 +643,210 @@ export const DateFormatExample: Story = {
634
643
  timeFormat: 'date',
635
644
  },
636
645
  };
646
+
647
+ export const SyncIdExample: Story = {
648
+ render: () => {
649
+ return (
650
+ <ChartLegendWrapper
651
+ colorSet={{
652
+ 'ip-10-160-122-207.eu-north-1.compute.internal':
653
+ lineTimeSeriesColorRange[0],
654
+ 'ip-10-160-122-207.eu-north-2.compute.internal':
655
+ lineTimeSeriesColorRange[1],
656
+ }}
657
+ >
658
+ <LineTimeSerieChart
659
+ syncId="sync-id"
660
+ series={{
661
+ above: [
662
+ {
663
+ data: prometheusData as [number, string | number | null][],
664
+ resource: 'ip-10-160-122-207.eu-north-1.compute.internal',
665
+ metricPrefix: 'in',
666
+ getTooltipLabel: (prefix, resource) => `${resource}-${prefix}`,
667
+ },
668
+ {
669
+ data: prometheusData2 as [number, string | number | null][],
670
+ resource: 'ip-10-160-122-207.eu-north-2.compute.internal',
671
+ metricPrefix: 'in',
672
+ getTooltipLabel: (prefix, resource) => `${resource}-${prefix}`,
673
+ },
674
+ ],
675
+ below: [
676
+ {
677
+ data: prometheusData3 as [number, string | number | null][],
678
+ resource: 'ip-10-160-122-207.eu-north-1.compute.internal',
679
+ metricPrefix: 'out',
680
+ getTooltipLabel: (prefix, resource) => `${resource}-${prefix}`,
681
+ },
682
+ {
683
+ data: prometheusData4 as [number, string | number | null][],
684
+ resource: 'ip-10-160-122-207.eu-north-2.compute.internal',
685
+ metricPrefix: 'out',
686
+ getTooltipLabel: (prefix, resource) => `${resource}-${prefix}`,
687
+ },
688
+ ],
689
+ }}
690
+ title="ControlPlane Bandwidth"
691
+ height={200}
692
+ startingTimeStamp={Number(prometheusData[0][0])}
693
+ unitRange={UNIT_RANGE_BS}
694
+ isLoading={false}
695
+ yAxisType={'symmetrical'}
696
+ yAxisTitle={'in(+)/out(-)'}
697
+ interval={SAMPLE_FREQUENCY_LAST_TWENTY_FOUR_HOURS}
698
+ duration={SAMPLE_DURATION_LAST_TWENTY_FOUR_HOURS}
699
+ />
700
+
701
+ <LineTimeSerieChart
702
+ syncId="sync-id"
703
+ series={{
704
+ above: [
705
+ {
706
+ data: prometheusData2 as [number, string | number | null][],
707
+ resource: 'ip-10-160-122-207.eu-north-1.compute.internal',
708
+ metricPrefix: 'in',
709
+ getTooltipLabel: (prefix, resource) => `${resource}-${prefix}`,
710
+ },
711
+ ],
712
+ below: [],
713
+ }}
714
+ title="ControlPlane Bandwidth 2"
715
+ height={200}
716
+ startingTimeStamp={Number(prometheusData2[0][0])}
717
+ unitRange={UNIT_RANGE_BS}
718
+ isLoading={false}
719
+ yAxisType={'symmetrical'}
720
+ yAxisTitle={'in(+)/out(-)'}
721
+ interval={SAMPLE_FREQUENCY_LAST_TWENTY_FOUR_HOURS}
722
+ duration={SAMPLE_DURATION_LAST_TWENTY_FOUR_HOURS}
723
+ />
724
+ <ChartLegend shape="line" direction="vertical" />
725
+ </ChartLegendWrapper>
726
+ );
727
+ },
728
+ };
729
+ export const CustomTooltipExample: Story = {
730
+ args: {
731
+ series: [
732
+ {
733
+ data: prometheusData,
734
+ resource: 'ip-10-160-122-207.eu-north-1.compute.internal',
735
+ metricPrefix: 'instance:10.160.122.207:9100',
736
+ getTooltipLabel: (prefix, resource) => `${resource}`,
737
+ },
738
+ ],
739
+ title: 'CPU Usage',
740
+ height: 200,
741
+ startingTimeStamp: prometheusData[0][0],
742
+ isLoading: false,
743
+ isLegendHidden: false,
744
+ helpText: 'This is the help text',
745
+ yAxisType: 'percentage',
746
+ yAxisTitle: '',
747
+ interval: SAMPLE_FREQUENCY_LAST_TWENTY_FOUR_HOURS,
748
+ duration: SAMPLE_DURATION_LAST_TWENTY_FOUR_HOURS,
749
+ timeFormat: 'date-time',
750
+ renderTooltip: (props) => {
751
+ return <div>Custom Tooltip</div>;
752
+ },
753
+ },
754
+ };
755
+
756
+ // Dynamic colorSet example components
757
+ const DynamicChart1 = (props) => {
758
+ const chartId = useChartId();
759
+ const { register } = useChartLegend();
760
+
761
+ useEffect(() => {
762
+ register(chartId, [
763
+ 'ip-10-160-122-207.eu-north-1.compute.internal',
764
+ 'ip-10-160-122-207.eu-north-2.compute.internal',
765
+ ]);
766
+ }, [chartId, register]);
767
+
768
+ return <LineTimeSerieChart {...props} />;
769
+ };
770
+
771
+ const DynamicChart2 = (props) => {
772
+ const chartId = useChartId();
773
+ const { register } = useChartLegend();
774
+
775
+ useEffect(() => {
776
+ register(chartId, ['ip-10-160-122-207.eu-north-1.compute.internal']);
777
+ }, [chartId, register]);
778
+
779
+ return <LineTimeSerieChart {...props} />;
780
+ };
781
+
782
+ const generateColors = (seriesNames: string[]) => {
783
+ const colors: Record<string, string> = {};
784
+ seriesNames.forEach((name, index) => {
785
+ colors[name] =
786
+ lineTimeSeriesColorRange[index % lineTimeSeriesColorRange.length];
787
+ });
788
+ return colors;
789
+ };
790
+
791
+ export const DynamicColorSetExample: Story = {
792
+ render: () => {
793
+ return (
794
+ <ChartLegendWrapper colorSet={generateColors}>
795
+ <div style={{ marginBottom: '20px' }}>
796
+ <h3>Chart 1 - Multiple Series</h3>
797
+ <DynamicChart1
798
+ series={{
799
+ above: [
800
+ {
801
+ data: prometheusData as [number, string | number | null][],
802
+ resource: 'ip-10-160-122-207.eu-north-1.compute.internal',
803
+ metricPrefix: 'in',
804
+ getTooltipLabel: (prefix, resource) =>
805
+ `${resource}-${prefix}`,
806
+ },
807
+ {
808
+ data: prometheusData2 as [number, string | number | null][],
809
+ resource: 'ip-10-160-122-207.eu-north-2.compute.internal',
810
+ metricPrefix: 'in',
811
+ getTooltipLabel: (prefix, resource) =>
812
+ `${resource}-${prefix}`,
813
+ },
814
+ ],
815
+ below: [],
816
+ }}
817
+ title="Dynamic Chart 1"
818
+ height={200}
819
+ startingTimeStamp={Number(prometheusData[0][0])}
820
+ isLoading={false}
821
+ yAxisType={'symmetrical'}
822
+ interval={SAMPLE_FREQUENCY_LAST_TWENTY_FOUR_HOURS}
823
+ duration={SAMPLE_DURATION_LAST_TWENTY_FOUR_HOURS}
824
+ />
825
+ </div>
826
+
827
+ <div style={{ marginBottom: '20px' }}>
828
+ <h3>Chart 2 - Single Series (Overlapping with Chart 1)</h3>
829
+ <DynamicChart2
830
+ series={[
831
+ {
832
+ data: prometheusData3 as [number, string | number | null][],
833
+ resource: 'ip-10-160-122-207.eu-north-1.compute.internal',
834
+ metricPrefix: 'instance:10.160.122.207:9100',
835
+ getTooltipLabel: (prefix, resource) => `${resource}`,
836
+ },
837
+ ]}
838
+ title="Dynamic Chart 2"
839
+ height={200}
840
+ startingTimeStamp={Number(prometheusData3[0][0])}
841
+ isLoading={false}
842
+ yAxisType={'percentage'}
843
+ interval={SAMPLE_FREQUENCY_LAST_TWENTY_FOUR_HOURS}
844
+ duration={SAMPLE_DURATION_LAST_TWENTY_FOUR_HOURS}
845
+ />
846
+ </div>
847
+
848
+ <ChartLegend shape="line" direction="vertical" />
849
+ </ChartLegendWrapper>
850
+ );
851
+ },
852
+ };