@@ -11,40 +11,24 @@ class Rectangle extends Component {
11
11
return color ;
12
12
}
13
13
14
- getGrandchildRatio ( grandchild ) {
15
- // const childInstance = pseudoChildComp.childrenArray.find()
16
- const pseudoParent = this . props . components . find (
17
- comp => comp . title === this . props . childComponentName ,
18
- ) ;
19
- const childInstance = pseudoParent . childrenArray . find (
20
- child => child . childId === grandchild . childId ,
21
- ) ;
22
- // console.log(
23
- // this.props.childId,
24
- // this.props.componentId,
25
- // this.props.childComponentName,
26
- // this.props.childComponentId,
27
- // );
28
- console . log ( grandchild , pseudoParent , childInstance ) ;
29
- // console.log(childInstance.position.width / pseudoParent.position.width);
30
- // console.log(childInstance.position.height / pseudoParent.position.height);
14
+ getPseudoChild ( grandchild ) {
15
+ // example: Board with direct child Row (where Row has a child Box)
16
+ // grandchild is a reference to the Box child of Row
17
+ // pseudoParent is a reference to Row itself (whose size is determined by its pseudoChild)
18
+ // directParent refers to the instance of Row
19
+ return this . props . components . find ( comp => comp . id === this . props . childComponentId ) ;
31
20
32
- console . log ( childInstance . position . x , pseudoParent . position . x ) ;
33
- console . log ( childInstance . position . y , pseudoParent . position . y ) ;
34
- const ratioObj = {
35
- // x:
36
- // grandchild.position.x
37
- // - (pseudoParent.position.x * childInstance.position.width) / pseudoParent.position.width,
38
- // y:
39
- // grandchild.position.y
40
- // - (pseudoParent.position.y * childInstance.position.height) / pseudoParent.position.height,
41
- x : childInstance . position . x - pseudoParent . position . x ,
42
- y : childInstance . position . y - pseudoParent . position . y ,
43
- width : childInstance . position . width / pseudoParent . position . width ,
44
- height : childInstance . position . height / pseudoParent . position . height ,
45
- } ;
46
- // console.log('ratioObj', ratioObj);
47
- return ratioObj ;
21
+ // const ratioObj = {
22
+ // x:
23
+ // ((grandchild.position.x - pseudoParent.position.x) * directParent.position.width)
24
+ // / pseudoParent.position.width,
25
+ // y:
26
+ // ((grandchild.position.y - pseudoParent.position.y) * directParent.position.height)
27
+ // / pseudoParent.position.height,
28
+ // width: grandchild.position.width / pseudoParent.position.width,
29
+ // height: grandchild.position.height / pseudoParent.position.height,
30
+ // };
31
+ // return ratioObj;
48
32
}
49
33
50
34
handleResize ( componentId , childId , target ) {
@@ -104,6 +88,7 @@ class Rectangle extends Component {
104
88
onDragEnd = { event => this . handleDrag ( componentId , childId , event . target ) }
105
89
>
106
90
< Rect
91
+ // a Konva Rect is generated for each child of the focusComponent (including the pseudochild, representing the focusComponent itself)
107
92
name = { `${ childId } ` }
108
93
className = { 'childRect' }
109
94
x = { 0 }
@@ -137,44 +122,51 @@ class Rectangle extends Component {
137
122
y = { childId === '-1' ? - 15 : 5 }
138
123
/>
139
124
</ Label >
140
- { focusChild
141
- && focusChild . childId === childId
142
- && draggable && (
143
- < TransformerComponent
144
- focusChild = { focusChild }
145
- rectClass = { 'childRect' }
146
- anchorSize = { 8 }
147
- color = { 'grey' }
148
- />
149
- ) }
150
- { childId !== '-1'
125
+ { // for all children other than the pseudoChild, find their component's children array and recursively render the children found there
126
+ childId !== '-1'
151
127
&& components
152
128
. find ( comp => comp . title === childComponentName )
153
129
. childrenArray . filter ( child => child . childId !== '-1' )
130
+ // .sort((a, b) => parseInt(a.childId) - parseInt(b.childId)) // using i within map below, sorting by childId might be necessary
154
131
. map ( ( grandchild , i ) => (
155
132
< GrandchildRectangle
156
133
key = { i }
157
134
components = { components }
158
135
componentId = { componentId }
136
+ directParentName = { childComponentName }
159
137
childComponentName = { grandchild . componentName }
160
138
childComponentId = { grandchild . childComponentId }
161
139
focusChild = { focusChild }
162
140
childId = { childId } // scary addition, grandchildren rects default to childId of "direct" children
163
- // x={grandchild.position.x * (width / window.innerWidth)}
164
- // y={grandchild.position.y * (height / window.innerHeight)}
141
+ // x={this.getPseudoChild().position.x}
142
+ // y={}
143
+ width = { grandchild . position . width * ( width / this . getPseudoChild ( ) . position . width ) }
144
+ height = {
145
+ grandchild . position . height * ( height / this . getPseudoChild ( ) . position . height )
146
+ }
147
+ x = {
148
+ ( grandchild . position . x - this . getPseudoChild ( ) . position . x )
149
+ * ( width / this . getPseudoChild ( ) . position . width )
150
+ }
151
+ y = {
152
+ ( grandchild . position . y - this . getPseudoChild ( ) . position . y )
153
+ * ( height / this . getPseudoChild ( ) . position . height )
154
+ }
165
155
// width={grandchild.position.width * (width / window.innerWidth)}
166
156
// height={grandchild.position.height * (height / window.innerHeight)}
167
- x = { this . getGrandchildRatio ( grandchild ) . x }
168
- y = { this . getGrandchildRatio ( grandchild ) . y }
169
- width = { width * this . getGrandchildRatio ( grandchild ) . width }
170
- height = { height * this . getGrandchildRatio ( grandchild ) . height }
171
- // x={grandchild.position.x}
172
- // y={grandchild.position.y}
173
- // width={grandchild.position.width}
174
- // height={grandchild.position.height}
175
157
// title={child.componentName + child.childId}
176
158
/>
177
159
) ) }
160
+ { focusChild
161
+ && focusChild . childId === childId
162
+ && draggable && (
163
+ < TransformerComponent
164
+ focusChild = { focusChild }
165
+ rectClass = { 'childRect' }
166
+ anchorSize = { 8 }
167
+ color = { 'grey' }
168
+ />
169
+ ) }
178
170
</ Group >
179
171
) ;
180
172
}
0 commit comments