Skip to content

Commit 3580b54

Browse files
committed
#36 sync parent children on position updates
1 parent aacde89 commit 3580b54

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

src/components/graph/MetaGraph.ts

+9-5
Original file line numberDiff line numberDiff line change
@@ -183,17 +183,21 @@ export class MetaGraph {
183183
return this.findNodeGraph(newPath);
184184
}
185185

186-
updateGraph(metaNodeModel: MetaNodeModel, cursorX: number, cursorY: number, isChild?: boolean) {
186+
updateGraph(metaNodeModel: MetaNodeModel, cursorX: number, cursorY: number) {
187187
// update the graph for right parent children relationship
188188
this.updateNodeContainerBoundingBox(metaNodeModel);
189-
if (!isChild) {
189+
if (!this.parentUpdating) {
190+
this.parentUpdating = true;
190191
let parent: MetaNodeModel|undefined = this.rootContainsNode(metaNodeModel, cursorX, cursorY);
191192
let newPath = this.findNewPath(metaNodeModel, parent, cursorX, cursorY);
192193
if (metaNodeModel.getGraphPath().join().toString() !== newPath.join().toString()) {
193194
this.updateNodeInGraph(metaNodeModel, newPath);
194195
}
196+
this.handleNodePositionChanged(metaNodeModel);
197+
this.parentUpdating = false;
198+
} else {
199+
this.handleNodePositionChanged(metaNodeModel);
195200
}
196-
this.handleNodePositionChanged(metaNodeModel);
197201
}
198202

199203
handleNodePositionChanged(metaNodeModel: MetaNodeModel){
@@ -266,7 +270,7 @@ export class MetaGraph {
266270
*/
267271
// @ts-ignore
268272
const localPosition = n.getLocalPosition()
269-
n.setChildPosition(metaNodeModel.getX() + localPosition.x, metaNodeModel.getY() + localPosition.y)
273+
n.setPosition(metaNodeModel.getX() + localPosition.x, metaNodeModel.getY() + localPosition.y)
270274

271275
})
272276
}
@@ -277,7 +281,7 @@ export class MetaGraph {
277281
}
278282

279283
updateNodeContainerBoundingBox(node: MetaNodeModel): void {
280-
node.setContainerBoundingBox({
284+
node.setNodeBoundingBox({
281285
left: node.getX(),
282286
top: node.getY(),
283287
bottom: node.getY() + node.height,

0 commit comments

Comments
 (0)