getSelectedDataPoints method

List<int> getSelectedDataPoints(
  1. CartesianSeries series
)

Provides the list of selected point indices for given series.

Implementation

List<int> getSelectedDataPoints(CartesianSeries series) {
  RenderChartPlotArea? plotArea;
  if (parentBox is RenderChartPlotArea) {
    plotArea = parentBox as RenderChartPlotArea;
  } else if (parentBox is RenderBehaviorArea) {
    final RenderBehaviorArea behaviorArea = parentBox as RenderBehaviorArea;
    plotArea = behaviorArea.plotArea;
  }

  if (plotArea == null) {
    return <int>[];
  }

  int seriesIndex = -1;
  RenderBox? child = plotArea.firstChild;
  while (child != null) {
    final ContainerParentDataMixin<RenderBox> childParentData =
        child.parentData! as ContainerParentDataMixin<RenderBox>;
    if (child is ChartSeriesRenderer && child.widget == series) {
      seriesIndex = child.index;
      break;
    }
    child = childParentData.nextSibling;
  }

  if (seriesIndex != -1) {
    final Map<int, List<int>> selectedDataPoints =
        plotArea.selectionController.selectedDataPoints;
    if (selectedDataPoints.containsKey(seriesIndex)) {
      return plotArea.selectionController.selectedDataPoints[seriesIndex]!;
    }
  }

  return <int>[];
}