clamp method

GraphViewport clamp(
  1. int count,
  2. double width, {
  3. int keep = 2,
})

Kept so that at least keep rows stay in view on either side.

Implementation

GraphViewport clamp(int count, double width, {int keep = 2}) {
  if (count == 0 || width <= 0) return this;
  final k = math.min(keep, count);
  final most = width / barSpacing - k, least = (k - count).toDouble();
  return GraphViewport(barSpacing: barSpacing, rightOffset: most < least ? least : rightOffset.clamp(least, most));
}