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
1 Answer
Reset to default 7Try graph.updateCellSize(cell, true);