Scaling via FreeTransform based on child elements. #3074
-
Beta Was this translation helpful? Give feedback.
Answered by
VictorPulzz
Sep 30, 2025
Replies: 1 comment
-
|
I solved it: export function getMinSizeByChildren(
graph: dia.Graph,
cell: dia.Cell,
offset = OFFSET_CHILDREN,
) {
const embeds = cell.getEmbeddedCells();
const currentBBox = cell.getBBox();
const getCells = graph.getCellsBBox(embeds);
if (getCells && embeds.length) {
return getCells.inflate(offset);
}
const { width, height } = DEFAULT_SIZE;
return new g.Rect(currentBBox.x, currentBBox.y, width, height);
}
minWidth: (cell, __, direction) => {
const cellBBox = cell.getBBox();
const childrenBBox = getMinSizeByChildren(graph, cell);
const cellLeft = cellBBox.x;
const cellRight = cellBBox.x + cellBBox.width;
const childLeft = childrenBBox.x;
const childRight = childrenBBox.x + childrenBBox.width;
if (['left', 'top-left', 'bottom-left'].includes(direction)) {
return Math.max(MIN_WIDTH, Math.round(cellRight - childLeft));
}
if (['right', 'top-right', 'bottom-right'].includes(direction)) {
return Math.max(MIN_WIDTH, Math.round(childRight - cellLeft));
}
return Math.max(MIN_WIDTH, Math.round(childrenBBox.width));
},
minHeight: (cell, __, direction) => {
const cellBBox = cell.getBBox();
const childrenBBox = getMinSizeByChildren(graph, cell);
const cellTop = cellBBox.y;
const cellBottom = cellBBox.y + cellBBox.height;
const childTop = childrenBBox.y;
const childBottom = childrenBBox.y + childrenBBox.height;
if (['top', 'top-left', 'top-right'].includes(direction)) {
return Math.max(MIN_HEIGHT, Math.round(cellBottom - childTop));
}
if (['bottom', 'bottom-left', 'bottom-right'].includes(direction)) {
return Math.max(MIN_HEIGHT, Math.round(childBottom - cellTop));
}
return Math.max(MIN_HEIGHT, Math.round(childrenBBox.height));
}, |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
VictorPulzz
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment

I solved it:
my be help somebody: