drawCandle method

void drawCandle(
  1. CandleEntity curPoint,
  2. Canvas canvas,
  3. double curX
)

Implementation

void drawCandle(CandleEntity curPoint, Canvas canvas, double curX) {
  var high = getY(curPoint.high);
  var low = getY(curPoint.low);
  var open = getY(curPoint.open);
  var close = getY(curPoint.close);
  double r = mCandleWidth / 2;
  double lineR = mCandleLineWidth / 2;
  if (open >= close) {
    // 实体高度>= CandleLineWidth
    if (open - close < mCandleLineWidth) {
      open = close + mCandleLineWidth;
    }
    chartPaint.color = this.chartColors.upColor;
    canvas.drawRect(
        Rect.fromLTRB(curX - r, close, curX + r, open), chartPaint);
    canvas.drawRect(
        Rect.fromLTRB(curX - lineR, high, curX + lineR, low), chartPaint);
  } else if (close > open) {
    // 实体高度>= CandleLineWidth
    if (close - open < mCandleLineWidth) {
      open = close - mCandleLineWidth;
    }
    chartPaint.color = this.chartColors.dnColor;
    canvas.drawRect(
        Rect.fromLTRB(curX - r, open, curX + r, close), chartPaint);
    canvas.drawRect(
        Rect.fromLTRB(curX - lineR, high, curX + lineR, low), chartPaint);
  }
}