Skip to content

Commit

Permalink
Updating the way of calculate the midPoint
Browse files Browse the repository at this point in the history
  • Loading branch information
jogaj committed Jul 27, 2023
1 parent 3e26bb6 commit 0ae57a6
Showing 1 changed file with 26 additions and 6 deletions.
32 changes: 26 additions & 6 deletions projects/swimlane/ngx-graph/src/lib/graph/graph.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1210,12 +1210,32 @@ export class GraphComponent implements OnInit, OnChanges, OnDestroy, AfterViewIn
if (points.length % 2 === 1) {
edge.midPoint = points[Math.floor(points.length / 2)];
} else {
const _first = points[points.length / 2];
const _second = points[points.length / 2 - 1];
edge.midPoint = {
x: (_first.x + _second.x) / 2,
y: (_first.y + _second.y) / 2
};
let _firstX = null;
let _secondX = null;
let _firstY = null;
let _secondY = null;
const dirRight = (this.layout as Layout).settings?.properties['elk.direction'] === 'RIGHT';
const hasBend = dirRight ? points.some(p => p.y !== points[0].y) : points.some(p => p.x !== points[0].x);

if (hasBend) {
// getting the last two points
_firstX = points[points.length - 1];
_secondX = points[points.length - 2];
_firstY = points[points.length - 1];
_secondY = points[points.length - 2];
} else {
if (dirRight) {
_firstX = points[0];
_secondX = points[points.length - 1];
_firstY = points[points.length / 2];
_secondY = points[points.length / 2 - 1];
} else {
_firstX = points[points.length / 2];
_secondX = points[points.length / 2 - 1];
_firstY = points[0];
_secondY = points[points.length - 1];
}
}
}
}

Expand Down

0 comments on commit 0ae57a6

Please sign in to comment.