applyView method

void applyView(
  1. Json view, {
  2. bool notify = true,
})

Sets the view from state: {barSpacing, rightOffset}, or {last: n} for the last n rows across the plot.

Implementation

void applyView(Json view, {bool notify = true}) {
  if (linear) {
    // `{from, to}`: a stretch of the scale.
    final lo = view['from'], hi = view['to'];
    if (lo is num && hi is num && hi > lo) _setLinear(lo.toDouble(), hi.toDouble());
    return;
  }
  if (view['last'] case final num n) {
    if (plotWidth <= 0) {
      _pendingView = view;
      return;
    }
    viewport = GraphViewport.showLast(n.toInt(), plotWidth, rightOffset: spec.x.rightOffset);
  } else {
    viewport = GraphViewport(
      barSpacing: (view['barSpacing'] as num?)?.toDouble() ?? viewport.barSpacing,
      rightOffset: (view['rightOffset'] as num?)?.toDouble() ?? viewport.rightOffset,
    );
  }
  if (notify) _settle();
}