Skip to content

Commit

Permalink
feat: basic dragging for elk compound nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
steveblue committed Jun 6, 2023
1 parent 0e445d0 commit ce09fa1
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
[id]="node.id"
[attr.transform]="node.transform"
(click)="onClick(node)"
(mousedown)="onNodeMouseDown($event, node)"
>
<ng-container
*ngIf="nodeTemplate"
Expand Down
21 changes: 19 additions & 2 deletions projects/swimlane/ngx-graph/src/lib/graph/layouts/elk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -240,8 +240,25 @@ export class ElkLayout implements Layout {
return result;
}

updateEdge(graph: Graph, edge: Edge): Observable<Graph> {
return this.outputGraph$.asObservable();
updateEdge(graph: Graph, edge: Edge): Graph {
const sourceNode = this.nodeMap.get(edge.source);
const targetNode = this.nodeMap.get(edge.target);

const dir = sourceNode.position.y <= targetNode.position.y ? -1 : 1;
const startingPoint = {
x: sourceNode.position.x,
y: sourceNode.position.y - dir * (sourceNode.dimension.height / 2)
};

// TODO: preserve bezier

const endingPoint = {
x: targetNode.position.x,
y: targetNode.position.y + dir * (targetNode.dimension.height / 2)
};

edge.points = [startingPoint, endingPoint];
return graph;
}

createGraph(graph: any): Promise<ElkNode> {
Expand Down

0 comments on commit ce09fa1

Please sign in to comment.