paintVertical method

void paintVertical(
  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. bool noSignal,
)

Implementation

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

  final usePeak = noSignal ? minimumLevel : peak ?? 0;

  int minimumPosition = y + height;
  int maximumPosition = y + 0;
  int magnitudePosition = (maximumPosition + (magnitude * scale)).floor();
  int peakPosition = (maximumPosition + (usePeak * scale)).floor();
  int peakHoldPosition = (maximumPosition + (peakHold * scale)).floor();
  int warningPosition = (maximumPosition + (warningLevel * scale)).floor();
  int errorPosition = (maximumPosition + (errorLevel * scale)).floor();

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

  if (clipping) {
    peakPosition = maximumPosition;
  }

  if (peakPosition >= minimumPosition) {
    fillRect(canvas, backgroundColor, x, warningPosition, width, nominalLength);
    fillRect(canvas, backgroundWarningColor, x, errorPosition, width, warningLength);
    fillRect(canvas, backgroundErrorColor, x, maximumPosition, width, errorLength);
  } else if (peakPosition > warningPosition) {
    fillRect(canvas, foregroundColor, x, peakPosition, width, minimumPosition - peakPosition);

    fillRect(canvas, backgroundColor, x, warningPosition, width, peakPosition - warningPosition);
    fillRect(canvas, backgroundWarningColor, x, errorPosition, width, warningLength);
    fillRect(canvas, backgroundErrorColor, x, maximumPosition, width, errorLength);
  } else if (peakPosition > errorPosition) {
    fillRect(canvas, foregroundColor, x, warningPosition, width, nominalLength);
    fillRect(canvas, foregroundWarningColor, x, peakPosition, width, warningPosition - peakPosition);
    fillRect(canvas, backgroundWarningColor, x, errorPosition, width, peakPosition - errorPosition);
    fillRect(canvas, backgroundErrorColor, x, maximumPosition, width, errorLength);
  } else if (peakPosition > maximumPosition) {
    fillRect(canvas, foregroundColor, x, warningPosition, width, nominalLength);
    fillRect(canvas, foregroundWarningColor, x, errorPosition, width, warningLength);
    fillRect(canvas, foregroundErrorColor, x, peakPosition, width, errorPosition - peakPosition);
    fillRect(canvas, backgroundErrorColor, x, maximumPosition, width, peakPosition - maximumPosition);
  } else {
    if (!clipping) {
      clipping = true;
    }

    int end = errorLength + warningLength + nominalLength;
    fillRect(canvas, foregroundErrorColor, x, maximumPosition, width, end);
  }

  if (noSignal) return;

  // Mini box
  if (peakHoldPosition + miniBox > minimumPosition) {
  } else if (peakHoldPosition > warningPosition)
    fillRect(canvas, foregroundColor, x, peakHoldPosition + miniBox, width, miniBox);
  else if (peakHoldPosition > errorPosition)
    fillRect(canvas, foregroundWarningColor, x, peakHoldPosition + miniBox, width, miniBox);
  else
    fillRect(canvas, foregroundErrorColor, x, peakHoldPosition + miniBox, width, miniBox);

  if (magnitudePosition + miniBox < minimumPosition)
    fillRect(canvas, magnitudeColor, x, magnitudePosition + miniBox, width, miniBox);
}