tooltipInfo method
TooltipInfo?
tooltipInfo(
{ - Offset? position,
- int? pointIndex,
})
override
Implementation
@override
TooltipInfo? tooltipInfo({Offset? position, int? pointIndex}) {
if (points.isEmpty) {
return null;
}
final List<Offset> linePoints = <Offset>[points.first, points.last];
pointDistance = series.markerSettings.width / 2;
final int nearestPointIndex =
position == null ? 0 : _nearestPointIndex(linePoints, position);
if (nearestPointIndex != -1) {
pointIndex ??= (position == null || nearestPointIndex == 0
? currentSegmentIndex
: currentSegmentIndex + 1);
CartesianChartPoint<D> chartPoint = _chartPoint(pointIndex);
List<Color?> markerColors = <Color?>[fillPaint.color];
if (chartPoint.y != null && chartPoint.y!.isNaN) {
pointIndex += 1;
chartPoint = _chartPoint(pointIndex);
markerColors = <Color?>[series.segments[pointIndex].fillPaint.color];
}
final ChartMarker marker = series.markerAt(pointIndex);
final double markerHeight =
series.markerSettings.isVisible ? marker.height / 2 : 0;
final Offset preferredPos = linePoints[nearestPointIndex];
return ChartTooltipInfo<T, D>(
primaryPosition:
series.localToGlobal(preferredPos.translate(0, -markerHeight)),
secondaryPosition:
series.localToGlobal(preferredPos.translate(0, markerHeight)),
text: series.tooltipText(chartPoint),
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: markerColors,
markerType: marker.type,
);
}
return null;
}