drawChart method

  1. @override
void drawChart(
  1. VolumeEntity lastPoint,
  2. VolumeEntity curPoint,
  3. double lastX,
  4. double curX,
  5. Size size,
  6. Canvas canvas,
)
override

Implementation

@override
void drawChart(VolumeEntity lastPoint, VolumeEntity curPoint, double lastX,
    double curX, Size size, Canvas canvas) {
  if (chartStyle.volisDouble) {
    /// 双成交量
    double left =
        curPoint.vol * curPoint.open * 1.2 / (curPoint.close + curPoint.open);
    double right = curPoint.vol *
        (curPoint.close + curPoint.open - curPoint.open * 1.2) /
        (curPoint.close + curPoint.open);
    // double r = mVolWidth / 2;
    double topLeft = getVolY(left);
    double topRight = getVolY(right);
    double bottom = chartRect.bottom;
    if (curPoint.vol != 0) {
      canvas.drawRect(
          Rect.fromLTRB(curX - mVolWidth, topLeft, curX - 1, bottom),
          chartPaint
            ..color =
                curPoint.close > curPoint.open || curPoint.open < curPoint.vol
                    ? chartColors.dnColor
                    : chartColors.upColor);

      canvas.drawRect(Rect.fromLTRB(curX - 1, topLeft, curX + 1, bottom),
          chartPaint..color = Colors.transparent);

      canvas.drawRect(
          Rect.fromLTRB(curX + 1, topRight, curX + mVolWidth, bottom),
          chartPaint
            ..color = curPoint.close > curPoint.open ||
                    curPoint.close >= curPoint.vol
                ? chartColors.upColor
                : chartColors.dnColor);
    }
  } else {
    /// 单成交量
    double r = mVolWidth / 2;
    double top = getVolY(curPoint.vol);
    double bottom = chartRect.bottom;
    if (curPoint.vol != 0) {
      canvas.drawRect(
          Rect.fromLTRB(curX - r, top, curX + r, bottom),
          chartPaint
            ..color = curPoint.close > curPoint.open
                ? chartColors.upColor
                : chartColors.dnColor);
    }
  }

  if (chartStyle.showMAVolume && lastPoint.MA5Volume != 0) {
    drawLine(lastPoint.MA5Volume, curPoint.MA5Volume, canvas, lastX, curX,
        chartColors.ma5Color);
  }

  if (chartStyle.showMAVolume && lastPoint.MA10Volume != 0) {
    drawLine(lastPoint.MA10Volume, curPoint.MA10Volume, canvas, lastX, curX,
        chartColors.ma10Color);
  }
}