Wrong margin with μ

A forum dedicated to WPF version of LightningChart Ultimate.

Moderator: Queue Moderators

Post Reply
MirroZV
Posts: 45
Joined: Wed May 13, 2020 10:41 am

Wrong margin with μ

Post by MirroZV » Tue Sep 12, 2023 6:32 am

Hello,

we are using 10.4.1.1 and there is problem when we have as a unit title for Y axis something starting with μ

It is 1 or 2 pixels cut.
image.png
image.png (20.75 KiB) Viewed 10121 times
you can see it on picture.

We can not use static margins, because this can be dynamically changed to another unit that can wider, or you want to zoom so much that numbers are big and whole unit is not visible.

Did you know anything about it ?

Thank you

ArctionKestutis
Posts: 555
Joined: Mon Mar 14, 2016 9:22 am

Re: Wrong margin with μ

Post by ArctionKestutis » Wed Sep 13, 2023 2:21 pm

Thank you for the report - we haven't been aware about such issue.
Upon more investigation, it seems that clipping is not specific to 'mu'/micro symbol. It can happen with other strings as well. And with Rendering Engine 9 clipping seems bigger than with Rendering Engine 11.
We don't know yet what is the reason for such clipping. However, it looks like some rounding error or underestimation of size of rendered text.
There is not much you can do about it. One workaround is to insert extra (meaningless) symbol in front of string. Unfortunately the whitespace is not going to work, because it is truncated, but 'dot' will do. For example, ".\u00B5g/min".
another work around is to rotate Unit string a little bit (property Units.Angle): 1-3 degrees should be sufficient (because for rotated string more space is reserved).

Hope this helps.

MirroZV
Posts: 45
Joined: Wed May 13, 2020 10:41 am

Re: Wrong margin with μ

Post by MirroZV » Mon Sep 18, 2023 11:57 am

Hello and thank you for replay.

we can not use additional symbol, but we tried Angle ant it is working. Have it 1 degree did not look good, but we tried 0.0001 degree, and it still fixed the issue, while looking much better.

We can use it as temporary workaround, but would prefer not to. Do you know if that is planed to be fixed in next major release ?

Thank you.

ArctionKestutis
Posts: 555
Joined: Mon Mar 14, 2016 9:22 am

Re: Wrong margin with μ

Post by ArctionKestutis » Tue Sep 19, 2023 8:46 am

We haven't fixed this issue yet, nor we set the release data.
The fix maybe trivial (as adding few more pixels to Unit-string estimate), but personally I would like to understand why current algorithm does not work for some strings. So it may take a while to find correct solution.

If you are in hurry and definitely want the fix or new feature to be released as soon as possible, please contact us directly for the customization work discussion. Sending email to Support would be just fine.

There is one more elaborated workaround, which in general suits for any margin issues. You would need to:
1) set manual margins (chart.ViewXY.AxisLayout.AutoAdjustMargins property);
2) create margins update method, where text size and Axis size is measured. E.g.

Code: Select all

        private void UpdateMargins()
        {
            PointFloat txtSize = _chart.MeasureTextPX(_chart.ViewXY.YAxes[0].Units.Text, _chart.ViewXY.YAxes[0].Units.Font);
            RectangleXY axisRect = _chart.ViewXY.YAxes[0].GetActiveAxisArea();
            double left = DpiHelper.PxToDip(txtSize.X + axisRect.Width +5);
            double top = 10;
            double right = 30;
            double button = 36;

            _chart.ViewXY.Margins = new Thickness(left, top, right, button);
        }
3) call this method once chart is loaded (chart.Loaded event handler);
4) update margins, once Axis.RangeChanged event is raised:

Code: Select all

        private void YAxis_RangeChanged(object sender, RangeChangedEventArgs e)
        {
            // update margins once chart is rendered (size of axis is known)
            _chart.AfterRendering += _chart_AfterRendering;
        }

        private void _chart_AfterRendering(object sender, AfterRenderingEventArgs e)
        {
            _chart.AfterRendering -= _chart_AfterRendering;
            UpdateMargins();
        }
Hope this helps.

Post Reply