panToDirection method

void panToDirection(
  1. String direction
)

Pans the plot area for given left, right, top, and bottom directions.

To perform this action, the plot area needs to be in zoomed state.

Implementation

void panToDirection(String direction) {
  final RenderBehaviorArea? parent = parentBox as RenderBehaviorArea?;
  if (parent == null) {
    return;
  }

  parent.hideInteractiveTooltip();
  final RenderCartesianAxes? cartesianAxes = parent.cartesianAxes;
  if (cartesianAxes == null) {
    return;
  }
  direction = direction.toLowerCase();
  cartesianAxes.visitChildren((RenderObject child) {
    if (child is RenderChartAxis) {
      final double currentZoomFactor = child.controller.zoomFactor;
      final double increaseZoomPosition =
          child.controller.zoomPosition + (child.isInversed ? -0.1 : 0.1);
      final double decreaseZoomPosition =
          child.controller.zoomPosition + (child.isInversed ? 0.1 : -0.1);
      if ((child.isVertical && direction == 'bottom') ||
          (!child.isVertical && direction == 'left')) {
        child.controller.zoomPosition =
            _minMax(decreaseZoomPosition, 0, 1 - currentZoomFactor);
      } else if ((child.isVertical && direction == 'top') ||
          (!child.isVertical && direction == 'right')) {
        child.controller.zoomPosition =
            _minMax(increaseZoomPosition, 0, 1 - currentZoomFactor);
      }
      if (parent.onZooming != null) {
        _bindZoomEvent(child, parent.onZooming!);
      }
    }
  });
  parent.invalidate();
}