paint method
Renders the series data on the canvas, using the data generated during the update call.
Implementation
@override
void paint(ChartCanvas canvas, double animationPercent) {
// Clean up the lines that no longer exist.
if (animationPercent == 1.0) {
final keysToRemove = <String>[];
_seriesLineMap.forEach((key, elements) {
elements.removeWhere(
(element) => element.animatingOut,
);
if (elements.isEmpty) {
keysToRemove.add(key);
}
});
keysToRemove.forEach(_seriesLineMap.remove);
}
_seriesLineMap.forEach((key, elements) {
if (config.includeArea) {
elements
.map<List<_AnimatedArea<D>>>(
(animatingElement) => animatingElement.areas!,
)
.expand<_AnimatedArea<D>>((areas) => areas)
.map<_AreaRendererElement<D>>(
(animatingArea) => animatingArea.getCurrentArea(animationPercent),
)
.forEach((area) {
canvas.drawPolygon(
clipBounds: _getClipBoundsForExtent(area.positionExtent),
fill: area.areaColor ?? area.color,
points: area.points.toPoints(),
);
});
}
if (_hasMeasureBounds) {
elements
.map<List<_AnimatedArea<D>>>(
(animatingElement) => animatingElement.bounds!,
)
.expand<_AnimatedArea<D>>((bounds) => bounds)
.map<_AreaRendererElement<D>>(
(animatingBounds) =>
animatingBounds.getCurrentArea(animationPercent),
)
.forEach((bound) {
canvas.drawPolygon(
clipBounds: _getClipBoundsForExtent(bound.positionExtent),
fill: bound.areaColor ?? bound.color,
points: bound.points.toPoints(),
);
});
}
if (config.includeLine) {
elements
.map<List<_AnimatedLine<D>>>(
(animatingElement) => animatingElement.lines,
)
.expand<_AnimatedLine<D>>((lines) => lines)
.map<_LineRendererElement<D>>(
(animatingLine) => animatingLine.getCurrentLine(animationPercent),
)
.forEach((line) {
canvas.drawLine(
clipBounds: _getClipBoundsForExtent(line.positionExtent!),
dashPattern: line.dashPattern,
points: line.points!.toPoints(),
stroke: line.color,
strokeWidthPx: line.strokeWidthPx,
roundEndCaps: line.roundEndCaps,
);
});
}
});
if (config.includePoints) {
_pointRenderer.paint(canvas, animationPercent);
}
}