@centreon/ui 24.4.63 → 24.4.64

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.
@@ -0,0 +1,91 @@
1
+ import { LineChartData } from '../common/models';
2
+
3
+ import dataLastDay from './mockedData/lastDay.json';
4
+ import dataLastDayWithNullValues from './mockedData/lastDayWithNullValues.json';
5
+ import dataLastDayWithIncompleteValues from './mockedData/lastDayWithIncompleteValues.json';
6
+ import { args as argumentsData } from './helpers/doc';
7
+
8
+ import WrapperLineChart from '.';
9
+
10
+ const initialize = (data = dataLastDay): void => {
11
+ cy.mount({
12
+ Component: (
13
+ <WrapperLineChart
14
+ {...argumentsData}
15
+ data={data as unknown as LineChartData}
16
+ />
17
+ )
18
+ });
19
+ };
20
+
21
+ describe('Line chart', () => {
22
+ describe('Tooltip', () => {
23
+ it('displays a tooltip when the graph is hovered', () => {
24
+ initialize();
25
+
26
+ cy.contains('oracle-buffer-hit-ratio graph on srv-oracle-users').should(
27
+ 'be.visible'
28
+ );
29
+ cy.contains('hitratio').should('be.visible');
30
+ cy.contains('querytime').should('be.visible');
31
+ cy.contains('connTime').should('be.visible');
32
+ cy.contains('Min: 70.31').should('be.visible');
33
+
34
+ cy.findByTestId('graph-interaction-zone').realMouseMove(250, 70);
35
+
36
+ cy.contains('06/18/2023').should('be.visible');
37
+
38
+ cy.contains('0.45 s').should('be.visible');
39
+ cy.contains('75.93%').should('be.visible');
40
+ cy.contains('0.43 s').should('be.visible');
41
+
42
+ cy.makeSnapshot();
43
+ });
44
+
45
+ it('displays a metric highlighted when the graph is hovered and the metric is the nearest point', () => {
46
+ initialize();
47
+
48
+ cy.contains('Min: 70.31').should('be.visible');
49
+
50
+ cy.findByTestId('graph-interaction-zone').realMouseMove(452, 26);
51
+
52
+ cy.get('[data-metric="querytime"]').should(
53
+ 'have.attr',
54
+ 'data-highlight',
55
+ 'true'
56
+ );
57
+ cy.get('[data-metric="connTime"]').should(
58
+ 'have.attr',
59
+ 'data-highlight',
60
+ 'false'
61
+ );
62
+
63
+ cy.makeSnapshot();
64
+ });
65
+
66
+ it('does not display the tooltip when null values are hovered', () => {
67
+ initialize(dataLastDayWithNullValues);
68
+
69
+ cy.contains('Min: 70.31').should('be.visible');
70
+
71
+ cy.findByTestId('graph-interaction-zone').realMouseMove(1160, 100);
72
+
73
+ cy.get('[data-metric="querytime"]').should('not.exist');
74
+
75
+ cy.makeSnapshot();
76
+ });
77
+
78
+ it('displays the tooltip with defined values whent the graph is hovered', () => {
79
+ initialize(dataLastDayWithIncompleteValues);
80
+
81
+ cy.contains('Min: 70.31').should('be.visible');
82
+
83
+ cy.findByTestId('graph-interaction-zone').realMouseMove(1150, 100);
84
+
85
+ cy.get('[data-metric="querytime"]').should('be.visible');
86
+ cy.get('[data-metric="hitratio"]').should('not.exist');
87
+
88
+ cy.makeSnapshot();
89
+ });
90
+ });
91
+ });
@@ -35,6 +35,14 @@ const useStyles = makeStyles()((theme) => ({
35
35
  fill: theme.palette.text.primary,
36
36
  position: 'relative'
37
37
  },
38
+ graphValueTooltip: {
39
+ backgroundColor: theme.palette.background.paper,
40
+ borderRadius: theme.shape.borderRadius,
41
+ boxShadow: theme.shadows[3],
42
+ color: theme.palette.text.primary,
43
+ maxWidth: 'none',
44
+ padding: 0
45
+ },
38
46
  header: {
39
47
  display: 'grid',
40
48
  gridTemplateColumns: '0.4fr 1fr 0.4fr',
@@ -8,6 +8,7 @@ import { ClickAwayListener, Fade, Skeleton, useTheme } from '@mui/material';
8
8
  import { getLeftScale, getRightScale, getXScale } from '../common/timeSeries';
9
9
  import { Line } from '../common/timeSeries/models';
10
10
  import { Thresholds as ThresholdsModel } from '../common/models';
11
+ import { Tooltip as MuiTooltip } from '../../components/Tooltip';
11
12
 
12
13
  import Axes from './BasicComponents/Axes';
13
14
  import Grids from './BasicComponents/Grids';
@@ -18,7 +19,6 @@ import useFilterLines from './BasicComponents/useFilterLines';
18
19
  import { useStyles } from './LineChart.styles';
19
20
  import Header from './Header';
20
21
  import InteractionWithGraph from './InteractiveComponents';
21
- import TooltipAnchorPoint from './InteractiveComponents/AnchorPoint/TooltipAnchorPoint';
22
22
  import GraphTooltip from './InteractiveComponents/Tooltip';
23
23
  import useGraphTooltip from './InteractiveComponents/Tooltip/useGraphTooltip';
24
24
  import Legend from './Legend';
@@ -34,6 +34,7 @@ import { useIntersection } from './useLineChartIntersection';
34
34
  import { CurveType } from './BasicComponents/Lines/models';
35
35
  import Thresholds from './BasicComponents/Thresholds';
36
36
  import { legendWidth } from './Legend/Legend.styles';
37
+ import GraphValueTooltip from './InteractiveComponents/GraphValueTooltip/GraphValueTooltip';
37
38
 
38
39
  const extraMargin = 10;
39
40
 
@@ -185,131 +186,128 @@ const LineChart = ({
185
186
 
186
187
  return (
187
188
  <>
188
- <Header
189
- displayTimeTick={displayAnchor?.displayGuidingLines ?? true}
190
- header={header}
191
- timeSeries={timeSeries}
192
- title={title}
193
- xScale={xScale}
194
- />
189
+ <Header header={header} title={title} />
195
190
  <ClickAwayListener onClickAway={graphTooltipData?.hideTooltip}>
196
- <div className={classes.container}>
197
- <LoadingProgress
198
- display={loading}
199
- height={graphHeight}
200
- width={width}
201
- />
202
- <svg height={graphHeight + margin.top} ref={graphSvgRef} width="100%">
203
- <Group.Group left={margin.left + extraMargin / 2} top={margin.top}>
204
- <Grids
205
- height={graphHeight - margin.top}
206
- leftScale={leftScale}
207
- width={graphWidth}
208
- xScale={xScale}
209
- />
210
- <Axes
211
- data={{
212
- baseAxis,
213
- lines: displayedLines,
214
- timeSeries,
215
- ...axis
216
- }}
217
- graphInterval={graphInterval}
218
- height={graphHeight - margin.top}
219
- leftScale={leftScale}
220
- rightScale={rightScale}
221
- width={graphWidth}
222
- xScale={xScale}
223
- />
224
-
225
- <Lines
226
- curve={curve}
227
- displayAnchor={displayAnchor}
228
- displayedLines={displayedLines}
229
- graphSvgRef={graphSvgRef}
230
- height={graphHeight - margin.top}
231
- leftScale={leftScale}
232
- rightScale={rightScale}
233
- timeSeries={timeSeries}
234
- width={graphWidth}
235
- xScale={xScale}
236
- {...shapeLines}
237
- />
238
-
239
- <InteractionWithGraph
240
- annotationData={{ ...annotationEvent }}
241
- commonData={{
242
- graphHeight,
243
- graphSvgRef,
244
- graphWidth,
245
- timeSeries,
246
- xScale
247
- }}
248
- timeShiftZonesData={{
249
- ...timeShiftZones,
250
- graphInterval,
251
- loading
252
- }}
253
- zoomData={{ ...zoomPreview }}
254
- />
191
+ <MuiTooltip
192
+ classes={{
193
+ tooltip: classes.graphValueTooltip
194
+ }}
195
+ placement="top-start"
196
+ title={<GraphValueTooltip base={baseAxis} />}
197
+ >
198
+ <div className={classes.container}>
199
+ <LoadingProgress
200
+ display={loading}
201
+ height={graphHeight}
202
+ width={width}
203
+ />
204
+ <svg
205
+ height={graphHeight + margin.top}
206
+ ref={graphSvgRef}
207
+ width="100%"
208
+ >
209
+ <Group.Group
210
+ left={margin.left + extraMargin / 2}
211
+ top={margin.top}
212
+ >
213
+ <Grids
214
+ height={graphHeight - margin.top}
215
+ leftScale={leftScale}
216
+ width={graphWidth}
217
+ xScale={xScale}
218
+ />
219
+ <Axes
220
+ data={{
221
+ baseAxis,
222
+ lines: displayedLines,
223
+ timeSeries,
224
+ ...axis
225
+ }}
226
+ graphInterval={graphInterval}
227
+ height={graphHeight - margin.top}
228
+ leftScale={leftScale}
229
+ rightScale={rightScale}
230
+ width={graphWidth}
231
+ xScale={xScale}
232
+ />
255
233
 
256
- {thresholds?.enabled && (
257
- <Thresholds
234
+ <Lines
235
+ curve={curve}
236
+ displayAnchor={displayAnchor}
258
237
  displayedLines={displayedLines}
259
- hideTooltip={hideThresholdTooltip}
238
+ graphSvgRef={graphSvgRef}
239
+ height={graphHeight - margin.top}
260
240
  leftScale={leftScale}
261
241
  rightScale={rightScale}
262
- showTooltip={showThresholdTooltip}
263
- thresholdUnit={thresholdUnit}
264
- thresholds={thresholds as ThresholdsModel}
242
+ timeSeries={timeSeries}
265
243
  width={graphWidth}
244
+ xScale={xScale}
245
+ {...shapeLines}
266
246
  />
267
- )}
268
- </Group.Group>
269
- </svg>
270
- {displayTooltip && (
271
- <GraphTooltip {...tooltip} {...graphTooltipData} />
272
- )}
273
- {(displayAnchor?.displayTooltipsGuidingLines ?? true) && (
274
- <TooltipAnchorPoint
275
- baseAxis={baseAxis}
276
- graphHeight={graphHeight - 35}
277
- graphWidth={graphWidth}
278
- leftScale={leftScale}
279
- lines={displayedLines}
280
- rightScale={rightScale}
281
- timeSeries={timeSeries}
282
- xScale={xScale}
283
- />
284
- )}
285
- <Fade in={thresholdTooltipOpen}>
286
- <Tooltip.Tooltip
287
- left={thresholdTooltipLeft}
288
- style={{
289
- ...baseStyles,
290
- backgroundColor: theme.palette.background.paper,
291
- color: theme.palette.text.primary,
292
- transform: `translate(${graphWidth / 2}px, -10px)`
293
- }}
294
- top={thresholdTooltipTop}
295
- >
296
- {thresholdTooltipData}
297
- </Tooltip.Tooltip>
298
- </Fade>
299
- </div>
247
+
248
+ <InteractionWithGraph
249
+ annotationData={{ ...annotationEvent }}
250
+ commonData={{
251
+ graphHeight,
252
+ graphSvgRef,
253
+ graphWidth,
254
+ leftScale,
255
+ lines: displayedLines,
256
+ rightScale,
257
+ timeSeries,
258
+ xScale
259
+ }}
260
+ timeShiftZonesData={{
261
+ ...timeShiftZones,
262
+ graphInterval,
263
+ loading
264
+ }}
265
+ zoomData={{ ...zoomPreview }}
266
+ />
267
+
268
+ {thresholds?.enabled && (
269
+ <Thresholds
270
+ displayedLines={displayedLines}
271
+ hideTooltip={hideThresholdTooltip}
272
+ leftScale={leftScale}
273
+ rightScale={rightScale}
274
+ showTooltip={showThresholdTooltip}
275
+ thresholdUnit={thresholdUnit}
276
+ thresholds={thresholds as ThresholdsModel}
277
+ width={graphWidth}
278
+ />
279
+ )}
280
+ </Group.Group>
281
+ </svg>
282
+ {displayTooltip && (
283
+ <GraphTooltip {...tooltip} {...graphTooltipData} />
284
+ )}
285
+ <Fade in={thresholdTooltipOpen}>
286
+ <Tooltip.Tooltip
287
+ left={thresholdTooltipLeft}
288
+ style={{
289
+ ...baseStyles,
290
+ backgroundColor: theme.palette.background.paper,
291
+ color: theme.palette.text.primary,
292
+ transform: `translate(${graphWidth / 2}px, -10px)`
293
+ }}
294
+ top={thresholdTooltipTop}
295
+ >
296
+ {thresholdTooltipData}
297
+ </Tooltip.Tooltip>
298
+ </Fade>
299
+ </div>
300
+ </MuiTooltip>
300
301
  </ClickAwayListener>
301
302
  {displayLegend && (
302
303
  <div ref={legendRef}>
303
304
  <Legend
304
305
  base={baseAxis}
305
- displayAnchor={displayAnchor?.displayGuidingLines ?? true}
306
306
  limitLegend={limitLegend}
307
307
  lines={newLines}
308
308
  renderExtraComponent={legend?.renderExtraComponent}
309
309
  setLinesGraph={setLinesGraph}
310
310
  shouldDisplayLegendInCompactMode={shouldDisplayLegendInCompactMode}
311
- timeSeries={timeSeries}
312
- xScale={xScale}
313
311
  />
314
312
  </div>
315
313
  )}