paint method

  1. @override
void paint(
  1. ChartCanvas canvas,
  2. double animationPercent
)
override

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((String key, List<_AnimatedElements<D>> elements) {
      elements.removeWhere(
              (_AnimatedElements<D> element) => element.animatingOut);

      if (elements.isEmpty) {
        keysToRemove.add(key);
      }
    });

    keysToRemove.forEach(_seriesLineMap.remove);
  }

  _seriesLineMap.forEach((String key, List<_AnimatedElements<D>> elements) {
    if (config.includeArea) {
      elements
          .map<List<_AnimatedArea<D>>>(
              (_AnimatedElements<D> animatingElement) =>
          animatingElement.areas!)
          .expand<_AnimatedArea<D>>((List<_AnimatedArea<D>> areas) => areas)
          .map<_AreaRendererElement<D>>((_AnimatedArea<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>>>(
              (_AnimatedElements<D> animatingElement) =>
          animatingElement.bounds!)
          .expand<_AnimatedArea<D>>((List<_AnimatedArea<D>> bounds) => bounds)
          .map<_AreaRendererElement<D>>((_AnimatedArea<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>>>(
              (_AnimatedElements<D> animatingElement) =>
          animatingElement.lines)
          .expand<_AnimatedLine<D>>((List<_AnimatedLine<D>> lines) => lines)
          .map<_LineRendererElement<D>>((_AnimatedLine<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);
  }
}