-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathNode.tsx
126 lines (111 loc) · 3.18 KB
/
Node.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
124
125
126
import React from "react"
import { useTheme } from "@material-ui/core"
import { Text } from "@visx/text"
import { NodeType } from "."
import { hasPositions, isExpanded } from "@utils"
import { LogoSVG } from "components/Logo"
const WIDTH = 75
const FONT_SIZE = "11px"
const TEXT_CENTER = 4
const TEXT_STYLE: React.CSSProperties = {
fontSize: FONT_SIZE,
// pointerEvents: "none",
lineHeight: 10,
}
export type NodeProps = {
node: NodeType
width?: number
height?: number
}
type CommonProps = {
data: string
}
type RootProps = CommonProps & {
width?: number
}
const RootNode = (props: RootProps) => {
const { data, width = WIDTH } = props
const radius = width / 2
const theme = useTheme()
const transform = "scale(0.25, 0.25) translate(-300, -200)"
return (
<>
{/* <circle r={radius} fill="url('#root-node-color')" />
<Text
width={width}
textAnchor="middle"
verticalAnchor="middle"
style={TEXT_STYLE}
>
{data}
</Text> */}
<circle r={40} cx={-25} fill="transparent"/>
<LogoSVG fill={theme.palette.text.primary} transform={transform}/>
</>
)
}
type ParentProps = CommonProps & {
isExpanded: boolean
isFocused?: boolean
}
const ParentNode = (props: ParentProps) => {
const { data, isExpanded, isFocused } = props
const shapeWidth = 8
const theme = useTheme()
const [hover, setHover] = React.useState(false)
return (
<>
<circle
r={shapeWidth / 2}
fill={isExpanded ? theme.palette.background.default : theme.treeColors.parentFill}
stroke={theme.treeColors.parentStroke}
/>
<text
textAnchor="end"
x={-shapeWidth}
y={TEXT_CENTER}
fill={
hover
? theme.palette.primary.light
: theme.palette.text.primary
}
style={TEXT_STYLE}
onMouseOver={() => setHover(true)}
onMouseOut={() => setHover(false)}
>
{data}
</text>
</>
)
}
type LeafProps = CommonProps & {}
const LeafNode = (props: LeafProps) => {
const { data } = props
const theme = useTheme()
return (
<text
textAnchor="start"
x={2}
y={TEXT_CENTER}
fill={theme.palette.text.primary}
style={TEXT_STYLE}
>
{data}
</text>
)
}
export default function Node(props: NodeProps) {
const { node } = props
const isRoot = node.depth === 0
const isParent = node.data.children && node.data.children.length > 0
const textToShow = `${
hasPositions(node.data.attributes.positions) ? "⭐" : ""
}${node.data.name} '${node.data.attributes.year.substring(2)}`
if (isRoot) {
return <RootNode data={textToShow} />
} else if (isParent) {
return <ParentNode data={textToShow} isExpanded={isExpanded(node)} />
} else {
return <LeafNode data={textToShow} />
}
}