getNearestDatumDetailPerSeries method
- Point<
double> chartPoint, - bool byDomain,
- Rectangle<
int> ? boundsOverride, { - bool selectOverlappingPoints = false,
- bool selectExactEventLocation = false,
Gets a list of the data from each series that is closest to a given point.
chartPoint
represents a point in the chart, such as a point that was
clicked/tapped on by a user.
selectOverlappingPoints
specifies whether to include all points that
overlap the tapped position in the result. If specified, the method will
return either the closest point or all the overlapping points with the
tapped position.
byDomain
specifies whether the nearest data should be defined by domain
distance, or relative Cartesian distance.
boundsOverride
optionally specifies a bounding box for the selection
event. If specified, then no data should be returned if chartPoint
lies
outside the box. If not specified, then each series renderer on the chart
will use its own component bounds for filtering out selection events
(usually the chart draw area).
Implementation
@override
List<DatumDetails<D>> getNearestDatumDetailPerSeries(
Point<double> chartPoint,
bool byDomain,
Rectangle<int>? boundsOverride, {
bool selectOverlappingPoints = false,
bool selectExactEventLocation = false,
}) {
final nearest = <DatumDetails<D>>[];
// Was it even in the component bounds?
if (!isPointWithinBounds(chartPoint, boundsOverride)) {
return nearest;
}
final arcLists = getArcLists();
for (final arcList in arcLists) {
if (arcList.series!.overlaySeries) {
return nearest;
}
final center = arcList.center!;
final innerRadius = arcList.innerRadius!;
final radius = arcList.radius!;
final distance = center.distanceTo(chartPoint);
// Calculate the angle of [chartPoint] from the center of the arcs.
var chartPointAngle =
atan2(chartPoint.y - center.y, chartPoint.x - center.x);
// atan2 returns NaN if we are at the exact center of the circle.
if (chartPointAngle.isNaN) {
chartPointAngle = config.startAngle;
}
// atan2 returns an angle in the range -PI..PI, from the positive x-axis.
// Our arcs start at the positive y-axis, in the range -PI/2..3PI/2. Thus,
// if angle is in the -x, +y section of the circle, we need to adjust the
// angle into our range.
if (chartPointAngle < config.startAngle && chartPointAngle < 0) {
chartPointAngle = 2 * pi + chartPointAngle;
}
for (final arc in arcList.arcs) {
if (innerRadius <= distance &&
distance <= radius &&
arc.currentArcStartAngle! <= chartPointAngle &&
chartPointAngle <= arc.currentArcEndAngle!) {
nearest.add(
DatumDetails<D>(
series: arcList.series,
datum: arc.datum,
domain: arc.domain,
domainDistance: 0,
measureDistance: 0,
),
);
}
}
}
return nearest;
}