paintHorizontal method

void paintHorizontal(
  1. Canvas canvas,
  2. int x,
  3. int y,
  4. int width,
  5. int height,
  6. double magnitude,
  7. double? peak,
  8. double peakHold,
  9. double? inputPeakHold,
  10. bool noSignal,
)

Implementation

void paintHorizontal(
  Canvas canvas,
  int x,
  int y,
  int width,
  int height,
  double magnitude,
  double? peak,
  double peakHold,
  double? inputPeakHold,
  bool noSignal,
) {
  final scale = width / minimumLevel;

  peak = noSignal ? minimumLevel : peak;

  int minimumPosition = x + 0;
  int maximumPosition = x + width;
  int magnitudePosition = (maximumPosition - (magnitude * scale)).floor();
  int peakPosition = (maximumPosition - (peak! * scale)).floor();

  // print(
  //     "maximumPosition=$maximumPosition, peak=$peak, peakHold=$peakHold, scale=$scale");
  int peakHoldPosition = (maximumPosition - (peakHold * scale)).floor();

  int warningPosition = (maximumPosition - (warningLevel * scale)).floor();
  int errorPosition = (maximumPosition - (errorLevel * scale)).floor();

  int nominalLength = warningPosition - minimumPosition;
  int warningLength = errorPosition - warningPosition;
  int errorLength = maximumPosition - errorPosition;

  if (clipping) {
    peakPosition = maximumPosition;
  }

  if (peakPosition <= minimumPosition) {
    fillRect(canvas, backgroundColor, minimumPosition, y, nominalLength, height);
    fillRect(canvas, backgroundWarningColor, warningPosition, y, warningLength, height);
    fillRect(canvas, backgroundErrorColor, errorPosition, y, errorLength, height);
  } else if (peakPosition < warningPosition) {
    fillRect(canvas, foregroundColor, minimumPosition, y, peakPosition - minimumPosition, height);
    fillRect(canvas, backgroundColor, peakPosition, y, warningPosition - peakPosition, height);
    fillRect(canvas, backgroundWarningColor, warningPosition, y, warningLength, height);
    fillRect(canvas, backgroundErrorColor, errorPosition, y, errorLength, height);
  } else if (peakPosition < errorPosition) {
    fillRect(canvas, foregroundColor, minimumPosition, y, nominalLength, height);
    fillRect(canvas, foregroundWarningColor, warningPosition, y, peakPosition - warningPosition, height);
    fillRect(canvas, backgroundWarningColor, peakPosition, y, errorPosition - peakPosition, height);
    fillRect(canvas, backgroundErrorColor, errorPosition, y, errorLength, height);
  } else if (peakPosition < maximumPosition) {
    fillRect(canvas, foregroundColor, minimumPosition, y, nominalLength, height);
    fillRect(canvas, foregroundWarningColor, warningPosition, y, warningLength, height);
    fillRect(canvas, foregroundErrorColor, errorPosition, y, peakPosition - errorPosition, height);
    fillRect(canvas, backgroundErrorColor, peakPosition, y, maximumPosition - peakPosition, height);
  } else if (magnitude != 0.0) {
    if (!clipping) {
      clipping = true;
    }

    int end = errorLength + warningLength + nominalLength;
    fillRect(canvas, foregroundErrorColor, minimumPosition, y, end, height);
  }

  if (noSignal) return;

  // Mini peak box
  if (peakHoldPosition - miniBox < minimumPosition) {
  } else if (peakHoldPosition < warningPosition) {
    fillRect(canvas, foregroundColor, peakHoldPosition - miniBox, y, miniBox, height);
  } else if (peakHoldPosition < errorPosition) {
    fillRect(canvas, foregroundWarningColor, peakHoldPosition - miniBox, y, miniBox, height);
  } else {
    fillRect(canvas, foregroundErrorColor, peakHoldPosition - miniBox, y, miniBox, height);
  }

  // Mini trailing box
  if (magnitudePosition - miniBox >= minimumPosition)
    fillRect(canvas, magnitudeColor, magnitudePosition - miniBox, y, miniBox, height);

  //   // summary box
  //   Color peakColor;
  //   if (inputPeakHold < minimumInputLevel)
  //     peakColor = backgroundColor;
  //   else if (inputPeakHold < warningLevel)
  //     peakColor = foregroundColor;
  //   else if (inputPeakHold < errorLevel)
  //     peakColor = foregroundWarningColor;
  //   else if (inputPeakHold <= clipLevel)
  //     peakColor = foregroundErrorColor;
  //   else
  //     peakColor = clipColor;

  //   fillRect(canvas, peakColor, 0, y, miniBox, height);
}