@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,11 @@
1
+ // Mock uuid module for Jest tests
2
+ let counter = 0;
3
+
4
+ const v4 = () => {
5
+ counter += 1;
6
+ return `mock-uuid-${Math.random().toString(36)}-${counter}`;
7
+ };
8
+
9
+ module.exports = {
10
+ v4,
11
+ };
@@ -1 +1 @@
1
- {"version":3,"file":"Barchart.component.d.ts","sourceRoot":"","sources":["../../../src/lib/components/barchartv2/Barchart.component.tsx"],"names":[],"mappings":"AAuBA,OAAO,EAAE,SAAS,EAAgB,MAAM,SAAS,CAAC;AAiBlD,MAAM,MAAM,QAAQ,GAAG;IACrB,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE;QACT,SAAS,EAAE,IAAI,CAAC;QAChB,OAAO,EAAE,IAAI,CAAC;QACd,QAAQ,EAAE,MAAM,CAAC;KAClB,CAAC;CACH,CAAC;AAEF,MAAM,MAAM,YAAY,GAAG;IACzB,IAAI,EAAE,UAAU,CAAC;IACjB,GAAG,CAAC,EAAE,MAAM,CAAC;CACd,CAAC;AACF,MAAM,MAAM,KAAK,GAAG;IAClB,GAAG,EAAE,MAAM,GAAG,MAAM,CAAC;IACrB,MAAM,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;CAC5C,CAAC;AAEF,MAAM,MAAM,YAAY,GAAG,SAAS;IAClC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB;;;OAGG;IACH,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC,SAAS,CAAC,MAAM,GAAG,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC,CAAC,EAAE,CAAC;CACvE,EAAE,CAAC;AAEJ,MAAM,MAAM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CAAC,SAAS,CAAC;IAC7B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB,CAAC;AAEF,UAAU,eAAe;IACvB,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IACV,OAAO,EAAE;QACP,KAAK,EAAE,MAAM,CAAC;KACf,CAAC;IACF,iBAAiB,EAAE,MAAM,CAAC;IAC1B,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,QAAQ,CAAC;CAChB;AAID;;;;;GAKG;AACH,eAAO,MAAM,UAAU,cACV,MAAM,YACP,MAAM,KACf,KAAK,CAAC,SAoBR,CAAC;AAEF,eAAO,MAAM,UAAU,uDAOpB,eAAe,4CAkCjB,CAAC;AA2EF,eAAO,MAAM,QAAQ,GAAI,CAAC,SAAS,YAAY,SAAS,aAAa,CAAC,CAAC,CAAC,4CAsJvE,CAAC"}
1
+ {"version":3,"file":"Barchart.component.d.ts","sourceRoot":"","sources":["../../../src/lib/components/barchartv2/Barchart.component.tsx"],"names":[],"mappings":"AAuBA,OAAO,EAAE,SAAS,EAAgB,MAAM,SAAS,CAAC;AAiBlD,MAAM,MAAM,QAAQ,GAAG;IACrB,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE;QACT,SAAS,EAAE,IAAI,CAAC;QAChB,OAAO,EAAE,IAAI,CAAC;QACd,QAAQ,EAAE,MAAM,CAAC;KAClB,CAAC;CACH,CAAC;AAEF,MAAM,MAAM,YAAY,GAAG;IACzB,IAAI,EAAE,UAAU,CAAC;IACjB,GAAG,CAAC,EAAE,MAAM,CAAC;CACd,CAAC;AACF,MAAM,MAAM,KAAK,GAAG;IAClB,GAAG,EAAE,MAAM,GAAG,MAAM,CAAC;IACrB,MAAM,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;CAC5C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CAAC;IACtB,WAAW,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IAC9B,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB;;;;;OAKG;IACH,cAAc,CAAC,EAAE,SAAS,GAAG,QAAQ,CAAC;IACtC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,UAAU,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IAC7B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB,CAAC;AAEF,UAAU,eAAe;IACvB,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IACV,OAAO,EAAE;QACP,KAAK,EAAE,MAAM,CAAC;KACf,CAAC;IACF,iBAAiB,EAAE,MAAM,CAAC;IAC1B,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,QAAQ,CAAC;CAChB;AAID;;;;;GAKG;AACH,eAAO,MAAM,UAAU,cACV,MAAM,YACP,MAAM,KACf,KAAK,CAAC,SAoBR,CAAC;AAEF,eAAO,MAAM,UAAU,uDAOpB,eAAe,4CAkCjB,CAAC;AA2EF,eAAO,MAAM,QAAQ,GAAI,CAAC,SAAS,YAAY,SAAS,aAAa,CAAC,CAAC,CAAC,4CAuJvE,CAAC"}
@@ -11,16 +11,16 @@ import { FormattedDateTime } from '../date/FormattedDateTime';
11
11
  import { IconHelp } from '../iconhelper/IconHelper';
12
12
  import { Loader } from '../loader/Loader.component';
13
13
  import { Text } from '../text/Text.component';
14
- import { ChartTooltip } from './ChartTooltip';
14
+ import { BarchartTooltip } from './BarchartTooltip';
15
15
  import { useChartData } from './utils';
16
16
  const CHART_CONSTANTS = {
17
- TICK_WIDTH_OFFSET: 5,
17
+ TICK_WIDTH_OFFSET: 4,
18
18
  BAR_SIZE: 12,
19
19
  MIN_POINT_SIZE: 3,
20
20
  DEFAULT_HEIGHT: 200,
21
21
  CHART_MARGIN: {
22
22
  left: 0,
23
- right: 0,
23
+ right: -10,
24
24
  top: 0,
25
25
  bottom: 0,
26
26
  },
@@ -122,5 +122,5 @@ export const Barchart = (props) => {
122
122
  stroke: theme.textSecondary,
123
123
  }, axisLine: {
124
124
  stroke: theme.textSecondary,
125
- } }), _jsx(Tooltip, { content: (props) => (_jsx(ChartTooltip, { type: type, colorSet: colorSet, tooltipProps: props, hoveredValue: hoveredValue, tooltip: tooltip })), cursor: false })] }) }))] }));
125
+ } }), _jsx(Tooltip, { content: (props) => (_jsx(BarchartTooltip, { type: type, colorSet: colorSet, tooltipProps: props, hoveredValue: hoveredValue, tooltip: tooltip, unitLabel: unitLabel })), cursor: false })] }) }))] }));
126
126
  };
@@ -0,0 +1,11 @@
1
+ import { BarchartBars, BarchartTooltipFn, CategoryType, TimeType } from './Barchart.component';
2
+ import { TooltipContentProps } from 'recharts';
3
+ export declare const BarchartTooltip: <T extends BarchartBars>({ type, tooltipProps, colorSet, hoveredValue, tooltip, unitLabel, }: {
4
+ type: TimeType | CategoryType;
5
+ tooltipProps: TooltipContentProps<number, string>;
6
+ colorSet?: Record<string, string>;
7
+ hoveredValue: string | undefined;
8
+ tooltip?: BarchartTooltipFn<T>;
9
+ unitLabel?: string;
10
+ }) => string | number | boolean | Iterable<import("react").ReactNode> | import("react/jsx-runtime").JSX.Element | null | undefined;
11
+ //# sourceMappingURL=BarchartTooltip.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"BarchartTooltip.d.ts","sourceRoot":"","sources":["../../../src/lib/components/barchartv2/BarchartTooltip.tsx"],"names":[],"mappings":"AAAA,OAAO,EACL,YAAY,EACZ,iBAAiB,EACjB,YAAY,EACZ,QAAQ,EACT,MAAM,sBAAsB,CAAC;AAE9B,OAAO,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAC;AAU/C,eAAO,MAAM,eAAe,GAAI,CAAC,SAAS,YAAY,uEAOnD;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;IAC/B,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,iIAyDA,CAAC"}
@@ -0,0 +1,27 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { FormattedDateTime } from '../date/FormattedDateTime';
3
+ import { getCurrentPoint } from './utils';
4
+ import { ChartTooltipContainer, ChartTooltipItem, ChartTooltipHeader, ChartTooltipItemsContainer, } from '../charttooltip/ChartTooltip';
5
+ import { LegendShape } from '../chartlegend/ChartLegend';
6
+ export const BarchartTooltip = ({ type, tooltipProps, colorSet, hoveredValue, tooltip, unitLabel, }) => {
7
+ const { active } = tooltipProps;
8
+ if (!active) {
9
+ return null;
10
+ }
11
+ const currentPoint = getCurrentPoint(tooltipProps, hoveredValue);
12
+ if (tooltip) {
13
+ return tooltip(currentPoint);
14
+ }
15
+ return (_jsxs(ChartTooltipContainer, { children: [_jsx(ChartTooltipHeader, { children: type.type === 'time' ? (_jsx(FormattedDateTime, { format: type.timeRange.interval < 24 * 60 * 60 * 1000
16
+ ? 'day-month-abbreviated-hour-minute-second'
17
+ : 'long-date-without-weekday', value: new Date(currentPoint.category) })) : (currentPoint.category) }), _jsx(ChartTooltipItemsContainer, { children: currentPoint.values.map((value) => {
18
+ const legendIcon = colorSet && (_jsx(LegendShape, { color: colorSet[value.label], shape: "rectangle", chartColors: colorSet }));
19
+ const formattedValue = Number.isInteger(value.value)
20
+ ? `${value.value}`
21
+ : value.value.toFixed(2);
22
+ const valueWithUnit = unitLabel
23
+ ? `${formattedValue} ${unitLabel}`
24
+ : formattedValue;
25
+ return (_jsx(ChartTooltipItem, { label: value.label, value: valueWithUnit, isHovered: value.isHovered, legendIcon: legendIcon }, value.label));
26
+ }) })] }));
27
+ };
@@ -1,7 +1,9 @@
1
+ import { TextVariant } from '../text/Text.component';
1
2
  type ChartLegendProps = {
2
3
  shape: 'line' | 'rectangle';
3
4
  disabled?: boolean;
4
5
  direction?: 'horizontal' | 'vertical';
6
+ legendSize?: TextVariant;
5
7
  };
6
8
  export declare const LegendItem: import("styled-components").StyledComponent<"div", import("styled-components").DefaultTheme, {
7
9
  disabled?: boolean;
@@ -12,6 +14,6 @@ export declare const LegendShape: import("styled-components").StyledComponent<"d
12
14
  shape: "line" | "rectangle";
13
15
  chartColors: Record<string, string>;
14
16
  }, never>;
15
- export declare const ChartLegend: ({ shape, disabled, direction, }: ChartLegendProps) => import("react/jsx-runtime").JSX.Element;
17
+ export declare const ChartLegend: ({ shape, disabled, direction, legendSize, }: ChartLegendProps) => import("react/jsx-runtime").JSX.Element;
16
18
  export {};
17
19
  //# sourceMappingURL=ChartLegend.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"ChartLegend.d.ts","sourceRoot":"","sources":["../../../src/lib/components/chartlegend/ChartLegend.tsx"],"names":[],"mappings":"AAMA,KAAK,gBAAgB,GAAG;IACtB,KAAK,EAAE,MAAM,GAAG,WAAW,CAAC;IAC5B,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,SAAS,CAAC,EAAE,YAAY,GAAG,UAAU,CAAC;CACvC,CAAC;AAUF,eAAO,MAAM,UAAU;eACV,OAAO;eACP,OAAO;SAYnB,CAAC;AAEF,eAAO,MAAM,WAAW;YACd,MAAM;WACP,MAAM,GAAG,WAAW;iBACd,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC;SAsBpC,CAAC;AAEF,eAAO,MAAM,WAAW,oCAIrB,gBAAgB,4CAyElB,CAAC"}
1
+ {"version":3,"file":"ChartLegend.d.ts","sourceRoot":"","sources":["../../../src/lib/components/chartlegend/ChartLegend.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAQ,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAI3D,KAAK,gBAAgB,GAAG;IACtB,KAAK,EAAE,MAAM,GAAG,WAAW,CAAC;IAC5B,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,SAAS,CAAC,EAAE,YAAY,GAAG,UAAU,CAAC;IACtC,UAAU,CAAC,EAAE,WAAW,CAAC;CAC1B,CAAC;AAUF,eAAO,MAAM,UAAU;eACV,OAAO;eACP,OAAO;SAYnB,CAAC;AAEF,eAAO,MAAM,WAAW;YACd,MAAM;WACP,MAAM,GAAG,WAAW;iBACd,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC;SAsBpC,CAAC;AAEF,eAAO,MAAM,WAAW,gDAKrB,gBAAgB,4CAyElB,CAAC"}
@@ -44,7 +44,7 @@ export const LegendShape = styled.div `
44
44
  }
45
45
  }}
46
46
  `;
47
- export const ChartLegend = ({ shape, disabled = false, direction = 'horizontal', }) => {
47
+ export const ChartLegend = ({ shape, disabled = false, direction = 'horizontal', legendSize = 'Basic', }) => {
48
48
  const { listResources, getColor, isSelected, addSelectedResource, removeSelectedResource, selectAllResources, selectOnlyResource, isOnlyOneSelected, } = useChartLegend();
49
49
  const resources = listResources();
50
50
  const handleLegendClick = useCallback((resource, event) => {
@@ -83,6 +83,6 @@ export const ChartLegend = ({ shape, disabled = false, direction = 'horizontal',
83
83
  return (_jsx(Legend, { direction: direction, children: resources.map((resource) => {
84
84
  const color = getColor(resource);
85
85
  const selected = isSelected(resource);
86
- return (_jsxs(LegendItem, { disabled: disabled, selected: selected, "aria-label": `${resource} ${selected ? 'selected' : 'not selected'}`, onClick: (event) => handleLegendClick(resource, event), children: [_jsx(LegendShape, { color: color, shape: shape, chartColors: chartColors }), _jsx(Text, { variant: "Basic", children: resource })] }, resource));
86
+ return (_jsxs(LegendItem, { disabled: disabled, selected: selected, "aria-label": `${resource} ${selected ? 'selected' : 'not selected'}`, onClick: (event) => handleLegendClick(resource, event), children: [_jsx(LegendShape, { color: color, shape: shape, chartColors: chartColors }), _jsx(Text, { variant: legendSize, children: resource })] }, resource));
87
87
  }) }));
88
88
  };
@@ -1,5 +1,6 @@
1
1
  import { ReactNode } from 'react';
2
2
  import { ChartColors } from '../../style/theme';
3
+ export declare const useChartId: () => string;
3
4
  export type ChartLegendState = {
4
5
  selectedResources: string[];
5
6
  addSelectedResource: (resource: string) => void;
@@ -10,10 +11,11 @@ export type ChartLegendState = {
10
11
  getColor: (resource: string) => string | undefined;
11
12
  listResources: () => string[];
12
13
  isOnlyOneSelected: () => boolean;
14
+ register: (chartId: string, seriesNames: string[]) => void;
13
15
  };
14
16
  export type ChartLegendWrapperProps = {
15
17
  children: ReactNode;
16
- colorSet: Record<string, ChartColors | string>;
18
+ colorSet: Record<string, ChartColors | string> | ((seriesNames: string[]) => Record<string, ChartColors | string>);
17
19
  };
18
20
  export declare const ChartLegendWrapper: ({ children, colorSet, }: ChartLegendWrapperProps) => import("react/jsx-runtime").JSX.Element;
19
21
  export declare const useChartLegend: () => ChartLegendState;
@@ -1 +1 @@
1
- {"version":3,"file":"ChartLegendWrapper.d.ts","sourceRoot":"","sources":["../../../src/lib/components/chartlegend/ChartLegendWrapper.tsx"],"names":[],"mappings":"AAAA,OAAO,EAIL,SAAS,EAGV,MAAM,OAAO,CAAC;AACf,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAEhD,MAAM,MAAM,gBAAgB,GAAG;IAC7B,iBAAiB,EAAE,MAAM,EAAE,CAAC;IAC5B,mBAAmB,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,IAAI,CAAC;IAChD,sBAAsB,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,IAAI,CAAC;IACnD,kBAAkB,EAAE,MAAM,IAAI,CAAC;IAC/B,kBAAkB,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,IAAI,CAAC;IAC/C,UAAU,EAAE,CAAC,QAAQ,EAAE,MA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CAAC,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,KAAK,IAAI,CAAC;CAC5D,CAAC;AAIF,MAAM,MAAM,uBAAuB,GAAG;IACpC,QAAQ,EAAE,SAAS,CAAC;IACpB,QAAQ,EACJ,MAAM,CAAC,MAAM,EAAE,WAAW,GAAG,MAAM,CAAC,GACpC,CAAC,CAAC,WAAW,EAAE,MAAM,EAAE,KAAK,MAAM,CAAC,MAAM,EAAE,WAAW,GAAG,MAAM,CAAC,CAAC,CAAC;CACvE,CAAC;AAEF,eAAO,MAAM,kBAAkB,4BAG5B,uBAAuB,4CA0HzB,CAAC;AAEF,eAAO,MAAM,cAAc,wBAM1B,CAAC"}
@@ -1,9 +1,42 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
- import { createContext, useContext, useState, useMemo, useCallback, } from 'react';
2
+ import { createContext, useContext, useState, useMemo, useCallback, useEffect, useRef, } from 'react';
3
+ import { v4 as uuidv4 } from 'uuid';
4
+ export const useChartId = () => {
5
+ const idRef = useRef(null);
6
+ if (idRef.current === null) {
7
+ idRef.current = uuidv4();
8
+ }
9
+ return idRef.current;
10
+ };
3
11
  const ChartLegendContext = createContext(null);
4
12
  export const ChartLegendWrapper = ({ children, colorSet, }) => {
5
- const allResources = Object.keys(colorSet);
13
+ const [registeredColorSets, setRegisteredColorSets] = useState({});
14
+ const [internalColorSet, setInternalColorSet] = useState(() => {
15
+ return typeof colorSet === 'function' ? {} : colorSet;
16
+ });
17
+ useEffect(() => {
18
+ if (typeof colorSet === 'function') {
19
+ const allUniqueSeriesNames = Array.from(new Set(Object.values(registeredColorSets).flat()));
20
+ if (allUniqueSeriesNames.length > 0) {
21
+ const newColorSet = colorSet(allUniqueSeriesNames);
22
+ setInternalColorSet(newColorSet);
23
+ }
24
+ }
25
+ else {
26
+ setInternalColorSet(colorSet);
27
+ }
28
+ }, [registeredColorSets, colorSet]);
29
+ const allResources = useMemo(() => Object.keys(internalColorSet), [internalColorSet]);
6
30
  const [selectedResources, setSelectedResources] = useState(allResources);
31
+ useEffect(() => {
32
+ setSelectedResources(allResources);
33
+ }, [allResources]);
34
+ const register = useCallback((chartId, seriesNames) => {
35
+ setRegisteredColorSets((prev) => ({
36
+ ...prev,
37
+ [chartId]: seriesNames,
38
+ }));
39
+ }, []);
7
40
  const addSelectedResource = useCallback((resource) => {
8
41
  setSelectedResources((prev) => prev.includes(resource) ? prev : [...prev, resource]);
9
42
  }, []);
@@ -11,8 +44,8 @@ export const ChartLegendWrapper = ({ children, colorSet, }) => {
11
44
  setSelectedResources((prev) => prev.filter((r) => r !== resource));
12
45
  }, []);
13
46
  const selectAllResources = useCallback(() => {
14
- setSelectedResources(allResources);
15
- }, [allResources]);
47
+ setSelectedResources(Object.keys(internalColorSet));
48
+ }, [internalColorSet]);
16
49
  const selectOnlyResource = useCallback((resource) => {
17
50
  setSelectedResources([resource]);
18
51
  }, []);
@@ -23,16 +56,16 @@ export const ChartLegendWrapper = ({ children, colorSet, }) => {
23
56
  return selectedResources.includes(resource);
24
57
  }, [selectedResources]);
25
58
  const getColor = useCallback((resource) => {
26
- const color = colorSet[resource];
59
+ const color = internalColorSet[resource];
27
60
  if (!color) {
28
61
  console.warn(`ChartLegendWrapper: No color defined for resource "${resource}"`);
29
62
  return undefined;
30
63
  }
31
64
  return color;
32
- }, [colorSet]);
65
+ }, [internalColorSet]);
33
66
  const listResources = useCallback(() => {
34
- return Object.keys(colorSet);
35
- }, [colorSet]);
67
+ return Object.keys(internalColorSet);
68
+ }, [internalColorSet]);
36
69
  const chartLegendState = useMemo(() => ({
37
70
  selectedResources,
38
71
  addSelectedResource,
@@ -43,6 +76,7 @@ export const ChartLegendWrapper = ({ children, colorSet, }) => {
43
76
  getColor,
44
77
  listResources,
45
78
  isOnlyOneSelected,
79
+ register,
46
80
  }), [
47
81
  selectedResources,
48
82
  addSelectedResource,
@@ -53,10 +87,10 @@ export const ChartLegendWrapper = ({ children, colorSet, }) => {
53
87
  getColor,
54
88
  listResources,
55
89
  isOnlyOneSelected,
90
+ register,
56
91
  ]);
57
92
  return (_jsx(ChartLegendContext.Provider, { value: chartLegendState, children: children }));
58
93
  };
59
- // Hook for accessing legend state in custom components
60
94
  export const useChartLegend = () => {
61
95
  const context = useContext(ChartLegendContext);
62
96
  if (!context) {
@@ -0,0 +1,13 @@
1
+ import React from 'react';
2
+ export declare const ChartTooltipContainer: import("styled-components").StyledComponent<"div", import("styled-components").DefaultTheme, {}, never>;
3
+ interface ChartTooltipItemProps {
4
+ label: React.ReactNode;
5
+ value: React.ReactNode;
6
+ isHovered?: boolean;
7
+ legendIcon?: React.ReactNode;
8
+ }
9
+ export declare const ChartTooltipItem: React.FC<ChartTooltipItemProps>;
10
+ export declare const ChartTooltipHeader: import("styled-components").StyledComponent<"div", import("styled-components").DefaultTheme, {}, never>;
11
+ export declare const ChartTooltipItemsContainer: import("styled-components").StyledComponent<"div", import("styled-components").DefaultTheme, {}, never>;
12
+ export {};
13
+ //# sourceMappingURL=ChartTooltip.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ChartTooltip.d.ts","sourceRoot":"","sources":["../../../src/lib/components/charttooltip/ChartTooltip.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAK1B,eAAO,MAAM,qBAAqB,yGAUjC,CAAC;AA+BF,UAAU,qBAAqB;IAC7B,KAAK,EAAE,KAAK,CAAC,SAAS,CAAC;IACvB,KAAK,EAAE,KAAK,CAAC,SAAS,CAAC;IACvB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,UAAU,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;CAC9B;AAED,eAAO,MAAM,gBAAgB,EAAE,KAAK,CAAC,EAAE,CAAC,qBAAqB,CAe5D,CAAC;AAEF,eAAO,MAAM,kBAAkB,yGAK9B,CAAC;AAEF,eAAO,MAAM,0BAA0B,yGAKtC,CAAC"}
@@ -0,0 +1,49 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import styled from 'styled-components';
3
+ import { spacing } from '../../spacing';
4
+ import { fontSize, fontWeight } from '../../style/theme';
5
+ export const ChartTooltipContainer = styled.div `
6
+ border: 1px solid ${({ theme }) => theme.border};
7
+ background-color: ${({ theme }) => theme.backgroundLevel1};
8
+ color: ${({ theme }) => theme.textPrimary};
9
+ border-radius: 4px;
10
+ font-size: ${fontSize.small};
11
+ padding: ${spacing.r8};
12
+ min-width: 10rem;
13
+ max-width: 250px;
14
+ box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
15
+ `;
16
+ const TooltipText = styled.div `
17
+ color: ${({ theme, isHovered }) => isHovered ? theme.textPrimary : theme.textSecondary};
18
+ font-size: ${fontSize.smaller};
19
+ font-weight: ${({ isHovered }) => isHovered ? fontWeight.bold : fontWeight.base};
20
+ text-align: ${({ align }) => align || 'left'};
21
+ ${({ align }) => align === 'right' && 'flex-shrink: 0;'}
22
+ `;
23
+ const TooltipRow = styled.div `
24
+ display: flex;
25
+ justify-content: space-between;
26
+ align-items: center;
27
+ gap: ${spacing.r32};
28
+ width: 100%;
29
+ `;
30
+ const TooltipLabel = styled.div `
31
+ display: flex;
32
+ align-items: center;
33
+ gap: ${spacing.r8};
34
+ flex: 1;
35
+ min-width: 0;
36
+ `;
37
+ export const ChartTooltipItem = ({ label, value, isHovered = false, legendIcon, }) => (_jsxs(TooltipRow, { children: [_jsxs(TooltipLabel, { children: [legendIcon, _jsx(TooltipText, { isHovered: isHovered, children: label })] }), _jsx(TooltipText, { isHovered: isHovered, align: "right", children: value })] }));
38
+ export const ChartTooltipHeader = styled.div `
39
+ color: ${({ theme }) => theme.textPrimary};
40
+ font-weight: ${fontWeight.bold};
41
+ text-align: center;
42
+ margin-bottom: ${spacing.r8};
43
+ `;
44
+ export const ChartTooltipItemsContainer = styled.div `
45
+ display: flex;
46
+ flex-direction: column;
47
+ gap: ${spacing.r8};
48
+ width: 100%;
49
+ `;
@@ -14,6 +14,10 @@ export type GlobalHealthProps = {
14
14
  height?: number;
15
15
  tooltipPosition?: Position;
16
16
  };
17
+ /**
18
+ * @deprecated Use GlobalHealthBar v2 instead
19
+ * @example import { GlobalHealthBar } from '@scality/core-ui/dist/next';
20
+ */
17
21
  declare function GlobalHealthBar({ id, alerts, start, end, height, tooltipPosition, }: GlobalHealthProps): import("react/jsx-runtime").JSX.Element;
18
22
  export { GlobalHealthBar };
19
23
  //# sourceMappingURL=GlobalHealthBar.component.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"GlobalHealthBar.component.d.ts","sourceRoot":"","sources":["../../../src/lib/components/globalhealthbar/GlobalHealthBar.component.tsx"],"names":[],"mappings":"AAKA,eAAO,MAAM,GAAG,QAAQ,CAAC;AACzB,eAAO,MAAM,MAAM,WAAW,CAAC;AAC/B,KAAK,QAAQ,GAAG,OAAO,GAAG,GAAG,OAAO,MAAM,CAAC;AAC3C,MAAM,MAAM,iBAAiB,GAAG;IAC9B,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,EAAE;QACN,WAAW,EAAE,MAAM,CAAC;QACpB,QAAQ,EAAE,MAAM,CAAC;QACjB,MAAM,EAAE,MAAM,CAAC;QACf,QAAQ,EAAE,MAAM,CAAC;KAClB,EAAE,CAAC;IACJ,KAAK,EAAE,MAAM,CAAC;IACd,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,eAAe,CAAC,EAAE,QAAQ,CAAC;CAC5B,CAAC;AAEF,iBAAS,eAAe,CAAC,EACvB,EAAE,EACF,MAAM,EACN,KAAK,EACL,GAAG,EACH,MAAU,EACV,eAAqB,GACtB,EAAE,iBAAiB,2CAyKnB;AAED,OAAO,EAAE,eAAe,EAAE,CAAC"}
1
+ {"version":3,"file":"GlobalHealthBar.component.d.ts","sourceRoot":"","sources":["../../../src/lib/components/globalhealthbar/GlobalHealthBar.component.tsx"],"names":[],"mappings":"AAKA,eAAO,MAAM,GAAG,QAAQ,CAAC;AACzB,eAAO,MAAM,MAAM,WAAW,CAAC;AAC/B,KAAK,QAAQ,GAAG,OAAO,GAAG,GAAG,OAAO,MAAM,CAAC;AAC3C,MAAM,MAAM,iBAAiB,GAAG;IAC9B,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,EAAE;QACN,WAAW,EAAE,MAAM,CAAC;QACpB,QAAQ,EAAE,MAAM,CAAC;QACjB,MAAM,EAAE,MAAM,CAAC;QACf,QAAQ,EAAE,MAAM,CAAC;KAClB,EAAE,CAAC;IACJ,KAAK,EAAE,MAAM,CAAC;IACd,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,eAAe,CAAC,EAAE,QAAQ,CAAC;CAC5B,CAAC;AACF;;;GAGG;AACH,iBAAS,eAAe,CAAC,EACvB,EAAE,EACF,MAAM,EACN,KAAK,EACL,GAAG,EACH,MAAU,EACV,eAAqB,GACtB,EAAE,iBAAiB,2CAyKnB;AAED,OAAO,EAAE,eAAe,EAAE,CAAC"}
@@ -6,6 +6,10 @@ import { useTheme } from 'styled-components';
6
6
  import { formatValue } from './tooltip/index';
7
7
  export const TOP = 'top';
8
8
  export const BOTTOM = 'bottom';
9
+ /**
10
+ * @deprecated Use GlobalHealthBar v2 instead
11
+ * @example import { GlobalHealthBar } from '@scality/core-ui/dist/next';
12
+ */
9
13
  function GlobalHealthBar({ id, alerts, start, end, height = 8, tooltipPosition = TOP, }) {
10
14
  const theme = useTheme();
11
15
  const trimAlerts = alerts.map((alert) => {
@@ -0,0 +1,10 @@
1
+ import { Alert } from './useHealthBarData';
2
+ export interface GlobalHealthProps {
3
+ id: string;
4
+ alerts: Alert[];
5
+ start: Date;
6
+ end: Date;
7
+ }
8
+ export declare function GlobalHealthBar({ id, alerts, start, end }: GlobalHealthProps): import("react/jsx-runtime").JSX.Element;
9
+ export type { Alert };
10
+ //# sourceMappingURL=GlobalHealthBarRecharts.component.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"GlobalHealthBarRecharts.component.d.ts","sourceRoot":"","sources":["../../../src/lib/components/globalhealthbar/GlobalHealthBarRecharts.component.tsx"],"names":[],"mappings":"AAiBA,OAAO,EAAE,KAAK,EAAoB,MAAM,oBAAoB,CAAC;AAE7D,MAAM,WAAW,iBAAiB;IAChC,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,EAAE,KAAK,EAAE,CAAC;IAChB,KAAK,EAAE,IAAI,CAAC;IACZ,GAAG,EAAE,IAAI,CAAC;CACX;AAMD,wBAAgB,eAAe,CAAC,EAAE,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,EAAE,EAAE,iBAAiB,2CAyK5E;AAGD,YAAY,EAAE,KAAK,EAAE,CAAC"}
@@ -0,0 +1,78 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useCallback, useMemo, useRef, useState } from 'react';
3
+ import { Bar, BarChart, ResponsiveContainer, Tooltip, YAxis, } from 'recharts';
4
+ import styled, { useTheme } from 'styled-components';
5
+ import { GlobalHealthBarTooltip } from './components/GlobalHealthBarTooltip';
6
+ import { HealthBarXAxis } from './components/HealthBarXAxis';
7
+ import { CHART_CONFIG, getNavigationAction, getNavigationStateUpdate, } from './healthBarUtils';
8
+ import { useHealthBarData } from './useHealthBarData';
9
+ const ChartInteractiveContainer = styled.div `
10
+ position: relative;
11
+ `;
12
+ export function GlobalHealthBar({ id, alerts, start, end }) {
13
+ const [tooltipData, setTooltipData] = useState(null);
14
+ const [focusedAlertIndex, setFocusedAlertIndex] = useState(-1);
15
+ const [keyboardActive, setKeyboardActive] = useState(false);
16
+ const chartContainerRef = useRef(null);
17
+ const theme = useTheme();
18
+ const startTimestamp = new Date(start).getTime();
19
+ const endTimestamp = new Date(end).getTime();
20
+ const { chartData, alertsMap, alertKeys } = useHealthBarData(alerts, startTimestamp, endTimestamp, id);
21
+ const handlePointerEnter = useCallback((key) => {
22
+ setTooltipData(alertsMap[key]);
23
+ }, [alertsMap]);
24
+ const handlePointerLeave = useCallback(() => {
25
+ if (!keyboardActive) {
26
+ setTooltipData(null);
27
+ }
28
+ }, [keyboardActive]);
29
+ const { warningKeys, criticalKeys, unavailableKeys } = alertKeys;
30
+ // Get all alert keys in order for keyboard navigation
31
+ const allAlertKeys = useMemo(() => {
32
+ return Object.values(alertsMap).sort((a, b) => {
33
+ return new Date(a.startsAt).getTime() - new Date(b.startsAt).getTime();
34
+ });
35
+ }, [alertsMap]);
36
+ // Handle keyboard navigation
37
+ const handleKeyDown = useCallback((event) => {
38
+ const action = getNavigationAction(event.key);
39
+ if (!action || allAlertKeys.length === 0)
40
+ return;
41
+ event.preventDefault();
42
+ const update = getNavigationStateUpdate(action, focusedAlertIndex, allAlertKeys);
43
+ setFocusedAlertIndex(update.newIndex);
44
+ setTooltipData(update.selectedAlert);
45
+ setKeyboardActive(update.shouldActivateKeyboard);
46
+ }, [allAlertKeys, focusedAlertIndex]);
47
+ // Handle focus events
48
+ const handleFocus = useCallback(() => {
49
+ if (allAlertKeys.length > 0 && focusedAlertIndex === -1) {
50
+ setFocusedAlertIndex(0);
51
+ setTooltipData(allAlertKeys[0]);
52
+ setKeyboardActive(true);
53
+ }
54
+ }, [allAlertKeys, focusedAlertIndex]);
55
+ const handleBlur = useCallback(() => {
56
+ setKeyboardActive(false);
57
+ setFocusedAlertIndex(-1);
58
+ setTooltipData(null);
59
+ }, []);
60
+ // Handle mouse enter to disable keyboard mode
61
+ const handleMouseEnter = useCallback(() => {
62
+ setKeyboardActive(false);
63
+ }, []);
64
+ const allAlertBars = useMemo(() => {
65
+ const configs = [
66
+ { keys: unavailableKeys, fill: theme.textSecondary },
67
+ { keys: warningKeys, fill: theme.statusWarning },
68
+ { keys: criticalKeys, fill: theme.statusCritical },
69
+ ];
70
+ return configs.flatMap(({ keys, fill }) => keys.map((key) => ({ key, fill })));
71
+ }, [unavailableKeys, warningKeys, criticalKeys, theme]);
72
+ return (_jsx(ChartInteractiveContainer, { ref: chartContainerRef, tabIndex: 0, role: "application", "aria-label": `Health bar chart with ${allAlertKeys.length} alerts. Use arrow keys to navigate, Escape to close tooltip.`, onKeyDown: handleKeyDown, onFocus: handleFocus, onBlur: handleBlur, onMouseEnter: handleMouseEnter, children: _jsx(ResponsiveContainer, { width: '100%', height: CHART_CONFIG.CHART_HEIGHT, children: _jsxs(BarChart, { data: chartData, layout: "vertical", barSize: CHART_CONFIG.BAR_SIZE, accessibilityLayer: true, margin: CHART_CONFIG.MARGINS, children: [_jsx(HealthBarXAxis, { startTimestamp: startTimestamp, endTimestamp: endTimestamp }), _jsx(Tooltip, { allowEscapeViewBox: { x: true, y: true }, isAnimationActive: false, shared: false, wrapperStyle: {
73
+ width: '20rem',
74
+ position: 'fixed',
75
+ }, content: (props) => {
76
+ return (_jsx(GlobalHealthBarTooltip, { tooltipData: tooltipData, tooltipProps: props, chartContainerRef: chartContainerRef, isKeyboardActive: keyboardActive, startTimestamp: startTimestamp, endTimestamp: endTimestamp }));
77
+ } }), _jsx(YAxis, { yAxisId: 'background', type: "category", hide: true }), allAlertBars.map(({ key }) => (_jsx(YAxis, { yAxisId: key, type: "category", hide: true }, `yAxis${key}`))), _jsx(Bar, { dataKey: "range", fill: theme.statusHealthy, radius: CHART_CONFIG.RADIUS_SIZE, yAxisId: "background", isAnimationActive: false }), allAlertBars.map(({ key, fill }) => (_jsx(Bar, { dataKey: key, yAxisId: key, fill: fill, onPointerEnter: () => handlePointerEnter(key), onPointerLeave: () => handlePointerLeave(), isAnimationActive: false })))] }) }) }));
78
+ }
@@ -0,0 +1,18 @@
1
+ import React from 'react';
2
+ import { Alert } from '../GlobalHealthBarRecharts.component';
3
+ import { TooltipContentProps } from 'recharts';
4
+ interface GlobalHealthBarTooltipProps {
5
+ tooltipData: Alert | null;
6
+ coordinate?: {
7
+ x: number;
8
+ y: number;
9
+ };
10
+ tooltipProps: TooltipContentProps<number, string>;
11
+ chartContainerRef: React.RefObject<HTMLDivElement>;
12
+ isKeyboardActive?: boolean;
13
+ startTimestamp?: number;
14
+ endTimestamp?: number;
15
+ }
16
+ export declare const GlobalHealthBarTooltip: (props: GlobalHealthBarTooltipProps) => React.ReactPortal | null;
17
+ export {};
18
+ //# sourceMappingURL=GlobalHealthBarTooltip.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"GlobalHealthBarTooltip.d.ts","sourceRoot":"","sources":["../../../../src/lib/components/globalhealthbar/components/GlobalHealthBarTooltip.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAY1B,OAAO,EAAE,KAAK,EAAE,MAAM,sCAAsC,CAAC;AAC7D,OAAO,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAC;AAI/C,UAAU,2BAA2B;IACnC,WAAW,EAAE,KAAK,GAAG,IAAI,CAAC;IAC1B,UAAU,CAAC,EAAE;QAAE,CAAC,EAAE,MAAM,CAAC;QAAC,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;IACtC,YAAY,EAAE,mBAAmB,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAClD,iBAAiB,EAAE,KAAK,CAAC,SAAS,CAAC,cAAc,CAAC,CAAC;IACnD,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAoBD,eAAO,MAAM,sBAAsB,UAAW,2BAA2B,6BA+HxE,CAAC"}
@@ -0,0 +1,95 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { createPortal } from 'react-dom';
3
+ import { useEffect, useState } from 'react';
4
+ import styled, { css, useTheme } from 'styled-components';
5
+ import { useFloating, autoUpdate, offset, flip, shift, } from '@floating-ui/react';
6
+ import { FormattedDateTime, Stack, Text, Wrap, spacing } from '../../../index';
7
+ import { zIndex } from '../../../style/theme';
8
+ import { CHART_CONFIG, getTooltipPosition } from '../healthBarUtils';
9
+ const TooltipContainer = styled.div `
10
+ ${(props) => {
11
+ const theme = useTheme();
12
+ return css `
13
+ border: 1px solid ${theme.border};
14
+ width: 24rem;
15
+ z-index: ${zIndex.tooltip};
16
+ color: ${theme.textSecondary};
17
+ background-color: ${theme.backgroundLevel1};
18
+ border-radius: 4px;
19
+ padding: ${spacing.r8};
20
+ pointer-events: none;
21
+ box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
22
+ `;
23
+ }}
24
+ `;
25
+ export const GlobalHealthBarTooltip = (props) => {
26
+ const { tooltipData, tooltipProps, chartContainerRef, isKeyboardActive = false, startTimestamp = 0, endTimestamp = 0, } = props;
27
+ const { coordinate } = tooltipProps;
28
+ const [virtualElement, setVirtualElement] = useState(null);
29
+ const { refs, floatingStyles } = useFloating({
30
+ elements: {
31
+ reference: virtualElement,
32
+ },
33
+ middleware: [
34
+ offset(({ placement }) => {
35
+ // Use larger offset when tooltip is on top
36
+ // to avoid tooltip over bar
37
+ return placement.includes('top') ? 20 : 30;
38
+ }),
39
+ flip(),
40
+ shift({ padding: 10 }),
41
+ ],
42
+ whileElementsMounted: autoUpdate,
43
+ });
44
+ // Create virtual element from coordinate
45
+ useEffect(() => {
46
+ if (chartContainerRef.current) {
47
+ const chartRect = chartContainerRef.current.getBoundingClientRect();
48
+ let tooltipX;
49
+ let tooltipY;
50
+ if (isKeyboardActive && tooltipData && startTimestamp && endTimestamp) {
51
+ // Calculate the chart's usable width (excluding margins)
52
+ const chartUsableWidth = chartRect.width -
53
+ CHART_CONFIG.MARGINS.left -
54
+ CHART_CONFIG.MARGINS.right;
55
+ // Use the same positioning logic as alert bars
56
+ const alertCenterX = getTooltipPosition(tooltipData, startTimestamp, endTimestamp, chartUsableWidth);
57
+ // Position tooltip at the center of the alert's time span
58
+ // alertCenterX already includes the margin offset, so just add chartRect.left
59
+ tooltipX = chartRect.left + alertCenterX;
60
+ tooltipY = chartRect.top + CHART_CONFIG.BAR_SIZE;
61
+ }
62
+ else {
63
+ // For mouse navigation, use the provided coordinate
64
+ tooltipX = chartRect.left + (coordinate === null || coordinate === void 0 ? void 0 : coordinate.x);
65
+ tooltipY = chartRect.top + (coordinate === null || coordinate === void 0 ? void 0 : coordinate.y);
66
+ }
67
+ setVirtualElement({
68
+ getBoundingClientRect() {
69
+ return {
70
+ width: 0,
71
+ height: 0,
72
+ x: tooltipX,
73
+ y: tooltipY,
74
+ left: tooltipX,
75
+ top: tooltipY,
76
+ right: tooltipX,
77
+ bottom: tooltipY,
78
+ };
79
+ },
80
+ });
81
+ }
82
+ }, [
83
+ coordinate,
84
+ chartContainerRef,
85
+ isKeyboardActive,
86
+ tooltipData,
87
+ startTimestamp,
88
+ endTimestamp,
89
+ ]);
90
+ if (!tooltipData)
91
+ return null;
92
+ const { description, startsAt, endsAt, severity } = tooltipData;
93
+ const tooltipContent = (_jsx(TooltipContainer, { ref: refs.setFloating, style: floatingStyles, children: _jsxs(Stack, { direction: "vertical", gap: "r8", children: [_jsxs(Wrap, { children: [_jsx(Text, { variant: "Smaller", children: "Severity" }), _jsx(Text, { color: "textPrimary", variant: "Smaller", children: severity })] }), _jsxs(Wrap, { children: [_jsx(Text, { variant: "Smaller", children: "Start" }), _jsx(Text, { color: "textPrimary", variant: "Smaller", children: _jsx(FormattedDateTime, { format: "date-time", value: new Date(startsAt) }) })] }), _jsxs(Wrap, { children: [_jsx(Text, { variant: "Smaller", children: "End" }), _jsx(Text, { color: "textPrimary", variant: "Smaller", children: _jsx(FormattedDateTime, { format: "date-time", value: new Date(endsAt) }) })] }), _jsxs(Wrap, { children: [_jsx(Text, { variant: "Smaller", style: { paddingRight: spacing.r32 }, children: "Description" }), _jsx(Text, { color: "textPrimary", variant: "Smaller", style: { whiteSpace: 'wrap', textAlign: 'justify' }, children: description })] })] }) }));
94
+ return createPortal(tooltipContent, document.body);
95
+ };
@@ -0,0 +1,7 @@
1
+ interface HealthBarXAxisProps {
2
+ startTimestamp: number;
3
+ endTimestamp: number;
4
+ }
5
+ export declare const HealthBarXAxis: ({ startTimestamp, endTimestamp, }: HealthBarXAxisProps) => import("react/jsx-runtime").JSX.Element;
6
+ export {};
7
+ //# sourceMappingURL=HealthBarXAxis.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"HealthBarXAxis.d.ts","sourceRoot":"","sources":["../../../../src/lib/components/globalhealthbar/components/HealthBarXAxis.tsx"],"names":[],"mappings":"AAWA,UAAU,mBAAmB;IAC3B,cAAc,EAAE,MAAM,CAAC;IACvB,YAAY,EAAE,MAAM,CAAC;CACtB;AAiDD,eAAO,MAAM,cAAc,sCAGxB,mBAAmB,4CA2BrB,CAAC"}
@@ -0,0 +1,25 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { XAxis } from 'recharts';
3
+ import { useTheme } from 'styled-components';
4
+ import { fontSize } from '../../../style/theme';
5
+ import { getTicks, calculateLabelVisibility, TIME_CONSTANTS, getEdgeMargin, } from '../healthBarUtils';
6
+ import { FormattedDateTime } from '../../date/FormattedDateTime';
7
+ const CustomTick = ({ tickProps, startTimestamp, endTimestamp, }) => {
8
+ const theme = useTheme();
9
+ const { y, payload, width, index, visibleTicksCount } = tickProps;
10
+ const span = endTimestamp - startTimestamp;
11
+ const is7DaySpan = span === 7 * TIME_CONSTANTS.ONE_DAY;
12
+ const isDaySpan = span === TIME_CONSTANTS.ONE_DAY;
13
+ const shouldShowLabel = calculateLabelVisibility(width, visibleTicksCount, span, index, endTimestamp);
14
+ const edgeMargin = getEdgeMargin(index, visibleTicksCount, isDaySpan);
15
+ return (
16
+ // use coordinate to center the text
17
+ shouldShowLabel && (_jsx("g", { transform: `translate(${payload.coordinate},${y})`, children: _jsx("text", { textAnchor: "middle", dy: 10, dx: edgeMargin, fontSize: fontSize.smaller, fill: theme.textSecondary, children: is7DaySpan || isDaySpan ? (_jsx(FormattedDateTime, { format: "day-month-abbreviated-hour-minute", value: new Date(payload.value) })) : (_jsx(FormattedDateTime, { format: "time", value: new Date(payload.value) })) }) })));
18
+ };
19
+ export const HealthBarXAxis = ({ startTimestamp, endTimestamp, }) => {
20
+ const theme = useTheme();
21
+ const ticks = getTicks(startTimestamp, endTimestamp);
22
+ return (_jsx(XAxis, { allowDataOverflow: true, dataKey: "start", type: "number", domain: [startTimestamp, endTimestamp], tickSize: 5, minTickGap: 10, interval: 0, tick: (props) => {
23
+ return (_jsx(CustomTick, { tickProps: props, startTimestamp: startTimestamp, endTimestamp: endTimestamp }));
24
+ }, ticks: ticks, tickLine: { stroke: theme.textSecondary }, axisLine: false }));
25
+ };