drawBPMLine method

void drawBPMLine(
  1. Canvas canvas,
  2. List<int>? list,
  3. Paint? lineStyle
)

Draws data points and connecting lines for BPM measurements

Implementation

void drawBPMLine(Canvas canvas, List<int>? list, Paint? lineStyle) {
  if (list == null || list.isEmpty) {
    return;
  }

  double startX, startY, stopX = 0, stopY = 0;
  int startData, stopData = 0;

  int i = mOffset;
  for (; i < list.length - 1 && i < (mOffset + pointsPerPage); i++) {
    startData = stopData;
    stopData = list[i];

    startX = stopX;
    startY = stopY;

    stopX = getScreenX(i);
    stopY = getYValueFromBPM(list[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.drawLine(
        Offset(startX, startY), Offset(stopX, stopY), lineStyle!);
  }
}