Skip to content

Commit

Permalink
fix: fix polyline misalignment in orth router between nodes (#6040)
Browse files Browse the repository at this point in the history
  • Loading branch information
yvonneyx authored Jul 16, 2024
1 parent 66a98a0 commit a82369e
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 2 deletions.
32 changes: 32 additions & 0 deletions packages/g6/__tests__/bugs/element-orth-router.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { createGraph } from '@@/utils';

describe('element orth router', () => {
it('test polyline orth', async () => {
const graph = createGraph({
animation: true,
data: {
nodes: [
{
id: 'node-1',
style: { x: 310, y: 280, size: 80 },
},
{
id: 'node-2',
style: { x: 300, y: 175 },
},
],
edges: [{ id: 'edge-1', source: 'node-1', target: 'node-2' }],
},
edge: {
type: 'polyline',
style: {
router: true,
},
},
});

await graph.draw();

await expect(graph).toMatchSnapshot(__filename);
});
});
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions packages/g6/src/utils/router/orth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -243,8 +243,8 @@ export function nodeToNode(from: Point, to: Point, fromBBox: AABB, toBBox: AABB)
const p2 = toVector3(route.points[0]);

if (isPointInBBox(p2, fromBBox)) {
const fromBorder = moveTo(from, p2, getBBoxSize(fromBBox, getDirection(from, p2)) / 2);
const toBorder = moveTo(to, p1, getBBoxSize(toBBox, getDirection(to, p1)) / 2);
const fromBorder = moveTo(from, p1, getBBoxSize(fromBBox, getDirection(from, p1)) / 2);
const toBorder = moveTo(to, p2, getBBoxSize(toBBox, getDirection(to, p2)) / 2);
const midPoint: Point = [(fromBorder[0] + toBorder[0]) / 2, (fromBorder[1] + toBorder[1]) / 2];

const startRoute = nodeToPoint(from, midPoint, fromBBox);
Expand Down

0 comments on commit a82369e

Please sign in to comment.