@@ -18,92 +18,101 @@ Description:
18
18
</template >
19
19
20
20
<script >
21
- import { tree } from ' vued3tree'
22
- import { mapState } from ' vuex'
21
+ import { tree } from " vued3tree" ;
22
+ import { mapState } from " vuex" ;
23
23
export default {
24
- name: ' Tree' ,
24
+ name: " Tree" ,
25
25
components: {
26
- tree
26
+ tree,
27
27
},
28
28
computed: {
29
- ... mapState ([' componentMap' ]),
29
+ ... mapState ([" componentMap" , " activeComponent " ]),
30
30
// Returns project tree on re-render
31
- computedTree () {
31
+ computedTree () {
32
32
// console.log('buildtree', this.buildTree())
33
- return this .buildTree ()
34
- }
33
+ return this .buildTree ();
34
+ },
35
35
},
36
- data () {
36
+ data () {
37
37
return {
38
- tree: null
39
- }
38
+ tree: null ,
39
+ };
40
40
},
41
41
methods: {
42
42
// Called by transformToTree, formats componentMap
43
- formatComponentMap (compMap ) {
43
+ formatComponentMap (compMap ) {
44
44
// console.log('compMap', compMap)
45
- let result = []
46
- Object .values (compMap).forEach (compData => {
45
+ let result = [];
46
+ Object .values (compMap).forEach (( compData ) => {
47
47
result .push ({
48
48
name: compData .componentName ,
49
- children: compData .children
50
- })
51
- })
49
+ children: compData .children ,
50
+ });
51
+ });
52
+ console .log (JSON .stringify (result))
52
53
// console.log('Formatcomponent map result', result)
53
- return result
54
+ return result;
54
55
},
55
56
// Called by buildTree, transforms componentMap
56
- transformToTree (data ) {
57
- let result = {}
58
- const nodes = {}
59
- const formattedData = this .formatComponentMap (data)
57
+ transformToTree (data ) {
58
+ let result = {};
59
+ const nodes = {};
60
+ const formattedData = this .formatComponentMap (data);
60
61
61
- formattedData .forEach (component => {
62
+ formattedData .forEach (( component ) => {
62
63
if (! nodes[component .name ]) {
63
- nodes[component .name ] = { name: component .name , children: [] }
64
- result = nodes
64
+ nodes[component .name ] = { name: component .name , children: [] };
65
+ result = nodes;
65
66
}
66
- component .children .forEach (child => {
67
- nodes[child] = { name: child, children: [] }
68
- nodes[component .name ].children .push (nodes[child])
69
- })
70
- })
71
- return result
67
+ component .children .forEach ((child ) => {
68
+ if (! nodes[child]) nodes[child] = { name: child, children: [] };
69
+ nodes[component .name ].children .push (nodes[child]);
70
+ });
71
+ });
72
+ console .log (nodes)
73
+ console .log (result)
74
+ return result;
72
75
},
73
76
// Called by computedTree, calls transformToTree
74
- buildTree () {
75
- let build = this .transformToTree (this .componentMap )
76
- return build[' App' ]
77
+ buildTree () {
78
+ let build = this .transformToTree (this .componentMap );
79
+ return build[" App" ];
80
+ },
81
+ },
82
+ watch: {
83
+ componentMap: {
84
+ deep: true ,
85
+ handler (){
86
+ this .buildTree ()
87
+ }
77
88
}
78
89
}
79
- }
90
+ };
80
91
</script >
81
92
82
93
<style lang="stylus">
83
- .container {
84
- height : 100% ;
85
- width : 100% ;
86
- }
94
+ .container
95
+ height 100%
96
+ width 100%
87
97
88
- .treeclass .nodetree text {
89
- font-size : 19px !important ;
90
- cursor : pointer ;
91
- text-shadow : none !important ;
92
- font-weight : bold ;
93
- fill : #F F F ;
98
+ .treeclass .nodetree text
99
+ font-size 19px !important
100
+ cursor pointer
101
+ text-shadow none !important
102
+ font-weight bold
103
+ fill #F F F
94
104
/* none of these classes work
95
105
color: white !important;
96
106
background: white;
97
107
margin: 1rem; */
98
- }
99
- /* changes the circle node color */
100
- .treeclass .nodetree circle {
101
- fill : #A2 D9 FF ;
102
- }
108
+
109
+ /* changes the circle node color */
110
+ .treeclass .nodetree circle
111
+ fill #A2 D9 FF
112
+
103
113
/* changes the stroke color */
104
- .treeclass .linktree {
105
- stroke : $secondary !important ;
106
- stroke-opacity : 0.4 ;
107
- stroke-width : 8px ;
108
- }
114
+ .treeclass .linktree
115
+ stroke $secondary !important
116
+ stroke-opacity .4
117
+ stroke-width 8px
109
118
</style >
0 commit comments