getStackedHighlight method

Highlight? getStackedHighlight(
  1. Highlight high,
  2. IBarDataSet set,
  3. double xVal,
  4. double yVal,
)

This method creates the Highlight object that also indicates which value of a stacked BarEntry has been selected.

@param high the Highlight to work with looking for stacked values @param set @param xVal @param yVal @return

Implementation

Highlight? getStackedHighlight(
    Highlight high, IBarDataSet set, double xVal, double yVal) {
  BarEntry? entry = set.getEntryForXValue2(xVal, yVal);

  if (entry == null) return null;

  // not stacked
  if (entry.yVals == null) {
    return high;
  } else {
    List<Range?> ranges = entry.ranges!;

    if (ranges.isNotEmpty) {
      int stackIndex = getClosestStackIndex(ranges, yVal);

      MPPointD pixels = provider!
          .getTransformer(set.getAxisDependency())!
          .getPixelForValues(high.x!, ranges[stackIndex]!.to);

      Highlight stackedHigh = Highlight(
          x: entry.x,
          y: entry.y,
          xPx: pixels.x,
          yPx: pixels.y,
          dataSetIndex: high.dataSetIndex,
          stackIndex: stackIndex,
          axis: high.axis);

      MPPointD.recycleInstance2(pixels);

      return stackedHigh;
    }
  }
  return null;
}