Following the stashed HtmlLabel story I tried to implement a similar use case. By default it doesn't seem like cells resize correctly according to the content of the label div or do it at the right times when I set autosize to true as follows:
this.graph.setAutoSizeCells(true);
this.graph.autoSizeCellsOnAdd = true;
I figured that the label size might not be calculating correctly so I overrode the getPreferredSizeForCell method:
const oldGetPreferredSizeForCell = this.graph.getPreferredSizeForCell;
this.graph.getPreferredSizeForCell = function (cell) {
const result = oldGetPreferredSizeForCell.apply(this, arguments);
if (result != null && cell._htmlLabel) {
result.width = Math.max(
result.width,
cell._htmlLabel.offsetWidth,
cell._htmlLabel.getBoundingClientRect().width
);
result.height = Math.max(
result.height,
cell._htmlLabel.offsetHeight,
cell._htmlLabel.getBoundingClientRect().height
);
}
return result;
};
With this approach:
- the labels still don't get sized correctly during initiation (I imagine it's something to do with when
convertValueToString gets executed) so I have to manually call updateCellSize on every cell after setting up the graph
- And the size still seems to get miscalculated on some cells for some reason.
Is there a recommended approach for this use case?
Following the stashed HtmlLabel story I tried to implement a similar use case. By default it doesn't seem like cells resize correctly according to the content of the label div or do it at the right times when I set autosize to true as follows:
I figured that the label size might not be calculating correctly so I overrode the
getPreferredSizeForCellmethod:With this approach:
convertValueToStringgets executed) so I have to manually callupdateCellSizeon every cell after setting up the graphIs there a recommended approach for this use case?