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 points that no longer exist.
  if (animationPercent == 1.0) {
    final keysToRemove = <String>[];

    seriesPointMap.forEach((String key, List<AnimatedPoint<D>> points) {
      points.removeWhere((AnimatedPoint<D> point) => point.animatingOut);

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

    keysToRemove.forEach(seriesPointMap.remove);
  }

  seriesPointMap.forEach((String key, List<AnimatedPoint<D>> points) {
    points
        .map<PointRendererElement<D>>((AnimatedPoint<D> animatingPoint) =>
            animatingPoint.getCurrentPoint(animationPercent))
        .forEach((point) {
      // Decorate the points with decorators that should appear below the main
      // series data.
      pointRendererDecorators
          .where((decorator) => !decorator.renderAbove)
          .forEach((decorator) {
        decorator.decorate(point, canvas, graphicsFactory!,
            drawBounds: componentBounds!,
            animationPercent: animationPercent,
            rtl: isRtl);
      });

      // Skip points whose center lies outside the draw bounds. Those that lie
      // near the edge will be allowed to render partially outside. This
      // prevents harshly clipping off half of the shape.
      if (point.point!.y != null &&
          componentBounds!.containsPoint(point.point!.toPoint())) {
        final bounds = Rectangle<double>(
            point.point!.x! - point.radiusPx,
            point.point!.y! - point.radiusPx,
            point.radiusPx * 2,
            point.radiusPx * 2);

        if (point.symbolRendererId == defaultSymbolRendererId) {
          symbolRenderer!.paint(canvas, bounds,
              fillColor: point.fillColor,
              strokeColor: point.color,
              strokeWidthPx: point.strokeWidthPx);
        } else {
          final id = point.symbolRendererId;
          if (!config.customSymbolRenderers!.containsKey(id)) {
            throw ArgumentError('Invalid custom symbol renderer id "${id}"');
          }

          final customRenderer = config.customSymbolRenderers![id]!;
          customRenderer.paint(canvas, bounds,
              fillColor: point.fillColor,
              strokeColor: point.color,
              strokeWidthPx: point.strokeWidthPx);
        }
      }

      // Decorate the points with decorators that should appear above the main
      // series data. This is the typical place for labels.
      pointRendererDecorators
          .where((decorator) => decorator.renderAbove)
          .forEach((decorator) {
        decorator.decorate(point, canvas, graphicsFactory!,
            drawBounds: componentBounds!,
            animationPercent: animationPercent,
            rtl: isRtl);
      });
    });
  });
}