@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
@@ -1,4 +1,5 @@
1
1
  import { CoreUITheme } from '../../style/theme';
2
+ export type TextVariant = 'ChartTitle' | 'Basic' | 'Smaller' | 'Larger' | 'Large' | 'Small';
2
3
  type Status = 'unknown' | 'healthy' | 'warning' | 'critical';
3
4
  type Props = {
4
5
  children: React.ReactNode | string;
@@ -22,7 +23,7 @@ export declare const GentleEmphaseSecondaryText: import("styled-components").Sty
22
23
  alignRight?: boolean;
23
24
  }, never>;
24
25
  export declare const Text: import("styled-components").StyledComponent<"span", import("styled-components").DefaultTheme, {
25
- variant?: "ChartTitle" | "Basic" | "Smaller" | "Larger" | "Large";
26
+ variant?: TextVariant;
26
27
  color?: keyof CoreUITheme;
27
28
  isEmphazed?: boolean;
28
29
  isGentleEmphazed?: boolean;
@@ -1 +1 @@
1
- {"version":3,"file":"Text.component.d.ts","sourceRoot":"","sources":["../../../src/lib/components/text/Text.component.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAGhD,KAAK,MAAM,GAAG,SAAS,GAAG,SAAS,GAAG,SAAS,GAAG,UAAU,CAAC;AAC7D,KAAK,KAAK,GAAG;IACX,QAAQ,EAAE,KAAK,CAAC,SAAS,GAAG,MAAM,CAAC;IACnC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,EAAE,CAAC,EAAE,MAAM,CAAC;CACb,CAAC;AAsDF,eAAO,MAAM,uBAAuB;iBACrB,MAAM;SAIpB,CAAC;AAIF,wBAAgB,SAAS,CAAC,EAAE,QAAQ,EAAE,GAAG,IAAI,EAAE,EAAE,KAAK,2CAErD;AACD,wBAAgB,aAAa,CAAC,EAAE,QAAQ,EAAE,GAAG,IAAI,EAAE,EA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AAC;AAEF,eAAO,MAAM,IAAI,uGAchB,CAAC"}
@@ -116,7 +116,12 @@ export const Text = styled.span `
116
116
  line-height: 1.4;
117
117
  letter-spacing: 2%;// to be defined, percentage value is not valid
118
118
  `
119
- : `
119
+ : props.variant === 'Small'
120
+ ? `
121
+ font-size: 0.85rem;
122
+ line-height: 1.4;
123
+ `
124
+ : `
120
125
  font-size: 1rem;
121
126
  line-height: ${spacing.r24};
122
127
  `}
package/dist/next.d.ts CHANGED
@@ -14,9 +14,11 @@ export { Box } from './components/box/Box';
14
14
  export { Input } from './components/inputv2/inputv2';
15
15
  export { Accordion } from './components/accordion/Accordion.component';
16
16
  export { Barchart, BarchartSortFn, BarchartTooltipFn, } from './components/barchartv2/Barchart.component';
17
- export { ChartTooltip } from './components/barchartv2/ChartTooltip';
18
- export { ChartLegendWrapper } from './components/chartlegend/ChartLegendWrapper';
17
+ export { BarchartTooltip } from './components/barchartv2/BarchartTooltip';
18
+ export { ChartLegendWrapper, useChartId, } from './components/chartlegend/ChartLegendWrapper';
19
19
  export { ChartLegend } from './components/chartlegend/ChartLegend';
20
20
  export { LineTimeSerieChart } from './components/linetimeseriechart/linetimeseriechart.component';
21
+ export { ChartTooltipContainer, ChartTooltipItem, ChartTooltipHeader, ChartTooltipItemsContainer, } from './components/charttooltip/ChartTooltip';
21
22
  export { CoreUITheme } from './style/theme';
23
+ export { GlobalHealthBar } from './components/globalhealthbar/GlobalHealthBarRecharts.component';
22
24
  //# sourceMappingURL=next.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"next.d.ts","sourceRoot":"","sources":["../src/lib/next.ts"],"names":[],"mappings":"AAAA,OAAO,2CAA2C,CAAC;AACnD,OAAO,aAAa,CAAC;AACrB,OAAO,EAAE,MAAM,EAAE,MAAM,0CAA0C,CAAC;AAClE,OAAO,EAAE,UAAU,EAAE,MAAM,4CAA4C,CAAC;AACxE,OAAO,EAAE,IAAI,EAAE,GAAG,EAAE,MAAM,sCAAsC,CAAC;AACjE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M,4DAA4D,CAAC;AAC/F,OAAO,EACL,uBAAuB,EACvB,kBAAkB,GACnB,MAAM,uDAAuD,CAAC;AAC/D,OAAO,EAAE,kBAAkB,EAAE,MAAM,6CAA6C,CAAC;AACjF,OAAO,EAAE,MAAM,EAAE,MAAM,0CAA0C,CAAC;AAClE,OAAO,EAAE,cAAc,EAAE,MAAM,wDAAwD,CAAC;AACxF,OAAO,EAAE,mBAAmB,EAAE,MAAM,sDAAsD,CAAC;AAC3F,OAAO,EAAE,GAAG,EAAE,MAAM,sBAAsB,CAAC;AAC3C,OAAO,EAAE,KAAK,EAAE,MAAM,8BAA8B,CAAC;AACrD,OAAO,EAAE,SAAS,EAAE,MAAM,4CAA4C,CAAC;AACvE,OAAO,EACL,QAAQ,EACR,cAAc,EACd,iBAAiB,GAClB,MAAM,4CAA4C,CAAC;AACpD,OAAO,EAAE,eAAe,EAAE,MAAM,yCAAyC,CAAC;AAC1E,OAAO,EACL,kBAAkB,EAClB,UAAU,GACX,MAAM,6CAA6C,CAAC;AACrD,OAAO,EAAE,WAAW,EAAE,MAAM,sCAAsC,CAAC;AACnE,OAAO,EAAE,kBAAkB,EAAE,MAAM,8DAA8D,CAAC;AAClG,OAAO,EACL,qBAAqB,EACrB,gBAAgB,EAChB,kBAAkB,EAClB,0BAA0B,GAC3B,MAAM,wCAAwC,CAAC;AAChD,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,eAAe,EAAE,MAAM,gEAAgE,CAAC"}
package/dist/next.js CHANGED
@@ -14,7 +14,9 @@ export { Box } from './components/box/Box';
14
14
  export { Input } from './components/inputv2/inputv2';
15
15
  export { Accordion } from './components/accordion/Accordion.component';
16
16
  export { Barchart, } from './components/barchartv2/Barchart.component';
17
- export { ChartTooltip } from './components/barchartv2/ChartTooltip';
18
- export { ChartLegendWrapper } from './components/chartlegend/ChartLegendWrapper';
17
+ export { BarchartTooltip } from './components/barchartv2/BarchartTooltip';
18
+ export { ChartLegendWrapper, useChartId, } from './components/chartlegend/ChartLegendWrapper';
19
19
  export { ChartLegend } from './components/chartlegend/ChartLegend';
20
20
  export { LineTimeSerieChart } from './components/linetimeseriechart/linetimeseriechart.component';
21
+ export { ChartTooltipContainer, ChartTooltipItem, ChartTooltipHeader, ChartTooltipItemsContainer, } from './components/charttooltip/ChartTooltip';
22
+ export { GlobalHealthBar } from './components/globalhealthbar/GlobalHealthBarRecharts.component';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@scality/core-ui",
3
- "version": "0.170.0",
3
+ "version": "0.172.0",
4
4
  "description": "Scality common React component library",
5
5
  "author": "Scality Engineering",
6
6
  "license": "SEE LICENSE IN LICENSE",
@@ -20,7 +20,7 @@
20
20
  "prepare": "npm run build",
21
21
  "postbuild": "npm run copy-files",
22
22
  "test": "jest",
23
- "storybook": "storybook dev -p 3000",
23
+ "storybook": "storybook dev -p 3001",
24
24
  "build-storybook": "storybook build",
25
25
  "storybook:deploy": "npm run build-storybook && gh-pages -d storybook-static -u \"github-actions-bot <support+actions@github.com>\""
26
26
  },
@@ -61,6 +61,7 @@
61
61
  "@types/react-window": "^1.8.5",
62
62
  "@types/styled-components": "^5.1.25",
63
63
  "@types/styled-system": "^5.1.15",
64
+ "@types/uuid": "^10.0.0",
64
65
  "@typescript-eslint/eslint-plugin": "^6.12.0",
65
66
  "@typescript-eslint/parser": "^6.12.0",
66
67
  "copyfiles": "^2.4.1",
@@ -109,6 +110,7 @@
109
110
  "recharts": "^3.0.2",
110
111
  "styled-components": "^5.2.1",
111
112
  "styled-system": "^5.1.5",
113
+ "uuid": "^13.0.0",
112
114
  "vega": "^5.17.3",
113
115
  "vega-embed": "6.0.0",
114
116
  "vega-lite": "5.0.0",
@@ -20,17 +20,17 @@ import { FormattedDateTime } from '../date/FormattedDateTime';
20
20
  import { IconHelp } from '../iconhelper/IconHelper';
21
21
  import { Loader } from '../loader/Loader.component';
22
22
  import { Text } from '../text/Text.component';
23
- import { ChartTooltip } from './ChartTooltip';
23
+ import { BarchartTooltip } from './BarchartTooltip';
24
24
  import { UnitRange, useChartData } from './utils';
25
25
 
26
26
  const CHART_CONSTANTS = {
27
- TICK_WIDTH_OFFSET: 5,
27
+ TICK_WIDTH_OFFSET: 4,
28
28
  BAR_SIZE: 12,
29
29
  MIN_POINT_SIZE: 3,
30
30
  DEFAULT_HEIGHT: 200,
31
31
  CHART_MARGIN: {
32
32
  left: 0,
33
- right: 0,
33
+ right: -10,
34
34
  top: 0,
35
35
  bottom: 0,
36
36
  },
@@ -393,12 +393,13 @@ export const Barchart = <T extends BarchartBars>(props: BarchartProps<T>) => {
393
393
 
394
394
  <Tooltip
395
395
  content={(props: TooltipContentProps<number, string>) => (
396
- <ChartTooltip
396
+ <BarchartTooltip
397
397
  type={type}
398
398
  colorSet={colorSet}
399
399
  tooltipProps={props}
400
400
  hoveredValue={hoveredValue}
401
401
  tooltip={tooltip}
402
+ unitLabel={unitLabel}
402
403
  />
403
404
  )}
404
405
  cursor={false}
@@ -1,6 +1,6 @@
1
1
  import React from 'react';
2
2
  import { render, screen } from '@testing-library/react';
3
- import { ChartTooltip } from './ChartTooltip';
3
+ import { BarchartTooltip } from './BarchartTooltip';
4
4
 
5
5
  const ONE_DAY_IN_MILLISECONDS = 24 * 60 * 60 * 1000;
6
6
  const ONE_HOUR_IN_MILLISECONDS = 60 * 60 * 1000;
@@ -27,12 +27,13 @@ describe('ChartTooltip', () => {
27
27
  successValue: () => screen.queryByText(SUCCESS_VALUE),
28
28
  failed: () => screen.queryByText(/Failed/),
29
29
  failedValue: () => screen.queryByText(FAILED_VALUE),
30
- date: () => screen.queryByText(/Monday, 01 July 2024/),
31
- time: () => screen.queryByText(/00:00/),
30
+ longDate: () => screen.queryByText(/01 July 2024/),
31
+ date: () => screen.queryByText(/\b01 Jul\b/),
32
+ time: () => screen.queryByText(/00:00:00/),
32
33
  };
33
- it('should render the ChartTooltip component', () => {
34
+ it('should render the BarchartTooltip component', () => {
34
35
  render(
35
- <ChartTooltip
36
+ <BarchartTooltip
36
37
  type={{ type: 'category' }}
37
38
  tooltipProps={testTooltipProps}
38
39
  hoveredValue="Success"
@@ -47,7 +48,7 @@ describe('ChartTooltip', () => {
47
48
  });
48
49
  it('should render tooltip when tooltip is provided', () => {
49
50
  render(
50
- <ChartTooltip
51
+ <BarchartTooltip
51
52
  type={{ type: 'category' }}
52
53
  tooltipProps={testTooltipProps}
53
54
  hoveredValue="Success"
@@ -58,7 +59,7 @@ describe('ChartTooltip', () => {
58
59
  });
59
60
  it('should not render tooltip when tooltipProps is not active', () => {
60
61
  render(
61
- <ChartTooltip
62
+ <BarchartTooltip
62
63
  type={{ type: 'category' }}
63
64
  tooltipProps={{ ...testTooltipProps, active: false }}
64
65
  hoveredValue="Success"
@@ -71,7 +72,7 @@ describe('ChartTooltip', () => {
71
72
  // timestamp for Mon Jul 01 2024 00:00:00 GMT+0000 (Coordinated Universal Time)
72
73
  const label = date;
73
74
  render(
74
- <ChartTooltip
75
+ <BarchartTooltip
75
76
  type={{
76
77
  type: 'time',
77
78
  timeRange: {
@@ -84,19 +85,18 @@ describe('ChartTooltip', () => {
84
85
  hoveredValue="Success"
85
86
  />,
86
87
  );
87
-
88
88
  expect(selectors.success()).toBeInTheDocument();
89
89
  expect(selectors.successValue()).toBeInTheDocument();
90
90
  expect(selectors.failed()).toBeInTheDocument();
91
91
  expect(selectors.failedValue()).toBeInTheDocument();
92
-
93
- expect(selectors.date()).toBeInTheDocument();
92
+ expect(selectors.date()).not.toBeInTheDocument();
93
+ expect(selectors.longDate()).toBeInTheDocument();
94
94
  expect(selectors.time()).not.toBeInTheDocument();
95
95
  });
96
96
  it('should render time tooltip when type is time and interval is one hour', () => {
97
97
  const label = date;
98
98
  render(
99
- <ChartTooltip
99
+ <BarchartTooltip
100
100
  type={{
101
101
  type: 'time',
102
102
  timeRange: {
@@ -114,6 +114,29 @@ describe('ChartTooltip', () => {
114
114
  expect(selectors.failed()).toBeInTheDocument();
115
115
  expect(selectors.failedValue()).toBeInTheDocument();
116
116
  expect(selectors.date()).toBeInTheDocument();
117
+ expect(selectors.longDate()).not.toBeInTheDocument();
117
118
  expect(selectors.time()).toBeInTheDocument();
118
119
  });
120
+ it('should render with correctly formatted values when unitLabel is provided', () => {
121
+ const FREE_VALUE = 123.456789;
122
+ const USED_VALUE = 20;
123
+ const tooltipProps = {
124
+ ...testTooltipProps,
125
+ payload: [
126
+ { name: 'Free', value: FREE_VALUE },
127
+ { name: 'Used', value: USED_VALUE },
128
+ ],
129
+ };
130
+ render(
131
+ <BarchartTooltip
132
+ type={{ type: 'category' }}
133
+ tooltipProps={tooltipProps}
134
+ hoveredValue="Success"
135
+ unitLabel="kB"
136
+ />,
137
+ );
138
+
139
+ expect(screen.getByText('123.46 kB')).toBeInTheDocument();
140
+ expect(screen.getByText('20 kB')).toBeInTheDocument();
141
+ });
119
142
  });
@@ -0,0 +1,89 @@
1
+ import {
2
+ BarchartBars,
3
+ BarchartTooltipFn,
4
+ CategoryType,
5
+ TimeType,
6
+ } from './Barchart.component';
7
+ import { FormattedDateTime } from '../date/FormattedDateTime';
8
+ import { TooltipContentProps } from 'recharts';
9
+ import { getCurrentPoint } from './utils';
10
+ import {
11
+ ChartTooltipContainer,
12
+ ChartTooltipItem,
13
+ ChartTooltipHeader,
14
+ ChartTooltipItemsContainer,
15
+ } from '../charttooltip/ChartTooltip';
16
+ import { LegendShape } from '../chartlegend/ChartLegend';
17
+
18
+ export const BarchartTooltip = <T extends BarchartBars>({
19
+ type,
20
+ tooltipProps,
21
+ colorSet,
22
+ hoveredValue,
23
+ tooltip,
24
+ unitLabel,
25
+ }: {
26
+ type: TimeType | CategoryType;
27
+ tooltipProps: TooltipContentProps<number, string>;
28
+ colorSet?: Record<string, string>;
29
+ hoveredValue: string | undefined;
30
+ tooltip?: BarchartTooltipFn<T>;
31
+ unitLabel?: string;
32
+ }) => {
33
+ const { active } = tooltipProps;
34
+
35
+ if (!active) {
36
+ return null;
37
+ }
38
+
39
+ const currentPoint = getCurrentPoint(tooltipProps, hoveredValue);
40
+ if (tooltip) {
41
+ return tooltip(currentPoint);
42
+ }
43
+
44
+ return (
45
+ <ChartTooltipContainer>
46
+ <ChartTooltipHeader>
47
+ {type.type === 'time' ? (
48
+ <FormattedDateTime
49
+ format={
50
+ type.timeRange.interval < 24 * 60 * 60 * 1000
51
+ ? 'day-month-abbreviated-hour-minute-second'
52
+ : 'long-date-without-weekday'
53
+ }
54
+ value={new Date(currentPoint.category)}
55
+ />
56
+ ) : (
57
+ currentPoint.category
58
+ )}
59
+ </ChartTooltipHeader>
60
+ <ChartTooltipItemsContainer>
61
+ {currentPoint.values.map((value) => {
62
+ const legendIcon = colorSet && (
63
+ <LegendShape
64
+ color={colorSet[value.label as keyof typeof colorSet]}
65
+ shape="rectangle"
66
+ chartColors={colorSet}
67
+ />
68
+ );
69
+
70
+ const formattedValue = Number.isInteger(value.value)
71
+ ? `${value.value}`
72
+ : value.value.toFixed(2);
73
+ const valueWithUnit = unitLabel
74
+ ? `${formattedValue} ${unitLabel}`
75
+ : formattedValue;
76
+ return (
77
+ <ChartTooltipItem
78
+ key={value.label}
79
+ label={value.label}
80
+ value={valueWithUnit}
81
+ isHovered={value.isHovered}
82
+ legendIcon={legendIcon}
83
+ />
84
+ );
85
+ })}
86
+ </ChartTooltipItemsContainer>
87
+ </ChartTooltipContainer>
88
+ );
89
+ };
@@ -1,6 +1,6 @@
1
1
  import styled from 'styled-components';
2
2
  import { useChartLegend } from './ChartLegendWrapper';
3
- import { Text } from '../text/Text.component';
3
+ import { Text, TextVariant } from '../text/Text.component';
4
4
  import { chartColors } from '../../style/theme';
5
5
  import { useCallback } from 'react';
6
6
 
@@ -8,6 +8,7 @@ type ChartLegendProps = {
8
8
  shape: 'line' | 'rectangle';
9
9
  disabled?: boolean;
10
10
  direction?: 'horizontal' | 'vertical';
11
+ legendSize?: TextVariant;
11
12
  };
12
13
 
13
14
  const Legend = styled.div<{ direction: 'horizontal' | 'vertical' }>`
@@ -65,6 +66,7 @@ export const ChartLegend = ({
65
66
  shape,
66
67
  disabled = false,
67
68
  direction = 'horizontal',
69
+ legendSize = 'Basic',
68
70
  }: ChartLegendProps) => {
69
71
  const {
70
72
  listResources,
@@ -132,7 +134,7 @@ export const ChartLegend = ({
132
134
  shape={shape}
133
135
  chartColors={chartColors}
134
136
  />
135
- <Text variant="Basic">{resource}</Text>
137
+ <Text variant={legendSize}>{resource}</Text>
136
138
  </LegendItem>
137
139
  );
138
140
  })}
@@ -0,0 +1,197 @@
1
+ import { render, screen } from '@testing-library/react';
2
+ import React, { useEffect } from 'react';
3
+ import {
4
+ ChartLegendWrapper,
5
+ useChartId,
6
+ useChartLegend,
7
+ } from './ChartLegendWrapper';
8
+ import { ChartLegend } from './ChartLegend';
9
+ import userEvent from '@testing-library/user-event';
10
+
11
+ describe('ChartLegendWrapper', () => {
12
+ beforeEach(() => {
13
+ jest.clearAllMocks();
14
+ });
15
+
16
+ const TestChart = ({ seriesNames }: { seriesNames: string[] }) => {
17
+ const chartId = useChartId();
18
+ const { register } = useChartLegend();
19
+
20
+ useEffect(() => {
21
+ register(chartId, seriesNames);
22
+ }, [chartId, register, seriesNames]);
23
+
24
+ return <div data-testid={`chart-${chartId}`}>Test Chart</div>;
25
+ };
26
+
27
+ const generateColors = (seriesNames: string[]) => {
28
+ const colors: Record<string, string> = {};
29
+ const colorPalette = ['red', 'blue', 'green', 'yellow', 'purple'];
30
+ seriesNames.forEach((name, index) => {
31
+ colors[name] = colorPalette[index % colorPalette.length];
32
+ });
33
+ return colors;
34
+ };
35
+
36
+ describe('Dynamic Color Generation', () => {
37
+ it('should generate colors dynamically based on registered series', () => {
38
+ render(
39
+ <ChartLegendWrapper colorSet={generateColors}>
40
+ <TestChart seriesNames={['CPU', 'Memory']} />
41
+ <ChartLegend shape="line" />
42
+ </ChartLegendWrapper>,
43
+ );
44
+
45
+ expect(screen.getByText('CPU')).toBeInTheDocument();
46
+ expect(screen.getByText('Memory')).toBeInTheDocument();
47
+ expect(screen.getByLabelText('CPU selected')).toBeInTheDocument();
48
+ expect(screen.getByLabelText('Memory selected')).toBeInTheDocument();
49
+ });
50
+
51
+ it('should handle multiple charts with overlapping series', () => {
52
+ const TestChart1 = () => {
53
+ const chartId = useChartId();
54
+ const { register } = useChartLegend();
55
+
56
+ useEffect(() => {
57
+ register(chartId, ['CPU', 'Memory']);
58
+ }, [chartId, register]);
59
+
60
+ return <div data-testid={`chart1-${chartId}`}>Test Chart 1</div>;
61
+ };
62
+
63
+ const TestChart2 = () => {
64
+ const chartId = useChartId();
65
+ const { register } = useChartLegend();
66
+
67
+ useEffect(() => {
68
+ register(chartId, ['CPU', 'Disk']);
69
+ }, [chartId, register]);
70
+
71
+ return <div data-testid={`chart2-${chartId}`}>Test Chart 2</div>;
72
+ };
73
+
74
+ render(
75
+ <ChartLegendWrapper colorSet={generateColors}>
76
+ <TestChart1 />
77
+ <TestChart2 />
78
+ <ChartLegend shape="line" />
79
+ </ChartLegendWrapper>,
80
+ );
81
+
82
+ // Should show unique series from both charts
83
+ expect(screen.getByText('CPU')).toBeInTheDocument();
84
+ expect(screen.getByText('Memory')).toBeInTheDocument();
85
+ expect(screen.getByText('Disk')).toBeInTheDocument();
86
+
87
+ // All should be selected by default
88
+ expect(screen.getByLabelText('CPU selected')).toBeInTheDocument();
89
+ expect(screen.getByLabelText('Memory selected')).toBeInTheDocument();
90
+ expect(screen.getByLabelText('Disk selected')).toBeInTheDocument();
91
+ });
92
+
93
+ it('should handle empty series registration', () => {
94
+ render(
95
+ <ChartLegendWrapper colorSet={generateColors}>
96
+ <TestChart seriesNames={[]} />
97
+ <ChartLegend shape="line" />
98
+ </ChartLegendWrapper>,
99
+ );
100
+
101
+ // Should not crash and should render empty legend
102
+ expect(screen.queryByRole('button')).not.toBeInTheDocument();
103
+ });
104
+
105
+ it('should maintain selection state when new series are added', () => {
106
+ const { rerender } = render(
107
+ <ChartLegendWrapper colorSet={generateColors}>
108
+ <TestChart seriesNames={['CPU']} />
109
+ <ChartLegend shape="line" />
110
+ </ChartLegendWrapper>,
111
+ );
112
+
113
+ // Initially only CPU
114
+ expect(screen.getByText('CPU')).toBeInTheDocument();
115
+ expect(screen.getByLabelText('CPU selected')).toBeInTheDocument();
116
+
117
+ // Select only CPU
118
+ userEvent.click(screen.getByText('CPU'));
119
+ expect(screen.getByLabelText('CPU selected')).toBeInTheDocument();
120
+
121
+ // Add more series
122
+ rerender(
123
+ <ChartLegendWrapper colorSet={generateColors}>
124
+ <TestChart seriesNames={['CPU', 'Memory']} />
125
+ <ChartLegend shape="line" />
126
+ </ChartLegendWrapper>,
127
+ );
128
+
129
+ // New series should be added and all should be selected (reset behavior)
130
+ expect(screen.getByText('CPU')).toBeInTheDocument();
131
+ expect(screen.getByText('Memory')).toBeInTheDocument();
132
+ expect(screen.getByLabelText('CPU selected')).toBeInTheDocument();
133
+ expect(screen.getByLabelText('Memory selected')).toBeInTheDocument();
134
+ });
135
+
136
+ it('should work with different chart configurations', () => {
137
+ render(
138
+ <ChartLegendWrapper colorSet={generateColors}>
139
+ <TestChart seriesNames={['Series1', 'Series2', 'Series3']} />
140
+ <ChartLegend shape="rectangle" direction="vertical" />
141
+ </ChartLegendWrapper>,
142
+ );
143
+
144
+ expect(screen.getByText('Series1')).toBeInTheDocument();
145
+ expect(screen.getByText('Series2')).toBeInTheDocument();
146
+ expect(screen.getByText('Series3')).toBeInTheDocument();
147
+ });
148
+ });
149
+
150
+ describe('Static Color Set', () => {
151
+ const staticColorSet = {
152
+ CPU: 'red',
153
+ Memory: 'blue',
154
+ Disk: 'green',
155
+ };
156
+
157
+ it('should work with static color sets', () => {
158
+ render(
159
+ <ChartLegendWrapper colorSet={staticColorSet}>
160
+ <ChartLegend shape="line" />
161
+ </ChartLegendWrapper>,
162
+ );
163
+
164
+ expect(screen.getByText('CPU')).toBeInTheDocument();
165
+ expect(screen.getByText('Memory')).toBeInTheDocument();
166
+ expect(screen.getByText('Disk')).toBeInTheDocument();
167
+ });
168
+
169
+ it('should ignore registration when using static color sets', () => {
170
+ render(
171
+ <ChartLegendWrapper colorSet={staticColorSet}>
172
+ <TestChart seriesNames={['DifferentSeries']} />
173
+ <ChartLegend shape="line" />
174
+ </ChartLegendWrapper>,
175
+ );
176
+
177
+ // Should only show static color set items, not registered series
178
+ expect(screen.getByText('CPU')).toBeInTheDocument();
179
+ expect(screen.getByText('Memory')).toBeInTheDocument();
180
+ expect(screen.getByText('Disk')).toBeInTheDocument();
181
+ expect(screen.queryByText('DifferentSeries')).not.toBeInTheDocument();
182
+ });
183
+ });
184
+
185
+ describe('Error Handling', () => {
186
+ it('should throw error when useChartLegend is used outside wrapper', () => {
187
+ const TestComponent = () => {
188
+ useChartLegend();
189
+ return <div>Test</div>;
190
+ };
191
+
192
+ expect(() => render(<TestComponent />)).toThrow(
193
+ 'useChartLegend must be used within a ChartLegendWrapper',
194
+ );
195
+ });
196
+ });
197
+ });