onDragUpdate method

  1. @override
bool onDragUpdate(
  1. Point<double> localPosition,
  2. double scale
)
override

Implementation

@override
bool onDragUpdate(Point<double> localPosition, double scale) {
  // Swipe gestures should be handled by the [PanBehavior].
  if (scale == 1.0) {
    _isZooming = false;
    return super.onDragUpdate(localPosition, scale);
  }

  // No further events in this chain should be handled by [PanBehavior].
  cancelPanning();

  final chart = this.chart;
  if (!_isZooming || lastPosition == null || chart == null) {
    return false;
  }

  // Update the domain axis's viewport scale factor to zoom the chart.
  final domainAxis = chart.domainAxis;

  if (domainAxis == null) {
    return false;
  }

  // This is set during onDragUpdate and NOT onDragStart because we don't yet
  // know during onDragStart whether pan/zoom behavior is panning or zooming.
  // During zoom in / zoom out, domain tick provider set to return existing
  // cached ticks.
  domainAxisTickProvider.mode = PanningTickProviderMode.useCachedTicks;

  // Clamp the scale to prevent zooming out beyond the range of the data, or
  // zooming in so far that we show nothing useful.
  final newScalingFactor =
      min(max(_scalingFactor * scale, _minScalingFactor), _maxScalingFactor);

  domainAxis.setViewportSettings(
      newScalingFactor, domainAxis.viewportTranslatePx,
      drawAreaWidth: chart.drawAreaBounds.width,
      drawAreaHeight: chart.drawAreaBounds.height);

  chart.redraw(skipAnimation: true, skipLayout: true);

  return true;
}