/
LineageButton.tsx
123 lines (122 loc) · 3.44 KB
/
LineageButton.tsx
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
import {Popover2, Tooltip2} from "@blueprintjs/popover2";
import {Button, Colors} from "@blueprintjs/core";
import React, {useState} from "react";
import {useTable} from "../hooks/useTable";
import EChartsReact from "echarts-for-react";
import {friendlyName} from "common";
const Content = () => {
const currentTable = useTable()
if (currentTable.status !== 'success')
return null
const table = currentTable.data.tables[currentTable.data.baseTable]
const commonNodeProps = {
symbol: 'circle',
symbolSize: 20,
}
const height = table.dependentTables.length + table.sourceTables.length
const sourceNodes = table.sourceTables.map((name, idx) => ({
...commonNodeProps,
name: friendlyName(name),
x: 50 * idx,
y: 100 * idx,
itemStyle: {
color: Colors.BLUE3,
}
}))
const middleNode = {
...commonNodeProps,
name: friendlyName(table.name),
x: 0,
y: 100 * table.sourceTables.length,
itemStyle: {
color: Colors.BLUE3,
},
label: {
fontWeight: 'bold',
}
}
const dependentNodes = table.dependentTables.map((name, idx) => ({
...commonNodeProps,
name: friendlyName(name),
x: 50 * idx,
y: 100 * (height - idx),
itemStyle: {
color: Colors.ORANGE3,
}
}))
const nodes = [...sourceNodes, middleNode, ...dependentNodes]
const edges = [
...table.sourceTables.map(source => ({
source: friendlyName(source),
target: friendlyName(table.name),
lineStyle: {
color: Colors.BLUE3,
},
})),
...table.dependentTables.map(target => ({
source: friendlyName(table.name),
target: friendlyName(target),
lineStyle: {
color: Colors.ORANGE3,
},
})),
]
const options = {
animationDurationUpdate: 1500,
animationEasingUpdate: 'quinticInOut',
grid: {
left: 0,
right: 0
},
series: [{
type: 'graph',
data: nodes,
links: edges,
lineStyle: {
width: 1.5,
curveness: 0.1,
color: Colors.DARK_GRAY5,
cap: 'round',
opacity: 1,
},
label: {
show: true,
position: 'right',
},
edgeSymbol: ['circle', 'arrow'],
edgeSymbolSize: [0, 10],
center: [50, height * 100 / 2],
zoom: 1.0,
cursor: 'default',
silent: true,
}],
}
return (
<div style={{width: 300, padding: 5}}>
<EChartsReact
option={options}
/>
</div>
)
return (
<span>Hello</span>
)
}
export const LineageButton = () => {
const [isOpen, setIsOpen] = useState(false)
return (
<Popover2
content={<Content />}
interactionKind={'click'}
isOpen={isOpen}
onInteraction={setIsOpen}
position={'right'}
lazy={true}
fill={true}
>
<Tooltip2 content="View a partial lineage graph for this table">
<Button minimal={true} icon={'data-lineage'} text='Show lineage' />
</Tooltip2>
</Popover2>
)
}