drawTocoLine method

void drawTocoLine(
  1. List<int>? tocoEntries,
  2. int pages
)

Draws the TOCO line on the graph for the given list of TOCO entries and pages. tocoEntries is the list of TOCO entries. pages is the number of pages to draw the TOCO line on.

Implementation

void drawTocoLine(List<int>? tocoEntries, int pages) {
  if (mData!.tocoEntries == null) {
    return;
  }

  for (int pageNumber = 0; pageNumber < pages; pageNumber++) {
    double startX, startY, stopX = 0, stopY = 0;
    int startData, stopData = 0;

    for (int i = (pageNumber * pointsPerPage), j = 0;
        i < tocoEntries!.length && j < pointsPerPage;
        i++, j++) {
      startData = stopData;
      stopData = tocoEntries[i];

      startX = stopX;
      startY = stopY;

      stopX = getScreenX(i, pageNumber);
      stopY = getYValueFromToco(tocoEntries[i]); // getScreenY(stopData);

      if (i < 1) continue;
      if (startData == 0 ||
          stopData == 0 ||
          startData > 210 ||
          stopData > 210 ||
          (startData - stopData).abs() > 30) {
        continue;
      }

      // a. If the value is 0, it is not drawn
      // b. If the results of the two values before and after are different by more than 30, they are not connected.

      canvas[pageNumber].drawLine(
          Offset(startX, startY), Offset(stopX, stopY), graphBpmLine!);
    }
  }
}