drawLine method

void drawLine(
  1. List<int>? bpmList,
  2. int pages,
  3. Paint? style
)

Draws a line on the graph for the given list of BPM values and pages. bpmList is the list of BPM values. pages is the number of pages to draw the line on. style is the paint style to use for the line.

Implementation

void drawLine(List<int>? bpmList, int pages, Paint? style) {
  if (bpmList == 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 < bpmList.length && j < pointsPerPage;
        i++, j++) {
      startData = stopData;
      stopData = bpmList[i];

      startX = stopX;
      startY = stopY;

      stopX = getScreenX(i, pageNumber);
      stopY = getYValueFromBPM(bpmList[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), style!);
    }

    canvas[pageNumber].drawParagraph(
        getParagraphLong("page ${pageNumber + 1} of $pages", 200,
            align: TextAlign.right),
        Offset(screenWidth - paddingRight! - pixelsPerOneCM! * 2,
            screenHeight - pixelsPerOneMM! * 5));
  }
}