4

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;
c4ffein
  • 73
  • 1
  • 7

1 Answers1

6

Try graph.updateCellSize(cell, true);

user1084282
  • 1,003
  • 7
  • 6