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

Legend hittest always return null #2034

Open
mikezw opened this issue Aug 21, 2023 · 4 comments
Open

Legend hittest always return null #2034

mikezw opened this issue Aug 21, 2023 · 4 comments

Comments

@mikezw
Copy link

mikezw commented Aug 21, 2023

Hi, I want to use hittest of legend, but it always return null. And because of SeriesPosMap is private, If I implementation mylegend base Legend , I must copy all logic of SeriesPosMap. So I make some changes like belows.

Changes

  protected override HitTestResult LegendHitTest(HitTestArguments args)
        {
            HitTestResult hitTestResult = null;
            if (this.IsLegendVisible && this.PlotModel.IsLegendVisible)
            {
                ScreenPoint point = args.Point;
                if (this.IsPointInLegend(point))
                {
                    Element seriesElement = null;
                    if (this.SeriesPosMap != null && this.SeriesPosMap.Count > 0)
                    {
                        foreach (KeyValuePair<Series.Series, OxyRect> kvp in this.SeriesPosMap)
                        {
                            if (kvp.Value.Contains(point))
                            {
                                if (this.ShowInvisibleSeries)
                                {
                                    kvp.Key.IsVisible = !kvp.Key.IsVisible;
                                    this.PlotModel.InvalidatePlot(false);
                                    seriesElement = kvp.Key;
                                    break;
                                }
                            }
                        }
                    }
                    //Return Series if ShowInvisibleSeries is true .
                    hitTestResult = new HitTestResult(this, point, seriesElement);
                }
            }
            return hitTestResult;
        }

Can these be added to the release?

@VisualMelon
Copy link
Contributor

Linking #1814

@VisualMelon
Copy link
Contributor

Exposing this sort of thing is definitely something I'd like to look into. There is additional discussion in #1657

@mikezw
Copy link
Author

mikezw commented Aug 21, 2023

So how about the progress? Change SeriesPosMap to protect will give more expandable to legend.

Is there anything I can do to help?

@VisualMelon
Copy link
Contributor

VisualMelon commented Aug 21, 2023

I wouldn't want to expose SeriesPostMap in its current state. We need a more comprehensive design that includes e.g. showing non-series items on the legend/multiple entries per series. If there is demand (and there seems to be) I'd sooner add something like your HitTest method which uses the existing abstractions, but will need a proper review to see if it makes sense.

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

No branches or pull requests

2 participants