Skip to content

Commit

Permalink
#36 sync parent children on position updates
Browse files Browse the repository at this point in the history
  • Loading branch information
ddelpiano committed Oct 28, 2022
1 parent aacde89 commit 3580b54
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/components/graph/MetaGraph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,17 +183,21 @@ export class MetaGraph {
return this.findNodeGraph(newPath);
}

updateGraph(metaNodeModel: MetaNodeModel, cursorX: number, cursorY: number, isChild?: boolean) {
updateGraph(metaNodeModel: MetaNodeModel, cursorX: number, cursorY: number) {
// update the graph for right parent children relationship
this.updateNodeContainerBoundingBox(metaNodeModel);
if (!isChild) {
if (!this.parentUpdating) {
this.parentUpdating = true;
let parent: MetaNodeModel|undefined = this.rootContainsNode(metaNodeModel, cursorX, cursorY);
let newPath = this.findNewPath(metaNodeModel, parent, cursorX, cursorY);
if (metaNodeModel.getGraphPath().join().toString() !== newPath.join().toString()) {
this.updateNodeInGraph(metaNodeModel, newPath);
}
this.handleNodePositionChanged(metaNodeModel);
this.parentUpdating = false;
} else {
this.handleNodePositionChanged(metaNodeModel);
}
this.handleNodePositionChanged(metaNodeModel);
}

handleNodePositionChanged(metaNodeModel: MetaNodeModel){
Expand Down Expand Up @@ -266,7 +270,7 @@ export class MetaGraph {
*/
// @ts-ignore
const localPosition = n.getLocalPosition()
n.setChildPosition(metaNodeModel.getX() + localPosition.x, metaNodeModel.getY() + localPosition.y)
n.setPosition(metaNodeModel.getX() + localPosition.x, metaNodeModel.getY() + localPosition.y)

})
}
Expand All @@ -277,7 +281,7 @@ export class MetaGraph {
}

updateNodeContainerBoundingBox(node: MetaNodeModel): void {
node.setContainerBoundingBox({
node.setNodeBoundingBox({
left: node.getX(),
top: node.getY(),
bottom: node.getY() + node.height,
Expand Down

0 comments on commit 3580b54

Please sign in to comment.