/// <summary> /// This method creates the Highlight object that also indicates which value of a stacked BarEntry has been /// selected. /// </summary> /// <param name="high">the Highlight to work with looking for stacked values</param> /// <param name="dataSet"></param> /// <param name="xVal"></param> /// <param name="yVal"></param> /// <returns></returns> public Highlight GetStackedHighlight(Highlight high, IDataSet <BarEntry> dataSet, float xVal, float yVal) { BarEntry entry = dataSet.EntryForXValue(xVal, yVal); if (entry == null) { return(null); } // not stacked if (entry.YVals == null) { return(high); } else { var ranges = entry.Ranges; if (ranges.Count > 0) { int stackIndex = GetClosestStackIndex(ranges, yVal); var pixels = Chart.GetTransformer(dataSet.AxisDependency).PointValueToPixel(high.X, ranges[stackIndex].To); Highlight stackedHigh = new Highlight( entry.X, entry.Y, (float)pixels.X, (float)pixels.Y, high.DataSetIndex, stackIndex, high.Axis ); return(stackedHigh); } } return(null); }
/// <summary> /// An array of `Highlight` objects corresponding to the selected xValue and dataSetIndex. /// </summary> protected virtual IList <Highlight> BuildHighlights(IDataSet set, int dataSetIndex, float xVal, DataSetRounding rounding) { IList <Highlight> highlights = new List <Highlight>(); //noinspection unchecked IList <Entry> entries = set.EntriesForXValue(xVal); if (entries.Count == 0) { // Try to find closest x-value and take all entries for that x-value Entry closest = set.EntryForXValue(xVal, float.NaN, rounding); if (closest != null) { //noinspection unchecked entries = set.EntriesForXValue(closest.X); } } if (entries.Count == 0) { return(highlights); } foreach (Entry e in entries) { var pixels = Chart.GetTransformer( set.AxisDependency).PointValueToPixel(e.X, e.Y); highlights.Add(new Highlight( e.X, e.Y, (float)pixels.X, (float)pixels.Y, dataSetIndex, set.AxisDependency)); } return(highlights); }