drawAvgLine method Null safety

void drawAvgLine(
  1. Canvas canvas,
  2. Size size,
  3. bool isBottom
)

평균선을 그립니다.

Implementation

void drawAvgLine(Canvas canvas, Size size, bool isBottom) {
  final linePath = Path();
  var current = Offset.zero;

  for (var k = 0; k < barItemsDay!.length; k++) {
    var barDataHour = barItemsDay![k].barDataHour;
    var offsetDx = offset.dx + ((barWidth * hourCntInDay + barSpace * hourCntInDay) * k);

    for (var i = 0; i < barDataHour.length; i++) {
      if (barDataHour[i] == null) continue;
      var barHeight;
      if (isBottom) {
        barHeight = (isGroupAvg ? barDataHour[i]!.groupAvgValueBottom : barDataHour[i]!.totalAvgValueBottom) * barHeightRatio;
        current = Offset(
          offsetDx + barStartOffsetX + yLabelWidth + yLabelMargin + (barWidth / 2) + (barWidth + barSpace) * i,
          baseOffsetY + size.height - xLabelDaySize - xLabelDayMargin - xLabelHourSize - xLabelHourMargin - horizontalLineHeight + barHeight,
        );
      } else {
        barHeight = (isGroupAvg ? barDataHour[i]!.groupAvgValue : barDataHour[i]!.totalAvgValue) * barHeightRatio;
        current = Offset(
          offsetDx + barStartOffsetX + yLabelWidth + yLabelMargin + (barWidth / 2) + (barWidth + barSpace) * i,
          baseOffsetY + size.height - xLabelDaySize - xLabelDayMargin - xLabelHourSize - xLabelHourMargin - horizontalLineHeight - barHeight,
        );
      }

      if (k == 0 && i == 0) {
        linePath.moveTo(current.dx, current.dy);
      } else {
        linePath.lineTo(current.dx, current.dy);
      }

      canvas.drawCircle(current, 3, lineDotPaint);
    }
  }
  canvas.drawPath(linePath, linePaint);
}