Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tooltips and legends textsize does not take in account screen size and scaling #906

Closed
vadimffe opened this issue Jan 28, 2023 · 2 comments
Labels
bug Something isn't working maui

Comments

@vadimffe
Copy link
Contributor

vadimffe commented Jan 28, 2023

Describe the bug
2.0.0-beta.701 does not take screen resolution and scaling in account for tooltips and legends. Setting font size to constant value does not work on different screen size and scaling. For example setting TooltipTextSize="14" on 3000x2000 and screen scale 200% looks too small, while same setup on 1920x1080 and screen scale 125% looks fine.

Desktop (please complete the following information):

  • OS: Windows
  • Version LiveChartsCore.SkiaSharpView.Maui
@vadimffe
Copy link
Contributor Author

vadimffe commented May 13, 2023

Just discovered some possible fixes can be implemented in future releases. This particular example is about circles in legend displayed next to chart items. Value can be passed from CustomLegend class. However this would require additional parameters to AsDrawnControl method as follows.

using LiveChartsCore.Drawing;
using LiveChartsCore.Kernel.Drawing;
using LiveChartsCore.SkiaSharpView.Drawing;
using LiveChartsCore.VisualElements;

namespace LiveChartsCore.SkiaSharpView.VisualElements
{
    /// <summary>
    /// Defines the visual elements extensions class.
    /// </summary>
    public static class VisualElementsExtensions
    {
        /// <summary>
        /// Creates a relative panel control from a given sketch.
        /// </summary>
        public static RelativePanel<SkiaSharpDrawingContext> AsDrawnControl(
            this Sketch<SkiaSharpDrawingContext> sketch, float width = float.NaN, float height = float.NaN, int baseZIndex = 10050)
        {
            var relativePanel = new RelativePanel<SkiaSharpDrawingContext>();

            if (!float.IsNaN(width) && !float.IsNaN(height))
            {
                relativePanel.Size = new LvcSize(width, height);
            }

            foreach (var schedule in sketch.PaintSchedules)
            {
                foreach (var g in schedule.Geometries)
                {
                    var sizedGeometry = (ISizedGeometry<SkiaSharpDrawingContext>)g;
                    var vgv = new VariableGeometryVisual(sizedGeometry);

                    if (!float.IsNaN(width))
                    {
                        vgv.Width = width == float.NaN ? sizedGeometry.Width : width;
                    }

                    if (!float.IsNaN(height))
                    {
                        vgv.Height = height == float.NaN ? sizedGeometry.Height : height;
                    }

                    schedule.PaintTask.ZIndex = schedule.PaintTask.ZIndex + 1 + baseZIndex;

                    if (schedule.PaintTask.IsFill) vgv.Fill = schedule.PaintTask;
                    if (schedule.PaintTask.IsStroke) vgv.Stroke = schedule.PaintTask;
                    _ = relativePanel.Children.Add(vgv);
                }
            }

            return relativePanel;
        }
    }
}  

Then width and heigh can be either increased or passed directly as values. In case on increasing, for example:

                    if (!float.IsNaN(width))
                    {
                        vgv.Width = sizedGeometry.Width * width;
                    }

                    if (!float.IsNaN(height))
                    {
                        vgv.Height = sizedGeometry.Height * height;
                    }

Then spacing between circles and labels should be also increased. Same for legend and tooltip

@beto-rodriguez beto-rodriguez added the bug Something isn't working label Jun 7, 2023
@beto-rodriguez
Copy link
Owner

This is now fixed with the referenced commit and will be included in the next version of the library. thanks for the report.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working maui
Projects
None yet
Development

No branches or pull requests

2 participants