@centreon/ui 23.10.18-MON-17793-create-graph-component-centreon-ui.0 → 23.10.18-MON-17793-create-graph-component-centreon-ui.1

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 (105) hide show
  1. package/package.json +1 -1
  2. package/src/Button/Icon/index.tsx +1 -1
  3. package/src/Button/Save/index.tsx +1 -1
  4. package/src/FileDropZone/index.tsx +1 -1
  5. package/src/Form/FormButtons.tsx +1 -2
  6. package/src/Form/Inputs/Autocomplete.tsx +1 -1
  7. package/src/Form/Inputs/Radio.tsx +1 -1
  8. package/src/Form/Inputs/Switch.tsx +1 -1
  9. package/src/Graph/{Axes → BasicComponents/Axes}/UnitLabel.tsx +1 -1
  10. package/src/Graph/{Axes → BasicComponents/Axes}/index.tsx +9 -24
  11. package/src/Graph/{Axes → BasicComponents/Axes}/models.ts +1 -1
  12. package/src/Graph/{Axes → BasicComponents/Axes}/useAxisY.ts +2 -2
  13. package/src/Graph/{Lines → BasicComponents/Lines}/RegularLines/index.tsx +3 -3
  14. package/src/Graph/{Lines → BasicComponents/Lines}/RegularLines/useRegularLines.ts +2 -2
  15. package/src/Graph/{Lines → BasicComponents/Lines}/StackedLines/index.tsx +4 -4
  16. package/src/Graph/{Lines → BasicComponents/Lines}/StackedLines/useStackedLines.ts +1 -1
  17. package/src/Graph/{Lines → BasicComponents/Lines}/index.tsx +3 -3
  18. package/src/Graph/{Lines → BasicComponents/Lines}/models.ts +1 -1
  19. package/src/Graph/Graph.styles.ts +37 -0
  20. package/src/Graph/Graph.tsx +86 -61
  21. package/src/Graph/Header/index.tsx +1 -1
  22. package/src/Graph/{InteractionWithGraph → IntercatifsComponents}/AnchorPoint/useAnchorPoint.ts +1 -3
  23. package/src/Graph/IntercatifsComponents/Annotations/Annotation/Area.tsx +114 -0
  24. package/src/Graph/IntercatifsComponents/Annotations/Annotation/Line.tsx +103 -0
  25. package/src/Graph/IntercatifsComponents/Annotations/Annotation/index.tsx +81 -0
  26. package/src/Graph/IntercatifsComponents/Annotations/Area/Downtime.tsx +27 -0
  27. package/src/Graph/IntercatifsComponents/Annotations/EventAnnotations.tsx +61 -0
  28. package/src/Graph/IntercatifsComponents/Annotations/Line/Acknowledgement.tsx +27 -0
  29. package/src/Graph/IntercatifsComponents/Annotations/Line/Comments.tsx +25 -0
  30. package/src/Graph/IntercatifsComponents/Annotations/annotationsAtoms.ts +183 -0
  31. package/src/Graph/IntercatifsComponents/Annotations/index.tsx +49 -0
  32. package/src/Graph/IntercatifsComponents/Annotations/models.ts +25 -0
  33. package/src/Graph/IntercatifsComponents/Annotations/useAnnotation.ts +62 -0
  34. package/src/Graph/IntercatifsComponents/TimeShiftZones/TimeShiftIcon.tsx +58 -0
  35. package/src/Graph/IntercatifsComponents/TimeShiftZones/TimeShiftZone.tsx +74 -0
  36. package/src/Graph/IntercatifsComponents/TimeShiftZones/index.tsx +84 -0
  37. package/src/Graph/IntercatifsComponents/TimeShiftZones/models.ts +12 -0
  38. package/src/Graph/IntercatifsComponents/TimeShiftZones/useTimeShiftZones.ts +72 -0
  39. package/src/Graph/IntercatifsComponents/Tooltip/index.tsx +64 -0
  40. package/src/Graph/IntercatifsComponents/Tooltip/models.ts +9 -0
  41. package/src/Graph/IntercatifsComponents/Tooltip/useGraphTooltip.ts +77 -0
  42. package/src/Graph/{InteractionWithGraph → IntercatifsComponents}/ZoomPreview/index.tsx +5 -3
  43. package/src/Graph/{InteractionWithGraph → IntercatifsComponents}/ZoomPreview/models.ts +2 -7
  44. package/src/Graph/{InteractionWithGraph → IntercatifsComponents}/ZoomPreview/useZoomPreview.ts +23 -11
  45. package/src/Graph/IntercatifsComponents/ZoomPreview/zoomPreviewAtoms.ts +3 -0
  46. package/src/Graph/{InteractionWithGraph → IntercatifsComponents}/index.tsx +51 -10
  47. package/src/Graph/{InteractionWithGraph/mouseTimeValueAtoms.ts → IntercatifsComponents/interactionWithGraphAtoms.ts} +8 -5
  48. package/src/Graph/helpers/doc.ts +21 -10
  49. package/src/Graph/helpers/index.ts +35 -3
  50. package/src/Graph/icons/Downtime.tsx +9 -0
  51. package/src/Graph/icons/downtime.icon.svg +1 -0
  52. package/src/Graph/index.stories.tsx +143 -12
  53. package/src/Graph/index.tsx +18 -9
  54. package/src/Graph/map.md +51 -0
  55. package/src/Graph/mockedData/annotationData.json +189 -0
  56. package/src/Graph/mockedData/lastDay.json +1338 -0
  57. package/src/Graph/mockedData/lastDayForward.json +1338 -0
  58. package/src/Graph/mockedData/lastMonth.json +1674 -0
  59. package/src/Graph/mockedData/lastWeek.json +2202 -0
  60. package/src/Graph/mockedData/zoomPreview.json +350 -0
  61. package/src/Graph/models.ts +47 -11
  62. package/src/Graph/translatedLabels.ts +6 -0
  63. package/src/Graph/useGraphData.ts +22 -76
  64. package/src/InputField/Select/Autocomplete/Connected/index.tsx +5 -3
  65. package/src/InputField/Select/Autocomplete/index.tsx +1 -1
  66. package/src/InputField/Select/index.tsx +1 -1
  67. package/src/InputField/Text/index.tsx +1 -1
  68. package/src/Listing/ActionBar/index.tsx +1 -1
  69. package/src/Listing/index.tsx +1 -2
  70. package/src/ListingPage/index.tsx +1 -1
  71. package/src/Panel/Memoized.tsx +1 -1
  72. package/src/Panel/Section/index.tsx +1 -1
  73. package/src/SortableItems/SortableItem.tsx +1 -1
  74. package/src/TimePeriods/CustomTimePeriod/PopoverCustomTimePeriod/PickersStartEndDate.tsx +5 -2
  75. package/src/TimePeriods/DateTimePickerInput.tsx +21 -71
  76. package/src/TimePeriods/TimePeriods.cypress.spec.tsx +42 -29
  77. package/src/TimePeriods/index.stories.tsx +1 -1
  78. package/src/TimePeriods/index.tsx +21 -5
  79. package/src/TimePeriods/map.md +34 -0
  80. package/src/TimePeriods/models.ts +7 -11
  81. package/src/TimePeriods/timePeriodsAtoms.ts +9 -0
  82. package/src/index.ts +2 -18
  83. package/src/utils/getNormalizedId.ts +1 -3
  84. package/src/utils/index.ts +15 -0
  85. package/src/utils/useCopyToClipboard.ts +2 -3
  86. package/src/{TimePeriods → utils}/useDateTimePickerAdapter.ts +70 -90
  87. package/src/utils/useDebounce.ts +1 -3
  88. package/src/utils/useDeepCallback.ts +1 -3
  89. package/src/utils/useDeepMemo.ts +1 -3
  90. package/src/utils/useIntersectionObserver.ts +1 -3
  91. package/src/utils/useKeyObserver.tsx +1 -3
  92. package/src/utils/useLocaleDateTimeFormat/index.test.tsx +1 -1
  93. package/src/utils/useLocaleDateTimeFormat/index.ts +1 -2
  94. package/src/utils/useLocaleDateTimeFormat/localeFallback.test.tsx +1 -1
  95. package/src/utils/useMemoComponent.ts +1 -3
  96. package/src/Graph/InteractionWithGraph/ZoomPreview/zoomPreviewAtoms.ts +0 -5
  97. package/src/Graph/InteractionWithGraph/interactionWithGraphAtoms.ts +0 -7
  98. package/src/Graph/data.json +0 -1338
  99. /package/src/Graph/{Grids → BasicComponents/Grids}/index.tsx +0 -0
  100. /package/src/Graph/{LoadingProgress.tsx → BasicComponents/LoadingProgress.tsx} +0 -0
  101. /package/src/Graph/{InteractionWithGraph → IntercatifsComponents}/AnchorPoint/RegularAnchorPoint.tsx +0 -0
  102. /package/src/Graph/{InteractionWithGraph → IntercatifsComponents}/AnchorPoint/StackedAnchorPoint.tsx +0 -0
  103. /package/src/Graph/{InteractionWithGraph → IntercatifsComponents}/AnchorPoint/index.tsx +0 -0
  104. /package/src/Graph/{InteractionWithGraph → IntercatifsComponents}/AnchorPoint/models.ts +0 -0
  105. /package/src/Graph/{InteractionWithGraph → IntercatifsComponents}/Bar.tsx +0 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@centreon/ui",
3
- "version": "23.10.18-MON-17793-create-graph-component-centreon-ui.0",
3
+ "version": "23.10.18-MON-17793-create-graph-component-centreon-ui.1",
4
4
  "description": "Centreon UI Components",
5
5
  "scripts": {
6
6
  "eslint": "eslint ./src --ext .js,.jsx,.ts,.tsx --max-warnings 0",
@@ -6,7 +6,7 @@ import {
6
6
  Tooltip
7
7
  } from '@mui/material';
8
8
 
9
- import getNormalizedId from '../../utils/getNormalizedId';
9
+ import { getNormalizedId } from '../../utils';
10
10
 
11
11
  const useStyles = makeStyles()((theme) => ({
12
12
  button: {
@@ -4,7 +4,7 @@ import { makeStyles } from 'tss-react/mui';
4
4
  import { Theme, Tooltip } from '@mui/material';
5
5
  import { LoadingButton } from '@mui/lab';
6
6
 
7
- import getNormalizedId from '../../utils/getNormalizedId';
7
+ import { getNormalizedId } from '../../utils';
8
8
 
9
9
  import StartIcon from './StartIcon';
10
10
  import Content from './Content';
@@ -17,7 +17,7 @@ import { alpha, Box, FormHelperText, Typography } from '@mui/material';
17
17
 
18
18
  import { userAtom } from '@centreon/ui-context';
19
19
 
20
- import useMemoComponent from '../utils/useMemoComponent';
20
+ import { useMemoComponent } from '../utils';
21
21
 
22
22
  import { labelDropOr, labelSelectAFile } from './translatedLabels';
23
23
  import useDropzone, { UseDropzoneState } from './useDropzone';
@@ -8,8 +8,7 @@ import { makeStyles } from 'tss-react/mui';
8
8
  import { Button } from '@mui/material';
9
9
 
10
10
  import SaveButton from '../Button/Save';
11
- import useMemoComponent from '../utils/useMemoComponent';
12
- import getNormalizedId from '../utils/getNormalizedId';
11
+ import { useMemoComponent, getNormalizedId } from '../utils';
13
12
 
14
13
  import {
15
14
  labelReset,
@@ -9,7 +9,7 @@ import { FormHelperText, Stack } from '@mui/material';
9
9
  import SingleAutocompleteField from '../../InputField/Select/Autocomplete';
10
10
  import { labelPressEnterToAccept } from '../translatedLabels';
11
11
  import MultiAutocompleteField from '../../InputField/Select/Autocomplete/Multi';
12
- import useMemoComponent from '../../utils/useMemoComponent';
12
+ import { useMemoComponent } from '../../utils';
13
13
  import { SelectEntry } from '../../InputField/Select';
14
14
 
15
15
  import { InputPropsWithoutGroup, InputType } from './models';
@@ -11,7 +11,7 @@ import {
11
11
  } from '@mui/material';
12
12
 
13
13
  import { useMemoComponent } from '../..';
14
- import getNormalizedId from '../../utils/getNormalizedId';
14
+ import { getNormalizedId } from '../../utils';
15
15
 
16
16
  import { InputPropsWithoutGroup } from './models';
17
17
 
@@ -6,7 +6,7 @@ import { useTranslation } from 'react-i18next';
6
6
 
7
7
  import { FormControlLabel, Switch as MUISwitch } from '@mui/material';
8
8
 
9
- import getNormalizedId from '../../utils/getNormalizedId';
9
+ import { getNormalizedId } from '../../utils/getNormalizedId';
10
10
  import { useMemoComponent } from '../..';
11
11
 
12
12
  import { InputPropsWithoutGroup } from './models';
@@ -1,4 +1,4 @@
1
- import { commonTickLabelProps } from '../common';
1
+ import { commonTickLabelProps } from '../../common';
2
2
 
3
3
  interface UnitLabelProps {
4
4
  unit: string;
@@ -1,14 +1,11 @@
1
1
  import { Axis } from '@visx/visx';
2
2
  import { ScaleLinear } from 'd3-scale';
3
- import dayjs from 'dayjs';
4
- import { gte } from 'ramda';
5
3
 
6
- import useLocaleDateTimeFormat, {
7
- dateFormat,
8
- timeFormat
9
- } from '../../utils/useLocaleDateTimeFormat';
10
- import { GraphParameters } from '../models';
11
- import { getUnits } from '../timeSeries';
4
+ import { useLocaleDateTimeFormat } from '@centreon/ui';
5
+
6
+ import { getUnits } from '../../timeSeries';
7
+ import { getXAxisTickFormat } from '../../helpers';
8
+ import { GraphInterval } from '../../models';
12
9
 
13
10
  import UnitLabel from './UnitLabel';
14
11
  import { Data } from './models';
@@ -16,9 +13,9 @@ import useAxisY from './useAxisY';
16
13
 
17
14
  interface Props {
18
15
  data: Data;
16
+ graphInterval: GraphInterval;
19
17
  height: number;
20
18
  leftScale: ScaleLinear<number, number>;
21
- queryParameters?: GraphParameters;
22
19
  rightScale: ScaleLinear<number, number>;
23
20
  width: number;
24
21
  xScale: ScaleLinear<number, number>;
@@ -31,7 +28,7 @@ const Axes = ({
31
28
  rightScale,
32
29
  leftScale,
33
30
  xScale,
34
- queryParameters
31
+ graphInterval
35
32
  }: Props): JSX.Element => {
36
33
  const { format } = useLocaleDateTimeFormat();
37
34
  const { lines } = data;
@@ -42,20 +39,8 @@ const Axes = ({
42
39
 
43
40
  const xTickCount = Math.ceil(width / 82);
44
41
 
45
- const getXAxisTickFormat = (): string => {
46
- const parameters = queryParameters;
47
- if (!parameters) {
48
- return timeFormat;
49
- }
50
-
51
- const numberDays = dayjs
52
- .duration(dayjs(parameters.end).diff(dayjs(parameters.start)))
53
- .asDays();
54
-
55
- return gte(numberDays, 2) ? dateFormat : timeFormat;
56
- };
57
-
58
- const tickFormat = data?.axisX?.xAxisTickFormat || getXAxisTickFormat();
42
+ const tickFormat =
43
+ data?.axisX?.xAxisTickFormat ?? getXAxisTickFormat(graphInterval);
59
44
 
60
45
  const formatAxisTick = (tick): string =>
61
46
  format({ date: new Date(tick), formatString: tickFormat });
@@ -1,4 +1,4 @@
1
- import { Line, TimeValue } from '../timeSeries/models';
1
+ import { Line, TimeValue } from '../../timeSeries/models';
2
2
 
3
3
  export interface LabelProps {
4
4
  [x: string]: unknown;
@@ -3,8 +3,8 @@ import { Axis } from '@visx/visx';
3
3
 
4
4
  import { useTheme } from '@mui/material';
5
5
 
6
- import { formatMetricValue, getUnits } from '../timeSeries';
7
- import { commonTickLabelProps } from '../common';
6
+ import { formatMetricValue, getUnits } from '../../timeSeries';
7
+ import { commonTickLabelProps } from '../../common';
8
8
 
9
9
  import { Data, LabelProps } from './models';
10
10
 
@@ -4,9 +4,9 @@ import { Curve, Shape } from '@visx/visx';
4
4
  import { ScaleLinear, ScaleTime } from 'd3-scale';
5
5
  import { equals, isNil, prop } from 'ramda';
6
6
 
7
- import { getTime } from '../../timeSeries';
8
- import { TimeValue } from '../../timeSeries/models';
9
- import { getFillColor } from '../../common';
7
+ import { getTime } from '../../../timeSeries';
8
+ import { TimeValue } from '../../../timeSeries/models';
9
+ import { getFillColor } from '../../../common';
10
10
 
11
11
  interface Props {
12
12
  areaColor: string;
@@ -1,7 +1,7 @@
1
1
  import { difference } from 'ramda';
2
2
 
3
- import { Line } from '../../timeSeries/models';
4
- import { getSortedStackedLines } from '../../timeSeries';
3
+ import { Line } from '../../../timeSeries/models';
4
+ import { getSortedStackedLines } from '../../../timeSeries';
5
5
 
6
6
  interface RegularLines {
7
7
  regularLines: Array<Line>;
@@ -4,10 +4,10 @@ import { map, nth, pipe, path, all, not, isNil, prop } from 'ramda';
4
4
  import { Shape, Curve } from '@visx/visx';
5
5
  import { ScaleLinear, ScaleTime } from 'd3-scale';
6
6
 
7
- import { Line, TimeValue } from '../../timeSeries/models';
8
- import { getTime } from '../../timeSeries';
9
- import { getFillColor } from '../../common';
10
- import { StackedAnchorPoint } from '../../InteractionWithGraph/AnchorPoint/models';
7
+ import { Line, TimeValue } from '../../../timeSeries/models';
8
+ import { getTime } from '../../../timeSeries';
9
+ import { getFillColor } from '../../../common';
10
+ import { StackedAnchorPoint } from '../../../IntercatifsComponents/AnchorPoint/models';
11
11
 
12
12
  interface Props {
13
13
  lines: Array<Line>;
@@ -2,7 +2,7 @@ import {
2
2
  getInvertedStackedLines,
3
3
  getNotInvertedStackedLines,
4
4
  getTimeSeriesForLines
5
- } from '../../timeSeries';
5
+ } from '../../../timeSeries';
6
6
  import { LinesData } from '../models';
7
7
 
8
8
  interface StackedLines {
@@ -2,12 +2,12 @@ import { ReactNode } from 'react';
2
2
 
3
3
  import { isEmpty, isNil } from 'ramda';
4
4
 
5
- import { getStackedYScale, getUnits, getYScale } from '../timeSeries';
6
- import { Line } from '../timeSeries/models';
5
+ import { getStackedYScale, getUnits, getYScale } from '../../timeSeries';
6
+ import { Line } from '../../timeSeries/models';
7
7
  import {
8
8
  RegularLinesAnchorPoint,
9
9
  StackedAnchorPoint
10
- } from '../InteractionWithGraph/AnchorPoint/models';
10
+ } from '../../IntercatifsComponents/AnchorPoint/models';
11
11
 
12
12
  import RegularLine from './RegularLines';
13
13
  import StackedLines from './StackedLines';
@@ -1,6 +1,6 @@
1
1
  import { ScaleLinear } from 'd3-scale';
2
2
 
3
- import { Line, TimeValue } from '../timeSeries/models';
3
+ import { Line, TimeValue } from '../../timeSeries/models';
4
4
 
5
5
  export interface ShapeGraphData {
6
6
  [x: string]: unknown;
@@ -0,0 +1,37 @@
1
+ import { makeStyles } from 'tss-react/mui';
2
+
3
+ const useStyles = makeStyles()((theme) => ({
4
+ container: {
5
+ '& .visx-axis-bottom': {
6
+ '& .visx-axis-tick': {
7
+ '& .visx-line': {
8
+ stroke: theme.palette.text.primary
9
+ }
10
+ }
11
+ },
12
+ '& .visx-axis-line': {
13
+ stroke: theme.palette.text.primary
14
+ },
15
+ '& .visx-axis-right': {
16
+ '& .visx-axis-tick': {
17
+ '& .visx-line': {
18
+ stroke: theme.palette.text.primary
19
+ }
20
+ }
21
+ },
22
+ '& .visx-columns': {
23
+ '& .visx-line': {
24
+ stroke: theme.palette.divider
25
+ }
26
+ },
27
+ '& .visx-rows': {
28
+ '& .visx-line': {
29
+ stroke: theme.palette.divider
30
+ }
31
+ },
32
+ fill: theme.palette.text.primary,
33
+ position: 'relative'
34
+ }
35
+ }));
36
+
37
+ export { useStyles };
@@ -2,30 +2,36 @@ import { useMemo, useRef } from 'react';
2
2
 
3
3
  import { Group } from '@visx/visx';
4
4
 
5
- import Axes from './Axes';
6
- import Grids from './Grids';
5
+ import { ClickAwayListener } from '@mui/material';
6
+
7
+ import Axes from './BasicComponents/Axes';
8
+ import Grids from './BasicComponents/Grids';
9
+ import Lines from './BasicComponents/Lines';
10
+ import useRegularLines from './BasicComponents/Lines/RegularLines/useRegularLines';
11
+ import useStackedLines from './BasicComponents/Lines/StackedLines/useStackedLines';
12
+ import LoadingProgress from './BasicComponents/LoadingProgress';
13
+ import { margin } from './common';
14
+ import { useStyles } from './Graph.styles';
7
15
  import Header from './Header';
8
- import InteractionWithGraph from './InteractionWithGraph';
9
- import RegularAnchorPoint from './InteractionWithGraph/AnchorPoint/RegularAnchorPoint';
10
- import StackedAnchorPoint from './InteractionWithGraph/AnchorPoint/StackedAnchorPoint';
16
+ import InteractionWithGraph from './IntercatifsComponents';
11
17
  import {
12
18
  RegularLinesAnchorPoint,
13
- StackValue,
14
- StackedAnchorPoint as StackedAnchorPointModel
15
- } from './InteractionWithGraph/AnchorPoint/models';
16
- import useAnchorPoint from './InteractionWithGraph/AnchorPoint/useAnchorPoint';
17
- import Lines from './Lines';
18
- import useRegularLines from './Lines/RegularLines/useRegularLines';
19
- import useStackedLines from './Lines/StackedLines/useStackedLines';
20
- import LoadingProgress from './LoadingProgress';
21
- import { margin } from './common';
22
- import { Data, GlobalAreaLines, GraphProps } from './models';
19
+ StackedAnchorPoint as StackedAnchorPointModel,
20
+ StackValue
21
+ } from './IntercatifsComponents/AnchorPoint/models';
22
+ import RegularAnchorPoint from './IntercatifsComponents/AnchorPoint/RegularAnchorPoint';
23
+ import StackedAnchorPoint from './IntercatifsComponents/AnchorPoint/StackedAnchorPoint';
24
+ import useAnchorPoint from './IntercatifsComponents/AnchorPoint/useAnchorPoint';
25
+ import GraphTooltip from './IntercatifsComponents/Tooltip';
26
+ import useGraphTooltip from './IntercatifsComponents/Tooltip/useGraphTooltip';
27
+ import { Data, GlobalAreaLines, GraphInterval, GraphProps } from './models';
23
28
  import { getLeftScale, getRightScale, getXScale } from './timeSeries';
24
29
 
25
30
  interface Props extends GraphProps {
26
31
  graphData: Data;
32
+ graphInterval: GraphInterval;
27
33
  loading: boolean;
28
- shapeLines: GlobalAreaLines;
34
+ shapeLines?: GlobalAreaLines;
29
35
  }
30
36
 
31
37
  const Graph = ({
@@ -36,14 +42,20 @@ const Graph = ({
36
42
  axis,
37
43
  anchorPoint,
38
44
  loading,
39
- zoomPreview
45
+ zoomPreview,
46
+ graphInterval,
47
+ timeShiftZones,
48
+ annotationEvent,
49
+ tooltip
40
50
  }: Props): JSX.Element => {
41
51
  const graphSvgRef = useRef<SVGSVGElement | null>(null);
42
52
 
53
+ const { classes } = useStyles();
54
+
43
55
  const graphWidth = width > 0 ? width - margin.left - margin.right : 0;
44
56
  const graphHeight = height > 0 ? height - margin.top - margin.bottom : 0;
45
57
 
46
- const { title, timeSeries, lines, baseAxis, queryParameters } = graphData;
58
+ const { title, timeSeries, lines, baseAxis } = graphData;
47
59
 
48
60
  const xScale = useMemo(
49
61
  () =>
@@ -87,6 +99,12 @@ const Graph = ({
87
99
 
88
100
  const { regularLines } = useRegularLines({ lines });
89
101
 
102
+ const graphTooltipData = useGraphTooltip({
103
+ graphWidth,
104
+ timeSeries,
105
+ xScale
106
+ });
107
+
90
108
  const commonLinesProps = {
91
109
  display: true,
92
110
  leftScale,
@@ -181,49 +199,56 @@ const Graph = ({
181
199
  timeTick={timeTick}
182
200
  title={title}
183
201
  />
184
- <LoadingProgress display={loading} height={height} width={width} />
185
- <svg height={height} ref={graphSvgRef} width="100%">
186
- <Group.Group left={margin.left} top={margin.top}>
187
- <Grids
188
- height={graphHeight}
189
- leftScale={leftScale}
190
- width={graphWidth}
191
- xScale={xScale}
192
- />
193
-
194
- <Axes
195
- data={{
196
- baseAxis,
197
- lines,
198
- timeSeries,
199
- ...axis
200
- }}
201
- height={graphHeight}
202
- leftScale={leftScale}
203
- queryParameters={queryParameters}
204
- rightScale={rightScale}
205
- width={graphWidth}
206
- xScale={xScale}
207
- />
208
-
209
- <Lines
210
- anchorPoint={{
211
- renderRegularLinesAnchorPoint,
212
- renderStackedAnchorPoint
213
- }}
214
- height={graphHeight}
215
- shape={{ areaRegularLines, areaStackedLines }}
216
- />
217
-
218
- <InteractionWithGraph
219
- commonData={{ graphHeight, graphSvgRef, graphWidth }}
220
- zoomData={{
221
- xScale,
222
- ...zoomPreview
223
- }}
224
- />
225
- </Group.Group>
226
- </svg>
202
+ <ClickAwayListener onClickAway={graphTooltipData?.hideTooltip}>
203
+ <div className={classes.container}>
204
+ <LoadingProgress display={loading} height={height} width={width} />
205
+ <svg height={height} ref={graphSvgRef} width="100%">
206
+ <Group.Group left={margin.left} top={margin.top}>
207
+ <Grids
208
+ height={graphHeight}
209
+ leftScale={leftScale}
210
+ width={graphWidth}
211
+ xScale={xScale}
212
+ />
213
+ <Axes
214
+ data={{
215
+ baseAxis,
216
+ lines,
217
+ timeSeries,
218
+ ...axis
219
+ }}
220
+ graphInterval={graphInterval}
221
+ height={graphHeight}
222
+ leftScale={leftScale}
223
+ rightScale={rightScale}
224
+ width={graphWidth}
225
+ xScale={xScale}
226
+ />
227
+
228
+ <Lines
229
+ anchorPoint={{
230
+ renderRegularLinesAnchorPoint,
231
+ renderStackedAnchorPoint
232
+ }}
233
+ height={graphHeight}
234
+ shape={{ areaRegularLines, areaStackedLines }}
235
+ />
236
+
237
+ <InteractionWithGraph
238
+ annotationData={{ ...annotationEvent }}
239
+ commonData={{ graphHeight, graphSvgRef, graphWidth, xScale }}
240
+ timeShiftZonesData={{
241
+ ...timeShiftZones,
242
+ graphInterval,
243
+ loading
244
+ }}
245
+ zoomData={{ ...zoomPreview }}
246
+ />
247
+ </Group.Group>
248
+ </svg>
249
+ <GraphTooltip {...tooltip} {...graphTooltipData} />
250
+ </div>
251
+ </ClickAwayListener>
227
252
  </>
228
253
  );
229
254
  };
@@ -2,7 +2,7 @@ import { isNil } from 'ramda';
2
2
 
3
3
  import Typography from '@mui/material/Typography';
4
4
 
5
- import useLocaleDateTimeFormat from '../../utils/useLocaleDateTimeFormat';
5
+ import { useLocaleDateTimeFormat } from '@centreon/ui';
6
6
 
7
7
  interface Props {
8
8
  displayTimeTick?: boolean;
@@ -12,9 +12,7 @@ import {
12
12
  MousePosition,
13
13
  changeMousePositionAndTimeValueDerivedAtom,
14
14
  mousePositionAtom,
15
- timeValueAtom
16
- } from '../mouseTimeValueAtoms';
17
- import {
15
+ timeValueAtom,
18
16
  eventMouseDownAtom,
19
17
  eventMouseMovingAtom
20
18
  } from '../interactionWithGraphAtoms';
@@ -0,0 +1,114 @@
1
+ import { Shape } from '@visx/visx';
2
+ import { ScaleTime } from 'd3-scale';
3
+ import { max, pick, prop } from 'ramda';
4
+ import { useAtom, useAtomValue } from 'jotai';
5
+ import { makeStyles } from 'tss-react/mui';
6
+
7
+ import { useLocaleDateTimeFormat, useMemoComponent } from '@centreon/ui';
8
+
9
+ import { labelFrom, labelTo } from '../../../translatedLabels';
10
+ import {
11
+ annotationHoveredAtom,
12
+ getFillColorDerivedAtom,
13
+ getIconColorDerivedAtom
14
+ } from '../annotationsAtoms';
15
+
16
+ import Annotation, { Props as AnnotationProps, yMargin, iconSize } from '.';
17
+
18
+ type Props = {
19
+ Icon: (props) => JSX.Element | null;
20
+ ariaLabel: string;
21
+ color: string;
22
+ endDate: string;
23
+ graphHeight: number;
24
+ startDate: string;
25
+ xScale: ScaleTime<number, number>;
26
+ } & Omit<AnnotationProps, 'marker' | 'xIcon' | 'header' | 'icon'>;
27
+
28
+ const useStyles = makeStyles()((theme) => ({
29
+ icon: {
30
+ transition: theme.transitions.create('color', {
31
+ duration: theme.transitions.duration.shortest
32
+ })
33
+ }
34
+ }));
35
+
36
+ const AreaAnnotation = ({
37
+ Icon,
38
+ ariaLabel,
39
+ color,
40
+ graphHeight,
41
+ xScale,
42
+ startDate,
43
+ endDate,
44
+ ...props
45
+ }: Props): JSX.Element => {
46
+ const { toDateTime } = useLocaleDateTimeFormat();
47
+
48
+ const { classes } = useStyles();
49
+
50
+ const [annotationHovered, setAnnotationHovered] = useAtom(
51
+ annotationHoveredAtom
52
+ );
53
+ const getFillColor = useAtomValue(getFillColorDerivedAtom);
54
+ const getIconColor = useAtomValue(getIconColorDerivedAtom);
55
+
56
+ const xIconMargin = -iconSize / 2;
57
+
58
+ const xStart = max(xScale(new Date(startDate)), 0);
59
+ const xEnd = endDate ? xScale(new Date(endDate)) : xScale.range()[1];
60
+
61
+ const annotation = pick(['event', 'annotationHoveredId'], props);
62
+
63
+ const area = (
64
+ <Shape.Bar
65
+ fill={getFillColor({ annotation, color })}
66
+ height={graphHeight + iconSize / 2}
67
+ width={xEnd - xStart}
68
+ x={xStart}
69
+ y={yMargin + iconSize + 2}
70
+ onMouseEnter={(): void =>
71
+ setAnnotationHovered(() => ({
72
+ annotation,
73
+ annotationHoveredId: prop('annotationHoveredId', props)
74
+ }))
75
+ }
76
+ onMouseLeave={(): void => setAnnotationHovered(() => undefined)}
77
+ />
78
+ );
79
+
80
+ const from = `${labelFrom} ${toDateTime(startDate)}`;
81
+ const to = endDate ? ` ${labelTo} ${toDateTime(endDate)}` : '';
82
+
83
+ const header = `${from}${to}`;
84
+
85
+ const icon = (
86
+ <Icon
87
+ aria-label={ariaLabel}
88
+ className={classes.icon}
89
+ height={iconSize}
90
+ style={{
91
+ color: getIconColor({
92
+ annotation,
93
+ color
94
+ })
95
+ }}
96
+ width={iconSize}
97
+ />
98
+ );
99
+
100
+ return useMemoComponent({
101
+ Component: (
102
+ <Annotation
103
+ header={header}
104
+ icon={icon}
105
+ marker={area}
106
+ xIcon={xStart + (xEnd - xStart) / 2 + xIconMargin}
107
+ {...props}
108
+ />
109
+ ),
110
+ memoProps: [annotationHovered, xStart, xEnd]
111
+ });
112
+ };
113
+
114
+ export default AreaAnnotation;