@@ -6,7 +6,7 @@ Description:
6
6
7
7
<template >
8
8
<div class =" container" >
9
- <!-- < tree
9
+ <tree
10
10
:key =" computedTree"
11
11
:data =" computedTree"
12
12
node-text =" name"
@@ -15,17 +15,8 @@ Description:
15
15
:zoomable =" true"
16
16
:radius =" 4"
17
17
:duration =" 10"
18
- ></tree> -->
19
- <tree
20
- :key =" testTree"
21
- :data =" testTree"
22
- node-text =" name"
23
- layoutType =" vertical"
24
- type =" tree"
25
- :zoomable =" true"
26
- :radius =" 4"
27
- :duration =" 10"
28
18
></tree >
19
+ <!-- <tree v-bind:data="tree" ></tree> -->
29
20
</div >
30
21
</template >
31
22
@@ -38,75 +29,69 @@ export default {
38
29
tree
39
30
},
40
31
computed: {
41
- // ...mapState(['componentMap', 'activeComponent']),
32
+ ... mapState ([' componentMap' , ' activeComponent' ]),
42
33
// Returns project tree on re-render
43
34
computedTree () {
44
- return 1 ;
45
- // return this.buildTree()
35
+ // console.log('buildtree', this.buildTree())
36
+ return this .buildTree ()
46
37
}
47
38
},
48
39
data () {
49
40
return {
50
41
tree: null ,
51
42
treeKey: ' key' ,
52
- testTree: {
53
- name: ' father' ,
54
- children: [{
55
- name: ' son1'
56
- }]
57
- }
58
43
}
59
44
},
60
- // methods: {
61
- // // Called by transformToTree, formats componentMap
62
- // formatComponentMap (compMap) {
63
- // let result = []
64
- // Object.values(compMap).forEach((compData) => {
65
- // result.push({
66
- // name: compData.componentName,
67
- // children: compData.children
68
- // })
69
- // });
70
- // // ***** Infinite loop
71
- // // result = [{ name: 'App', children: [] }, { name: 'HomeView', children: [] }]
72
- // return result
73
- // },
74
- // // Called by buildTree, transforms componentMap
75
- // transformToTree (data) {
76
- // let result = {}
77
- // const nodes = {}
78
- // const formattedData = this.formatComponentMap(data)
79
-
80
- // formattedData.forEach(( component) => {
81
- // if (!nodes[component.name]) {
82
- // nodes[component.name] = { name: component.name, children: [] }
83
- // result = nodes
84
- // }
85
- // component.children.forEach(( child) => {
86
- // if (!nodes[child]) nodes[child] = { name: child, children: [] }
87
- // nodes[component.name].children.push(nodes[child] )
88
- // } )
89
- // } )
90
- // return result
91
- // },
92
- // // Called by computedTree, calls transformToTree
93
- // buildTree () {
94
- // let build = this.transformToTree(this.componentMap);
95
- // return build['App']
96
- // }
97
- // },
98
- // watch: {
99
- // componentMap: {
100
- // deep: true,
101
- // handler () {
102
- // this.buildTree()
103
- // }
104
- // }
105
- // }
45
+ methods: {
46
+ // Called by transformToTree, formats componentMap
47
+ formatComponentMap (compMap ) {
48
+ let result = []
49
+ Object .values (compMap).forEach ((compData ) => {
50
+ result .push ({
51
+ name: compData .componentName ,
52
+ children: compData .children
53
+ })
54
+ })
55
+
56
+ return result
57
+ },
58
+ // Called by buildTree, transforms componentMap
59
+ transformToTree ( data ) {
60
+ let result = {}
61
+ const nodes = {}
62
+ const formattedData = this . formatComponentMap (data)
63
+ formattedData . forEach (( component ) => {
64
+ if ( ! nodes[ component . name ]) {
65
+ nodes[ component . name ] = { name : component . name , children : [] }
66
+ result = nodes
67
+ }
68
+ component . children . forEach (( child ) => {
69
+ if ( ! nodes[child]) nodes[child] = { name : child, children : [] }
70
+ nodes[ component .name ]. children .push (nodes[ child])
71
+ })
72
+ } )
73
+ // console.log(nodes )
74
+ // console.log(result )
75
+ return result
76
+ },
77
+ // Called by computedTree, calls transformToTree
78
+ buildTree () {
79
+ let build = this .transformToTree (this .componentMap )
80
+ return build[' App' ]
81
+ }
82
+ },
83
+ watch: {
84
+ componentMap: {
85
+ deep: true ,
86
+ handler () {
87
+ this .buildTree ()
88
+ }
89
+ }
90
+ }
106
91
}
107
92
</script >
108
93
109
- <style lang="scss" scoped >
94
+ <style lang="scss">
110
95
.container {
111
96
height : 100% ;
112
97
width : 100% ;
@@ -119,18 +104,22 @@ export default {
119
104
font-weight : bold ;
120
105
fill : #FFF ;
121
106
transform : rotate (-90deg );
107
+ /* none of these classes work
108
+ color: white !important;
109
+ background: white;
110
+ margin: 1rem; */
122
111
}
123
112
124
-
125
113
/* changes the circle node color */
126
114
.treeclass .nodetree circle {
127
- fill : #A2D9FF ;
115
+ fill : #A2D9FF ;
128
116
}
129
-
117
+
130
118
/* changes the stroke color */
131
119
.treeclass .linktree {
132
120
stroke : $secondary !important ;
133
121
stroke-opacity : .4 ;
134
122
stroke-width : 8px ;
135
123
}
124
+
136
125
</style >
0 commit comments