Welcome to yEd Q&A!
Here you can ask questions and receive answers from other members of the community and yEd developers. And you can tell us your most wanted feature requests.

Categories

How to manually resize the width of nodes to enclose label

0 votes
I would like to know how yEd rescales the node width to enclose the label text. When I change the font size, it automatically rescales the width of the node. I want to know the relationship between the width of the node, the font size and the number of characters, because I am parsing xgml and would like to rescale the nodes to fit the labels.

Originally I thought I could rescale the width of each node via multipliying constants, i.e. c1(fontsize) + c2(number of characters) and at times the width is greater than the automatically rescaled width on yEd which isn't too bad, however at other times it is less than the automatically rescaled width on yEd which means that it won't enclose the label of the nodes.
in Help by (150 points)

1 Answer

+1 vote

Essentially, yEd determines the size of labels by quering the Java platform for the width and height of the label's text when rendered with the label's font.
However, other properties such as label Insets and Size policy also factor into the actual label width and height.
Unfortunately, XGML is a fairly simple format that does not store insets or size policies. Thus the best you can do is creating a java.awt.Font corresponding to the data in XGML's LabelGraphics section and using Java's font measuring utilities to determine the width and height of your label's text while assuming default values for insets and size policy. This means that you cannot accurately calculate label width/height in some cases like e.g. group node labels whose size usually depends on the width of the corresponding group node.
Consequently, a much better approach would be parsing GraphML instead of XGML. GraphML actually stores the label's width and height, thus width/height calculations are not necessary at all. Of course, GraphML is much more complex than XGML, but the reason for the additional complexity is the fact that GraphML stores a lot more information than XGML.
Please note, since label width and height usually depend on the font used for rendering the label and font measuring and rendering is highly operating system dependent, the values for width/height of a label may differ in GraphML files that were created e.g. on Windows and Linux even though all "primary" label properties (i.e. text, insets, size policy) are the same.

by [yWorks] (161k points)
Legal Disclosure | Privacy Policy
...