Hi,
I am using the SwimLaneLayout in GoJS Extension but want to modify its behavior.
By using the given code, if a lane is empty without nodes in it, it does not take any space, as shown below
However, what I want is to keep the empty lanes a minimum height (as shown below) so that users can drag nodes to it.
After studying the given SwimLaneLayout example, I modified the commitLayers
function by using the top
variable to remember the y
value of each lane and using the extraSpaces
map to adjust the node positions.
commitLayers: function (layerRects, offset) {
if (layerRects.length === 0) return;
var rect = layerRects[layerRects.length - 1];
var totallength = rect.right;
let extraSpace = 0;
const extraSpaces = new go.Map();
let top = 0;
for (var i = 0; i < laneNames.length; i++) {
var lane = laneNames[i];
extraSpaces.set(lane, extraSpace);
var group = this.diagram.findNodeForKey(lane);
if (group === null) {
this.diagram.model.addNodeData({
key: lane,
isGroup: true,
});
group = this.diagram.findNodeForKey(lane);
}
group.location = new go.Point(
-this.layerSpacing / 2,
top + offset.y,
);
var ph = group.findObject("PLACEHOLDER");
if (ph === null) ph = group;
let laneHeight =
this.laneBreadths.get(lane) * this.columnSpacing;
if (laneHeight === 0) {
extraSpace += MIN_LANE_HEIGHT;
laneHeight = MIN_LANE_HEIGHT;
}
ph.desiredSize = new go.Size(totallength, laneHeight);
top += laneHeight;
}
const nodes = this.diagram.nodes;
while (nodes.next()) {
const node = nodes.value;
const position = nodes.value.position;
const extraY = extraSpaces.get(node.data.group);
nodes.value.position = new go.Point(
position.x,
position.y + extraY,
);
}
},
The code works so far. But I am wondering if it is the recommended approach.
My next question is more generic:
After I studied some extended layout code, I realized that many layout extensions override non-public methods like nodeMinLayerSpace
, nodeMinColumnSpace
, reduceCrossings
, etc. Those methods are not listed in GoJS API.
Where could we find the explanation of those non-public but override-able methods? Is there any comprehensive list? Such list will dramatically ease our job of extending the given layout for our unique use cases.
Looking forward to hearing from you! And happy holidays!
Min