Skip to content

Commit

Permalink
feat: methods for getting cells from graph
Browse files Browse the repository at this point in the history
  • Loading branch information
bubkoo committed Dec 19, 2019
1 parent 5be114e commit ff712a0
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
2 changes: 1 addition & 1 deletion packages/x6/src/graph/group-manager.ts
Expand Up @@ -173,7 +173,7 @@ export class GroupManager extends BaseManager {
for (let i = cells.length - 1; i >= 0; i -= 1) {
let geo = this.graph.getCellGeometry(cells[i])
if (geo != null) {
const children = this.graph.getChildren(cells[i])
const children = this.graph.getVisibleChildren(cells[i])
if (children != null && children.length > 0) {
const bounds = this.graph.getBoundingBoxFromGeometry(children, true)
if (bounds != null && bounds.width > 0 && bounds.height > 0) {
Expand Down
26 changes: 21 additions & 5 deletions packages/x6/src/graph/retrieval-accessor.ts
Expand Up @@ -92,21 +92,21 @@ export class RetrievalAccessor extends BaseGraph {
/**
* Returns the visible child nodes of the given parent.
*/
getChildNodes(parent: Cell) {
return this.getChildren(parent, true, false)
getVisibleChildNodes(parent: Cell) {
return this.getVisibleChildren(parent, true, false)
}

/**
* Returns the visible child edges of the given parent.
*/
getChildEdges(parent: Cell) {
return this.getChildren(parent, false, true)
getVisibleChildEdges(parent: Cell) {
return this.getVisibleChildren(parent, false, true)
}

/**
* Returns the visible child nodes or edges of the given parent.
*/
getChildren(
getVisibleChildren(
parent: Cell = this.getDefaultParent(),
includeNodes: boolean = false,
includeEdges: boolean = false,
Expand All @@ -115,6 +115,22 @@ export class RetrievalAccessor extends BaseGraph {
return cells.filter(cell => this.isCellVisible(cell))
}

getChildNodes(parent: Cell) {
return this.getChildren(parent, true, false)
}

getChildEdges(parent: Cell) {
return this.getChildren(parent, false, true)
}

getChildren(
parent: Cell = this.getDefaultParent(),
includeNodes: boolean = false,
includeEdges: boolean = false,
) {
return this.model.getChildren(parent, includeNodes, includeEdges)
}

/**
* Returns all visible edges connected to the given cell without loops.
*/
Expand Down
2 changes: 1 addition & 1 deletion packages/x6/src/handler/node/preview.ts
Expand Up @@ -179,7 +179,7 @@ export class Preview extends Disposable {
}

protected updateMinBounds() {
const children = this.graph.getChildren(this.state.cell)
const children = this.graph.getVisibleChildren(this.state.cell)
if (children.length > 0) {
this.minBounds = this.graph.view.getBounds(children)
if (this.minBounds != null) {
Expand Down

0 comments on commit ff712a0

Please sign in to comment.