@@ -12,7 +12,7 @@ let TreeChart = React.createClass({
12
12
componentWillMount ( ) {
13
13
this . setState ( {
14
14
path : this . props . path ,
15
- focus : false ,
15
+ focus : this . props . path ,
16
16
element : { // start with empty element designed to show loading
17
17
elements : { }
18
18
}
@@ -61,20 +61,14 @@ let TreeChart = React.createClass({
61
61
self . addElement ( 0 ) ;
62
62
}
63
63
} ) ;
64
- this . refs . children . addEventListener ( 'tap' , function ( event ) {
65
- event . stopPropagation ( ) ;
66
- if ( event . dataPath ) {
67
- self . setState ( { focus : event . dataPath } ) ;
68
- }
69
- } ) ;
70
64
// stop propagation between layers
71
65
this . refs . root . addEventListener ( 'dropped' , function ( event ) {
72
66
event . stopPropagation ( ) ;
73
67
} ) ;
74
68
} ,
75
69
addElement ( index ) {
76
70
this . firebaseRefs . element . child ( 'elements' ) . push ( {
77
- title : "" ,
71
+ title : "New Element " ,
78
72
index : index ,
79
73
importance : 1 ,
80
74
elements : [ ]
@@ -114,7 +108,10 @@ let TreeChart = React.createClass({
114
108
firebase . database ( ) . ref ( this . props . path + '/elements/' + key ) . remove ( ) ;
115
109
} ,
116
110
focus ( path ) {
117
- this . setState ( { focus : path } ) ;
111
+ if ( path ) {
112
+ this . setState ( { focus : path } ) ;
113
+ }
114
+ return this . state . focus ;
118
115
} ,
119
116
render ( ) {
120
117
let self = this ;
@@ -132,7 +129,7 @@ let TreeChart = React.createClass({
132
129
133
130
let childElements = [ ] ;
134
131
135
- let focusedChild = self . state . focus ;
132
+ let focusedChild = self . props . focus ? self . props . focus ( ) : self . focus ( ) ;
136
133
137
134
rows . forEach ( ( row , index ) => {
138
135
childElements . push (
@@ -145,11 +142,10 @@ let TreeChart = React.createClass({
145
142
self . removeChild ( column . key ) ;
146
143
}
147
144
let path = self . props . path + '/elements/' + column . key ;
148
- let visible = focusedChild === false
149
- || focusedChild === path
150
- || focusedChild === self . props . path ; // focusing on self
145
+ let visible = focusedChild === self . props . path || focusedChild . indexOf ( path ) === 0 ; // this one parent of focused child
146
+
151
147
let height = row . height ;
152
- if ( focusedChild === path ) {
148
+ if ( focusedChild && focusedChild . indexOf ( path ) === 0 ) {
153
149
height = '100%' ;
154
150
}
155
151
@@ -159,7 +155,8 @@ let TreeChart = React.createClass({
159
155
key = { column . key }
160
156
visible = { visible }
161
157
height = { height }
162
- focused = { focusedChild === path }
158
+ focus = { self . props . focus || self . focus } // pass back focus
159
+ focused = { focusedChild && focusedChild . indexOf ( path ) === 0 }
163
160
move = { self . moveChild }
164
161
remove = { remove } /> ) ;
165
162
} ) ;
0 commit comments