attachTo method

  1. @override
void attachTo(
  1. BaseChart<D> chart
)
override

Injects the behavior into a chart.

Implementation

@override
void attachTo(BaseChart<D> chart) {
  if (chart is! CartesianChart<D>) {
    throw ArgumentError(
        'PanBehavior can only be attached to a CartesianChart<D>');
  }

  _chart = chart;
  chart.addGestureListener(_listener);

  // Disable the autoViewport feature to enable panning.
  chart.domainAxis!.autoViewport = false;

  // Wrap domain axis tick provider with the panning behavior one.
  _domainAxisTickProvider =
      PanningTickProvider<D>(chart.domainAxis!.tickProvider!);
  chart.domainAxis!.tickProvider = _domainAxisTickProvider;
}