onPaint method
Draws segment in series bounds.
Implementation
@override
void onPaint(Canvas canvas) {
if (fillPaint != null && _seriesRenderer._reAnimate ||
(!(_seriesRenderer._chartState!._widgetNeedUpdate &&
_oldSeriesRenderer != null &&
!_seriesRenderer._chartState!._isLegendToggled))) {
_path = Path();
if (!_isTransposed &&
_currentPoint!.lowerQuartile! > _currentPoint!.upperQuartile!) {
final double temp = _upperY;
_upperY = _lowerY;
_lowerY = temp;
}
if (_seriesRenderer._chartState!._isLegendToggled) {
animationFactor = 1;
}
if (_lowerY > _upperY) {
_centersY = _upperY + ((_upperY - _lowerY).abs() / 2);
_topRectY = _centersY - ((_centersY - _upperY).abs() * animationFactor);
_bottomRectY =
_centersY + ((_centersY - _lowerY).abs() * animationFactor);
} else {
_centersY = _lowerY + ((_lowerY - _upperY).abs() / 2);
_topRectY = _centersY - ((_centersY - _upperY).abs() * animationFactor);
_bottomRectY =
_centersY + ((_centersY - _lowerY).abs() * animationFactor);
}
_topLineY = _topRectY - ((_topRectY - _maxY).abs() * animationFactor);
_bottomLineY =
_bottomRectY + ((_bottomRectY - _minY).abs() * animationFactor);
_bottomLineY = _minY < _lowerY
? _bottomRectY + ((_upperY - _maxY).abs() * animationFactor)
: _bottomLineY;
_topLineY = _maxY > _upperY
? _topRectY - ((_lowerY - _minY).abs() * animationFactor)
: _topLineY;
if (_isTransposed) {
if (_lowerX > _upperX) {
_centersY = _upperX + ((_lowerX - _upperX).abs() / 2);
_topRectY =
_centersY + ((_centersY - _lowerX).abs() * animationFactor);
_bottomRectY =
_centersY - ((_centersY - _upperX).abs() * animationFactor);
} else {
_centersY = _lowerX + (_upperX - _lowerX).abs() / 2;
_topRectY =
_centersY + ((_centersY - _upperX).abs() * animationFactor);
_bottomRectY =
_centersY - ((_centersY - _lowerX).abs() * animationFactor);
}
_path.moveTo(_centerMax, _upperY);
_path.lineTo(_centerMax, _lowerY);
if (_centerMax < _upperX) {
_path.moveTo(_bottomRectY, _maxY);
_path.lineTo(
_topRectY - ((_lowerX - _centerMax).abs() * animationFactor),
_maxY);
} else {
_path.moveTo(_topRectY, _maxY);
_path.lineTo(
_topRectY + ((_upperX - _centerMax).abs() * animationFactor),
_maxY);
}
_path.moveTo(_medianX, _upperY);
_path.lineTo(_medianX, _lowerY);
if (_centerMin > _lowerX) {
_path.moveTo(_topRectY, _maxY);
_path.lineTo(
_bottomRectY + ((_upperX - _centerMin).abs() * animationFactor),
_maxY);
} else {
_path.moveTo(_bottomRectY, _maxY);
_path.lineTo(
_bottomRectY - ((_lowerX - _centerMin).abs() * animationFactor),
_maxY);
}
_path.moveTo(_centerMin, _upperY);
_path.lineTo(_centerMin, _lowerY);
if (_boxAndWhiskerSeries.showMean) {
_drawMeanLine(
canvas,
Offset(_currentPoint!.centerMeanPoint!.y,
_currentPoint!.centerMeanPoint!.x),
Size(_series.markerSettings.width, _series.markerSettings.height),
_isTransposed);
}
_lowerX == _upperX
? canvas.drawLine(
Offset(_lowerX, _lowerY), Offset(_upperX, _upperY), fillPaint!)
: _drawRectPath();
} else {
if (_currentPoint!.lowerQuartile! > _currentPoint!.upperQuartile!) {
final double temp = _upperY;
_upperY = _lowerY;
_lowerY = temp;
}
_drawLine(canvas);
if (_boxAndWhiskerSeries.showMean) {
_drawMeanLine(
canvas,
Offset(_currentPoint!.centerMeanPoint!.x,
_currentPoint!.centerMeanPoint!.y),
Size(_series.markerSettings.width, _series.markerSettings.height),
_isTransposed);
}
_lowerY == _upperY
? canvas.drawLine(
Offset(_lowerX, _lowerY), Offset(_upperX, _upperY), fillPaint!)
: _drawRectPath();
}
if (_series.dashArray[0] != 0 &&
_series.dashArray[1] != 0 &&
_series.animationDuration <= 0) {
canvas.drawPath(_path, fillPaint!);
_drawDashedLine(canvas, _series.dashArray, strokePaint!, _path);
} else {
canvas.drawPath(_path, fillPaint!);
canvas.drawPath(_path, strokePaint!);
}
if (fillPaint!.style == PaintingStyle.fill) {
if (_isTransposed) {
if (_currentPoint!.lowerQuartile! > _currentPoint!.upperQuartile!) {
_drawFillLine(canvas);
}
if (_boxAndWhiskerSeries.showMean) {
_drawMeanLine(
canvas,
Offset(_currentPoint!.centerMeanPoint!.y,
_currentPoint!.centerMeanPoint!.x),
Size(_series.markerSettings.width,
_series.markerSettings.height),
_isTransposed);
}
} else {
_drawLine(canvas);
if (_boxAndWhiskerSeries.showMean) {
_drawMeanLine(
canvas,
Offset(_currentPoint!.centerMeanPoint!.x,
_currentPoint!.centerMeanPoint!.y),
Size(_series.markerSettings.width,
_series.markerSettings.height),
_isTransposed);
}
}
}
} else if (!_seriesRenderer._chartState!._isLegendToggled) {
final BoxAndWhiskerSegment currentSegment = _seriesRenderer
._segments[currentSegmentIndex!] as BoxAndWhiskerSegment;
final BoxAndWhiskerSegment? oldSegment = (currentSegment
._oldSeriesRenderer!._segments.isNotEmpty &&
currentSegment._oldSeriesRenderer!._segments[0]
is BoxAndWhiskerSegment &&
currentSegment._oldSeriesRenderer!._segments.length - 1 >=
currentSegmentIndex!)
? currentSegment._oldSeriesRenderer!._segments[currentSegmentIndex!]
as BoxAndWhiskerSegment?
: null;
_animateBoxSeries(
_boxAndWhiskerSeries.showMean,
Offset(_currentPoint!.centerMeanPoint!.x,
_currentPoint!.centerMeanPoint!.y),
Offset(_currentPoint!.centerMeanPoint!.y,
_currentPoint!.centerMeanPoint!.x),
Size(_series.markerSettings.width, _series.markerSettings.height),
_max,
_isTransposed,
_currentPoint!.lowerQuartile!,
_currentPoint!.upperQuartile!,
_minY,
_maxY,
oldSegment?._minY,
oldSegment?._maxY,
_lowerX,
_lowerY,
_upperX,
_upperY,
_centerMin,
_centerMax,
oldSegment?._lowerX,
oldSegment?._lowerY,
oldSegment?._upperX,
oldSegment?._upperY,
oldSegment?._centerMin,
oldSegment?._centerMax,
_medianX,
_medianY,
animationFactor,
fillPaint!,
strokePaint!,
canvas,
_seriesRenderer);
}
}