javascript - mxGraph - 如果 mxCell 超过默认大小,如何自动将其调整为内容宽度

标签 javascript html mxgraph

我如何创建一个 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/

相关文章:

javascript - 如何更改 mxCell 的父级

javascript - 如何轻松地向 MxGraph 添加复杂的形状?

javascript - 尝试在 html 电子邮件中插入一个 ajax 调用

javascript - 将一个表的数据复制到另一个表时切换按钮

jquery - Fancytip 无法正常工作

html - 使 overflow-y 显示在 <ul> 边框内

javascript - 在 Jquery 中使用 .css() 中的变量

javascript - VueJS : @keydown, @keyup 和 this.$refs 适用于输入,但不适用于 md-textarea

html - 使用 html 和 css(无 javascript)只能将 255 个字符输入到文本区域

javascript - 使用 Angular 在 MxGraph 上覆盖 graphHandlerMouseUp 时无限循环