我如何创建一个 mxCell,设置它的 mxGeometry 的最小宽度,但如果它比默认宽度更高,它会调整到它的值字段的 html 元素的宽度?
现在我有这段代码
var style = 'rounded=0;whiteSpace=wrap;html=1;autosize=1;resizable=0;';
var cell = new mxCell(value, new mxGeometry(0, 0, width, height), style);
但是当我创建这个 mxCell 时,它的大小总是“宽度”和“高度”,即使它包含的 html 元素(一个 h3 标题)超过了 mxRectangle。我该如何解决这个问题?
编辑:谢谢,它使用 graph.updateCellSize() 工作。因为我只想在必须高于默认值时才更改大小,所以我编写了这段代码
this.graph.updateCellSize(cell, true);
var geom = cell.getGeometry();
geom.width = geom.width > width ? geom.width : width;
它改变了两次值,这是低效的。我找到了另一种使用 getPreferredSizeForCell 的方法
var preferred = this.graph.getPreferredSizeForCell(cell);
var current = cell.getGeometry();
current.width = preferred.width > width ? preferred.width : width;
current.height = preferred.height > height ? preferred.height : height;
最佳答案
试试 graph.updateCellSize(cell, true);
关于javascript - mxGraph - 如果 mxCell 超过默认大小,如何自动将其调整为内容宽度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51619879/