There is swimlane example in mxgraph but it is not automatic. So I took the graphlayout example as a basis instead and made few changes:
Here's how I create swimlanes:
var lane1 = graph.insertVertex(parent, null, 'Lane 1', 0, 0, 1000, 100, 'swimlane');
var lane2 = graph.insertVertex(parent, null, 'Lane 2', 0, 100, 1000, 100, 'swimlane');
// use as parent...
var v1 = graph.insertVertex(lane1, null, 'A', 0, 0, w, h);
and execute the layout:
layout.orientation = mxConstants.DIRECTION_WEST;
layout.resizeParent = true;
layout.execute(parent, [lane1, lane2]);
Here's the test page.
Now, there are two problems here:
Far from perfect, but somehow improvement:
Demo
I've added:
layout.execute(lane1, [v1,v2,v3,v4]);
layout.execute(lane2, [v5,v6,v7,v8]);
and changed resizeParent
to false
, looks like lanes are respected but still don't look pleasant.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With