nearestIndex method
The column index nearest pixel px, clamped to 0..count-1. A non-finite
px (which would make round() throw) resolves to the first column.
Implementation
int nearestIndex(double px) {
if (count <= 1 || !px.isFinite) return 0;
final slot = bounds.width / (count - 1);
if (slot <= 0) return 0;
final raw = ((px - bounds.left) / slot).round();
return raw.clamp(0, count - 1);
}