createSegments method

  1. @override
void createSegments ()
override

Creates a collection of segments for the points in the series.

Implementation

@override
void createSegments() {
  List<num> values = <num>[];
  int segmentIndex = 0;
  for (int i = 0; i < _dataPoints.length; i++) {
    if (_dataPoints.length > 1) {
      if (values != null && values.isNotEmpty && values.length > 2) {
        values[0] = values[2];
        values[1] = values[3];
        values.removeRange(2, 4);
      }
      if (_dataPoints[i].isVisible) {
        if (_dataPoints[i].isGap != true) {
          if (values.isEmpty ||
              (values.isNotEmpty &&
                  !(values[0] == _dataPoints[i].xValue &&
                      values[1] == _dataPoints[i].yValue))) {
            values.add(_dataPoints[i].xValue);
            values.add(_dataPoints[i].yValue);
          }
        }
        if ((i == 0 || _dataPoints[i - 1].isGap == true) &&
            _dataPoints[i].isGap != true &&
            _dataPoints[i + 1].isGap != true &&
            _dataPoints[i + 1].isVisible) {
          values.add(_dataPoints[i + 1].xValue);
          values.add(_dataPoints[i + 1].yValue);
        } else if (_dataPoints[i].isGap == true) {
          values = <num>[];
        }
      }
    }

    if (values != null && values.isNotEmpty && values.length > 2) {
      _createSegment(values, _dataPoints[i], segmentIndex);
      segmentIndex++;
    }
  }
}