tom
2023-12-06 9e968679ed2e6937aeb7b50a6c450d5d19251f42
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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8"><meta http-equiv="Expires" content="0"><meta http-equiv="Pragma" content="no-cache"><meta http-equiv="Cache-control" content="no-cache"><meta http-equiv="Cache" content="no-cache">
        <script src="node_data.js"></script>
        <script src="../js/vue/vue.js"></script>
        <script src="../js/vue/axios/dist/axios.min.js"></script>
        <script src="https://gw.alipayobjects.com/os/lib/antv/g6/4.3.2/dist/g6.min.js"></script>
        <!-- <script src="https://gw.alipayobjects.com/os/antv/pkg/_antv.g6-3.1.1/build/minimap.js"></script> -->
        <!-- <script src="https://gw.alipayobjects.com/os/antv/pkg/_antv.g6-3.1.1/build/g6.js"></script> -->
        <script src="echarts.js"></script>
        <script src="../js/vue/elementDefault.js"></script>
        <script src="../js/vue/element-ui/element-ui_15/index.js"></script>
        <!-- <script src="https://cdn.jsdelivr.net/npm/insert-css@2.0.0/index.min.js"></script> -->
        
        <link href="../js/vue/element-ui/element-ui_15/theme-chalk/index.css" rel="stylesheet">
        <title>Indented-Card</title>
    </head>
    <body>
        <div id="vbody">
            <div id="page_root">
                <div class="topbar">
                    <span>{{title}}</span>
                </div>
                
                <!-- G6容器 -->
                <div id="container"></div>
                
                <!-- dialog -->
                <el-dialog
                  title=""
                  :visible.sync="dialogVisible"
                  width="70%"
                  height="500px">
                  
                    <iframe ref="chart_iframe" style="height: 100%; width: 100%;" frameborder="0" :src="chart_iframe"></iframe>
                  
                    <span slot="footer" class="dialog-footer">
                        <el-button @click="dialogVisible = false">取 消</el-button>
                    </span>
                </el-dialog>
            </div>
        </div>
        
        <style>
            .dialog-page {
                position: absolute;
                width: 1000px;
                height: 600px;
                background-color: #fbffef;
                border-radius: 1%;
                bottom: 50px;
                left: 200px;
            }
            
            .el-dialog__body {
                height: 350px;
            }
            
            /* .g6-minimap {
                position: absolute;
                right: 0px;
                top: 0px;
                background-color: #fff;
            } */
        </style>
        
        <script type="text/javascript">
            // insertCss(`
            //     .g6-minimap-container {
            //         border: 1px solid #e2e2e2;
            //         position: absolute;
            //         right: 0px;
            //         top: 0px;
            //     }
            //     .g6-minimap-viewport {
            //         border: 2px solid rgb(25, 128, 255);
            //     }
            // `);
            new Vue({
                el: "#vbody",
                data: {
                    dataname: "",
                    title: "POC",
                    dialogVisible: false,
                    chart_iframe: "./chart_iframe.html"
                },
                created() {},
                
                mounted() {
                    //获取数据
                    this.initData();
                },
                
                methods:{
                    initData() {
                        var me = this;
                        
                        this.initG6()
                    },
                    
                    openInfoWindow(obj) {
                        this.dialogVisible = true;
                    },
                    
                    closeInfoWindow() {
                        this.dialogVisible = false;
                        this.containerG6 = true;
                    },
                    
                    initG6() {
                        var me = this;
                        
                        var nodeBasicMethod = {
                            afterDraw(cfg, group) {
                                var picBox = group.findByClassName("pic-icon");
                                
                                picBox.on("click", function (obj) {
                                    me.openInfoWindow(obj);
                                });
                            },
                        };
                        
                        G6.registerNode("card-node", {
                            draw: function drawShape(cfg, group) {
                                const r = 2;
                                const color = "#5B8FF9";
                                const w = cfg.size[0];
                                const h = cfg.size[1];
                                const shape = group.addShape("rect", {
                                    attrs: {
                                        x: -w / 2,
                                        y: -h / 2,
                                        width: w, //240,
                                        height: h, // 160
                                        stroke: "gold",
                                        radius: r,
                                        fill:
                                            cfg.absent == "1"
                                            ? "Crimson"
                                            : cfg.absent == "2"
                                            ? "DarkOrange"
                                            : color,
                                    },
                                    className: "main-box",
                                    draggable: true,
                                });
                    
                                group.addShape("rect", {
                                    attrs: {
                                        x: -w / 2,
                                        y: -h / 2,
                                        width: w / 3, //80
                                        height: h, // 160
                                        // fill: color,
                                        // opacity: 0,
                                        radius: [r, r, 0, 0],
                                    },
                                    name: "profile-box",
                                    draggable: true,
                                });
                        
                                group.addShape("rect", {
                                    attrs: {
                                        x: -w / 2,
                                        y: -h / 2,
                                        width: 80,
                                        height: 100,
                                        // fill: color,
                                        cursor: "pointer",
                                        // opacity: 1,
                                    },
                                    tooltip: "pic",
                                });
                        
                                group.addShape("image", {
                                    attrs: {
                                        x: -w / 2,
                                        y: -h / 2 + 15,
                                        height: 95,
                                        width: 95,
                                        img: "pic.png",
                                        cursor: "pointer",
                                        opacity: 1,
                                    },
                                    className: "pic-icon",
                                });
                        
                                // name text
                                group.addShape("text", {
                                    attrs: {
                                        textBaseline: "top",
                                        x: -w / 2 + 27,
                                        y: -h / 2 + 120,
                                        lineHeight: 20,
                                        fontSize: 14,
                                        fontWeight: "600",
                                        text: cfg.name,
                                        fill: "#fff",
                                    },
                                    name: "name",
                                });
                        
                                group.addShape("rect", {
                                    attrs: {
                                        x: -w / 2 + 80,
                                        y: -h / 2,
                                        width: 160, 
                                        height: 40,
                                        // fill: color,
                                        radius: [r, r, 0, 0],
                                    },
                                    name: "1-box",
                                    draggable: true,
                                  });
                        
                                group.addShape("text", {
                                    attrs: {
                                        textBaseline: "top",
                                        x: -w / 2 + 100,
                                        y: -h / 2 + 18,
                                        lineHeight: 20,
                                        text: cfg.id,
                                        fill: "#fff",
                                    },
                                    name: "grade",
                                });
                        
                                group.addShape("rect", {
                                    attrs: {
                                        x: -w / 2 + 80,
                                        y: -h / 2 + 40,
                                        width: 160,
                                        height: 40,
                                        // fill: color,
                                        radius: [r, r, 0, 0],
                                    },
                                    name: "2-box",
                                    draggable: true,
                                });
                        
                                group.addShape("text", {
                                    attrs: {
                                        textBaseline: "top",
                                        x: -w / 2 + 100,
                                        y: -h / 2 + 58,
                                        lineHeight: 20,
                                        text: "XXXXXXXXXXXX",
                                        fill: "#fff",
                                    },
                                    name: "X",
                                });
                        
                                group.addShape("rect", {
                                    attrs: {
                                        x: -w / 2 + 80,//-40
                                        y: -h / 2 + 80,//0
                                        width: 160,
                                        height: 40,
                                        // fill: color,
                                        radius: [r, r, 0, 0],
                                    },
                                    name: "3-box",
                                    draggable: true,
                                });
                        
                                group.addShape("text", {
                                    attrs: {
                                        textBaseline: "top",
                                        x: -w / 2 + 100,//-20
                                        y: -h / 2 + 98,//-18
                                        lineHeight: 20,
                                        text: "YYYYYYYYYYYY",
                                        fill: "#fff",
                                    },
                                    name: "Y",
                                });
                        
                                group.addShape("rect", {
                                    attrs: {
                                        x: -w / 2 + 80,//-40
                                        y: -h / 2 + 120,//-40
                                        width: 160, 
                                        height: 40, 
                                        // fill: color,
                                        radius: [r, r, 0, 0],
                                    },
                                    name: "4-box",
                                    draggable: true,
                                });
                        
                                group.addShape("text", {
                                    attrs: {
                                        textBaseline: "top",
                                        x: -w / 2 + 100,//-20
                                        y: -h / 2 + 138,//58
                                        lineHeight: 20,
                                        text: "ZZZZZZZZZZZZ",
                                        fill: "#fff",
                                    },
                                    name: "Z",
                                });
                        
                                  // group.addShape("img", {
                                  //   attrs: {
                                  //     x: -w / 2,
                                  //     y: -h / 2,
                                  //     width: w / 3, //200,
                                  //     height: h, // 60
                                  //     fill: color,
                                  //     radius: [r, r, 0, 0],
                                  //   },
                                  //   name: "title-box",
                                  //   draggable: true,
                                  // });
                        
                                cfg.children &&
                                group.addShape("marker", {
                                    attrs: {
                                        x: w / 2,
                                        y: 0,
                                        r: 6,
                                        cursor: "pointer",
                                        symbol: G6.Marker.collapse,
                                        stroke: "#666",
                                        lineWidth: 1,
                                        fill: "#fff",
                                    },
                                    name: "collapse-icon",
                                });
                    
                              // group.addShape("text", {
                              //   attrs: {
                              //     textBaseline: "top",
                              //     x: -w / 2 + 100,
                              //     y: -h / 2 + 40,
                              //     lineHeight: 20,
                              //     text: "data",
                              //     fill: "rgba(0,0,0, 1)",
                              //   },
                              //   name: `data`,
                              // });
                    
                                return shape;
                            },
                    
                            afterDraw: nodeBasicMethod.afterDraw,
                    
                            setState(name, value, item) {
                                if (name === "collapsed") {
                                    const marker = item
                                    .get("group")
                                    .find((ele) => ele.get("name") === "collapse-icon");
                                    const icon = value ? G6.Marker.expand : G6.Marker.collapse;
                                    marker.attr("symbol", icon);
                                }
                            },
                        });
                        
                        const data = nodeData;
                        
                        const container = document.getElementById("container");
                        const width = container.scrollWidth;
                        const height = container.scrollHeight || 700;
                        // console.log(container.scrollHeight);
                        // console.log(container.clientHeight);
                        // console.log(document.body.scrollHeight);
                        // console.log(document.documentElement.scrollHeight);
                        // console.log(document.body.scrollHeight);
                        console.log(container.scrollWidth);
                        
                        // 实例化 minimap 插件
                        // const minimap = new G6.Minimap({
                        //     size: [100, 100],
                        //     className: 'minimap',
                        //     type: 'default',
                        // });
                        
                        const graph = new G6.TreeGraph({
                            container: "container",
                            width,
                            height,
                            modes: {
                                default: ["drag-canvas", "zoom-canvas"],
                            },
                            defaultNode: {
                                type: "card-node",
                                size: [240, 160],
                            },
                            defaultEdge: {
                                type: "cubic-horizontal",
                                style: {
                                    endArrow: true,
                                },
                            },
                            // 将 minimap 实例配置到图上
                            // plugins: [minimap], 
                            layout: {
                                type: "indented",
                                direction: "LR",
                                dropCap: false,
                                indent: 350,
                                getHeight: () => {
                                    return 150;
                                },
                            },
                        });
                        
                        G6.Util.traverseTree(data, function (item) {
                            if (item.isLast) {
                                item.collapsed = true;
                            }
                        });
                    
                        graph.data(data);
                        // graph.addChild(data, '小区11');
                        graph.render();
                        graph.zoom(0.8);
                        graph.moveTo(180, 50, true, {
                            duration: 100,
                        });
                        // graph.fitView();
                        graph.on("node:click", (e) => {
                            if (e.target.get("name") === "collapse-icon") {
                                e.item.getModel().collapsed = !e.item.getModel().collapsed;
                                graph.setItemState(e.item, "collapsed", e.item.getModel().collapsed);
                                graph.layout();
                            }
                        });
                        
                        if (typeof window !== "undefined"){
                            window.onresize = () => {
                                if (!graph || graph.get("destroyed")) return;
                                if (!container || !container.scrollWidth || !container.scrollHeight)
                                    return;
                                graph.changeSize(container.scrollWidth, container.scrollHeight);
                            };
                        }
                    }
                }    
            });
        </script>
    </body>
</html>