detectTappedNode function
Determines if a tap hit a node and returns its id
; returns null if no node is hit
nodes
is the list of SankeyNode objects and tapPos
is the Offset of
the tap event in the canvas coordinate space
Implementation
int? detectTappedNode(List<SankeyNode> nodes, Offset tapPos) {
for (var node in nodes) {
final rect =
Rect.fromLTWH(node.x0, node.y0, node.x1 - node.x0, node.y1 - node.y0);
if (rect.contains(tapPos)) return node.id;
}
return null;
}