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) {
  ActualRangeChangedArgs rangeChangedArgs;
  if (_axisDetails.dateTimeCategoryAxis.labelPlacement ==
      LabelPlacement.betweenTicks) {
    range.minimum -= 0.5;
    range.maximum += 0.5;
    range.delta = range.maximum - range.minimum;
  }

  if (_axisDetails.dateTimeCategoryAxis.isVisible &&
      !(_axisDetails.dateTimeCategoryAxis.minimum != null &&
          _axisDetails.dateTimeCategoryAxis.maximum != null)) {
    ///Calculating range padding
    _axisDetails.applyRangePaddings(
        this, _axisDetails.stateProperties, range, interval!);
  }

  calculateVisibleRange(
      Size(_axisDetails.rect.width, _axisDetails.rect.height));

  /// Setting range as visible zoomRange
  if ((_axisDetails.dateTimeCategoryAxis.visibleMinimum != null ||
          _axisDetails.dateTimeCategoryAxis.visibleMaximum != null) &&
      (_axisDetails.dateTimeCategoryAxis.visibleMinimum !=
          _axisDetails.dateTimeCategoryAxis.visibleMaximum) &&
      (!_axisDetails.stateProperties.isRedrawByZoomPan)) {
    _axisDetails.stateProperties.isRedrawByZoomPan = false;
    _axisDetails.visibleRange!.minimum = _axisDetails.visibleMinimum != null
        ? _axisDetails.getEffectiveRange(
            DateTime.fromMillisecondsSinceEpoch(
                _axisDetails.visibleMinimum!.toInt()),
            true)
        : _axisDetails.getEffectiveRange(
                _axisDetails.dateTimeCategoryAxis.visibleMinimum, true) ??
            _axisDetails.actualRange!.minimum;
    _axisDetails.visibleRange!.maximum = _axisDetails.visibleMaximum != null
        ? _axisDetails.getEffectiveRange(
            DateTime.fromMillisecondsSinceEpoch(
                _axisDetails.visibleMaximum!.toInt()),
            false)
        : _axisDetails.getEffectiveRange(
                _axisDetails.dateTimeCategoryAxis.visibleMaximum, false) ??
            _axisDetails.actualRange!.maximum;
    if (_axisDetails.dateTimeCategoryAxis.labelPlacement ==
        LabelPlacement.betweenTicks) {
      _axisDetails.visibleRange!.minimum = _axisDetails.visibleMinimum != null
          ? _axisDetails.getEffectiveRange(
                  DateTime.fromMillisecondsSinceEpoch(
                      _axisDetails.visibleMinimum!.toInt()),
                  true)! -
              0.5
          : (_axisDetails.dateTimeCategoryAxis.visibleMinimum != null
              ? _axisDetails.getEffectiveRange(
                      _axisDetails.dateTimeCategoryAxis.visibleMinimum,
                      true)! -
                  0.5
              : _axisDetails.visibleRange!.minimum);
      _axisDetails.visibleRange!.maximum = _axisDetails.visibleMaximum != null
          ? _axisDetails.getEffectiveRange(
                  DateTime.fromMillisecondsSinceEpoch(
                      _axisDetails.visibleMaximum!.toInt()),
                  false)! +
              0.5
          : (_axisDetails.dateTimeCategoryAxis.visibleMaximum != null
              ? _axisDetails.getEffectiveRange(
                      _axisDetails.dateTimeCategoryAxis.visibleMaximum,
                      false)! +
                  0.5
              : _axisDetails.visibleRange!.maximum);
    }
    _axisDetails.visibleRange!.delta = _axisDetails.visibleRange!.maximum -
        _axisDetails.visibleRange!.minimum;
    _axisDetails.visibleRange!.interval = interval == null
        ? calculateInterval(_axisDetails.visibleRange!, _axisDetails.axisSize)
        : _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.dateTimeCategoryAxis,
        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
        ? _axisDetails.getEffectiveRange(rangeChangedArgs.visibleMin, true)
        : rangeChangedArgs.visibleMin;
    _axisDetails.visibleRange!.maximum = rangeChangedArgs.visibleMax
            is DateTime
        ? _axisDetails.getEffectiveRange(rangeChangedArgs.visibleMax, false)
        : 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;
  }
}