onPaint method
Draws segment in series bounds.
Implementation
@override
void onPaint(Canvas canvas) {
if (fillPaint != null &&
(_seriesRenderer._reAnimate ||
!(_seriesRenderer._chartState!._widgetNeedUpdate &&
!_seriesRenderer._chartState!._isLegendToggled))) {
_path = Path();
_linePath = Path();
if (!_isTransposed &&
_currentPoint!.open > _currentPoint!.close == true) {
final double temp = _closeY;
_closeY = _openY;
_openY = temp;
}
if (_seriesRenderer._chartState!._isLegendToggled) {
animationFactor = 1;
}
_centersY = _closeY + ((_closeY - _openY).abs() / 2);
_topRectY = _centersY - ((_centersY - _closeY).abs() * animationFactor);
_topLineY = _topRectY - ((_topRectY - _highY).abs() * animationFactor);
_bottomRectY = _centersY + ((_centersY - _openY).abs() * animationFactor);
_bottomLineY =
_bottomRectY + ((_bottomRectY - _lowY).abs() * animationFactor);
_bottomLineY = _lowY < _openY
? _bottomRectY - ((_openY - _lowY).abs() * animationFactor)
: _bottomLineY;
_topLineY = _highY > _closeY
? _topRectY + ((_closeY - _highY).abs() * animationFactor)
: _topLineY;
if (_isTransposed) {
(_currentPoint!.open > _currentPoint!.close) == true
? _calculateCandlePositions(_openX, _closeX)
: _calculateCandlePositions(_closeX, _openX);
if (_showSameValue) {
canvas.drawLine(Offset(_centerHighPoint.x, _centerHighPoint.y),
Offset(_centerLowPoint.x, _centerHighPoint.y), fillPaint!);
} else {
_path.moveTo(_topRectY, _highY);
_centerHigh < _closeX
? _path.lineTo(
_topRectY - ((_closeX - _centerHigh).abs() * animationFactor),
_highY)
: _path.lineTo(
_topRectY + ((_closeX - _centerHigh).abs() * animationFactor),
_highY);
_path.moveTo(_bottomRectY, _highY);
_centerLow > _openX
? _path.lineTo(
_bottomRectY +
((_openX - _centerLow).abs() * animationFactor),
_highY)
: _path.lineTo(
_bottomRectY -
((_openX - _centerLow).abs() * animationFactor),
_highY);
_linePath = _path;
}
_openX == _closeX
? canvas.drawLine(
Offset(_openX, _openY), Offset(_closeX, _closeY), fillPaint!)
: _drawRectPath();
} else {
_showSameValue
? canvas.drawLine(Offset(_centerHighPoint.x, _highPoint.y),
Offset(_centerHighPoint.x, _lowPoint.y), fillPaint!)
: _drawLine(canvas);
_openY == _closeY
? canvas.drawLine(
Offset(_openX, _openY), Offset(_closeX, _closeY), fillPaint!)
: _drawRectPath();
}
if (_series.dashArray[0] != 0 &&
_series.dashArray[1] != 0 &&
fillPaint!.style != PaintingStyle.fill &&
_series.animationDuration <= 0) {
_drawDashedLine(canvas, _series.dashArray, fillPaint!, _path);
} else {
canvas.drawPath(_path, fillPaint!);
if (fillPaint!.style == PaintingStyle.fill) {
if (_isTransposed) {
_showSameValue
? canvas.drawLine(
Offset(_centerHighPoint.x, _centerHighPoint.y),
Offset(_centerLowPoint.x, _centerHighPoint.y),
fillPaint!)
: _drawFillLine(canvas);
} else {
_showSameValue
? canvas.drawLine(Offset(_centerHighPoint.x, _highPoint.y),
Offset(_centerHighPoint.x, _lowPoint.y), fillPaint!)
: _drawLine(canvas);
}
}
}
} else if (!_seriesRenderer._chartState!._isLegendToggled) {
_currentSegment =
_seriesRenderer._segments[currentSegmentIndex!] as CandleSegment;
_oldSegment = !_seriesRenderer._reAnimate &&
(_currentSegment._oldSeriesRenderer != null &&
_currentSegment._oldSeriesRenderer!._segments.isNotEmpty &&
_currentSegment._oldSeriesRenderer!._segments[0]
is CandleSegment &&
_currentSegment._oldSeriesRenderer!._segments.length - 1 >=
currentSegmentIndex!)
? _currentSegment._oldSeriesRenderer!._segments[currentSegmentIndex!]
as CandleSegment?
: null;
_animateCandleSeries(
_showSameValue,
_high,
_isTransposed,
_currentPoint!.open!.toDouble(),
_currentPoint!.close!.toDouble(),
_lowY,
_highY,
_oldSegment?._lowY,
_oldSegment?._highY,
_openX,
_openY,
_closeX,
_closeY,
_centerLow,
_centerHigh,
_oldSegment?._openX,
_oldSegment?._openY,
_oldSegment?._closeX,
_oldSegment?._closeY,
_oldSegment?._centerLow,
_oldSegment?._centerHigh,
animationFactor,
fillPaint!,
canvas,
_seriesRenderer);
}
}