forked from patternfly/patternfly-react
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathChartUtilInvertedStatic.tsx
More file actions
65 lines (59 loc) · 1.79 KB
/
ChartUtilInvertedStatic.tsx
File metadata and controls
65 lines (59 loc) · 1.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import { ChartDonutThreshold, ChartDonutUtilization } from '@patternfly/react-charts/victory';
import { useEffect, useState } from 'react';
interface UsageData {
x?: string;
y?: number;
name?: string;
}
export const ChartUtilInvertedStatic: React.FunctionComponent = () => {
const [used, setUsed] = useState(100);
useEffect(() => {
const interval = setInterval(() => {
setUsed((prevUsed) => {
const val = (prevUsed - 10 + 100) % 100;
return val;
});
}, 1000);
return () => clearInterval(interval);
}, []);
const dataThreshold: UsageData[] = [
{ x: 'Warning at 60%', y: 60 },
{ x: 'Danger at 20%', y: 20 }
];
const dataUtil: UsageData = { x: 'Storage capacity', y: used };
const legendData: UsageData[] = [
{ name: `Storage capacity: ${used}%` },
{ name: 'Warning threshold at 60%' },
{ name: 'Danger threshold at 20%' }
];
return (
<div style={{ height: '230px', width: '500px' }}>
<ChartDonutThreshold
ariaDesc="Storage capacity"
ariaTitle="Donut utilization chart with static threshold example"
constrainToVisibleArea
data={dataThreshold}
invert
labels={({ datum }) => (datum.x ? datum.x : null)}
name="chart12"
padding={{
bottom: 20,
left: 20,
right: 290, // Adjusted to accommodate legend
top: 20
}}
width={500}
>
<ChartDonutUtilization
data={dataUtil}
labels={({ datum }) => (datum.x ? `${datum.x}: ${datum.y}%` : null)}
legendData={legendData}
legendOrientation="vertical"
subTitle="of 100 GBps"
title={`${used}%`}
thresholds={[{ value: 60 }, { value: 20 }]}
/>
</ChartDonutThreshold>
</div>
);
};