0.6.1-alpha.8 • Published 8 months ago

@revesuite/connector v0.6.1-alpha.8

Weekly downloads
-
License
MPL-2.0
Repository
github
Last release
8 months ago

@blocksuite/connector

How to use

import { route, Rectangle } from '@blocksuite/connector';

const rects = [
  new Rectangle(30, 30, 200, 200),
  new Rectangle(160, 160, 300, 300),
];

const points = [
  { x: 50, y: 30 },
  { x: 160, y: 200 },
];

const path = route(rects, points);
console.log('path', path);

Example

See packages/playground/examples/canvas/connector.html

Info

The main idea comes from https://medium.com/swlh/routing-orthogonal-diagram-connectors-in-javascript-191dc2c5ff70 . The final implementation is based on the idea of the blog and modifies the following parts:

  • When generating graph, do not rely on the binding of rectangle and point
  • When generating graphs, do not limit the number of rectangles and points
  • When the path is finally calculated, select any two points from the graph
  • When there are only two points or only one rectangle, manually generate the points of the graph

Problems caused by modifications:

  • The Graph becomes larger, and more points.length lines are added, causing the final path point to increase points.length * 2n

References

Blog:

Code:

Visualized path finding:

0.6.1-alpha.8

8 months ago

0.6.1-alpha.7

8 months ago

0.6.1-alpha.6

8 months ago

0.6.1-alpha.5

8 months ago

0.6.1-alpha.3

8 months ago

0.6.1-alpha.2

8 months ago

0.6.1-alpha.1

8 months ago

0.6.1-alpha.0

8 months ago