@@ -6,7 +6,7 @@ Description:
66
77<template >
88 <div class =" container" >
9- <!-- < tree
9+ <tree
1010 :key =" computedTree"
1111 :data =" computedTree"
1212 node-text =" name"
@@ -15,17 +15,8 @@ Description:
1515 :zoomable =" true"
1616 :radius =" 4"
1717 :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"
2818 ></tree >
19+ <!-- <tree v-bind:data="tree" ></tree> -->
2920 </div >
3021</template >
3122
@@ -38,75 +29,69 @@ export default {
3829 tree
3930 },
4031 computed: {
41- // ...mapState(['componentMap', 'activeComponent']),
32+ ... mapState ([' componentMap' , ' activeComponent' ]),
4233 // Returns project tree on re-render
4334 computedTree () {
44- return 1 ;
45- // return this.buildTree()
35+ // console.log('buildtree', this.buildTree())
36+ return this .buildTree ()
4637 }
4738 },
4839 data () {
4940 return {
5041 tree: null ,
5142 treeKey: ' key' ,
52- testTree: {
53- name: ' father' ,
54- children: [{
55- name: ' son1'
56- }]
57- }
5843 }
5944 },
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+ }
10691}
10792 </script >
10893
109- <style lang="scss" scoped >
94+ <style lang="scss">
11095.container {
11196 height : 100% ;
11297 width : 100% ;
@@ -119,18 +104,22 @@ export default {
119104 font-weight : bold ;
120105 fill : #FFF ;
121106 transform : rotate (-90deg );
107+ /* none of these classes work
108+ color: white !important;
109+ background: white;
110+ margin: 1rem; */
122111}
123112
124-
125113/* changes the circle node color */
126114.treeclass .nodetree circle {
127- fill : #A2D9FF ;
115+ fill : #A2D9FF ;
128116}
129-
117+
130118/* changes the stroke color */
131119.treeclass .linktree {
132120 stroke : $secondary !important ;
133121 stroke-opacity : .4 ;
134122 stroke-width : 8px ;
135123}
124+
136125 </style >
0 commit comments