applyRangePadding method

  1. @override
void applyRangePadding(
  1. VisibleRange range,
  2. num? interval
)
override

Applies range padding to auto, normal, additional, round, and none types.

Implementation

@override
void applyRangePadding(VisibleRange range, num? interval) {
  _axisDetails.min = range.minimum.toInt();
  _axisDetails.max = range.maximum.toInt();
  ActualRangeChangedArgs rangeChangedArgs;
  if (_axisDetails.dateTimeAxis.minimum == null &&
      _axisDetails.dateTimeAxis.maximum == null) {
    final ChartRangePadding rangePadding =
        _axisDetails.calculateRangePadding(this, _axisDetails.chart);
    final DateTime minimum =
        DateTime.fromMillisecondsSinceEpoch(_axisDetails.min!.toInt());
    final DateTime maximum =
        DateTime.fromMillisecondsSinceEpoch(_axisDetails.max!.toInt());
    if (rangePadding == ChartRangePadding.none) {
      _axisDetails.min = minimum.millisecondsSinceEpoch;
      _axisDetails.max = maximum.millisecondsSinceEpoch;
    } else if (rangePadding == ChartRangePadding.additional ||
        rangePadding == ChartRangePadding.round) {
      switch (_axisDetails.actualIntervalType) {
        case DateTimeIntervalType.years:
          _axisDetails._calculateYear(
              minimum, maximum, rangePadding, interval!.toInt());
          break;
        case DateTimeIntervalType.months:
          _axisDetails._calculateMonth(
              minimum, maximum, rangePadding, interval!.toInt());
          break;
        case DateTimeIntervalType.days:
          _axisDetails._calculateDay(
              minimum, maximum, rangePadding, interval!.toInt());
          break;
        case DateTimeIntervalType.hours:
          _axisDetails._calculateHour(
              minimum, maximum, rangePadding, interval!.toInt());
          break;
        case DateTimeIntervalType.minutes:
          _axisDetails._calculateMinute(
              minimum, maximum, rangePadding, interval!.toInt());
          break;
        case DateTimeIntervalType.seconds:
          _axisDetails._calculateSecond(
              minimum, maximum, rangePadding, interval!.toInt());
          break;
        case DateTimeIntervalType.milliseconds:
          _axisDetails._calculateMilliSecond(
              minimum, maximum, rangePadding, interval!.toInt());
          break;
        case DateTimeIntervalType.auto:
          break;
      }
    }
  }
  range.minimum = _axisDetails.min;
  range.maximum = _axisDetails.max;
  range.delta = range.maximum - range.minimum;

  calculateVisibleRange(_axisDetails.axisSize);

  /// Setting range as visible zoomRange
  if ((_axisDetails.dateTimeAxis.visibleMinimum != null ||
          _axisDetails.dateTimeAxis.visibleMaximum != null) &&
      (_axisDetails.dateTimeAxis.visibleMinimum !=
          _axisDetails.dateTimeAxis.visibleMaximum) &&
      (!_axisDetails.stateProperties.isRedrawByZoomPan)) {
    _axisDetails.stateProperties.isRedrawByZoomPan = false;
    _axisDetails.visibleRange!.minimum = _axisDetails.visibleMinimum ??
        (_axisDetails.dateTimeAxis.visibleMinimum != null
            ? _axisDetails.dateTimeAxis.visibleMinimum!.millisecondsSinceEpoch
            : _axisDetails.actualRange!.minimum);
    _axisDetails.visibleRange!.maximum = _axisDetails.visibleMaximum ??
        (_axisDetails.dateTimeAxis.visibleMaximum != null
            ? _axisDetails.dateTimeAxis.visibleMaximum!.millisecondsSinceEpoch
            : _axisDetails.actualRange!.maximum);
    _axisDetails.visibleRange!.delta = _axisDetails.visibleRange!.maximum -
        _axisDetails.visibleRange!.minimum;
    _axisDetails.visibleRange!.interval =
        calculateInterval(_axisDetails.visibleRange!, _axisDetails.axisSize);
    _axisDetails.visibleRange!.interval =
        interval != null && interval % 1 != 0
            ? interval
            : _axisDetails.visibleRange!.interval;
    _axisDetails.zoomFactor =
        _axisDetails.visibleRange!.delta / (range.delta);
    _axisDetails.zoomPosition = (_axisDetails.visibleRange!.minimum -
            _axisDetails.actualRange!.minimum) /
        range.delta;
  }
  if (_axisDetails.chart.onActualRangeChanged != null) {
    rangeChangedArgs = ActualRangeChangedArgs(
        _axisDetails.name!,
        _axisDetails.dateTimeAxis,
        range.minimum,
        range.maximum,
        range.interval,
        _axisDetails.orientation!);
    rangeChangedArgs.visibleMin = _axisDetails.visibleRange!.minimum;
    rangeChangedArgs.visibleMax = _axisDetails.visibleRange!.maximum;
    rangeChangedArgs.visibleInterval = _axisDetails.visibleRange!.interval;
    _axisDetails.chart.onActualRangeChanged!(rangeChangedArgs);
    _axisDetails.visibleRange!.minimum =
        rangeChangedArgs.visibleMin is DateTime
            ? rangeChangedArgs.visibleMin.millisecondsSinceEpoch
            : rangeChangedArgs.visibleMin;
    _axisDetails.visibleRange!.maximum =
        rangeChangedArgs.visibleMax is DateTime
            ? rangeChangedArgs.visibleMax.millisecondsSinceEpoch
            : rangeChangedArgs.visibleMax;
    _axisDetails.visibleRange!.delta = _axisDetails.visibleRange!.maximum -
        _axisDetails.visibleRange!.minimum;
    _axisDetails.visibleRange!.interval = rangeChangedArgs.visibleInterval;
    _axisDetails.zoomFactor =
        _axisDetails.visibleRange!.delta / (range.delta);
    _axisDetails.zoomPosition = (_axisDetails.visibleRange!.minimum -
            _axisDetails.actualRange!.minimum) /
        range.delta;
  }
}