forked from patternfly/patternfly-react
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBasic.tsx
More file actions
94 lines (88 loc) · 1.63 KB
/
Basic.tsx
File metadata and controls
94 lines (88 loc) · 1.63 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
import React from 'react';
import { Sankey } from '@patternfly/react-charts/next';
import { getResizeObserver } from '@patternfly/react-core';
export const FormBasic: React.FunctionComponent = () => {
const data = [
{
name: 'a'
},
{
name: 'b'
},
{
name: 'a1'
},
{
name: 'a2'
},
{
name: 'b1'
},
{
name: 'c'
}
];
const links = [
{
source: 'a',
target: 'a1',
value: 5
},
{
source: 'a',
target: 'a2',
value: 3
},
{
source: 'b',
target: 'b1',
value: 8
},
{
source: 'a',
target: 'b1',
value: 3
},
{
source: 'b1',
target: 'a1',
value: 1
},
{
source: 'b1',
target: 'c',
value: 2
}
];
// let observer = () => {};
const containerRef = React.useRef<HTMLDivElement>();
const [width, setWidth] = React.useState(0);
React.useEffect(() => {
const handleResize = () => {
if (containerRef.current && containerRef.current.clientWidth) {
setWidth(containerRef.current.clientWidth);
}
};
let observer = () => {};
observer = getResizeObserver(containerRef.current, handleResize);
return () => {
observer();
};
}, [containerRef, width]);
return (
<div ref={containerRef}>
<Sankey
height={400}
series={[{ data, links }]}
title={{
subtext: 'This is a Sankey chart',
left: 'center'
}}
tooltip={{
valueFormatter: (value) => `${value} GiB`
}}
width={width}
/>
</div>
);
};