AnnotationsXY Table Resizing and Fonts

A forum dedicated to WinForms version of LightningChart Ultimate.

Moderator: Queue Moderators

Post Reply
plotter
Posts: 41
Joined: Thu Apr 06, 2017 2:29 am

AnnotationsXY Table Resizing and Fonts

Post by plotter » Fri May 05, 2017 2:02 pm

Hi,
I have implemented several AnnotationsXY 'Tables' based on your example.
They have size and location persistence as well as dynamic height based on content.

I need help with the resizing though.
The fonts need to scale as well as the table cell proportions.

Currently, during table creation, I am storing the creation font in the Tag object,

Code: Select all

       foreach (AnnotationXY axy in _chart.ViewXY.Annotations)
            {
                axy.Tag = axy.TextStyle.Font;
            }
            return elementCount;
Here is my Font resizing, it mostly works, keyword 'Mostly'

Could you PLEASE take a look at it please and tell me where I am going wrong?

Code: Select all

 if ((_table_prev_width != width) || (_table_prev_height != height))
            {
                float ratioWidth = _orig_Width / width;
                float ratioHeight = (float)((_orig_ActualHeight / height) * .70); //.70 was a feeble attempt to keep text from overlapping...
                float ratioMax = Math.Max(ratioWidth, ratioHeight);
                for (int index = _startingCellOfTable; index < _endingCellOfTable - 1; index++)
                {
                    AnnotationXY axy = _chart.ViewXY.Annotations[index];
                    Font origFont = (Font)axy.Tag;
                    float origSize = origFont.SizeInPoints;
                    float newSize = origSize * 1 / ratioMax;
                    Font newFont = new Font(origFont.Name, newSize, origFont.Style);
                    axy.TextStyle.Font = newFont;
                }
            }

Thanks.

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

Re: AnnotationsXY Table Resizing and Fonts

Post by ArctionKestutis » Mon May 08, 2017 10:17 am

Hi,

I think you would benefit from MeasureText method. For example.

Code: Select all

_chart.MeasureText( Annotation.Text, Annotation.TextStyle.Font);    // output in DIP units
Don't forget, that for accurate reading from this method, Chart must be rendered first (_chart.EndUpdate() call or _chart.AfterRendering event). In addition, please note the units (DIP to PX conversion is important in WPF).

Next your would need to find the longest text/Annotation in each column and compare to the size you want to assign. For example, our 'Annotations 'Table' would need this comparison

Code: Select all

while (width < (AnnSize3.X + AnnSize4.X + AnnSize8.X) * DpiHelper.DpiXFactor)
{    }
Finally, you would need to reduce font size by some value and MeasureText again.

Hope this helps.
All the best,
Kestutis

Post Reply