-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
200 lines (194 loc) · 8.32 KB
/
index.html
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title> sheauren's learning path</title>
<link rel="stylesheet" href="https://unpkg.com/antd@4.23.5/dist/antd.compact.min.css" />
<link rel="stylesheet" href="style.css" />
<script src="https://unpkg.com/react@18.2.0/umd/react.development.js"></script>
<script src="https://unpkg.com/react-dom@18.2.0/umd/react-dom.production.min.js"></script>
<script src="https://unpkg.com/@babel/standalone/babel.min.js"></script>
<script src="https://unpkg.com/axios@1.1.2/dist/axios.min.js"></script>
<script src="https://unpkg.com/screen-size-detector@1.0.4/dist/screen-size-detector.min.js"></script>
<script src="https://unpkg.com/antd@4.23.5/dist/antd.min.js"></script>
<script src="https://unpkg.com/@antv/g6@4.7.6/dist/g6.min.js"></script>
</head>
<body>
<div id="container"></div>
<script type="text/babel">
const screen = new ScreenSizeDetector();
console.log('screen',screen)
let graph = null
function showMindmap(data) {
if (!graph) {
let graphWidth = (screen.width-200)
let graphHeight=(screen.height-80)
//console.log('graphWidth',graphWidth,'graphHeight',graphHeight)
graph = new G6.TreeGraph({
container: 'mindmap',
width: graphWidth,
height: graphHeight,
fitCenter: true,
fitView: true,
modes: {
default: [
{
type: 'collapse-expand',
onChange: function onChange(item, collapsed) {
const data = item.etModel()
data.collapsed = collapsed
return true
}
},
'drag-canvas',
'zoom-canvas'
]
},
defaultNode: {
size: 26,
anchorPoints: [
[0, 0.5],
[1, 0.5]
]
},
defaultEdge: {
type: 'cubic-horizontal',
style: {
lineWidth: 5,
startArrow: true,
stroke: 'lightblue'
}
},
layout: {
type: 'compactBox',
direction: 'LR',
getId: function getId(d) {
return d.id
},
getHeight: function getHeiht() {
return 16
},
getWidth: function getWidth() {
return 16
},
getVGap: function getVGap() {
return 10
},
getHGap: function getHGap() {
return 100
}
}
})
graph.node(function (node) {
return {
label: node.title,
labelCfg: {
offset: 10,
position: 'right'
},
style: {
fill: node['background-color']
}
}
})
graph.data(data)
graph.render()
}
else {
graph.changeData(data)
}
}
function createMenus(menus, parent) {
function selectItem(key, item) {
if (item.node.data == null) {
// folder
//item.node.expanded=!item.node.expanded
return
}
parent.setNavList(item.node.nav)
let url = item.node.data
axios.get(url).then(res => {
showMindmap(res.data)
})
}
let expandedKeys=[]
for(let i=1;i<10;i++){
expandedKeys.push(`root-${i}`)
}
return (
<antd.Tree.DirectoryTree
showLine='true'
defaultExpandedKeys={expandedKeys}
treeData={menus}
onSelect={selectItem}/>
)
}
class Application extends React.Component {
constructor(props) {
super(props)
self.menus = props.menus
this.state = {
navList: ['/ overview'],
isOverview:true
}
}
overview(){
console.log('overview')
this.setNavList(['overview'],true)
}
setNavList(newNavList,isOverview =false) {
newNavList[0]='/ '+newNavList[0]
this.setState({ navList: newNavList,isOverview:isOverview })
}
render() {
return (
<antd.Layout id='app'>
<antd.Layout.Header id='header' className='header'>
<div style={{ 'float': 'left', 'color': 'white', 'fontSize': '14px', 'paddingLeft': '10px', 'color': '#f5f5dc' }}>
sheauren's learning path
</div>
</antd.Layout.Header>
<antd.Layout.Content id='main-content' className='main-content' style={{ 'height': screen.height - 60 }}>
<antd.Layout id='sub-content' className='sub-content'>
<antd.Layout.Sider id='sider' className='sider' width='200' collapseWith='200'>
<div style={{'textAlign':'center'}}>
<antd.Button onClick={()=>this.overview()} size='small' className='overview'>Overview</antd.Button>
</div>
{createMenus(menus, this)}
</antd.Layout.Sider>
</antd.Layout>
<antd.Layout.Content id='detail-content' className='detail-content'>
<antd.Breadcrumb id='navigator' style={{ 'margin': '0px 20px' }}>
{
this.state.navList.map(m => {
return (
<antd.Breadcrumb.Item key={m}>{m}</antd.Breadcrumb.Item>
)
})
}
</antd.Breadcrumb>
<div style={{'display':!this.state.isOverview?'block':'none'}} id='mindmap' className='show-region'>
</div>
<div style={{'display':this.state.isOverview?'block':'none'}} id='overview' className='show-region'>
</div>
</antd.Layout.Content>
</antd.Layout.Content>
<antd.Layout.Footer id='footer' className='footer' style={{ "textAlign": "center" }}>
sheauren's learning path @2022 Created by sheauren
</antd.Layout.Footer>
</antd.Layout>
)
}
}
function render(menus){
ReactDOM.render((
<Application menus={menus} />
),document.getElementById('container'))
}
axios.get("menu.json").then(res => {
console.log('menu',res.data)
render(res.data)
})
</script>
</body>
</html>