c4f*_*ein 3 html javascript mxgraph
如何创建 mxCell,设置其 mxGeometry 的最小宽度,但如果它比默认宽度高,则会调整为其 value 字段的 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);
Run Code Online (Sandbox Code Playgroud)
但是当我创建这个 mxCell 时,它的大小总是“宽度”和“高度”,即使它包含的 html 元素(一个 h3 标题)超过了 mxRectangle。我怎样才能解决这个问题?
编辑:谢谢,它使用 graph.updateCellSize() 工作。因为我只想在它必须高于默认值时更改大小,所以我写了这段代码
this.graph.updateCellSize(cell, true);
var geom = cell.getGeometry();
geom.width = geom.width > width ? geom.width : width;
Run Code Online (Sandbox Code Playgroud)
它将值更改两次,这是低效的。我找到了另一种使用 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;
Run Code Online (Sandbox Code Playgroud)