renderCandles method
Implementation
void renderCandles(CanvasRenderingContext2D ctx) {
candlePoints.clear();
for (var i = 0; i < candleData.length; i++) {
final candleRow = candleData[i];
final x = axis.style.leftMargin + axis.xStepPix * i;
final x0 = x - axis.xStepPix / 2;
final x1 = x + axis.xStepPix / 2;
final y0 = height -
axis.style.bottomMargin -
(candleRow.open - axis.yFrom) / axis.yScaleValue;
final y1 = height -
axis.style.bottomMargin -
(candleRow.close - axis.yFrom) / axis.yScaleValue;
ctx
..beginPath()
..lineWidth = 1;
if (candleRow.open > candleRow.close) {
ctx
..fillStyle = '#dc3912'
..strokeStyle = '#dc3912'
..fillRect(x0, y1, x1 - x0, y0 - y1);
} else {
ctx
..fillStyle = '#33bb33'
..strokeStyle = '#33bb33'
..fillRect(x0, y0, x1 - x0, y1 - y0);
}
final midX = x + 0.5;
var z0 = min(y0, y1);
var z1 = max(y0, y1);
if (candleRow.low < candleRow.open && candleRow.low < candleRow.close) {
z0 = height -
axis.style.bottomMargin -
(candleRow.low - axis.yFrom) / axis.yScaleValue;
}
if (candleRow.high > candleRow.open && candleRow.high > candleRow.close) {
z1 = height -
axis.style.bottomMargin -
(candleRow.high - axis.yFrom) / axis.yScaleValue;
}
ctx
..moveTo(midX, z0)
..lineTo(midX, z1)
..stroke();
candlePoints.add(CandlePoint(x0, y0, x1, y1, candleRow));
}
}