@centreon/ui 24.8.2 → 24.8.3
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.
- package/package.json +14 -17
- package/src/Graph/BarChart/BarChart.cypress.spec.tsx +38 -79
- package/src/Graph/BarChart/BarChart.tsx +4 -4
- package/src/Graph/BarChart/BarGroup.tsx +81 -92
- package/src/Graph/BarChart/BarStack.tsx +21 -13
- package/src/Graph/BarChart/ResponsiveBarChart.tsx +26 -50
- package/src/Graph/BarChart/Tooltip/BarChartTooltip.tsx +1 -1
- package/src/Graph/BarChart/useBarStack.ts +1 -1
- package/src/Graph/{LineChart → Chart}/BasicComponents/Lines/Point.tsx +1 -1
- package/src/Graph/Chart/BasicComponents/Lines/StackedLines/useStackedLines.ts +67 -0
- package/src/Graph/{LineChart → Chart}/BasicComponents/Lines/Threshold/ThresholdWithPatternLines.tsx +4 -7
- package/src/Graph/{LineChart → Chart}/BasicComponents/Lines/Threshold/index.tsx +6 -9
- package/src/Graph/{LineChart → Chart}/BasicComponents/Lines/Threshold/models.ts +1 -2
- package/src/Graph/{LineChart → Chart}/BasicComponents/Lines/Threshold/useScaleThreshold.ts +8 -20
- package/src/Graph/{LineChart → Chart}/BasicComponents/Lines/index.tsx +64 -43
- package/src/Graph/{LineChart/LineChart.cypress.spec.tsx → Chart/Chart.cypress.spec.tsx} +272 -23
- package/src/Graph/{LineChart/index.stories.tsx → Chart/Chart.stories.tsx} +217 -24
- package/src/Graph/{LineChart/LineChart.styles.ts → Chart/Chart.styles.ts} +1 -1
- package/src/Graph/{LineChart/LineChart.tsx → Chart/Chart.tsx} +84 -100
- package/src/Graph/{LineChart → Chart}/InteractiveComponents/AnchorPoint/RegularAnchorPoint.tsx +5 -1
- package/src/Graph/{LineChart → Chart}/InteractiveComponents/AnchorPoint/StackedAnchorPoint.tsx +6 -1
- package/src/Graph/Chart/InteractiveComponents/GraphValueTooltip/GraphValueTooltip.tsx +61 -0
- package/src/Graph/{LineChart/InteractiveComponents/GraphValueTooltip/GraphValueTooltip.tsx → Chart/InteractiveComponents/GraphValueTooltip/GraphValueTooltipContent.tsx} +2 -2
- package/src/Graph/{LineChart → Chart}/InteractiveComponents/index.tsx +11 -15
- package/src/Graph/{LineChart → Chart}/Legend/Legend.styles.ts +1 -7
- package/src/Graph/{LineChart → Chart}/Legend/LegendHeader.tsx +9 -5
- package/src/Graph/{LineChart → Chart}/Legend/index.tsx +2 -1
- package/src/Graph/Chart/graphAtoms.ts +6 -0
- package/src/Graph/{LineChart → Chart}/index.tsx +10 -7
- package/src/Graph/{LineChart → Chart}/models.ts +8 -3
- package/src/Graph/common/Axes/AxisStyles.ts +11 -0
- package/src/Graph/common/Axes/UnitLabel.tsx +41 -10
- package/src/Graph/common/Axes/index.tsx +18 -12
- package/src/Graph/common/Axes/models.ts +4 -2
- package/src/Graph/common/Axes/useAxisY.ts +22 -12
- package/src/Graph/common/BaseChart/BaseChart.tsx +2 -2
- package/src/Graph/common/BaseChart/ChartSvgWrapper.tsx +8 -5
- package/src/Graph/common/BaseChart/useComputeBaseChartDimensions.ts +1 -1
- package/src/Graph/common/Grids/index.tsx +2 -2
- package/src/Graph/common/Thresholds/ThresholdLine.tsx +1 -1
- package/src/Graph/common/Thresholds/Thresholds.tsx +10 -15
- package/src/Graph/common/timeSeries/index.ts +109 -131
- package/src/Graph/common/timeSeries/models.ts +4 -5
- package/src/Graph/index.ts +4 -4
- package/src/Graph/mockedData/lastDayWithLotOfUnits.json +1668 -0
- package/src/Graph/mockedData/pingService.json +46 -1
- package/src/Graph/mockedData/pingServiceLinesBars.json +253 -0
- package/src/Graph/mockedData/pingServiceLinesBarsMixed.json +253 -0
- package/src/Graph/mockedData/pingServiceLinesBarsStacked.json +253 -0
- package/src/Graph/mockedData/pingServiceMixedStacked.json +46 -1
- package/src/Graph/mockedData/pingServiceStacked.json +46 -1
- package/src/Typography/EllipsisTypography.tsx +5 -2
- package/src/components/Form/AccessRights/AccessRights.cypress.spec.tsx +16 -24
- package/src/components/Form/AccessRights/AccessRights.stories.tsx +5 -5
- package/src/components/Form/AccessRights/AccessRights.tsx +3 -3
- package/src/components/Form/index.ts +2 -2
- package/src/utils/index.ts +2 -2
- package/src/Graph/BarChart/SingleBar.tsx +0 -62
- package/src/Graph/BarChart/useSingleBar.ts +0 -199
- package/src/Graph/LineChart/BasicComponents/Lines/StackedLines/useStackedLines.ts +0 -39
- package/src/Graph/LineChart/graphAtoms.ts +0 -3
- /package/src/Graph/{LineChart → Chart}/BasicComponents/Lines/RegularLines/index.tsx +0 -0
- /package/src/Graph/{LineChart → Chart}/BasicComponents/Lines/RegularLines/useRegularLines.ts +0 -0
- /package/src/Graph/{LineChart → Chart}/BasicComponents/Lines/StackedLines/index.tsx +0 -0
- /package/src/Graph/{LineChart → Chart}/BasicComponents/Lines/Threshold/BasicThreshold.tsx +0 -0
- /package/src/Graph/{LineChart → Chart}/BasicComponents/Lines/Threshold/Circle.tsx +0 -0
- /package/src/Graph/{LineChart → Chart}/BasicComponents/Lines/Threshold/ThresholdWithVariation.tsx +0 -0
- /package/src/Graph/{LineChart → Chart}/BasicComponents/Lines/Threshold/helpers/index.ts +0 -0
- /package/src/Graph/{LineChart → Chart}/BasicComponents/Lines/Threshold/useCoordinateCircle.ts +0 -0
- /package/src/Graph/{LineChart → Chart}/BasicComponents/Lines/models.ts +0 -0
- /package/src/Graph/{LineChart → Chart}/InteractiveComponents/AnchorPoint/GuidingLines.tsx +0 -0
- /package/src/Graph/{LineChart → Chart}/InteractiveComponents/AnchorPoint/index.tsx +0 -0
- /package/src/Graph/{LineChart → Chart}/InteractiveComponents/AnchorPoint/models.ts +0 -0
- /package/src/Graph/{LineChart → Chart}/InteractiveComponents/AnchorPoint/useTickGraph.ts +0 -0
- /package/src/Graph/{LineChart → Chart}/InteractiveComponents/Annotations/Annotation/Area.tsx +0 -0
- /package/src/Graph/{LineChart → Chart}/InteractiveComponents/Annotations/Annotation/Line.tsx +0 -0
- /package/src/Graph/{LineChart → Chart}/InteractiveComponents/Annotations/Annotation/index.tsx +0 -0
- /package/src/Graph/{LineChart → Chart}/InteractiveComponents/Annotations/Area/Downtime.tsx +0 -0
- /package/src/Graph/{LineChart → Chart}/InteractiveComponents/Annotations/EventAnnotations.tsx +0 -0
- /package/src/Graph/{LineChart → Chart}/InteractiveComponents/Annotations/Line/Acknowledgement.tsx +0 -0
- /package/src/Graph/{LineChart → Chart}/InteractiveComponents/Annotations/Line/Comments.tsx +0 -0
- /package/src/Graph/{LineChart → Chart}/InteractiveComponents/Annotations/annotationsAtoms.ts +0 -0
- /package/src/Graph/{LineChart → Chart}/InteractiveComponents/Annotations/index.tsx +0 -0
- /package/src/Graph/{LineChart → Chart}/InteractiveComponents/Annotations/models.ts +0 -0
- /package/src/Graph/{LineChart → Chart}/InteractiveComponents/Annotations/useAnnotation.ts +0 -0
- /package/src/Graph/{LineChart → Chart}/InteractiveComponents/Bar.tsx +0 -0
- /package/src/Graph/{LineChart → Chart}/InteractiveComponents/GraphValueTooltip/useGraphValueTooltip.ts +0 -0
- /package/src/Graph/{LineChart → Chart}/InteractiveComponents/GraphValueTooltip/useGraphValueTooltipStyles.ts +0 -0
- /package/src/Graph/{LineChart → Chart}/InteractiveComponents/TimeShiftZones/TimeShiftIcon.tsx +0 -0
- /package/src/Graph/{LineChart → Chart}/InteractiveComponents/TimeShiftZones/TimeShiftZone.tsx +0 -0
- /package/src/Graph/{LineChart → Chart}/InteractiveComponents/TimeShiftZones/index.tsx +0 -0
- /package/src/Graph/{LineChart → Chart}/InteractiveComponents/TimeShiftZones/models.ts +0 -0
- /package/src/Graph/{LineChart → Chart}/InteractiveComponents/TimeShiftZones/useTimeShiftZones.ts +0 -0
- /package/src/Graph/{LineChart → Chart}/InteractiveComponents/Tooltip/index.tsx +0 -0
- /package/src/Graph/{LineChart → Chart}/InteractiveComponents/Tooltip/models.ts +0 -0
- /package/src/Graph/{LineChart → Chart}/InteractiveComponents/Tooltip/useGraphTooltip.ts +0 -0
- /package/src/Graph/{LineChart → Chart}/InteractiveComponents/ZoomPreview/index.tsx +0 -0
- /package/src/Graph/{LineChart → Chart}/InteractiveComponents/ZoomPreview/models.ts +0 -0
- /package/src/Graph/{LineChart → Chart}/InteractiveComponents/ZoomPreview/useZoomPreview.ts +0 -0
- /package/src/Graph/{LineChart → Chart}/InteractiveComponents/ZoomPreview/zoomPreviewAtoms.ts +0 -0
- /package/src/Graph/{LineChart → Chart}/InteractiveComponents/interactionWithGraphAtoms.ts +0 -0
- /package/src/Graph/{LineChart → Chart}/Legend/LegendContent.tsx +0 -0
- /package/src/Graph/{LineChart → Chart}/Legend/models.ts +0 -0
- /package/src/Graph/{LineChart → Chart}/Legend/useLegend.ts +0 -0
- /package/src/Graph/{LineChart → Chart}/LoadingSkeleton.tsx +0 -0
- /package/src/Graph/{LineChart → Chart}/common/index.ts +0 -0
- /package/src/Graph/{LineChart → Chart}/helpers/doc.ts +0 -0
- /package/src/Graph/{LineChart → Chart}/helpers/index.ts +0 -0
- /package/src/Graph/{LineChart → Chart}/translatedLabels.ts +0 -0
- /package/src/Graph/{LineChart/useLineChartData.ts → Chart/useChartData.ts} +0 -0
- /package/src/Graph/{LineChart/useLineChartIntersection.ts → Chart/useChartIntersection.ts} +0 -0
|
@@ -3,8 +3,8 @@ import { MutableRefObject } from 'react';
|
|
|
3
3
|
import { Group } from '@visx/visx';
|
|
4
4
|
import { equals } from 'ramda';
|
|
5
5
|
|
|
6
|
-
import { margin } from '../../
|
|
7
|
-
import {
|
|
6
|
+
import { margin } from '../../Chart/common';
|
|
7
|
+
import { ChartAxis } from '../../Chart/models';
|
|
8
8
|
import Axes from '../Axes';
|
|
9
9
|
import Grids from '../Grids';
|
|
10
10
|
import { Line, TimeValue } from '../timeSeries/models';
|
|
@@ -12,7 +12,8 @@ import { Line, TimeValue } from '../timeSeries/models';
|
|
|
12
12
|
import { extraMargin } from './useComputeBaseChartDimensions';
|
|
13
13
|
|
|
14
14
|
interface Props {
|
|
15
|
-
|
|
15
|
+
allUnits: Array<string>;
|
|
16
|
+
axis?: ChartAxis;
|
|
16
17
|
base?: number;
|
|
17
18
|
children: JSX.Element;
|
|
18
19
|
displayedLines: Array<Line>;
|
|
@@ -42,7 +43,8 @@ const ChartSvgWrapper = ({
|
|
|
42
43
|
timeSeries,
|
|
43
44
|
axis,
|
|
44
45
|
children,
|
|
45
|
-
orientation = 'horizontal'
|
|
46
|
+
orientation = 'horizontal',
|
|
47
|
+
allUnits
|
|
46
48
|
}: Props): JSX.Element => {
|
|
47
49
|
const isHorizontal = equals(orientation, 'horizontal');
|
|
48
50
|
|
|
@@ -64,13 +66,14 @@ const ChartSvgWrapper = ({
|
|
|
64
66
|
/>
|
|
65
67
|
)}
|
|
66
68
|
<Axes
|
|
69
|
+
allUnits={allUnits}
|
|
67
70
|
data={{
|
|
68
71
|
baseAxis: base,
|
|
69
72
|
lines: displayedLines,
|
|
70
73
|
timeSeries,
|
|
71
74
|
...axis
|
|
72
75
|
}}
|
|
73
|
-
height={graphHeight
|
|
76
|
+
height={graphHeight}
|
|
74
77
|
leftScale={leftScale}
|
|
75
78
|
orientation={orientation}
|
|
76
79
|
rightScale={rightScale}
|
|
@@ -4,9 +4,9 @@ import { Grid } from '@visx/visx';
|
|
|
4
4
|
import { ScaleLinear } from 'd3-scale';
|
|
5
5
|
import { includes } from 'ramda';
|
|
6
6
|
|
|
7
|
-
import {
|
|
7
|
+
import { ChartAxis } from '../../Chart/models';
|
|
8
8
|
|
|
9
|
-
interface Props extends Pick<
|
|
9
|
+
interface Props extends Pick<ChartAxis, 'gridLinesType'> {
|
|
10
10
|
height: number;
|
|
11
11
|
leftScale: ScaleLinear<number, number>;
|
|
12
12
|
width: number;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { equals
|
|
1
|
+
import { equals } from 'ramda';
|
|
2
|
+
import { ScaleLinear } from 'd3-scale';
|
|
2
3
|
|
|
3
4
|
import { getUnits, getYScale } from '../timeSeries';
|
|
4
5
|
import { Line } from '../timeSeries/models';
|
|
@@ -10,40 +11,34 @@ interface Props {
|
|
|
10
11
|
displayedLines: Array<Line>;
|
|
11
12
|
hideTooltip: () => void;
|
|
12
13
|
isHorizontal?: boolean;
|
|
13
|
-
leftScale: (value: number) => number;
|
|
14
|
-
rightScale: (value: number) => number;
|
|
15
14
|
showTooltip: (props) => void;
|
|
16
15
|
thresholdUnit?: string;
|
|
17
16
|
thresholds: ThresholdsModel;
|
|
18
17
|
width: number;
|
|
18
|
+
yScalesPerUnit: Record<string, ScaleLinear<number, number>>;
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
const Thresholds = ({
|
|
22
22
|
thresholds,
|
|
23
|
-
leftScale,
|
|
24
|
-
rightScale,
|
|
25
23
|
width,
|
|
26
24
|
displayedLines,
|
|
27
25
|
thresholdUnit,
|
|
28
26
|
showTooltip,
|
|
29
27
|
hideTooltip,
|
|
28
|
+
yScalesPerUnit,
|
|
30
29
|
isHorizontal = true
|
|
31
30
|
}: Props): JSX.Element => {
|
|
32
|
-
const [firstUnit, secondUnit
|
|
33
|
-
displayedLines as Array<Line>
|
|
34
|
-
);
|
|
31
|
+
const [firstUnit, secondUnit] = getUnits(displayedLines as Array<Line>);
|
|
35
32
|
|
|
36
|
-
const shouldUseRightScale =
|
|
33
|
+
const shouldUseRightScale =
|
|
34
|
+
thresholdUnit && equals(thresholdUnit, secondUnit);
|
|
37
35
|
|
|
38
36
|
const yScale = shouldUseRightScale
|
|
39
|
-
?
|
|
37
|
+
? yScalesPerUnit[secondUnit]
|
|
40
38
|
: getYScale({
|
|
41
|
-
hasMoreThanTwoUnits: !isNil(thirdUnit),
|
|
42
39
|
invert: null,
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
secondUnit,
|
|
46
|
-
unit: firstUnit
|
|
40
|
+
unit: firstUnit,
|
|
41
|
+
yScalesPerUnit
|
|
47
42
|
});
|
|
48
43
|
|
|
49
44
|
return (
|
|
@@ -22,9 +22,6 @@ import {
|
|
|
22
22
|
add,
|
|
23
23
|
isEmpty,
|
|
24
24
|
any,
|
|
25
|
-
not,
|
|
26
|
-
min,
|
|
27
|
-
max,
|
|
28
25
|
lt,
|
|
29
26
|
identity,
|
|
30
27
|
head,
|
|
@@ -33,10 +30,12 @@ import {
|
|
|
33
30
|
always,
|
|
34
31
|
T,
|
|
35
32
|
includes,
|
|
36
|
-
split
|
|
33
|
+
split,
|
|
34
|
+
negate,
|
|
35
|
+
isNotNil
|
|
37
36
|
} from 'ramda';
|
|
38
37
|
|
|
39
|
-
import { margin } from '../../
|
|
38
|
+
import { margin } from '../../Chart/common';
|
|
40
39
|
import { LineChartData } from '../models';
|
|
41
40
|
|
|
42
41
|
import {
|
|
@@ -46,7 +45,6 @@ import {
|
|
|
46
45
|
AxeScale,
|
|
47
46
|
Xscale,
|
|
48
47
|
FormatMetricValueProps,
|
|
49
|
-
YScales,
|
|
50
48
|
TimeValueProps
|
|
51
49
|
} from './models';
|
|
52
50
|
|
|
@@ -119,12 +117,14 @@ const toLine = ({
|
|
|
119
117
|
average_value,
|
|
120
118
|
minimum_value,
|
|
121
119
|
maximum_value,
|
|
122
|
-
metric_id
|
|
120
|
+
metric_id,
|
|
121
|
+
displayAs
|
|
123
122
|
}: Metric): Line => ({
|
|
124
123
|
areaColor: ds_data.ds_color_area,
|
|
125
124
|
average_value,
|
|
126
125
|
color: ds_data.ds_color_line,
|
|
127
126
|
display: true,
|
|
127
|
+
displayAs,
|
|
128
128
|
filled: ds_data.ds_filled,
|
|
129
129
|
highlight: undefined,
|
|
130
130
|
invert: ds_data.ds_invert,
|
|
@@ -220,6 +220,7 @@ export const getLinesForMetrics = ({
|
|
|
220
220
|
filter(({ metric_id }) => metricIds.includes(metric_id), lines);
|
|
221
221
|
|
|
222
222
|
interface LinesTimeSeries {
|
|
223
|
+
invert?: boolean | string | null;
|
|
223
224
|
lines: Array<Line>;
|
|
224
225
|
timeSeries: Array<TimeValue>;
|
|
225
226
|
}
|
|
@@ -269,17 +270,13 @@ const getSortedStackedLines = (lines: Array<Line>): Array<Line> =>
|
|
|
269
270
|
|
|
270
271
|
const getInvertedStackedLines = (lines: Array<Line>): Array<Line> =>
|
|
271
272
|
pipe(
|
|
272
|
-
|
|
273
|
-
lines
|
|
274
|
-
) => Array<Line>,
|
|
273
|
+
filter(({ invert }: Line): boolean => invert) as (lines) => Array<Line>,
|
|
275
274
|
getSortedStackedLines
|
|
276
275
|
)(lines);
|
|
277
276
|
|
|
278
277
|
const getNotInvertedStackedLines = (lines: Array<Line>): Array<Line> =>
|
|
279
278
|
pipe(
|
|
280
|
-
|
|
281
|
-
lines
|
|
282
|
-
) => Array<Line>,
|
|
279
|
+
reject(({ invert }: Line): boolean => invert) as (lines) => Array<Line>,
|
|
283
280
|
getSortedStackedLines
|
|
284
281
|
)(lines);
|
|
285
282
|
|
|
@@ -293,7 +290,8 @@ const hasUnitStackedLines = ({ lines, unit }: HasStackedLines): boolean =>
|
|
|
293
290
|
|
|
294
291
|
const getTimeSeriesForLines = ({
|
|
295
292
|
lines,
|
|
296
|
-
timeSeries
|
|
293
|
+
timeSeries,
|
|
294
|
+
invert
|
|
297
295
|
}: LinesTimeSeries): Array<TimeValue> => {
|
|
298
296
|
const metrics = map(prop('metric_id'), lines);
|
|
299
297
|
|
|
@@ -302,7 +300,10 @@ const getTimeSeriesForLines = ({
|
|
|
302
300
|
...reduce(
|
|
303
301
|
(acc, metric_id): Omit<TimeValue, 'timePick'> => ({
|
|
304
302
|
...acc,
|
|
305
|
-
[metric_id]:
|
|
303
|
+
[metric_id]:
|
|
304
|
+
invert && metricsValue[metric_id]
|
|
305
|
+
? negate(metricsValue[metric_id])
|
|
306
|
+
: metricsValue[metric_id]
|
|
306
307
|
}),
|
|
307
308
|
{},
|
|
308
309
|
metrics
|
|
@@ -314,39 +315,39 @@ const getTimeSeriesForLines = ({
|
|
|
314
315
|
};
|
|
315
316
|
|
|
316
317
|
interface GetYScaleProps {
|
|
317
|
-
hasMoreThanTwoUnits: boolean;
|
|
318
318
|
invert: string | null;
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
secondUnit: string;
|
|
319
|
+
scale?: 'linear' | 'logarithmic';
|
|
320
|
+
scaleLogarithmicBase?: number;
|
|
322
321
|
unit: string;
|
|
322
|
+
yScalesPerUnit: Record<string, ScaleLinear<number, number>>;
|
|
323
323
|
}
|
|
324
324
|
|
|
325
325
|
const getYScale = ({
|
|
326
|
-
hasMoreThanTwoUnits,
|
|
327
326
|
unit,
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
327
|
+
invert,
|
|
328
|
+
yScalesPerUnit,
|
|
329
|
+
scale = 'linear',
|
|
330
|
+
scaleLogarithmicBase
|
|
332
331
|
}: GetYScaleProps): ScaleLinear<number, number> => {
|
|
333
|
-
const
|
|
334
|
-
const scale = isLeftScale ? leftScale : rightScale;
|
|
332
|
+
const yScale = yScalesPerUnit[unit];
|
|
335
333
|
|
|
336
334
|
return invert
|
|
337
|
-
?
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
range:
|
|
335
|
+
? getScaleType(scale)({
|
|
336
|
+
base: scaleLogarithmicBase,
|
|
337
|
+
domain: yScale.domain().reverse(),
|
|
338
|
+
range: yScale.range().reverse()
|
|
341
339
|
})
|
|
342
|
-
:
|
|
340
|
+
: yScale;
|
|
343
341
|
};
|
|
344
342
|
|
|
345
343
|
const getScaleType = (
|
|
346
|
-
scale: 'linear' | '
|
|
344
|
+
scale: 'linear' | 'logarithmic'
|
|
347
345
|
): typeof Scale.scaleLinear | typeof Scale.scaleLog =>
|
|
348
346
|
equals(scale, 'logarithmic') ? Scale.scaleLog : Scale.scaleLinear;
|
|
349
347
|
|
|
348
|
+
const hasOnlyZeroesHasValue = (graphValues: Array<number>): boolean =>
|
|
349
|
+
graphValues.every((value) => equals(value, 0) || equals(value, null));
|
|
350
|
+
|
|
350
351
|
const getScale = ({
|
|
351
352
|
graphValues,
|
|
352
353
|
height,
|
|
@@ -355,17 +356,21 @@ const getScale = ({
|
|
|
355
356
|
isCenteredZero,
|
|
356
357
|
scale,
|
|
357
358
|
scaleLogarithmicBase,
|
|
358
|
-
isHorizontal
|
|
359
|
+
isHorizontal,
|
|
360
|
+
invert,
|
|
361
|
+
hasDisplayAsBar
|
|
359
362
|
}): ScaleLinear<number, number> => {
|
|
360
363
|
const isLogScale = equals(scale, 'logarithmic');
|
|
361
364
|
const minValue = Math.min(
|
|
362
|
-
|
|
365
|
+
hasDisplayAsBar && 0,
|
|
366
|
+
invert ? negate(getMax(graphValues)) : getMin(graphValues),
|
|
363
367
|
getMin(stackedValues),
|
|
364
368
|
Math.min(...thresholds)
|
|
365
369
|
);
|
|
366
370
|
const maxValue = Math.max(
|
|
367
371
|
getMax(graphValues),
|
|
368
372
|
getMax(stackedValues),
|
|
373
|
+
hasOnlyZeroesHasValue(graphValues) ? 1 : 0,
|
|
369
374
|
Math.max(...thresholds)
|
|
370
375
|
);
|
|
371
376
|
|
|
@@ -384,68 +389,15 @@ const getScale = ({
|
|
|
384
389
|
});
|
|
385
390
|
}
|
|
386
391
|
|
|
392
|
+
const domain = [isLogScale ? 0.001 : minValue, maxValue];
|
|
393
|
+
|
|
387
394
|
return scaleType<number>({
|
|
388
395
|
base: scaleLogarithmicBase || 2,
|
|
389
|
-
domain
|
|
396
|
+
domain,
|
|
390
397
|
range: isHorizontal ? range : range.reverse()
|
|
391
398
|
});
|
|
392
399
|
};
|
|
393
400
|
|
|
394
|
-
const getLeftScale = ({
|
|
395
|
-
dataLines,
|
|
396
|
-
dataTimeSeries,
|
|
397
|
-
valueGraphHeight,
|
|
398
|
-
thresholds,
|
|
399
|
-
thresholdUnit,
|
|
400
|
-
isCenteredZero,
|
|
401
|
-
scale,
|
|
402
|
-
scaleLogarithmicBase,
|
|
403
|
-
isHorizontal = true
|
|
404
|
-
}: AxeScale): ScaleLinear<number, number> => {
|
|
405
|
-
const [firstUnit, secondUnit, thirdUnit] = getUnits(dataLines);
|
|
406
|
-
|
|
407
|
-
const shouldApplyThresholds =
|
|
408
|
-
equals(thresholdUnit, firstUnit) ||
|
|
409
|
-
equals(thresholdUnit, thirdUnit) ||
|
|
410
|
-
!thresholdUnit;
|
|
411
|
-
|
|
412
|
-
const graphValues = isNil(thirdUnit)
|
|
413
|
-
? getMetricValuesForUnit({
|
|
414
|
-
lines: dataLines,
|
|
415
|
-
timeSeries: dataTimeSeries,
|
|
416
|
-
unit: firstUnit
|
|
417
|
-
})
|
|
418
|
-
: getMetricValuesForLines({
|
|
419
|
-
lines: dataLines,
|
|
420
|
-
timeSeries: dataTimeSeries
|
|
421
|
-
});
|
|
422
|
-
|
|
423
|
-
const firstUnitHasStackedLines =
|
|
424
|
-
isNil(thirdUnit) && not(isNil(firstUnit))
|
|
425
|
-
? hasUnitStackedLines({ lines: dataLines, unit: firstUnit })
|
|
426
|
-
: false;
|
|
427
|
-
|
|
428
|
-
const stackedValues = firstUnitHasStackedLines
|
|
429
|
-
? getStackedMetricValues({
|
|
430
|
-
lines: getSortedStackedLines(dataLines).filter(
|
|
431
|
-
({ unit }) => !equals(unit, secondUnit)
|
|
432
|
-
),
|
|
433
|
-
timeSeries: dataTimeSeries
|
|
434
|
-
})
|
|
435
|
-
: [0];
|
|
436
|
-
|
|
437
|
-
return getScale({
|
|
438
|
-
graphValues,
|
|
439
|
-
height: valueGraphHeight,
|
|
440
|
-
isCenteredZero,
|
|
441
|
-
isHorizontal,
|
|
442
|
-
scale,
|
|
443
|
-
scaleLogarithmicBase,
|
|
444
|
-
stackedValues,
|
|
445
|
-
thresholds: shouldApplyThresholds ? thresholds : []
|
|
446
|
-
});
|
|
447
|
-
};
|
|
448
|
-
|
|
449
401
|
const getXScale = ({
|
|
450
402
|
dataTime,
|
|
451
403
|
valueWidth
|
|
@@ -467,7 +419,7 @@ export const getXScaleBand = ({
|
|
|
467
419
|
});
|
|
468
420
|
};
|
|
469
421
|
|
|
470
|
-
const
|
|
422
|
+
const getYScaleUnit = ({
|
|
471
423
|
dataLines,
|
|
472
424
|
dataTimeSeries,
|
|
473
425
|
valueGraphHeight,
|
|
@@ -476,26 +428,32 @@ const getRightScale = ({
|
|
|
476
428
|
isCenteredZero,
|
|
477
429
|
scale,
|
|
478
430
|
scaleLogarithmicBase,
|
|
479
|
-
isHorizontal = true
|
|
480
|
-
|
|
481
|
-
|
|
431
|
+
isHorizontal = true,
|
|
432
|
+
unit,
|
|
433
|
+
invert
|
|
434
|
+
}: AxeScale & { invert?: boolean | string | null; unit: string }): ScaleLinear<
|
|
435
|
+
number,
|
|
436
|
+
number
|
|
437
|
+
> => {
|
|
438
|
+
const [firstUnit] = getUnits(dataLines);
|
|
439
|
+
const shouldApplyThresholds =
|
|
440
|
+
equals(unit, thresholdUnit) || (!thresholdUnit && equals(firstUnit, unit));
|
|
482
441
|
|
|
483
442
|
const graphValues = getMetricValuesForUnit({
|
|
484
443
|
lines: dataLines,
|
|
485
444
|
timeSeries: dataTimeSeries,
|
|
486
|
-
unit
|
|
445
|
+
unit
|
|
487
446
|
});
|
|
488
447
|
|
|
489
|
-
const
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
: hasUnitStackedLines({ lines: dataLines, unit: secondUnit });
|
|
448
|
+
const hasStackedLines = hasUnitStackedLines({
|
|
449
|
+
lines: dataLines,
|
|
450
|
+
unit
|
|
451
|
+
});
|
|
494
452
|
|
|
495
|
-
const stackedValues =
|
|
453
|
+
const stackedValues = hasStackedLines
|
|
496
454
|
? getStackedMetricValues({
|
|
497
|
-
lines: getSortedStackedLines(dataLines).filter(
|
|
498
|
-
equals(unit,
|
|
455
|
+
lines: getSortedStackedLines(dataLines).filter(
|
|
456
|
+
({ unit: stackedUnit }) => equals(unit, stackedUnit)
|
|
499
457
|
),
|
|
500
458
|
timeSeries: dataTimeSeries
|
|
501
459
|
})
|
|
@@ -503,7 +461,14 @@ const getRightScale = ({
|
|
|
503
461
|
|
|
504
462
|
return getScale({
|
|
505
463
|
graphValues,
|
|
464
|
+
hasDisplayAsBar: dataLines.some(
|
|
465
|
+
({ displayAs, unit: lineUnit, stackOrder }) =>
|
|
466
|
+
equals(unit, lineUnit) &&
|
|
467
|
+
equals(displayAs, 'bar') &&
|
|
468
|
+
isNotNil(stackOrder)
|
|
469
|
+
),
|
|
506
470
|
height: valueGraphHeight,
|
|
471
|
+
invert,
|
|
507
472
|
isCenteredZero,
|
|
508
473
|
isHorizontal,
|
|
509
474
|
scale,
|
|
@@ -513,6 +478,43 @@ const getRightScale = ({
|
|
|
513
478
|
});
|
|
514
479
|
};
|
|
515
480
|
|
|
481
|
+
const getYScalePerUnit = ({
|
|
482
|
+
dataLines,
|
|
483
|
+
dataTimeSeries,
|
|
484
|
+
valueGraphHeight,
|
|
485
|
+
thresholds,
|
|
486
|
+
thresholdUnit,
|
|
487
|
+
isCenteredZero,
|
|
488
|
+
scale,
|
|
489
|
+
scaleLogarithmicBase,
|
|
490
|
+
isHorizontal = true
|
|
491
|
+
}: AxeScale): Record<string, ScaleLinear<number, number>> => {
|
|
492
|
+
const units = getUnits(dataLines);
|
|
493
|
+
|
|
494
|
+
const scalePerUnit = units.reduce((acc, unit) => {
|
|
495
|
+
return {
|
|
496
|
+
...acc,
|
|
497
|
+
[unit]: getYScaleUnit({
|
|
498
|
+
dataLines,
|
|
499
|
+
dataTimeSeries,
|
|
500
|
+
invert: dataLines.some(
|
|
501
|
+
({ unit: lineUnit, invert }) => equals(lineUnit, unit) && invert
|
|
502
|
+
),
|
|
503
|
+
isCenteredZero,
|
|
504
|
+
isHorizontal,
|
|
505
|
+
scale,
|
|
506
|
+
scaleLogarithmicBase,
|
|
507
|
+
thresholdUnit,
|
|
508
|
+
thresholds,
|
|
509
|
+
unit,
|
|
510
|
+
valueGraphHeight
|
|
511
|
+
})
|
|
512
|
+
};
|
|
513
|
+
}, {});
|
|
514
|
+
|
|
515
|
+
return scalePerUnit;
|
|
516
|
+
};
|
|
517
|
+
|
|
516
518
|
const formatTime = (value: number): string => {
|
|
517
519
|
if (value < 1000) {
|
|
518
520
|
return `${numeral(value).format('0.[00]a')} ms`;
|
|
@@ -606,7 +608,7 @@ const formatMetricValueWithUnit = ({
|
|
|
606
608
|
}
|
|
607
609
|
|
|
608
610
|
if (equals('%', unit)) {
|
|
609
|
-
return `${numeral(
|
|
611
|
+
return `${numeral(value).format('0.[00]')}%`;
|
|
610
612
|
}
|
|
611
613
|
|
|
612
614
|
const formattedMetricValue = formatMetricValue({ base, unit, value });
|
|
@@ -616,29 +618,6 @@ const formatMetricValueWithUnit = ({
|
|
|
616
618
|
: `${formattedMetricValue} ${unit}`;
|
|
617
619
|
};
|
|
618
620
|
|
|
619
|
-
const getStackedYScale = ({
|
|
620
|
-
leftScale,
|
|
621
|
-
rightScale
|
|
622
|
-
}: YScales): ScaleLinear<number, number> => {
|
|
623
|
-
const minDomain = min(
|
|
624
|
-
getMin(leftScale.domain()),
|
|
625
|
-
getMin(rightScale.domain())
|
|
626
|
-
);
|
|
627
|
-
const maxDomain = max(
|
|
628
|
-
getMax(leftScale.domain()),
|
|
629
|
-
getMax(rightScale.domain())
|
|
630
|
-
);
|
|
631
|
-
|
|
632
|
-
const minRange = min(getMin(leftScale.range()), getMin(rightScale.range()));
|
|
633
|
-
const maxRange = max(getMax(leftScale.range()), getMax(rightScale.range()));
|
|
634
|
-
|
|
635
|
-
return Scale.scaleLinear<number>({
|
|
636
|
-
domain: [minDomain, maxDomain],
|
|
637
|
-
nice: true,
|
|
638
|
-
range: [maxRange, minRange]
|
|
639
|
-
});
|
|
640
|
-
};
|
|
641
|
-
|
|
642
621
|
const bisectDate = bisector(identity).center;
|
|
643
622
|
|
|
644
623
|
const getTimeValue = ({
|
|
@@ -707,13 +686,12 @@ export {
|
|
|
707
686
|
hasUnitStackedLines,
|
|
708
687
|
getYScale,
|
|
709
688
|
getScale,
|
|
710
|
-
getLeftScale,
|
|
711
689
|
getXScale,
|
|
712
|
-
getRightScale,
|
|
713
690
|
formatMetricValue,
|
|
714
|
-
getStackedYScale,
|
|
715
691
|
getTimeValue,
|
|
716
692
|
bisectDate,
|
|
717
693
|
getMetricWithLatestData,
|
|
718
|
-
formatMetricValueWithUnit
|
|
694
|
+
formatMetricValueWithUnit,
|
|
695
|
+
getYScaleUnit,
|
|
696
|
+
getYScalePerUnit
|
|
719
697
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ScaleLinear, ScaleTime } from 'd3-scale';
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import { ChartAxis } from '../../Chart/models';
|
|
4
4
|
|
|
5
5
|
interface DsData {
|
|
6
6
|
ds_color_area: string;
|
|
@@ -19,6 +19,7 @@ export interface Metric {
|
|
|
19
19
|
critical_high_threshold: number | null;
|
|
20
20
|
critical_low_threshold: number | null;
|
|
21
21
|
data: Array<number | null>;
|
|
22
|
+
displayAs?: 'line' | 'bar';
|
|
22
23
|
ds_data?: DsData;
|
|
23
24
|
legend: string;
|
|
24
25
|
maximum_value: number | null;
|
|
@@ -41,6 +42,7 @@ export interface Line {
|
|
|
41
42
|
average_value: number | null;
|
|
42
43
|
color: string;
|
|
43
44
|
display: boolean;
|
|
45
|
+
displayAs?: 'line' | 'bar';
|
|
44
46
|
filled: boolean;
|
|
45
47
|
highlight?: boolean;
|
|
46
48
|
invert: string | null;
|
|
@@ -70,10 +72,7 @@ export interface Xscale {
|
|
|
70
72
|
valueWidth: number;
|
|
71
73
|
}
|
|
72
74
|
export interface AxeScale
|
|
73
|
-
extends Pick<
|
|
74
|
-
LineChartAxis,
|
|
75
|
-
'isCenteredZero' | 'scale' | 'scaleLogarithmicBase'
|
|
76
|
-
> {
|
|
75
|
+
extends Pick<ChartAxis, 'isCenteredZero' | 'scale' | 'scaleLogarithmicBase'> {
|
|
77
76
|
dataLines: Array<Line>;
|
|
78
77
|
dataTimeSeries: Array<TimeValue>;
|
|
79
78
|
isHorizontal?: boolean;
|
package/src/Graph/index.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export { default as LineChart } from './
|
|
2
|
-
export { default as ThresholdLines } from './
|
|
3
|
-
export { default as useLineChartData } from './
|
|
1
|
+
export { default as LineChart } from './Chart';
|
|
2
|
+
export { default as ThresholdLines } from './Chart/BasicComponents/Lines/Threshold';
|
|
3
|
+
export { default as useLineChartData } from './Chart/useChartData';
|
|
4
4
|
export { default as BarChart } from './BarChart/BarChart';
|
|
5
5
|
export { Gauge } from './Gauge';
|
|
6
6
|
export { SingleBar } from './SingleBar';
|
|
@@ -13,5 +13,5 @@ export * from './Tree';
|
|
|
13
13
|
export type { LineChartData } from './common/models';
|
|
14
14
|
export * from './common/timeSeries';
|
|
15
15
|
export type { Metric } from './common/timeSeries/models';
|
|
16
|
-
export * from './
|
|
16
|
+
export * from './Chart/models';
|
|
17
17
|
export * from './PieChart/models';
|