Is possible to auto fit the texts in node

Hi,
In gojs, is that possible to auto fit the text’s in node based on text passing like ‘PEN’, ‘RATES’


In those diagram’s I have hardcoded height, spacingAbove and made those nodes. Can I get this same result by dynamic autofitting text’s.

I am getting node like this if I didnt hardcode height, spacingAbove:

This wasn’t an intended use case of spacingAbove and spacingBelow, but maybe there’s a way to accomodate.

Can you tell me more about your use case? Will there always be only one letter on each line, for instance?

yes. 1 letter on each line

As a fairly kludgey solution, you could attempt to measure the “amount” of spacing needed between the natural height of the Text and the height of the available area, and account for it with spacing.

So something like this:

          new go.Binding("spacingBelow", "height", function(h, obj) {
            var letters = obj.part.data.key.length;
            var lineHeight = 26; // 24px font = about 26 pixels high
            var height = lineHeight * letters;
            var deltaHeight = h - height;
            // Spacing is only between letters, so use letters - 1
             if (letters < 2) return 0; // edited to reflect walter's suggestion
            return (deltaHeight / (letters - 1));
          })

Shouldn’t that check be:

    if (letters < 2) return 0;

Thanks for your reply.
If I rotate Node expceting result as :

But Actual result is like,


Can you give some idea on this?

I think almost everyone would expect a rotated node to have the same appearance as seen from the new angle.

Besides, if you counter-rotated the TextBlock, I do not believe there is a way to control the distance betwen letters, unless you implement it by having a separate TextBlock for each letter. And doing so would potentially break in some languages.