Setting text baseline

Is there a way to set the text baseLine in GoJS ? It’s something i really need


Not exactly, but there are undocumented properties spacingAbove and spacingBelow, which you can set to numerical values to adjust TextBlock lines.

What are you trying to do?

I am trying to center vertically some text.

You see that the bounding box of the text is correct, but the text inside it is aligned on the top of the bounding box. This makes an ugly effect, as the picture is correctly centered, but not the text.

_$(go.TextBlock, { stroke: "white", margin: new go.Margin(0, titleMargin), background: 'blue', font: "12pt regular", wrap: go.TextBlock.None, alignment: go.Spot.Center, overflow: go.TextBlock.OverflowEllipsis },

what if you added:

spacingAbove: 2,
spacingBelow: -2

(or perhaps just the spacingAbove property)

Ok, by playing with these properties, i have a good result.
But i think it would be really nice to set the baseline of the text, or to have some example on how to center vertically a textBlock in a Panel. I find one example on CodePen, but there was the same issue, the bounding box of the text was right, but the text had a very small offset of -1, -2px

We don’t allow setting the text baseline, and our measuring isn’t always accurate for every font, especially some custom fonts with very large descents, which is why we have these two properties.

If your text was just "LgLgLgLgLg" you might notice that it looks much more balanced.

If you look at this example:

On my machine, if anything, there’s too much space at the top, not the bottom.

Also be sure you are using a font that renders as you’d expect cross-browser. “regular” is not a typical font name or family.

Ok… I agree with ‘LgLg’, but if use uppercase my word, ‘LGLGLGLGL’, then you will have this small offset in the bounding box, and it will become noticeable, because there is no ‘g’ to balance it

Yes, but I think most people want that, because they do not want the text to suddenly move (vertically) when you type characters that have a descender in their glyph.