onDrawCart method

  1. @override
void onDrawCart(
  1. Canvas canvas
)
override

Implementation

@override
void onDrawCart(Canvas canvas) {
  if (getValues().isEmpty) {
    return;
  }
  int length = values.length;
  if (getRealItemWidth() * scale < 1.5) {
    drawLineCart(
        canvas: canvas,
        maxLength: length,
        strokeWidth: strokeWidth,
        lineColor: upperColor);
  } else {
    List<double>? maStartYs;
    double startX = 0;
    for (int i = 0; i < length; i++) {
      final item = values[i];
      var high = valueToY(item.high);
      var low = valueToY(item.low);
      double x = indexToX(i) * scale;
      double open = valueToY(item.open);
      double close = valueToY(item.close);
      double cndleHeight = close - open;
      if (cndleHeight.abs() < 1) {
        open = cndleHeight < 0 ? close + 1 : close - 1;
      }

      Color color;
      PaintingStyle style;
      if (item.close >= item.open) {
        color = upperColor;
        style = upperStyle;
      } else {
        color = lowerColor;
        style = lowerStyle;
      }
      drawCandle(
          canvas: canvas,
          style: style,
          strokeWidth: strokeWidth,
          scale: scale,
          color: color,
          dx: x,
          width: getRealItemWidth(),
          highY: high,
          lowY: low,
          closeY: close,
          openY: open);

      if (item.mas != null) {
        double mx = x + getRealItemWidth() / 2 * scale;
        maStartYs ??= List.filled(item.mas!.length, 0);
        for (int m = 0, len = item.mas!.length; m < len; m++) {
          double ma = item.mas![m];
          if (ma > 0) {
            double my = valueToY(ma);
            if (maStartYs[m] == 0) {
              maStartYs[m] = my;
              startX = mx;
            }

            drawLine(
                canvas: canvas,
                startX: startX,
                startY: maStartYs[m],
                endX: mx,
                endY: my,
                strokeWidth: maStrokeWidth,
                color: maDayColors[m]);
            maStartYs[m] = my;
          }
        }
        startX = mx;
      }
    }
  }

  drawHighAndLowMark(canvas);
}