Skip to content

Implement IHittable for BarPlot #1891

@jhm-ciberman

Description

@jhm-ciberman

Feature Suggestion

First, thanks for making such amazing library. I love it.

Second, we are currently implementing charts in our business accounting application. They look amazing. For scatter plots we use the method described in Highlight the Data Point Near the Cursor to display details about every transaction in the side panel. It works like a charm.

image

The problem arises with bar plots. Since there is no MouseOver method, or any way to detect collisions with the figure:

image

We would like to display information when the user hovers over one bar.

It would be pretty easy to detect mouse over one square, but the problem is that there are so may variables that controls the positioning of each bar that it becomes a bit difficult. Also, all the position calculation is done in the Draw method, so there is no way to retrieve the current position and size of each bar.

Feature description:

My suggestion would be to implement the IHitable interface in the BarPlot class. I think it would be pretty easy. The same that is done for the Tooltip can be done:

  1. Inside the draw method store in a private variable the position and size of each bar.
  2. In the IHittable.HitTest() method, use that information from the last render to perform a point to AABB collision test.

it would be cool to have an overload of the HitTest method that returns the index of the hit bar too. Maybe as a separate interface, like IHittablePlot

interface IHittablePlot : IHittable
{
    bool HitTest(Coordinate coord, out int hitElementIndex);
}

Code example:

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions