drawBPMLine method

void drawBPMLine(
  1. Canvas canvas,
  2. List<int> list,
  3. Paint lineStyle, {
  4. int bpmOffset = 0,
})

Draws data points and connecting lines for BPM measurements. canvas is the canvas to draw on. list is the list of BPM values. lineStyle is the paint style for the line. bpmOffset is the optional offset for BPM values.

Implementation

void drawBPMLine(Canvas canvas, List<int> list, Paint lineStyle,
    {int bpmOffset = 0}) {
  if (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] + bpmOffset); // 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);
  }
}