getNearestDatumDetailPerSeries method
List<DatumDetails<D> >
getNearestDatumDetailPerSeries(
- Point<
double> chartPoint, - bool byDomain,
- Rectangle<
int> ? boundsOverride, { - bool selectOverlappingPoints = false,
- bool selectExactEventLocation = false,
inherited
Datum details of nearest rectangles in the treemap.
Implementation
@override
List<DatumDetails<D>> getNearestDatumDetailPerSeries(
Point<double> chartPoint,
bool byDomain,
Rectangle<int>? boundsOverride, {
bool selectOverlappingPoints = false,
bool selectExactEventLocation = false,
}) {
final nearest = <DatumDetails<D>>[];
// Checks if the [chartPoint] is within bounds.
if (!isPointWithinBounds(chartPoint, boundsOverride)) return nearest;
final root = _treeNodeToRendererElement.entries.first.key;
final queue = Queue<TreeNode<Object>>()..add(root);
while (queue.isNotEmpty) {
final node = queue.removeFirst();
final element = _getRendererElement(node);
if (element.boundingRect.containsPoint(chartPoint)) {
nearest.add(DatumDetails<D>(
index: element.index,
series: element.series,
datum: node,
domain: element.domain,
measure: element.measure,
domainDistance: 0.0,
measureDistance: 0.0,
));
// No need to verify remaining siblings.
queue.clear();
// Only processes nodes whose parents contain the [chartPoint].
// This reduces the number of nodes to verify.
queue.addAll(node.children);
}
}
// Prioritizes nodes with larger depth;
nearest.sort((a, b) {
final nodeA = a.datum as TreeNode<Object>;
final nodeB = b.datum as TreeNode<Object>;
return nodeB.depth.compareTo(nodeA.depth);
});
return nearest;
}