Skip to content

Commit

Permalink
#9 chore: WIP - Add container bounding box calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
afonsobspinto committed Aug 2, 2022
1 parent fdf2249 commit 316cb28
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/helpers/engineHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ export function updateNodeLocalPosition(metaGraph: MetaGraph, node: MetaNodeMode
}

// @ts-ignore
export function updateNodesContainerBoundingBoxes(nodes: MetaNodeModel[]): void {
// nodes.forEach(n => n.updateContainerBoundingBox(nodes))
export function updateNodesContainerBoundingBoxes(nodes: MetaNodeModel[], metaGraph: MetaGraph): void {
nodes.forEach(n => n.setContainerBoundingBox(metaGraph.getNodeContainerBoundingBox(n)))
}
4 changes: 2 additions & 2 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,9 @@ const MetaDiagram = ({

useEffect(() => {
// @ts-ignore
updateNodesContainerBoundingBoxes(model.getNodes())
updateNodesContainerBoundingBoxes(model.getNodes(), metaGraph)
// @ts-ignore
model.registerListener({nodesUpdated: (event => updateNodesContainerBoundingBoxes([event.node]))})
model.registerListener({nodesUpdated: (event => updateNodesContainerBoundingBoxes([event.node], metaGraph))})
}, [])


Expand Down
13 changes: 13 additions & 0 deletions src/models/MetaGraph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,14 @@ class Graph {
return false
}

getContainerBoundingBox() : {width: number, height: number} {
let width = this.getRoot().width
let height = this.getRoot().height
// TODO continue digging in depth
// consider position + width and height of children
return {width, height}
}

}


Expand Down Expand Up @@ -140,5 +148,10 @@ export class MetaGraph {
}
return undefined
}

getNodeContainerBoundingBox(node: MetaNodeModel) : {width: number, height: number} {
const graph = this.findGraph(node.getGraphPath())
return graph.getContainerBoundingBox()
}
}

10 changes: 4 additions & 6 deletions src/react-diagrams/MetaNodeModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,21 +41,19 @@ export class MetaNodeModel extends NodeModel {
}

// @ts-ignore
getContainerBoundingBox(nodes: MetaNodeModel[]): any {
getContainerBoundingBox(metaGraph: MetaNodeModel[]): any {
// @ts-ignore
// const parentId = this.options['parentId']
// const parent = getNode(parentId, nodes)
// return

}

updateLocalPosition(metaGraph: MetaGraph): void {
// @ts-ignore
this.options['localPosition'] = this.calculateLocalPosition(metaGraph)
}

updateContainerBoundingBox(nodes: MetaNodeModel[]): void {
setContainerBoundingBox(containerBoundingBox: {width: number, height: number} ): void {
// @ts-ignore
this.options['containerBB'] = this.calculateLocalPosition(nodes)
this.options['containerBoundingBox'] = containerBoundingBox
}

}

0 comments on commit 316cb28

Please sign in to comment.