tooltipInfo method

  1. @override
TooltipInfo? tooltipInfo({
  1. Offset? position,
  2. int? pointIndex,
})
override

Implementation

@override
TooltipInfo? tooltipInfo({Offset? position, int? pointIndex}) {
  if (segmentRect != null) {
    Rect outlierBounds = Rect.zero;
    int outlierIndex = -1;

    if (position != null) {
      final int length = _outlierPoints.length;
      for (int i = 0; i < length; i++) {
        final ChartMarker marker = series.markerAt(i);
        final Rect outlierRect = Rect.fromCenter(
            center: _outlierPoints[i],
            width: marker.width,
            height: marker.height);
        if (outlierRect.contains(position)) {
          outlierBounds = outlierRect;
          outlierIndex = i;
          break;
        }
      }
    }

    pointIndex ??= currentSegmentIndex;
    final CartesianChartPoint<D> chartPoint = _chartPoint();
    final TooltipPosition? tooltipPosition =
        series.parent?.tooltipBehavior?.tooltipPosition;
    Offset primaryPos;
    Offset secondaryPos;
    if (outlierIndex != -1) {
      primaryPos = series.localToGlobal(outlierBounds.topCenter);
      secondaryPos = series.localToGlobal(outlierBounds.bottomCenter);
    } else {
      if (points.isNotEmpty && points.length == 8) {
        primaryPos = secondaryPos = series.localToGlobal(points[3]);
      } else {
        primaryPos = tooltipPosition == TooltipPosition.pointer
            ? series.localToGlobal(position ?? segmentRect!.topCenter)
            : series.localToGlobal(segmentRect!.topCenter);
        secondaryPos = primaryPos;
      }
    }
    return ChartTooltipInfo<T, D>(
      primaryPosition: primaryPos,
      secondaryPosition: secondaryPos,
      text: series.tooltipText(chartPoint, outlierIndex),
      header: series.parent!.tooltipBehavior!.shared
          ? series.tooltipHeaderText(chartPoint)
          : series.name,
      data: series.dataSource![pointIndex],
      point: chartPoint,
      series: series.widget,
      renderer: series,
      seriesIndex: series.index,
      segmentIndex: currentSegmentIndex,
      pointIndex: pointIndex,
      markerColors: <Color?>[fillPaint.color],
    );
  }
  return null;
}