Thursday, March 3, 2011

.NET Library to draw routed lines avoiding obstacles

I've created a workflow/flowchart style designer for something. At the moment it is using relatively simple Bezier curve lines to connect up the various end points of the "blocks" on the workflow.

However I would like something a bit more intuitive for the user. I want the lines to avoid obstacles like other blocks (rectangles) and possibly other lines too.

I prefer the bezier splines rather than polylines because they are prettier and seem to fit in better with the designer in general. But am willing to compromise if they are much harder to accomplish.

I know there is a whole load of science behind this. I've looked into things like Graphviz, Microsoft's GLEE and their commericial AGL (automatic graph layout) library.

GLEE seems to barely be production worthy. And their commercial alternative is, well, a commercial alternative... it's quite expensive.

Graphviz doesn't seem to have been ported to .NET in any way.

I have seen a polyline implementation used by Windows Workflow Foundation for its "freeform designer". And this works, just, but it is not really of production grade appearance.

I'm surprised there isn't some plug'n'play .NET library for this type of thing? Something like:

Point[] RoutePolyline(Point begin, Point end, Rectangle[] rectObstacles, Point[] lineObstacles);

From stackoverflow
  • I haven't tried it (although I'm a happy customer of their Gantt product), but ILOG have a similar tool here.

    To quote:

    The ILOG Diagram for .NET algorithms share generic goals such as:

    • Minimizing the number of overlapping nodes
    • Minimizing the number of link crossing
    • Minimizing the total area of the drawing
    • Minimizing the number of bends (in orthogonal drawings)
    • Maximizing the smallest angle formed by consecutive incident links
    • Maximizing the display of symmetries
    • Supporting incremental layout, partial layout, subgraphs, intergraph links and nested layouts

    Perhaps worth a look, at least.

  • Diagram.NET is a free, open source diagramming library in C#. It hasn't been updated in quite some time, but it's certainly worth a look - there may something there which you can reuse.

    http://www.dalssoft.com/diagram/

  • Are you limited to managed code only?

    I did not have this restriction and the past and effectively integrated GraphViz with .Net. What we did was call an external process containing the natively compiled "dot" and parse the result in a .Net object model. It worked perfectly and was fast enough for our needs.

    I'm sure you could do better and easier with C++/CLI today.

0 comments:

Post a Comment