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 are clipped with owner control clipping #912

Open
picrap opened this issue Jan 31, 2023 · 12 comments
Open

Tooltips are clipped with owner control clipping #912

picrap opened this issue Jan 31, 2023 · 12 comments
Labels

Comments

@picrap
Copy link

picrap commented Jan 31, 2023

Starting at 2.0.0-beta.600, tooltips behavior has changed and they now are clipped with parent’s clip mask.
This occurs on WPF platform, here are a few samples:
c1
c2
(pardon my french 😉)

@beto-rodriguez
Copy link
Owner

beto-rodriguez commented Jun 7, 2023

Tooltips changed a lot in the last couple of versions, now we completely draw them.

In previous versions, we used the provided tooltips in every supported framework, but this was harder to maintain, especially in cross platform frameworks.

Now the library draws the tooltips, the problem now is that we cannot draw outside the control 😢

@picrap
Copy link
Author

picrap commented Jun 7, 2023

OK this makes sense. Is there a way to handle tooltip ourselves, then ? Such as a handler that we could listen to and intercept tooltip creation ?

@DavidWiseman
Copy link

I think this might explain this issue I have on WinForms where the tooltip doesn't display correctly.

image

I have a few charts stacked on top of each other so the height is limited for each chart. The tooltips are particularly important for the stacked bar charts and they don't display fully. I'm currently looking into upgrading from the old version and I think this will keep me on the old version for now. The new version does feel faster and seems to be progressing well - Thanks for the work you have put into this! ♥️

@garyhertel
Copy link

I'm investigating adding support for this library using AvaloniaUI and running into a similar issue with the tooltips being cutoff for small charts. To be fair, the existing OxyPlot library I'm using has a similar problem (although maybe not quite as bad since the tooltips there only show the closest series and not all of them).

My initial investigations into overriding this using a custom IChartTooltip in the base AvaloniaUI haven't been very successful either, although I might just need to try a different method than Avalonia Flyouts. (those don't seem to work well when following the mouse cursor)

@beto-rodriguez
Copy link
Owner

I made huge improvements related to this, in the next version tooltips should always be inside the chart. also when the text is too long, it should create multiple lines, so this issue will be improved.

But that solution is not perfect, ideally, we should use the tooltips provided in Avalonia. but that also means that we should do that for each platform, it would be a huge effort, that was the old behaviour of the library, but it was hard to maintain because all the supported platforms behave really different.

@picrap
Copy link
Author

picrap commented Sep 14, 2023

Again, if we can have an event handler to create tooltips by ourselsves, it’s a good start. This way, the responsability of specific platforms development is on our side, so you can focus on core development and don’t feel the pressure 😉.

@beto-rodriguez
Copy link
Owner

beto-rodriguez commented Sep 14, 2023

@picrap you can do that, here is an example that uses a custom tooltip rendered by WPF:

<lvc:CartesianChart
    Series="{Binding Series}"
    YAxes="{Binding YAxes}"
    LegendPosition="Left"
    LegendBackgroundPaint="{Binding LedgendBackgroundPaint}"
    LegendTextPaint="{Binding LegendTextPaint}"
    LegendTextSize="16">
    <lvc:CartesianChart.Tooltip>
        <local:WPFTooltip></local:WPFTooltip>
    </lvc:CartesianChart.Tooltip>
</lvc:CartesianChart>
public class WPFTooltip : ToolTip, IChartTooltip<SkiaSharpDrawingContext>
{
    public WPFTooltip()
    {
        Content = new Label
        {
            Content = "custom content here...",
        };
    }

    public void Show(IEnumerable<ChartPoint> foundPoints, Chart<SkiaSharpDrawingContext> chart)
    {
        // build the layout here using the WPF api...

        // then measure the control, so livecharts can calculate the position.
        Measure(new System.Windows.Size(double.PositiveInfinity, double.PositiveInfinity));
        var size = new LvcSize((float)DesiredSize.Width, (float)DesiredSize.Height);

        var start = ((CartesianChart)chart.View).PointToScreen(new System.Windows.Point(0, 0));
        var location = foundPoints.GetTooltipLocation(size, chart);

        IsOpen = true;
        Placement = System.Windows.Controls.Primitives.PlacementMode.Absolute;
        HorizontalOffset = location.X + start.X;
        VerticalOffset = location.Y + start.Y;
    }

    public void Hide(Chart<SkiaSharpDrawingContext> chart)
    {
        IsOpen = false;
    }
}

tooltip

@picrap
Copy link
Author

picrap commented Sep 18, 2023

Your solution for WPF tooltip is fine for me, thank you!

@DavidWiseman
Copy link

Thanks for your work on this. The tooltip is no longer displayed at the top of the bar which previously resulted in it being truncated. It can still be truncated if there is insufficient height available in the chart though. I guess the only solution would be to span outside of the control or have a wider tooltip with multiple columns.

I also noticed this behavior where the tooltip for 11:10 is located on either side of the 11:10 bar but won't display in its correct location. The text and icons are also misaligned which I'm guessing could be down to the length of the text.

livecharts

I'm using WinForms. Currently using v0 and looking to upgrade at some point. Awesome work on this charting component. ♥️

@DavidKarlas
Copy link

I wonder how hard would it be to maintain per platform support for "window" creation, so in case of Blazor, create Canvas and position it above certain point in original Canvas. But tooltip content is rendered fully by LiveCharts/Skia. If platform doesn't support this "window creation" logic, fall back to current thing.

@brunossn
Copy link

brunossn commented Nov 4, 2024

@beto-rodriguez Thanks for the suggestion, it works here. Is it possible to animate the ToolTip movement?

@beto-rodriguez
Copy link
Owner

@brunossn using the WPF tooltip?

if so, you can try this:

// change this:
//HorizontalOffset = location.X + start.X;
//VerticalOffset = location.Y + start.Y;

// to:
var d = TimeSpan.FromMilliseconds(300);
BeginAnimation(HorizontalOffsetProperty, new DoubleAnimation() { To = location.X + start.X, Duration = d });
BeginAnimation(VerticalOffsetProperty, new DoubleAnimation() { To = location.Y + start.Y, Duration = d });
`` 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants