最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - mxGraph - How to automatically resize mxCell to content width if it exceeds the default size - Stack Overflow

programmeradmin6浏览0评论

How can I create an mxCell, setting the minimum width of its mxGeometry, but that would resize to the width of the html element of its value field if it is higner than the default width?

For now I have this code

var style = 'rounded=0;whiteSpace=wrap;html=1;autosize=1;resizable=0;';
var cell = new mxCell(value, new mxGeometry(0, 0, width, height), style);

But when I create this mxCell, it is always of size "width" and "height", even when the html element it contains (an h3 title) exceeds the mxRectangle. How can I fix this?

Edit : Thanks, it worked using graph.updateCellSize(). As I wanted to change the size only if it had to be higher than default, I wrote this code

this.graph.updateCellSize(cell, true);
var geom = cell.getGeometry();
geom.width = geom.width > width ? geom.width : width;

It changes the value twice, which is inefficient. I found another way using 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;

How can I create an mxCell, setting the minimum width of its mxGeometry, but that would resize to the width of the html element of its value field if it is higner than the default width?

For now I have this code

var style = 'rounded=0;whiteSpace=wrap;html=1;autosize=1;resizable=0;';
var cell = new mxCell(value, new mxGeometry(0, 0, width, height), style);

But when I create this mxCell, it is always of size "width" and "height", even when the html element it contains (an h3 title) exceeds the mxRectangle. How can I fix this?

Edit : Thanks, it worked using graph.updateCellSize(). As I wanted to change the size only if it had to be higher than default, I wrote this code

this.graph.updateCellSize(cell, true);
var geom = cell.getGeometry();
geom.width = geom.width > width ? geom.width : width;

It changes the value twice, which is inefficient. I found another way using 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;
Share Improve this question edited Aug 2, 2018 at 0:42 c4ffein asked Jul 31, 2018 at 18:29 c4ffeinc4ffein 831 silver badge7 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 7

Try graph.updateCellSize(cell, true);

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论