@centreon/ui 23.10.30-MON-19324-dashboard-section-navigation.3 → 23.10.30

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 (205) hide show
  1. package/package.json +9 -12
  2. package/src/@assets/icons/downtime.icon.svg +1 -0
  3. package/src/Dashboard/DashboardLayout.stories.tsx +5 -3
  4. package/src/Dashboard/Layout.tsx +4 -4
  5. package/src/Dashboard/utils.ts +28 -28
  6. package/src/Graph/BasicComponents/Axes/UnitLabel.tsx +20 -0
  7. package/src/Graph/BasicComponents/Axes/index.tsx +88 -0
  8. package/src/Graph/BasicComponents/Axes/models.ts +26 -0
  9. package/src/Graph/BasicComponents/Axes/useAxisY.ts +100 -0
  10. package/src/Graph/BasicComponents/Grids/index.tsx +20 -0
  11. package/src/Graph/BasicComponents/Lines/RegularLines/index.tsx +91 -0
  12. package/src/Graph/BasicComponents/Lines/RegularLines/useRegularLines.ts +15 -0
  13. package/src/Graph/BasicComponents/Lines/StackedLines/index.tsx +76 -0
  14. package/src/Graph/BasicComponents/Lines/StackedLines/useStackedLines.ts +39 -0
  15. package/src/Graph/BasicComponents/Lines/Threshold/BasicThreshold.tsx +51 -0
  16. package/src/Graph/BasicComponents/Lines/Threshold/Circle.tsx +43 -0
  17. package/src/Graph/BasicComponents/Lines/Threshold/ThresholdWithPatternLines.tsx +73 -0
  18. package/src/Graph/BasicComponents/Lines/Threshold/ThresholdWithVariation.tsx +59 -0
  19. package/src/Graph/BasicComponents/Lines/Threshold/helpers/index.ts +69 -0
  20. package/src/Graph/BasicComponents/Lines/Threshold/index.tsx +138 -0
  21. package/src/Graph/BasicComponents/Lines/Threshold/models.ts +105 -0
  22. package/src/Graph/BasicComponents/Lines/Threshold/useCoordinateCircle.ts +46 -0
  23. package/src/Graph/BasicComponents/Lines/Threshold/useScaleThreshold.ts +171 -0
  24. package/src/Graph/BasicComponents/Lines/index.tsx +180 -0
  25. package/src/Graph/BasicComponents/Lines/models.ts +42 -0
  26. package/src/Graph/BasicComponents/LoadingProgress.tsx +46 -0
  27. package/src/Graph/BasicComponents/useFilterLines.ts +60 -0
  28. package/src/Graph/Graph.styles.ts +45 -0
  29. package/src/Graph/Graph.tsx +217 -0
  30. package/src/Graph/Header/index.tsx +65 -0
  31. package/src/Graph/Icons/Downtime.tsx +9 -0
  32. package/src/Graph/InteractiveComponents/AnchorPoint/AnchorPoint.styles.ts +58 -0
  33. package/src/Graph/InteractiveComponents/AnchorPoint/GuidingLines.tsx +45 -0
  34. package/src/Graph/InteractiveComponents/AnchorPoint/RegularAnchorPoint.tsx +66 -0
  35. package/src/Graph/InteractiveComponents/AnchorPoint/StackedAnchorPoint.tsx +76 -0
  36. package/src/Graph/InteractiveComponents/AnchorPoint/TooltipAnchorPoint.tsx +70 -0
  37. package/src/Graph/InteractiveComponents/AnchorPoint/index.tsx +20 -0
  38. package/src/Graph/InteractiveComponents/AnchorPoint/models.ts +62 -0
  39. package/src/Graph/InteractiveComponents/AnchorPoint/useTickGraph.ts +94 -0
  40. package/src/Graph/InteractiveComponents/AnchorPoint/useTooltipAnchorPoint.ts +107 -0
  41. package/src/Graph/InteractiveComponents/Annotations/Annotation/Area.tsx +114 -0
  42. package/src/Graph/InteractiveComponents/Annotations/Annotation/Line.tsx +103 -0
  43. package/src/Graph/InteractiveComponents/Annotations/Annotation/index.tsx +81 -0
  44. package/src/Graph/InteractiveComponents/Annotations/Area/Downtime.tsx +27 -0
  45. package/src/Graph/InteractiveComponents/Annotations/EventAnnotations.tsx +61 -0
  46. package/src/Graph/InteractiveComponents/Annotations/Line/Acknowledgement.tsx +27 -0
  47. package/src/Graph/InteractiveComponents/Annotations/Line/Comments.tsx +25 -0
  48. package/src/Graph/InteractiveComponents/Annotations/annotationsAtoms.ts +183 -0
  49. package/src/Graph/InteractiveComponents/Annotations/index.tsx +49 -0
  50. package/src/Graph/InteractiveComponents/Annotations/models.ts +25 -0
  51. package/src/Graph/InteractiveComponents/Annotations/useAnnotation.ts +56 -0
  52. package/src/Graph/InteractiveComponents/Bar.tsx +21 -0
  53. package/src/Graph/InteractiveComponents/TimeShiftZones/TimeShiftIcon.tsx +62 -0
  54. package/src/Graph/InteractiveComponents/TimeShiftZones/TimeShiftZone.tsx +74 -0
  55. package/src/Graph/InteractiveComponents/TimeShiftZones/index.tsx +85 -0
  56. package/src/Graph/InteractiveComponents/TimeShiftZones/models.ts +12 -0
  57. package/src/Graph/InteractiveComponents/TimeShiftZones/useTimeShiftZones.ts +72 -0
  58. package/src/Graph/InteractiveComponents/Tooltip/index.tsx +59 -0
  59. package/src/Graph/InteractiveComponents/Tooltip/models.ts +9 -0
  60. package/src/Graph/InteractiveComponents/Tooltip/useGraphTooltip.ts +67 -0
  61. package/src/Graph/InteractiveComponents/ZoomPreview/index.tsx +38 -0
  62. package/src/Graph/InteractiveComponents/ZoomPreview/models.ts +9 -0
  63. package/src/Graph/InteractiveComponents/ZoomPreview/useZoomPreview.ts +107 -0
  64. package/src/Graph/InteractiveComponents/ZoomPreview/zoomPreviewAtoms.ts +3 -0
  65. package/src/Graph/InteractiveComponents/index.tsx +168 -0
  66. package/src/Graph/InteractiveComponents/interactionWithGraphAtoms.ts +51 -0
  67. package/src/Graph/Legend/InteractiveValue.tsx +22 -0
  68. package/src/Graph/Legend/Legend.styles.ts +71 -0
  69. package/src/Graph/Legend/LegendContent.tsx +27 -0
  70. package/src/Graph/Legend/LegendHeader.tsx +45 -0
  71. package/src/Graph/Legend/Marker.tsx +43 -0
  72. package/src/Graph/Legend/index.tsx +166 -0
  73. package/src/Graph/Legend/models.ts +11 -0
  74. package/src/Graph/Legend/useInteractiveValues.ts +86 -0
  75. package/src/Graph/Legend/useLegend.ts +114 -0
  76. package/src/Graph/LoadingSkeleton.tsx +44 -0
  77. package/src/Graph/common/index.ts +35 -0
  78. package/src/Graph/graphAtoms.ts +6 -0
  79. package/src/Graph/helpers/doc.ts +560 -0
  80. package/src/Graph/helpers/index.ts +58 -0
  81. package/src/Graph/index.stories.tsx +372 -0
  82. package/src/Graph/index.tsx +90 -0
  83. package/src/Graph/mockedData/annotationData.json +326 -0
  84. package/src/Graph/mockedData/exclusionPeriodFirstPeriod.json +588 -0
  85. package/src/Graph/mockedData/exclusionPeriodSecondPeriod.json +588 -0
  86. package/src/Graph/mockedData/exclusionPeriodThirdPeriod.json +581 -0
  87. package/src/Graph/mockedData/lastDay.json +1326 -0
  88. package/src/Graph/mockedData/lastDayAreaStack.json +3106 -0
  89. package/src/Graph/mockedData/lastDayForward.json +1338 -0
  90. package/src/Graph/mockedData/lastDayThreshold.json +2352 -0
  91. package/src/Graph/mockedData/lastMonth.json +1674 -0
  92. package/src/Graph/mockedData/lastWeek.json +2202 -0
  93. package/src/Graph/mockedData/zoomPreview.json +742 -0
  94. package/src/Graph/models.ts +150 -0
  95. package/src/Graph/timeSeries/index.test.ts +506 -0
  96. package/src/Graph/timeSeries/index.ts +512 -0
  97. package/src/Graph/timeSeries/models.ts +120 -0
  98. package/src/Graph/translatedLabels.ts +9 -0
  99. package/src/Graph/useGraphData.ts +47 -0
  100. package/src/Graph/useGraphIntersection.ts +36 -0
  101. package/src/ThemeProvider/index.tsx +5 -6
  102. package/src/ThemeProvider/palettes.ts +215 -385
  103. package/src/TimePeriods/CustomTimePeriod/CompactCustomTimePeriod.styles.ts +51 -0
  104. package/src/TimePeriods/CustomTimePeriod/CompactCustomTimePeriod.tsx +95 -0
  105. package/src/TimePeriods/CustomTimePeriod/PopoverCustomTimePeriod/ErrorText.tsx +14 -0
  106. package/src/TimePeriods/CustomTimePeriod/PopoverCustomTimePeriod/PickersStartEndDate.tsx +163 -0
  107. package/src/TimePeriods/CustomTimePeriod/PopoverCustomTimePeriod/index.tsx +76 -0
  108. package/src/TimePeriods/CustomTimePeriod/PopoverCustomTimePeriod/models.ts +61 -0
  109. package/src/TimePeriods/CustomTimePeriod/PopoverCustomTimePeriod/usePickersStartEndDate.ts +82 -0
  110. package/src/TimePeriods/CustomTimePeriod/index.tsx +66 -0
  111. package/src/TimePeriods/DateTimePickerInput.tsx +49 -0
  112. package/src/TimePeriods/ResolutionTimePeriod.cypress.spec.tsx +65 -0
  113. package/src/TimePeriods/SelectedTimePeriod.tsx +102 -0
  114. package/src/TimePeriods/TimePeriods.cypress.spec.tsx +510 -0
  115. package/src/TimePeriods/TimePeriods.styles.ts +22 -0
  116. package/src/TimePeriods/helpers/index.ts +26 -0
  117. package/src/TimePeriods/index.stories.tsx +98 -0
  118. package/src/TimePeriods/index.tsx +78 -0
  119. package/src/TimePeriods/mockedData.ts +12 -0
  120. package/src/TimePeriods/models.ts +97 -0
  121. package/src/TimePeriods/timePeriodsAtoms.ts +102 -0
  122. package/src/TimePeriods/translatedLabels.ts +9 -0
  123. package/src/TimePeriods/useSortTimePeriods.ts +31 -0
  124. package/src/TimePeriods/useTimePeriod.ts +49 -0
  125. package/src/api/TestQueryProvider.tsx +1 -2
  126. package/src/api/useFetchQuery/index.ts +7 -8
  127. package/src/api/useMutationQuery/index.ts +10 -11
  128. package/src/components/Button/Button.styles.ts +3 -17
  129. package/src/components/Button/Button.tsx +3 -6
  130. package/src/components/Button/Icon/IconButton.styles.ts +2 -9
  131. package/src/components/DataTable/DataTable.stories.tsx +0 -9
  132. package/src/components/DataTable/DataTable.styles.ts +0 -5
  133. package/src/components/DataTable/DataTable.tsx +6 -8
  134. package/src/components/DataTable/EmptyState/DataTableEmptyState.tsx +1 -4
  135. package/src/components/DataTable/Item/DataTableItem.styles.ts +2 -5
  136. package/src/components/DataTable/Item/DataTableItem.tsx +18 -36
  137. package/src/components/Header/Header.stories.tsx +27 -0
  138. package/src/components/Header/Header.styles.ts +27 -0
  139. package/src/components/Header/Header.tsx +23 -0
  140. package/src/components/Header/index.ts +1 -1
  141. package/src/components/Modal/index.ts +0 -2
  142. package/src/components/index.ts +0 -3
  143. package/src/index.ts +2 -0
  144. package/src/layout/TiledListingPage/TiledListingActions.tsx +15 -0
  145. package/src/layout/TiledListingPage/TiledListingContent.tsx +21 -0
  146. package/src/layout/TiledListingPage/TiledListingList.tsx +11 -0
  147. package/src/layout/TiledListingPage/TiledListingPage.styles.ts +16 -0
  148. package/src/layout/TiledListingPage/TiledListingPage.tsx +15 -0
  149. package/src/layout/TiledListingPage/index.ts +4 -0
  150. package/src/screens/dashboard/DashboardsOverview.stories.tsx +102 -110
  151. package/src/utils/index.ts +1 -1
  152. package/src/utils/sanitizedHTML.ts +1 -1
  153. package/test/setupTests.js +0 -3
  154. package/src/base/tokens/README.md +0 -3
  155. package/src/base/tokens/source/$metadata.json +0 -5
  156. package/src/base/tokens/source/base.json +0 -142
  157. package/src/base/tokens/themes/base.tokens.d.ts +0 -38
  158. package/src/base/tokens/themes/base.tokens.json +0 -695
  159. package/src/base/tokens/themes/base.tokens.ts +0 -38
  160. package/src/base/tokens/themes/ui-dark.tokens.d.ts +0 -38
  161. package/src/base/tokens/themes/ui-dark.tokens.json +0 -695
  162. package/src/base/tokens/themes/ui-dark.tokens.ts +0 -38
  163. package/src/base/tokens/themes/ui-light.tokens.d.ts +0 -38
  164. package/src/base/tokens/themes/ui-light.tokens.json +0 -695
  165. package/src/base/tokens/themes/ui-light.tokens.ts +0 -38
  166. package/src/components/Header/PageHeader/PageHeader.stories.tsx +0 -88
  167. package/src/components/Header/PageHeader/PageHeader.styles.ts +0 -99
  168. package/src/components/Header/PageHeader/PageHeader.tsx +0 -15
  169. package/src/components/Header/PageHeader/PageHeaderActions.tsx +0 -17
  170. package/src/components/Header/PageHeader/PageHeaderMain.tsx +0 -15
  171. package/src/components/Header/PageHeader/PageHeaderMenu.tsx +0 -15
  172. package/src/components/Header/PageHeader/PageHeaderTitle.tsx +0 -47
  173. package/src/components/Header/PageHeader/index.ts +0 -12
  174. package/src/components/Layout/AreaIndicator.styles.ts +0 -33
  175. package/src/components/Layout/AreaIndicator.tsx +0 -35
  176. package/src/components/Layout/PageLayout/PageLayout.stories.tsx +0 -81
  177. package/src/components/Layout/PageLayout/PageLayout.styles.ts +0 -40
  178. package/src/components/Layout/PageLayout/PageLayout.tsx +0 -21
  179. package/src/components/Layout/PageLayout/PageLayoutActions.tsx +0 -15
  180. package/src/components/Layout/PageLayout/PageLayoutBody.tsx +0 -24
  181. package/src/components/Layout/PageLayout/PageLayoutHeader.tsx +0 -15
  182. package/src/components/Layout/PageLayout/index.ts +0 -10
  183. package/src/components/Layout/index.ts +0 -1
  184. package/src/components/Menu/Button/MenuButton.stories.tsx +0 -16
  185. package/src/components/Menu/Button/MenuButton.styles.ts +0 -27
  186. package/src/components/Menu/Button/MenuButton.tsx +0 -59
  187. package/src/components/Menu/Button/index.ts +0 -1
  188. package/src/components/Menu/Menu.stories.tsx +0 -71
  189. package/src/components/Menu/Menu.styles.ts +0 -70
  190. package/src/components/Menu/Menu.tsx +0 -25
  191. package/src/components/Menu/MenuDivider.tsx +0 -13
  192. package/src/components/Menu/MenuItem.tsx +0 -36
  193. package/src/components/Menu/MenuItems.tsx +0 -35
  194. package/src/components/Menu/index.ts +0 -12
  195. package/src/components/Menu/useMenu.tsx +0 -79
  196. package/src/components/Tooltip/TextOverflowTooltip/TextOverflowTooltip.stories.tsx +0 -71
  197. package/src/components/Tooltip/TextOverflowTooltip/TextOverflowTooltip.styles.ts +0 -5
  198. package/src/components/Tooltip/TextOverflowTooltip/TextOverflowTooltip.tsx +0 -115
  199. package/src/components/Tooltip/TextOverflowTooltip/index.tsx +0 -1
  200. package/src/components/Tooltip/Tooltip.stories.tsx +0 -41
  201. package/src/components/Tooltip/Tooltip.styles.ts +0 -5
  202. package/src/components/Tooltip/Tooltip.tsx +0 -46
  203. package/src/components/Tooltip/index.ts +0 -1
  204. package/src/screens/dashboard/DashboardsDetail.stories.tsx +0 -108
  205. package/src/utils/useResizeObserver.ts +0 -6
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@centreon/ui",
3
- "version": "23.10.30-MON-19324-dashboard-section-navigation.3",
3
+ "version": "23.10.30",
4
4
  "description": "Centreon UI Components",
5
5
  "scripts": {
6
6
  "eslint": "eslint ./src --ext .js,.jsx,.ts,.tsx --max-warnings 0",
@@ -8,12 +8,10 @@
8
8
  "storybook": "storybook dev -p 9001 -c .storybook",
9
9
  "build:storybook": "storybook build -c .storybook -o .out",
10
10
  "test": "jest",
11
- "test:storybook:local": "test-storybook --url http://127.0.0.1:9001",
12
11
  "test:ci": "jest --silent --reporter=jest-junit",
13
12
  "cypress:ui": "cypress open --component --browser=chrome",
14
13
  "cypress:cli:updateSnapshot": "pnpm cypress:cli --env updateSnapshots=true",
15
- "cypress:cli": "cypress run --component --browser=chrome",
16
- "tokens:transform": "TS_NODE_PROJECT=tsconfig.node.json ts-node style-dictionary.transform.ts"
14
+ "cypress:cli": "cypress run --component --browser=chrome"
17
15
  },
18
16
  "sideEffects": false,
19
17
  "repository": {
@@ -56,23 +54,18 @@
56
54
  "@storybook/addon-interactions": "^7.0.9",
57
55
  "@storybook/addon-styling": "^1.0.6",
58
56
  "@storybook/builder-vite": "^7.0.9",
59
- "@storybook/jest": "^0.1.0",
60
57
  "@storybook/manager-api": "^7.0.9",
61
58
  "@storybook/mdx2-csf": "^1.0.0",
62
59
  "@storybook/preview-api": "^7.0.9",
63
60
  "@storybook/react": "^7.0.9",
64
61
  "@storybook/react-vite": "^7.0.9",
65
- "@storybook/test-runner": "^0.10.0",
66
- "@storybook/testing-library": "^0.1.0",
67
62
  "@storybook/theming": "^7.0.9",
68
63
  "@testing-library/cypress": "^8.0.7",
69
- "@testing-library/jest-dom": "^5.16.5",
70
64
  "@testing-library/react": "^13.4.0",
71
65
  "@testing-library/react-hooks": "^8.0.1",
72
66
  "@types/jest": "^27.5.0",
73
67
  "@types/ramda": "^0.28.12",
74
68
  "@types/react": "^18.0.26",
75
- "@types/testing-library__jest-dom": "^5.14.6",
76
69
  "@vitejs/plugin-react": "^4.0.0",
77
70
  "@vitejs/plugin-react-swc": "^3.3.0",
78
71
  "axios-mock-adapter": "^1.21.4",
@@ -90,9 +83,6 @@
90
83
  "storybook": "^7.0.9",
91
84
  "storybook-addon-mock": "^4.0.0",
92
85
  "storybook-dark-mode": "^3.0.0",
93
- "style-dictionary": "^3.8.0",
94
- "ts-node": "^10.9.1",
95
- "use-resize-observer": "^9.1.0",
96
86
  "vite": "^4.3.5",
97
87
  "vite-plugin-svgr": "^3.2.0",
98
88
  "vite-plugin-turbosnap": "^1.0.2"
@@ -102,7 +92,14 @@
102
92
  "@lexical/react": "0.8.0",
103
93
  "@lexical/selection": "0.8.0",
104
94
  "@lexical/utils": "0.8.0",
95
+ "@visx/curve": "^2.1.0",
96
+ "@visx/pattern": "^3.0.0",
97
+ "@visx/scale": "^3.0.0",
98
+ "@visx/shape": "^2.12.2",
99
+ "@visx/threshold": "^2.12.2",
100
+ "@visx/visx": "2.16.0",
105
101
  "anylogger": "^1.0.11",
102
+ "d3-array": "3.2.0",
106
103
  "humanize-duration": "^3.27.3",
107
104
  "lexical": "0.8.0",
108
105
  "notistack": "^2.0.8",
@@ -0,0 +1 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"><defs><style>.a{fill:none;}.b{opacity:1;}</style></defs><g transform="translate(-94.852 -137.365)"><rect class="a" width="24" height="24" transform="translate(94.852 137.365)"/><g class="b" transform="translate(97.108 140.129)"><path d="M103.476,143.64a1.692,1.692,0,1,0-1.692-1.692A1.692,1.692,0,0,0,103.476,143.64Z" transform="translate(-97.132 -140.255)"/><path d="M114.266,150.2a1.05,1.05,0,0,0-.968-.647s-2.067-.275-2.68.125a2.464,2.464,0,0,0-.644.8l-3.454-.547c-.265-.874-1.4-4.183-1.4-4.183l-.846-1.353a1.743,1.743,0,0,0-1.438-.846,4.571,4.571,0,0,0-.677.084l-4.4,1.867v3.976H98l2.222.352-1.61,8.107h1.777l1.522-6.768,1.777,1.692v5.076h1.692v-6.345l-1.19-1.135,5.428.859-3.084,6.815,10.976-.11Zm-10.206-2.611s.577,1.356.88,2.089l-1.259-.2Zm-4.606,1.22v-2.212l1.522-.592-.586,2.952Z" transform="translate(-97.762 -139.74)"/></g></g></svg>
@@ -1,3 +1,5 @@
1
+ import { ReactElement } from 'react';
2
+
1
3
  import { ComponentMeta } from '@storybook/react';
2
4
  import { Layout } from 'react-grid-layout';
3
5
 
@@ -60,18 +62,18 @@ const generateLayout = (maxElements: number): Array<CustomLayout> => {
60
62
  };
61
63
 
62
64
  interface DashboardTemplateProps {
63
- header?: JSX.Element;
65
+ header?: ReactElement;
64
66
  layout?: Array<CustomLayout>;
65
67
  }
66
68
 
67
- const Header = (): JSX.Element => (
69
+ const Header = (): ReactElement => (
68
70
  <Typography variant="body2">The title</Typography>
69
71
  );
70
72
 
71
73
  const DashboardTemplate = ({
72
74
  header,
73
75
  layout = dashboardLayout
74
- }: DashboardTemplateProps): JSX.Element => (
76
+ }: DashboardTemplateProps): ReactElement => (
75
77
  <DashboardLayout.Layout<CustomLayout> layout={layout}>
76
78
  {layout.map(({ i, content, shouldUseFluidTypography }) => (
77
79
  <DashboardLayout.Item header={header} key={i}>
@@ -1,4 +1,4 @@
1
- import { useEffect, useState } from 'react';
1
+ import { ReactElement, useEffect, useState } from 'react';
2
2
 
3
3
  import { Responsive } from '@visx/visx';
4
4
  import GridLayout, { Layout, WidthProvider } from 'react-grid-layout';
@@ -14,7 +14,7 @@ const ReactGridLayout = WidthProvider(GridLayout);
14
14
 
15
15
  interface DashboardLayoutProps<T> {
16
16
  changeLayout?: (newLayout: Array<Layout>) => void;
17
- children: Array<JSX.Element>;
17
+ children: Array<ReactElement>;
18
18
  displayGrid?: boolean;
19
19
  layout: Array<T>;
20
20
  }
@@ -24,7 +24,7 @@ const Layout = <T extends Layout>({
24
24
  changeLayout,
25
25
  displayGrid,
26
26
  layout
27
- }: DashboardLayoutProps<T>): JSX.Element => {
27
+ }: DashboardLayoutProps<T>): ReactElement => {
28
28
  const { classes } = useDashboardLayoutStyles();
29
29
 
30
30
  const [columns, setColumns] = useState(getColumnsFromScreenSize());
@@ -45,7 +45,7 @@ const Layout = <T extends Layout>({
45
45
  Component: (
46
46
  <ResponsiveHeight>
47
47
  <Responsive.ParentSize>
48
- {({ width, height }): JSX.Element => (
48
+ {({ width, height }): ReactElement => (
49
49
  <div className={classes.container}>
50
50
  {displayGrid && (
51
51
  <Grid columns={columns} height={height} width={width} />
@@ -1,28 +1,28 @@
1
- import { lt } from 'ramda';
2
- import { Layout } from 'react-grid-layout';
3
-
4
- export const maxColumns = 12;
5
- const minColumns = 1;
6
- const breakpoint = 768;
7
-
8
- export const rowHeight = 64;
9
-
10
- export const getIsSmallScreenSize = (): boolean =>
11
- lt(window.innerWidth, breakpoint);
12
-
13
- export const getColumnsFromScreenSize = (): number =>
14
- getIsSmallScreenSize() ? minColumns : maxColumns;
15
-
16
- export const getLayout = <T extends Layout>(layout: Array<T>): Array<T> => {
17
- const isSmallScreenSize = getIsSmallScreenSize();
18
- if (!isSmallScreenSize) {
19
- return layout;
20
- }
21
-
22
- return layout
23
- .sort((a, b) => a.x + a.y - (b.x + b.y))
24
- .map((widget) => ({
25
- ...widget,
26
- w: 1
27
- }));
28
- };
1
+ import { lt } from 'ramda';
2
+ import { Layout } from 'react-grid-layout';
3
+
4
+ export const maxColumns = 12;
5
+ const minColumns = 1;
6
+ const breakpoint = 768;
7
+
8
+ export const rowHeight = 64;
9
+
10
+ export const getIsSmallScreenSize = (): boolean =>
11
+ lt(window.innerWidth, breakpoint);
12
+
13
+ export const getColumnsFromScreenSize = (): number =>
14
+ getIsSmallScreenSize() ? minColumns : maxColumns;
15
+
16
+ export const getLayout = <T extends Layout>(layout: Array<T>): Array<T> => {
17
+ const isSmallScreenSize = getIsSmallScreenSize();
18
+ if (!isSmallScreenSize) {
19
+ return layout;
20
+ }
21
+
22
+ return layout
23
+ .sort((a, b) => a.x + a.y - (b.x + b.y))
24
+ .map((widget) => ({
25
+ ...widget,
26
+ w: 1
27
+ }));
28
+ };
@@ -0,0 +1,20 @@
1
+ import { commonTickLabelProps } from '../../common';
2
+
3
+ interface UnitLabelProps {
4
+ unit: string;
5
+ x: number;
6
+ y?: number;
7
+ }
8
+
9
+ const UnitLabel = ({ x, y = 16, unit }: UnitLabelProps): JSX.Element => (
10
+ <text
11
+ fontFamily={commonTickLabelProps.fontFamily}
12
+ fontSize={commonTickLabelProps.fontSize}
13
+ x={x}
14
+ y={-y}
15
+ >
16
+ {unit}
17
+ </text>
18
+ );
19
+
20
+ export default UnitLabel;
@@ -0,0 +1,88 @@
1
+ import { Axis } from '@visx/visx';
2
+ import { ScaleLinear } from 'd3-scale';
3
+ import { isNil } from 'ramda';
4
+
5
+ import { useLocaleDateTimeFormat } from '@centreon/ui';
6
+
7
+ import { getXAxisTickFormat } from '../../helpers';
8
+ import { GraphInterval } from '../../models';
9
+ import { getUnits } from '../../timeSeries';
10
+
11
+ import UnitLabel from './UnitLabel';
12
+ import { Data } from './models';
13
+ import useAxisY from './useAxisY';
14
+
15
+ interface Props {
16
+ data: Data;
17
+ graphInterval: GraphInterval;
18
+ height: number;
19
+ leftScale: ScaleLinear<number, number>;
20
+ rightScale: ScaleLinear<number, number>;
21
+ width: number;
22
+ xScale: ScaleLinear<number, number>;
23
+ }
24
+
25
+ const Axes = ({
26
+ height,
27
+ width,
28
+ data,
29
+ rightScale,
30
+ leftScale,
31
+ xScale,
32
+ graphInterval
33
+ }: Props): JSX.Element => {
34
+ const { format } = useLocaleDateTimeFormat();
35
+ const { lines } = data;
36
+
37
+ const { axisLeft, axisRight } = useAxisY({ data, graphHeight: height });
38
+
39
+ const [firstUnit, secondUnit, thirdUnit] = getUnits(lines);
40
+
41
+ const xTickCount = Math.ceil(width / 82);
42
+
43
+ const tickFormat =
44
+ data?.axisX?.xAxisTickFormat ?? getXAxisTickFormat(graphInterval);
45
+
46
+ const formatAxisTick = (tick): string =>
47
+ format({ date: new Date(tick), formatString: tickFormat });
48
+
49
+ const hasMoreThanTwoUnits = !isNil(thirdUnit);
50
+ const displayAxisRight = !isNil(secondUnit) && !hasMoreThanTwoUnits;
51
+
52
+ return (
53
+ <g>
54
+ <Axis.AxisBottom
55
+ numTicks={xTickCount}
56
+ scale={xScale}
57
+ tickFormat={formatAxisTick}
58
+ top={height}
59
+ />
60
+
61
+ {axisLeft.displayUnit && <UnitLabel unit={firstUnit} x={-4} />}
62
+
63
+ <Axis.AxisLeft
64
+ numTicks={axisLeft?.numTicks}
65
+ orientation="left"
66
+ scale={leftScale}
67
+ tickFormat={axisLeft.tickFormat}
68
+ tickLabelProps={axisLeft.tickLabelProps}
69
+ tickLength={2}
70
+ />
71
+
72
+ {displayAxisRight && (
73
+ <Axis.AxisRight
74
+ left={width}
75
+ numTicks={axisRight?.numTicks}
76
+ orientation="right"
77
+ scale={rightScale}
78
+ tickFormat={axisRight.tickFormat}
79
+ tickLabelProps={axisRight.tickLabelProps}
80
+ tickLength={2}
81
+ />
82
+ )}
83
+ {axisRight.displayUnit && <UnitLabel unit={secondUnit} x={width} />}
84
+ </g>
85
+ );
86
+ };
87
+
88
+ export default Axes;
@@ -0,0 +1,26 @@
1
+ import { Line, TimeValue } from '../../timeSeries/models';
2
+
3
+ export interface LabelProps {
4
+ [x: string]: unknown;
5
+ textAnchor?: string;
6
+ }
7
+
8
+ export interface Axis {
9
+ displayUnit?: boolean;
10
+ }
11
+
12
+ export interface AxisYRight extends Axis {
13
+ display?: boolean;
14
+ }
15
+
16
+ export interface AxisX {
17
+ xAxisTickFormat?: string;
18
+ }
19
+ export interface Data {
20
+ axisX?: AxisX;
21
+ axisYLeft?: Axis;
22
+ axisYRight?: AxisYRight;
23
+ baseAxis: number;
24
+ lines: Array<Line>;
25
+ timeSeries: Array<TimeValue>;
26
+ }
@@ -0,0 +1,100 @@
1
+ import { isNil } from 'ramda';
2
+ import { Axis } from '@visx/visx';
3
+
4
+ import { useTheme } from '@mui/material';
5
+
6
+ import { formatMetricValue, getUnits } from '../../timeSeries';
7
+ import { commonTickLabelProps } from '../../common';
8
+
9
+ import { Data, LabelProps } from './models';
10
+
11
+ interface AxisYData {
12
+ displayUnit: boolean;
13
+ numTicks?: number;
14
+ tickFormat: (value: unknown) => string;
15
+ tickLabelProps: Axis.TickLabelProps<unknown>;
16
+ }
17
+
18
+ interface AxisRightData extends AxisYData {
19
+ display: boolean;
20
+ }
21
+
22
+ interface AxisY {
23
+ axisLeft: AxisYData;
24
+ axisRight: AxisRightData;
25
+ }
26
+
27
+ interface Props {
28
+ data: Omit<Data, 'timeSeries'>;
29
+ graphHeight?: number;
30
+ }
31
+
32
+ const useAxisY = ({ data, graphHeight }: Props): AxisY => {
33
+ const theme = useTheme();
34
+
35
+ const { lines } = data;
36
+ const [firstUnit, secondUnit, thirdUnit] = getUnits(lines);
37
+
38
+ const numTicks = graphHeight && Math.ceil(graphHeight / 30);
39
+
40
+ const hasMoreThanTwoUnits = !isNil(thirdUnit);
41
+ const hasTwoUnits = !isNil(secondUnit) && !hasMoreThanTwoUnits;
42
+
43
+ const displayAxisRight = data?.axisYRight?.display ?? hasTwoUnits;
44
+ const displayUnitAxisRight = data?.axisYRight?.displayUnit ?? hasTwoUnits;
45
+ const displayUnitAxisLeft =
46
+ data?.axisYLeft?.displayUnit ?? !hasMoreThanTwoUnits;
47
+
48
+ const formatTick =
49
+ ({ unit }) =>
50
+ (value): string => {
51
+ if (isNil(value)) {
52
+ return '';
53
+ }
54
+
55
+ return formatMetricValue({ base: data.baseAxis, unit, value }) as string;
56
+ };
57
+
58
+ const labelProps = ({
59
+ textAnchor,
60
+ ...rest
61
+ }: LabelProps): Record<string, unknown> => ({
62
+ ...commonTickLabelProps,
63
+ textAnchor,
64
+ ...rest
65
+ });
66
+
67
+ const tickLabelPropsAxisLeft = (): Record<string, unknown> =>
68
+ labelProps({
69
+ dx: theme.spacing(-1),
70
+ dy: theme.spacing(0.5),
71
+ textAnchor: 'end'
72
+ });
73
+
74
+ const tickLabelPropsAxisRight = (): Record<string, unknown> =>
75
+ labelProps({
76
+ dx: theme.spacing(0.5),
77
+ dy: theme.spacing(0.5),
78
+ textAnchor: 'start'
79
+ });
80
+
81
+ return {
82
+ axisLeft: {
83
+ displayUnit: displayUnitAxisLeft,
84
+ numTicks,
85
+ tickFormat: formatTick({
86
+ unit: hasMoreThanTwoUnits ? '' : firstUnit
87
+ }),
88
+ tickLabelProps: tickLabelPropsAxisLeft
89
+ },
90
+ axisRight: {
91
+ display: displayAxisRight,
92
+ displayUnit: displayUnitAxisRight,
93
+ numTicks,
94
+ tickFormat: formatTick({ unit: secondUnit }),
95
+ tickLabelProps: tickLabelPropsAxisRight
96
+ }
97
+ };
98
+ };
99
+
100
+ export default useAxisY;
@@ -0,0 +1,20 @@
1
+ import { Grid } from '@visx/visx';
2
+ import { ScaleLinear } from 'd3-scale';
3
+
4
+ interface Props {
5
+ height: number;
6
+ leftScale: ScaleLinear<number, number>;
7
+ width: number;
8
+ xScale: ScaleLinear<number, number>;
9
+ }
10
+
11
+ const Grids = ({ height, width, leftScale, xScale }: Props): JSX.Element => {
12
+ return (
13
+ <g>
14
+ <Grid.GridRows height={height} scale={leftScale} width={width} />
15
+ <Grid.GridColumns height={height} scale={xScale} width={width} />
16
+ </g>
17
+ );
18
+ };
19
+
20
+ export default Grids;
@@ -0,0 +1,91 @@
1
+ import { memo } from 'react';
2
+
3
+ import { Curve, Shape } from '@visx/visx';
4
+ import { ScaleLinear, ScaleTime } from 'd3-scale';
5
+ import { equals, isNil, prop } from 'ramda';
6
+
7
+ import { getTime } from '../../../timeSeries';
8
+ import { TimeValue } from '../../../timeSeries/models';
9
+ import { getFillColor } from '../../../common';
10
+
11
+ interface Props {
12
+ areaColor: string;
13
+ filled: boolean;
14
+ graphHeight: number;
15
+ highlight?: boolean;
16
+ lineColor: string;
17
+ metric: string;
18
+ shapeAreaClosed?: Record<string, unknown>;
19
+ shapeLinePath?: Record<string, unknown>;
20
+ timeSeries: Array<TimeValue>;
21
+ transparency: number;
22
+ unit: string;
23
+ xScale: ScaleTime<number, number>;
24
+ yScale: ScaleLinear<number, number>;
25
+ }
26
+
27
+ const RegularLine = ({
28
+ filled,
29
+ timeSeries,
30
+ highlight,
31
+ metric,
32
+ lineColor,
33
+ unit,
34
+ yScale,
35
+ xScale,
36
+ areaColor,
37
+ transparency,
38
+ graphHeight
39
+ }: Props): JSX.Element => {
40
+ const props = {
41
+ curve: Curve.curveLinear,
42
+ data: timeSeries,
43
+ defined: (value): boolean => !isNil(value[metric]),
44
+ opacity: 1,
45
+ stroke: lineColor,
46
+ strokeWidth: !highlight ? 1 : 2,
47
+ unit,
48
+ x: (timeValue): number => xScale(getTime(timeValue)) as number,
49
+ y: (timeValue): number => yScale(prop(metric, timeValue)) ?? null
50
+ };
51
+
52
+ if (filled) {
53
+ return (
54
+ <Shape.AreaClosed<TimeValue>
55
+ fill={getFillColor({ areaColor, transparency })}
56
+ fillRule="nonzero"
57
+ key={metric}
58
+ y0={Math.min(yScale(0), graphHeight)}
59
+ yScale={yScale}
60
+ {...props}
61
+ />
62
+ );
63
+ }
64
+
65
+ return <Shape.LinePath<TimeValue> {...props} />;
66
+ };
67
+
68
+ export default memo(RegularLine, (prevProps, nextProps) => {
69
+ const {
70
+ timeSeries: prevTimeSeries,
71
+ graphHeight: prevGraphHeight,
72
+ highlight: prevHighlight,
73
+ xScale: prevXScale
74
+ } = prevProps;
75
+ const {
76
+ timeSeries: nextTimeSeries,
77
+ graphHeight: nextGraphHeight,
78
+ highlight: nextHighlight,
79
+ xScale: nextXScale
80
+ } = nextProps;
81
+
82
+ const prevXScaleRange = prevXScale.range();
83
+ const nextXScaleRange = nextXScale.range();
84
+
85
+ return (
86
+ equals(prevTimeSeries, nextTimeSeries) &&
87
+ equals(prevGraphHeight, nextGraphHeight) &&
88
+ equals(prevHighlight, nextHighlight) &&
89
+ equals(prevXScaleRange, nextXScaleRange)
90
+ );
91
+ });
@@ -0,0 +1,15 @@
1
+ import { difference } from 'ramda';
2
+
3
+ import { Line } from '../../../timeSeries/models';
4
+ import { getSortedStackedLines } from '../../../timeSeries';
5
+
6
+ interface RegularLines {
7
+ regularLines: Array<Line>;
8
+ }
9
+ const useRegularLines = ({ lines }): RegularLines => {
10
+ const stackedLines = getSortedStackedLines(lines);
11
+
12
+ return { regularLines: difference(lines, stackedLines) };
13
+ };
14
+
15
+ export default useRegularLines;
@@ -0,0 +1,76 @@
1
+ import { Curve, Shape } from '@visx/visx';
2
+ import { ScaleLinear, ScaleTime } from 'd3-scale';
3
+ import { all, isNil, map, not, nth, path, pipe, prop } from 'ramda';
4
+
5
+ import StackedAnchorPoint from '../../../InteractiveComponents/AnchorPoint/StackedAnchorPoint';
6
+ import { StackValue } from '../../../InteractiveComponents/AnchorPoint/models';
7
+ import { getFillColor } from '../../../common';
8
+ import { getTime } from '../../../timeSeries';
9
+ import { Line, TimeValue } from '../../../timeSeries/models';
10
+
11
+ interface Props {
12
+ displayAnchor: boolean;
13
+ lines: Array<Line>;
14
+ timeSeries: Array<TimeValue>;
15
+ xScale: ScaleTime<number, number>;
16
+ yScale: ScaleLinear<number, number>;
17
+ }
18
+
19
+ const StackLines = ({
20
+ timeSeries,
21
+ lines,
22
+ yScale,
23
+ xScale,
24
+ displayAnchor
25
+ }: Props): JSX.Element => {
26
+ return (
27
+ <Shape.AreaStack
28
+ curve={Curve.curveLinear}
29
+ data={timeSeries}
30
+ defined={(d): boolean => {
31
+ return pipe(
32
+ map(prop('metric')) as unknown as (displayedLines) => Array<string>,
33
+ all((metric) => pipe(path(['data', metric]), isNil, not)(d))
34
+ )(lines);
35
+ }}
36
+ keys={map(prop('metric'), lines)}
37
+ x={(d): number => xScale(getTime(d.data)) ?? 0}
38
+ y0={(d): number => yScale(d[0]) ?? 0}
39
+ y1={(d): number => yScale(d[1]) ?? 0}
40
+ >
41
+ {({ stacks, path: linePath }): Array<JSX.Element> => {
42
+ return stacks.map((stack, index) => {
43
+ const { areaColor, transparency, lineColor, highlight } = nth(
44
+ index,
45
+ lines
46
+ ) as Line;
47
+
48
+ return (
49
+ <g key={`stack-${prop('key', stack)}`}>
50
+ {displayAnchor && (
51
+ <StackedAnchorPoint
52
+ areaColor={areaColor}
53
+ lineColor={lineColor}
54
+ stackValues={stack as unknown as Array<StackValue>}
55
+ timeSeries={timeSeries}
56
+ transparency={transparency}
57
+ xScale={xScale}
58
+ yScale={yScale}
59
+ />
60
+ )}
61
+ <path
62
+ d={linePath(stack) || ''}
63
+ fill={getFillColor({ areaColor, transparency })}
64
+ opacity={highlight === false ? 0.3 : 1}
65
+ stroke={lineColor}
66
+ strokeWidth={highlight ? 2 : 1}
67
+ />
68
+ </g>
69
+ );
70
+ });
71
+ }}
72
+ </Shape.AreaStack>
73
+ );
74
+ };
75
+
76
+ export default StackLines;
@@ -0,0 +1,39 @@
1
+ import {
2
+ getInvertedStackedLines,
3
+ getNotInvertedStackedLines,
4
+ getTimeSeriesForLines
5
+ } from '../../../timeSeries';
6
+ import { LinesData } from '../models';
7
+
8
+ interface StackedLines {
9
+ invertedStackedLinesData: LinesData;
10
+ stackedLinesData: LinesData;
11
+ }
12
+
13
+ const useStackedLines = ({ lines, timeSeries }): StackedLines => {
14
+ const regularStackedLines = getNotInvertedStackedLines(lines);
15
+
16
+ const regularStackedTimeSeries = getTimeSeriesForLines({
17
+ lines: regularStackedLines,
18
+ timeSeries
19
+ });
20
+
21
+ const invertedStackedLines = getInvertedStackedLines(lines);
22
+ const invertedStackedTimeSeries = getTimeSeriesForLines({
23
+ lines: invertedStackedLines,
24
+ timeSeries
25
+ });
26
+
27
+ return {
28
+ invertedStackedLinesData: {
29
+ lines: invertedStackedLines,
30
+ timeSeries: invertedStackedTimeSeries
31
+ },
32
+ stackedLinesData: {
33
+ lines: regularStackedLines,
34
+ timeSeries: regularStackedTimeSeries
35
+ }
36
+ };
37
+ };
38
+
39
+ export default useStackedLines;