X Tutup
Skip to content

BarSeriesBase: HitTest does not deliver the correct BarItem, when there are invalid items in Data #2038

@belucha

Description

@belucha

Steps to reproduce

  1. Use the following PlotModel
var model = new PlotModel();
model.MouseDown += (s, e) =>
{
	if (e.ChangedButton == OxyMouseButton.Left)
	{
		foreach (var hit in model.HitTest(new HitTestArguments(e.Position, 0)))
		{
			if (hit.Item is BarItem barItem)
			{
				// change the color of the clicked Bar Item to
				barItem.Color = OxyColors.Red;
				model.InvalidatePlot(false);
			}
		}
	}
};
var s1 = new BarSeries { Title = "Series 1", IsStacked = true, StrokeColor = OxyColors.Black, StrokeThickness = 1, StackGroup = "3" };
int i = 0;
s1.Items.Add(new BarItem { Value = 25, CategoryIndex = i++ });
s1.Items.Add(new BarItem { Value = double.NaN, CategoryIndex = i++ }); // add one invalid item
s1.Items.Add(new BarItem { Value = 18, CategoryIndex = i++ });
s1.Items.Add(new BarItem { Value = 40, CategoryIndex = i++ });
model.Series.Add(s1);
  1. Now Click on the top item, the HistTest returns the wrong item

Platform:
.NET version: All

Expected behaviour

The HitTest should return the correct item. Thus the clicked BarItem should change color!

Actual behaviour

The wrong item changes color.
image

Problem description

I found the source of the misbehaviour in BarSeriesBase.UpdateValidData when the index in the reverse lookup dictionary is not correctly calculated.

I will provide a merge request to fix this bug.

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

      X Tutup