@centreon/ui 23.10.1-MON-20802-fe-implement-new-visualization.2 → 23.10.1-MON-21543-implement-top-bottom-widget.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/Dashboard/Dashboard.styles.ts +6 -1
- package/src/Dashboard/Item.tsx +4 -1
- package/src/Dashboard/Layout.tsx +1 -1
- package/src/Graph/Gauge/Gauge.stories.tsx +10 -0
- package/src/Graph/Gauge/Gauge.tsx +10 -1
- package/src/Graph/Gauge/PieData.tsx +8 -8
- package/src/Graph/Gauge/ResponsiveGauge.tsx +32 -23
- package/src/Graph/Gauge/Thresholds.tsx +2 -25
- package/src/Graph/Gauge/models.ts +1 -0
- package/src/Graph/SingleBar/ResponsiveSingleBar.tsx +41 -24
- package/src/Graph/SingleBar/SingleBar.stories.tsx +46 -0
- package/src/Graph/SingleBar/ThresholdLine.tsx +31 -12
- package/src/Graph/SingleBar/Thresholds.tsx +5 -1
- package/src/Graph/SingleBar/models.ts +4 -0
- package/src/Graph/Text/Text.stories.tsx +13 -0
- package/src/Graph/Text/Text.tsx +19 -12
- package/src/Graph/common/timeSeries/index.test.ts +106 -3
- package/src/Graph/common/timeSeries/index.ts +67 -4
- package/src/Graph/common/timeSeries/models.ts +6 -3
- package/src/Graph/common/utils.ts +4 -2
- package/src/InputField/Select/Autocomplete/Multi/index.tsx +4 -2
- package/src/InputField/Select/Autocomplete/index.tsx +3 -1
- package/src/InputField/Text/index.tsx +10 -7
- package/src/RichTextEditor/ContentEditable.tsx +0 -1
- package/src/RichTextEditor/RichTextEditor.cypress.spec.tsx +5 -13
- package/src/RichTextEditor/RichTextEditor.tsx +5 -2
- package/src/RichTextEditor/plugins/AutoLinkPlugin/index.tsx +40 -1
- package/src/RichTextEditor/plugins/FloatingLinkEditorPlugin.tsx +33 -8
- package/src/RichTextEditor/plugins/ToolbarPlugin/index.tsx +10 -4
- package/src/ThemeProvider/index.tsx +6 -4
- package/src/TopCounterElements/index.tsx +0 -1
- package/src/api/useFetchQuery/index.ts +10 -8
- package/src/components/Inputs/Switch/Switch.stories.tsx +22 -0
- package/src/components/Inputs/Switch/Switch.styles.ts +13 -0
- package/src/components/Inputs/Switch/Switch.tsx +18 -0
- package/src/components/Inputs/index.ts +1 -0
- package/src/components/Modal/Modal.styles.ts +3 -1
- package/src/components/index.ts +1 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@centreon/ui",
|
|
3
|
-
"version": "23.10.1-MON-
|
|
3
|
+
"version": "23.10.1-MON-21543-implement-top-bottom-widget.0",
|
|
4
4
|
"description": "Centreon UI Components",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"eslint": "eslint ./src --ext .js,.jsx,.ts,.tsx --max-warnings 0",
|
|
@@ -79,7 +79,12 @@ export const useDashboardItemStyles = makeStyles<{ hasHeader: boolean }>()(
|
|
|
79
79
|
'&:hover': {
|
|
80
80
|
backgroundColor: theme.palette.action.hover
|
|
81
81
|
},
|
|
82
|
-
|
|
82
|
+
'&[data-canMove="false"]': {
|
|
83
|
+
cursor: 'default'
|
|
84
|
+
},
|
|
85
|
+
'&[data-canMove="true"]': {
|
|
86
|
+
cursor: 'move'
|
|
87
|
+
},
|
|
83
88
|
padding: theme.spacing(0.5, 2)
|
|
84
89
|
},
|
|
85
90
|
widgetPadding: {
|
package/src/Dashboard/Item.tsx
CHANGED
|
@@ -15,6 +15,7 @@ import { useMemoComponent } from '../utils';
|
|
|
15
15
|
import { useDashboardItemStyles } from './Dashboard.styles';
|
|
16
16
|
|
|
17
17
|
interface DashboardItemProps {
|
|
18
|
+
canMove?: boolean;
|
|
18
19
|
children: ReactElement;
|
|
19
20
|
className?: string;
|
|
20
21
|
disablePadding?: boolean;
|
|
@@ -37,7 +38,8 @@ const Item = forwardRef(
|
|
|
37
38
|
onMouseUp,
|
|
38
39
|
onTouchEnd,
|
|
39
40
|
id,
|
|
40
|
-
disablePadding = false
|
|
41
|
+
disablePadding = false,
|
|
42
|
+
canMove = false
|
|
41
43
|
}: DashboardItemProps,
|
|
42
44
|
ref: ForwardedRef<HTMLDivElement>
|
|
43
45
|
): ReactElement => {
|
|
@@ -66,6 +68,7 @@ const Item = forwardRef(
|
|
|
66
68
|
<div
|
|
67
69
|
{...listeners}
|
|
68
70
|
className={classes.widgetHeader}
|
|
71
|
+
data-canMove={canMove}
|
|
69
72
|
data-testid={`${id}_move_panel`}
|
|
70
73
|
>
|
|
71
74
|
{header}
|
package/src/Dashboard/Layout.tsx
CHANGED
|
@@ -134,3 +134,13 @@ export const withRangeThresholds: Story = {
|
|
|
134
134
|
},
|
|
135
135
|
render: Template
|
|
136
136
|
};
|
|
137
|
+
|
|
138
|
+
export const RawValue: Story = {
|
|
139
|
+
args: {
|
|
140
|
+
data: dataLastWeek,
|
|
141
|
+
displayAsRaw: true,
|
|
142
|
+
thresholdTooltipLabels: ['Warning', 'Critical'],
|
|
143
|
+
thresholds: [0.5, 0.6]
|
|
144
|
+
},
|
|
145
|
+
render: Template
|
|
146
|
+
};
|
|
@@ -7,11 +7,18 @@ import { Metric } from '../common/timeSeries/models';
|
|
|
7
7
|
import ResponsiveGauge from './ResponsiveGauge';
|
|
8
8
|
|
|
9
9
|
interface Props {
|
|
10
|
+
baseColor?: string;
|
|
10
11
|
data?: LineChartData;
|
|
12
|
+
displayAsRaw?: boolean;
|
|
11
13
|
thresholds: Thresholds;
|
|
12
14
|
}
|
|
13
15
|
|
|
14
|
-
export const Gauge = ({
|
|
16
|
+
export const Gauge = ({
|
|
17
|
+
thresholds,
|
|
18
|
+
data,
|
|
19
|
+
displayAsRaw,
|
|
20
|
+
baseColor
|
|
21
|
+
}: Props): JSX.Element | null => {
|
|
15
22
|
if (!data) {
|
|
16
23
|
return null;
|
|
17
24
|
}
|
|
@@ -22,6 +29,8 @@ export const Gauge = ({ thresholds, data }: Props): JSX.Element | null => {
|
|
|
22
29
|
<Responsive.ParentSize>
|
|
23
30
|
{({ width, height }) => (
|
|
24
31
|
<ResponsiveGauge
|
|
32
|
+
baseColor={baseColor}
|
|
33
|
+
displayAsRaw={displayAsRaw}
|
|
25
34
|
height={height}
|
|
26
35
|
metric={metric}
|
|
27
36
|
thresholds={thresholds}
|
|
@@ -16,7 +16,8 @@ const PieData = ({
|
|
|
16
16
|
metric,
|
|
17
17
|
adaptedMaxValue,
|
|
18
18
|
thresholds,
|
|
19
|
-
radius
|
|
19
|
+
radius,
|
|
20
|
+
baseColor
|
|
20
21
|
}: Omit<
|
|
21
22
|
GaugeProps,
|
|
22
23
|
'width' | 'height' | 'showTooltip' | 'hideTooltip' | 'thresholdTooltipLabels'
|
|
@@ -24,13 +25,12 @@ const PieData = ({
|
|
|
24
25
|
const theme = useTheme();
|
|
25
26
|
|
|
26
27
|
const pieData = [metric.data[0], adaptedMaxValue - metric.data[0]];
|
|
27
|
-
const pieColor =
|
|
28
|
-
|
|
29
|
-
:
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
});
|
|
28
|
+
const pieColor = getColorFromDataAndTresholds({
|
|
29
|
+
baseColor,
|
|
30
|
+
data: metric.data[0],
|
|
31
|
+
theme,
|
|
32
|
+
thresholds
|
|
33
|
+
});
|
|
34
34
|
|
|
35
35
|
const getDataColor = scaleOrdinal({
|
|
36
36
|
domain: pieData,
|
|
@@ -7,7 +7,7 @@ import { Tooltip } from '@visx/visx';
|
|
|
7
7
|
import { Box, Fade, useTheme } from '@mui/material';
|
|
8
8
|
|
|
9
9
|
import { Metric } from '../common/timeSeries/models';
|
|
10
|
-
import {
|
|
10
|
+
import { formatMetricValueWithUnit } from '../common/timeSeries';
|
|
11
11
|
import { getColorFromDataAndTresholds } from '../common/utils';
|
|
12
12
|
import { margins } from '../common/margins';
|
|
13
13
|
|
|
@@ -15,7 +15,8 @@ import Thresholds from './Thresholds';
|
|
|
15
15
|
import PieData from './PieData';
|
|
16
16
|
import { GaugeProps } from './models';
|
|
17
17
|
|
|
18
|
-
interface Props extends Pick<GaugeProps, 'thresholds'> {
|
|
18
|
+
interface Props extends Pick<GaugeProps, 'thresholds' | 'baseColor'> {
|
|
19
|
+
displayAsRaw?: boolean;
|
|
19
20
|
height: number;
|
|
20
21
|
metric: Metric;
|
|
21
22
|
width: number;
|
|
@@ -30,7 +31,9 @@ const ResponsiveGauge = ({
|
|
|
30
31
|
width,
|
|
31
32
|
height,
|
|
32
33
|
thresholds,
|
|
33
|
-
metric
|
|
34
|
+
metric,
|
|
35
|
+
displayAsRaw,
|
|
36
|
+
baseColor
|
|
34
37
|
}: Props): JSX.Element => {
|
|
35
38
|
const svgRef = useRef<SVGSVGElement>(null);
|
|
36
39
|
|
|
@@ -50,28 +53,36 @@ const ResponsiveGauge = ({
|
|
|
50
53
|
const centerY = innerHeight / 2;
|
|
51
54
|
const centerX = innerWidth / 2;
|
|
52
55
|
const radius = Math.min(innerWidth, innerHeight) / 2;
|
|
53
|
-
const thresholdValues =
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
56
|
+
const thresholdValues = thresholds.enabled
|
|
57
|
+
? flatten([
|
|
58
|
+
pluck('value', thresholds.warning),
|
|
59
|
+
pluck('value', thresholds.critical)
|
|
60
|
+
])
|
|
61
|
+
: [0];
|
|
57
62
|
const adaptedMaxValue = Math.max(
|
|
58
63
|
metric.maximum_value || 0,
|
|
59
64
|
Math.max(...thresholdValues) * 1.1,
|
|
60
65
|
head(metric.data) as number
|
|
61
66
|
);
|
|
62
67
|
|
|
63
|
-
const pieColor =
|
|
64
|
-
|
|
65
|
-
:
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
});
|
|
68
|
+
const pieColor = getColorFromDataAndTresholds({
|
|
69
|
+
baseColor,
|
|
70
|
+
data: metric.data[0],
|
|
71
|
+
theme,
|
|
72
|
+
thresholds
|
|
73
|
+
});
|
|
70
74
|
|
|
71
75
|
const svgTop = svgRef.current?.getBoundingClientRect().top || 0;
|
|
72
76
|
const svgLeft = svgRef.current?.getBoundingClientRect().left || 0;
|
|
73
77
|
|
|
74
|
-
const
|
|
78
|
+
const isSmallWidget = height < 240;
|
|
79
|
+
|
|
80
|
+
const gaugeValue = formatMetricValueWithUnit({
|
|
81
|
+
base: 1000,
|
|
82
|
+
isRaw: displayAsRaw,
|
|
83
|
+
unit: metric.unit,
|
|
84
|
+
value: metric.data[0]
|
|
85
|
+
});
|
|
75
86
|
|
|
76
87
|
return (
|
|
77
88
|
<Box sx={{ position: 'relative' }}>
|
|
@@ -87,6 +98,7 @@ const ResponsiveGauge = ({
|
|
|
87
98
|
/>
|
|
88
99
|
<PieData
|
|
89
100
|
adaptedMaxValue={adaptedMaxValue}
|
|
101
|
+
baseColor={baseColor}
|
|
90
102
|
metric={metric}
|
|
91
103
|
radius={radius}
|
|
92
104
|
thresholds={thresholds}
|
|
@@ -97,18 +109,15 @@ const ResponsiveGauge = ({
|
|
|
97
109
|
style={{
|
|
98
110
|
fill: pieColor,
|
|
99
111
|
...theme.typography.h3,
|
|
100
|
-
fontSize:
|
|
112
|
+
fontSize:
|
|
113
|
+
Math.min(width, height) / 7 -
|
|
114
|
+
(isSmallWidget ? 0 : (gaugeValue?.length || 0) * 2)
|
|
101
115
|
}}
|
|
102
116
|
textAnchor="middle"
|
|
103
117
|
x="50%"
|
|
104
|
-
y={
|
|
118
|
+
y={isSmallWidget ? 130 : height - height / 2.3}
|
|
105
119
|
>
|
|
106
|
-
{
|
|
107
|
-
base: 1000,
|
|
108
|
-
unit: metric.unit,
|
|
109
|
-
value: metric.data[0]
|
|
110
|
-
})}{' '}
|
|
111
|
-
{metric.unit}
|
|
120
|
+
{gaugeValue}
|
|
112
121
|
</text>
|
|
113
122
|
</svg>
|
|
114
123
|
<Fade in={tooltipOpen && thresholds.enabled}>
|
|
@@ -16,7 +16,7 @@ const Thresholds = ({
|
|
|
16
16
|
showTooltip,
|
|
17
17
|
hideTooltip,
|
|
18
18
|
metric
|
|
19
|
-
}: Omit<GaugeProps, 'width' | 'height'>): JSX.Element => {
|
|
19
|
+
}: Omit<GaugeProps, 'width' | 'height'>): JSX.Element | null => {
|
|
20
20
|
const theme = useTheme();
|
|
21
21
|
|
|
22
22
|
const criticalThresholdValues = pluck('value', thresholds.critical);
|
|
@@ -65,30 +65,7 @@ const Thresholds = ({
|
|
|
65
65
|
});
|
|
66
66
|
|
|
67
67
|
if (!thresholds.enabled) {
|
|
68
|
-
return
|
|
69
|
-
<Pie
|
|
70
|
-
data={successThresholdArc}
|
|
71
|
-
endAngle={-Math.PI / 2}
|
|
72
|
-
innerRadius={radius - thresholdThickness}
|
|
73
|
-
outerRadius={radius}
|
|
74
|
-
pieSortValues={() => -1}
|
|
75
|
-
pieValue={(d) => d.value}
|
|
76
|
-
startAngle={Math.PI / 2}
|
|
77
|
-
>
|
|
78
|
-
{(pie) => (
|
|
79
|
-
<AnimatedPie<{ name: string; value: number }>
|
|
80
|
-
{...pie}
|
|
81
|
-
animate
|
|
82
|
-
getColor={(arc) => successThresholdScaleOrdinal(arc.data.name)}
|
|
83
|
-
getKey={(arc) => `${arc.data.name}_${arc.data.value}`}
|
|
84
|
-
hideTooltip={hideTooltip}
|
|
85
|
-
metric={metric}
|
|
86
|
-
showTooltip={showTooltip}
|
|
87
|
-
thresholds={thresholds}
|
|
88
|
-
/>
|
|
89
|
-
)}
|
|
90
|
-
</Pie>
|
|
91
|
-
);
|
|
68
|
+
return null;
|
|
92
69
|
}
|
|
93
70
|
|
|
94
71
|
const arcs = [
|
|
@@ -2,23 +2,22 @@ import { useMemo, useRef } from 'react';
|
|
|
2
2
|
|
|
3
3
|
import { Group, Tooltip } from '@visx/visx';
|
|
4
4
|
import { scaleLinear } from '@visx/scale';
|
|
5
|
-
import { flatten, head, pluck } from 'ramda';
|
|
5
|
+
import { equals, flatten, head, pluck } from 'ramda';
|
|
6
6
|
import { Bar } from '@visx/shape';
|
|
7
7
|
import { useSpring, animated } from '@react-spring/web';
|
|
8
8
|
|
|
9
9
|
import { alpha, Box, Fade, useTheme } from '@mui/material';
|
|
10
10
|
|
|
11
11
|
import {
|
|
12
|
-
|
|
12
|
+
formatMetricValueWithUnit,
|
|
13
13
|
getMetricWithLatestData
|
|
14
14
|
} from '../common/timeSeries';
|
|
15
15
|
import { Metric } from '../common/timeSeries/models';
|
|
16
16
|
import { getColorFromDataAndTresholds } from '../common/utils';
|
|
17
|
-
import { margins } from '../common/margins';
|
|
18
17
|
|
|
19
18
|
import { SingleBarProps } from './models';
|
|
20
19
|
import Thresholds, { groupMargin } from './Thresholds';
|
|
21
|
-
import {
|
|
20
|
+
import { barHeights } from './ThresholdLine';
|
|
22
21
|
|
|
23
22
|
interface Props extends SingleBarProps {
|
|
24
23
|
height: number;
|
|
@@ -34,25 +33,29 @@ const ResponsiveSingleBar = ({
|
|
|
34
33
|
data,
|
|
35
34
|
thresholds,
|
|
36
35
|
width,
|
|
37
|
-
height
|
|
36
|
+
height,
|
|
37
|
+
displayAsRaw,
|
|
38
|
+
baseColor,
|
|
39
|
+
size = 'medium',
|
|
40
|
+
showLabels = true
|
|
38
41
|
}: Props): JSX.Element => {
|
|
39
42
|
const theme = useTheme();
|
|
40
43
|
|
|
41
44
|
const metric = getMetricWithLatestData(data) as Metric;
|
|
42
45
|
const latestMetricData = head(metric.data) as number;
|
|
43
|
-
const thresholdValues =
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
46
|
+
const thresholdValues = thresholds.enabled
|
|
47
|
+
? flatten([
|
|
48
|
+
pluck('value', thresholds.warning),
|
|
49
|
+
pluck('value', thresholds.critical)
|
|
50
|
+
])
|
|
51
|
+
: [0];
|
|
52
|
+
|
|
47
53
|
const adaptedMaxValue = Math.max(
|
|
48
54
|
metric.maximum_value || 0,
|
|
49
55
|
Math.max(...thresholdValues) * 1.1,
|
|
50
56
|
head(metric.data) as number
|
|
51
57
|
);
|
|
52
58
|
|
|
53
|
-
const innerHeight = height;
|
|
54
|
-
const centerY = innerHeight / 4;
|
|
55
|
-
|
|
56
59
|
const {
|
|
57
60
|
showTooltip,
|
|
58
61
|
hideTooltip,
|
|
@@ -66,6 +69,7 @@ const ResponsiveSingleBar = ({
|
|
|
66
69
|
const barColor = useMemo(
|
|
67
70
|
() =>
|
|
68
71
|
getColorFromDataAndTresholds({
|
|
72
|
+
baseColor,
|
|
69
73
|
data: latestMetricData,
|
|
70
74
|
theme,
|
|
71
75
|
thresholds
|
|
@@ -73,20 +77,31 @@ const ResponsiveSingleBar = ({
|
|
|
73
77
|
[latestMetricData, thresholds, theme]
|
|
74
78
|
);
|
|
75
79
|
|
|
76
|
-
const
|
|
80
|
+
const isSmall = equals(size, 'small');
|
|
81
|
+
|
|
82
|
+
const textStyle = isSmall
|
|
83
|
+
? {
|
|
84
|
+
...theme.typography.h6
|
|
85
|
+
}
|
|
86
|
+
: theme.typography.h3;
|
|
87
|
+
|
|
88
|
+
const text = showLabels && (
|
|
77
89
|
<text
|
|
78
90
|
dominantBaseline="middle"
|
|
79
|
-
style={{
|
|
91
|
+
style={{
|
|
92
|
+
fill: barColor,
|
|
93
|
+
...textStyle
|
|
94
|
+
}}
|
|
80
95
|
textAnchor="middle"
|
|
81
96
|
x="50%"
|
|
82
|
-
y={25}
|
|
97
|
+
y={isSmall ? 10 : 25}
|
|
83
98
|
>
|
|
84
|
-
{
|
|
99
|
+
{formatMetricValueWithUnit({
|
|
85
100
|
base: 1000,
|
|
101
|
+
isRaw: displayAsRaw,
|
|
86
102
|
unit: metric.unit,
|
|
87
103
|
value: metric.data[0]
|
|
88
|
-
})}
|
|
89
|
-
{metric.unit}
|
|
104
|
+
})}
|
|
90
105
|
</text>
|
|
91
106
|
);
|
|
92
107
|
|
|
@@ -113,31 +128,32 @@ const ResponsiveSingleBar = ({
|
|
|
113
128
|
return (
|
|
114
129
|
<Box sx={{ position: 'relative' }}>
|
|
115
130
|
<svg height={height} ref={svgRef} width={width}>
|
|
116
|
-
<Group.Group
|
|
131
|
+
<Group.Group>
|
|
117
132
|
{text}
|
|
118
133
|
<animated.rect
|
|
119
134
|
data-testid={`${latestMetricData}-bar-${barColor}`}
|
|
120
135
|
fill={barColor}
|
|
121
|
-
height={
|
|
136
|
+
height={barHeights[size]}
|
|
122
137
|
rx={4}
|
|
123
138
|
style={springStyle}
|
|
124
139
|
x={0}
|
|
125
|
-
y={groupMargin
|
|
140
|
+
y={groupMargin}
|
|
126
141
|
/>
|
|
127
142
|
<Bar
|
|
128
143
|
fill="transparent"
|
|
129
|
-
height={
|
|
144
|
+
height={barHeights[size]}
|
|
130
145
|
rx={4}
|
|
131
146
|
ry={4}
|
|
132
147
|
stroke={alpha(theme.palette.text.primary, 0.3)}
|
|
133
148
|
width={maxBarWidth}
|
|
134
149
|
x={0}
|
|
135
|
-
y={groupMargin
|
|
150
|
+
y={groupMargin}
|
|
136
151
|
/>
|
|
137
152
|
{thresholds.enabled && (
|
|
138
153
|
<Thresholds
|
|
139
154
|
hideTooltip={hideTooltip}
|
|
140
155
|
showTooltip={showTooltip}
|
|
156
|
+
size={size}
|
|
141
157
|
thresholds={thresholds}
|
|
142
158
|
xScale={xScale}
|
|
143
159
|
/>
|
|
@@ -151,7 +167,8 @@ const ResponsiveSingleBar = ({
|
|
|
151
167
|
...baseStyles,
|
|
152
168
|
backgroundColor: theme.palette.background.paper,
|
|
153
169
|
color: theme.palette.text.primary,
|
|
154
|
-
transform:
|
|
170
|
+
transform: `translate(-50%, ${isSmall ? -60 : -20}px)`,
|
|
171
|
+
zIndex: theme.zIndex.tooltip
|
|
155
172
|
}}
|
|
156
173
|
top={tooltipTop}
|
|
157
174
|
>
|
|
@@ -156,3 +156,49 @@ export const rangeThresholds: Story = {
|
|
|
156
156
|
},
|
|
157
157
|
render: Template
|
|
158
158
|
};
|
|
159
|
+
|
|
160
|
+
export const RawValue: Story = {
|
|
161
|
+
args: {
|
|
162
|
+
data: dataLastWeek,
|
|
163
|
+
displayAsRaw: true,
|
|
164
|
+
thresholds: {
|
|
165
|
+
critical: [
|
|
166
|
+
{
|
|
167
|
+
label: 'Critical',
|
|
168
|
+
value: 0.6
|
|
169
|
+
}
|
|
170
|
+
],
|
|
171
|
+
enabled: false,
|
|
172
|
+
warning: [
|
|
173
|
+
{
|
|
174
|
+
label: 'Warning',
|
|
175
|
+
value: 0.5
|
|
176
|
+
}
|
|
177
|
+
]
|
|
178
|
+
}
|
|
179
|
+
},
|
|
180
|
+
render: Template
|
|
181
|
+
};
|
|
182
|
+
|
|
183
|
+
export const Small: Story = {
|
|
184
|
+
args: {
|
|
185
|
+
data: dataLastWeek,
|
|
186
|
+
size: 'small',
|
|
187
|
+
thresholds: {
|
|
188
|
+
critical: [
|
|
189
|
+
{
|
|
190
|
+
label: 'Critical',
|
|
191
|
+
value: 0.6
|
|
192
|
+
}
|
|
193
|
+
],
|
|
194
|
+
enabled: true,
|
|
195
|
+
warning: [
|
|
196
|
+
{
|
|
197
|
+
label: 'Warning',
|
|
198
|
+
value: 0.5
|
|
199
|
+
}
|
|
200
|
+
]
|
|
201
|
+
}
|
|
202
|
+
},
|
|
203
|
+
render: Template
|
|
204
|
+
};
|
|
@@ -4,18 +4,22 @@ import { useTheme } from '@mui/material';
|
|
|
4
4
|
|
|
5
5
|
import { groupMargin } from './Thresholds';
|
|
6
6
|
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
export const barHeights = {
|
|
8
|
+
medium: 72,
|
|
9
|
+
small: 22
|
|
10
|
+
};
|
|
11
11
|
export const margin = 40;
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
const lineMargins = {
|
|
14
|
+
medium: 10,
|
|
15
|
+
small: 5
|
|
16
|
+
};
|
|
14
17
|
|
|
15
18
|
interface Props {
|
|
16
19
|
hideTooltip: () => void;
|
|
17
20
|
label: string;
|
|
18
21
|
showTooltip: (args) => void;
|
|
22
|
+
size: 'small' | 'medium';
|
|
19
23
|
thresholdType: string;
|
|
20
24
|
value: number;
|
|
21
25
|
xScale: (value: number) => number;
|
|
@@ -27,13 +31,20 @@ export const ThresholdLine = ({
|
|
|
27
31
|
xScale,
|
|
28
32
|
thresholdType,
|
|
29
33
|
showTooltip,
|
|
30
|
-
hideTooltip
|
|
34
|
+
hideTooltip,
|
|
35
|
+
size
|
|
31
36
|
}: Props): JSX.Element => {
|
|
32
37
|
const theme = useTheme();
|
|
33
38
|
|
|
34
39
|
const scaledValue = xScale(value) || 0;
|
|
35
40
|
|
|
36
|
-
const
|
|
41
|
+
const lineMargin = lineMargins[size];
|
|
42
|
+
|
|
43
|
+
const thresholdLineHeight = barHeights[size] + 2 * lineMargin;
|
|
44
|
+
|
|
45
|
+
const isSmall = equals(size, 'small');
|
|
46
|
+
|
|
47
|
+
const bottom = barHeights[size] + margin * 2;
|
|
37
48
|
|
|
38
49
|
const onMouseEnter = (left) => (): void =>
|
|
39
50
|
showTooltip({
|
|
@@ -51,12 +62,16 @@ export const ThresholdLine = ({
|
|
|
51
62
|
<line
|
|
52
63
|
data-testid={`${thresholdType}-line-${value}`}
|
|
53
64
|
stroke={lineColor}
|
|
54
|
-
strokeDasharray=
|
|
65
|
+
strokeDasharray="6, 6"
|
|
55
66
|
strokeWidth={2}
|
|
56
67
|
x1={scaledValue}
|
|
57
68
|
x2={scaledValue}
|
|
58
|
-
y1={groupMargin + 3 * lineMargin}
|
|
59
|
-
y2={
|
|
69
|
+
y1={isSmall ? groupMargin - lineMargin : groupMargin + 3 * lineMargin}
|
|
70
|
+
y2={
|
|
71
|
+
isSmall
|
|
72
|
+
? thresholdLineHeight + groupMargin - lineMargin
|
|
73
|
+
: groupMargin + 3 * lineMargin
|
|
74
|
+
}
|
|
60
75
|
/>
|
|
61
76
|
<line
|
|
62
77
|
data-testid={`${thresholdType}-line-${value}-tooltip`}
|
|
@@ -64,8 +79,12 @@ export const ThresholdLine = ({
|
|
|
64
79
|
strokeWidth={5}
|
|
65
80
|
x1={scaledValue}
|
|
66
81
|
x2={scaledValue}
|
|
67
|
-
y1={groupMargin + 3 * lineMargin}
|
|
68
|
-
y2={
|
|
82
|
+
y1={isSmall ? groupMargin - lineMargin : groupMargin + 3 * lineMargin}
|
|
83
|
+
y2={
|
|
84
|
+
isSmall
|
|
85
|
+
? thresholdLineHeight + groupMargin - lineMargin
|
|
86
|
+
: groupMargin + 3 * lineMargin
|
|
87
|
+
}
|
|
69
88
|
onMouseEnter={onMouseEnter(scaledValue)}
|
|
70
89
|
onMouseLeave={hideTooltip}
|
|
71
90
|
/>
|
|
@@ -7,6 +7,7 @@ export const groupMargin = 25;
|
|
|
7
7
|
interface Props {
|
|
8
8
|
hideTooltip: () => void;
|
|
9
9
|
showTooltip: (args) => void;
|
|
10
|
+
size: 'small' | 'medium';
|
|
10
11
|
thresholds: Thresholds;
|
|
11
12
|
xScale: (value: number) => number;
|
|
12
13
|
}
|
|
@@ -15,7 +16,8 @@ const Thresholds = ({
|
|
|
15
16
|
xScale,
|
|
16
17
|
thresholds,
|
|
17
18
|
showTooltip,
|
|
18
|
-
hideTooltip
|
|
19
|
+
hideTooltip,
|
|
20
|
+
size
|
|
19
21
|
}: Props): JSX.Element => (
|
|
20
22
|
<>
|
|
21
23
|
{thresholds.warning.map(({ value, label }) => (
|
|
@@ -24,6 +26,7 @@ const Thresholds = ({
|
|
|
24
26
|
key={`warning-${value.toString()}`}
|
|
25
27
|
label={label}
|
|
26
28
|
showTooltip={showTooltip}
|
|
29
|
+
size={size}
|
|
27
30
|
thresholdType="warning"
|
|
28
31
|
value={value}
|
|
29
32
|
xScale={xScale}
|
|
@@ -35,6 +38,7 @@ const Thresholds = ({
|
|
|
35
38
|
key={`critical-${value.toString()}`}
|
|
36
39
|
label={label}
|
|
37
40
|
showTooltip={showTooltip}
|
|
41
|
+
size={size}
|
|
38
42
|
thresholdType="critical"
|
|
39
43
|
value={value}
|
|
40
44
|
xScale={xScale}
|
|
@@ -52,3 +52,16 @@ export const critical: Story = {
|
|
|
52
52
|
},
|
|
53
53
|
render: Template
|
|
54
54
|
};
|
|
55
|
+
|
|
56
|
+
export const rawValue: Story = {
|
|
57
|
+
args: {
|
|
58
|
+
data: dataLastWeek,
|
|
59
|
+
displayAsRaw: true,
|
|
60
|
+
labels: {
|
|
61
|
+
critical: 'Critical',
|
|
62
|
+
warning: 'Warning'
|
|
63
|
+
},
|
|
64
|
+
thresholds: [0.5, 1.5]
|
|
65
|
+
},
|
|
66
|
+
render: Template
|
|
67
|
+
};
|