Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updating the way of calculate the midPoint #519

Merged
merged 2 commits into from
Jul 28, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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';
Copy link
Contributor

@steveblue steveblue Jul 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The layout won't always be Elk, so this check needs to be more generic.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please also change the name of this variable to orientation and make the direction more explicit.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, thanks

Please also change the name of this variable to orientation and make the direction more explicit.

Done, thanks

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
Loading