paint method

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

Paints the current bar data on the canvas.

Implementation

@override
void paint(ChartCanvas canvas, double animationPercent) {
  // Clean up the bars that no longer exist.
  if (animationPercent == 1.0) {
    final keysToRemove = HashSet<String>();

    _barStackMap.forEach((String key, List<B> barStackList) {
      barStackList.retainWhere(
          (B bar) => !bar.animatingOut && !bar.targetBar!.measureIsNull!);

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

    // When cleaning up the animation, also clean up the keys used to lookup
    // if a bar is selected.
    for (final key in keysToRemove) {
      _barStackMap.remove(key);
      _currentKeys.remove(key);
    }
    _currentGroupsStackKeys.forEach((domain, keys) {
      keys.removeWhere(keysToRemove.contains);
    });
  }

  _barStackMap.forEach((String stackKey, List<B> barStack) {
    // Turn this into a list so that the getCurrentBar isn't called more than
    // once for each animationPercent if the barElements are iterated more
    // than once.
    final barElements = barStack
        .map((B animatingBar) => animatingBar.getCurrentBar(animationPercent))
        .toList();

    if (barElements.isNotEmpty) {
      paintBar(canvas, animationPercent, barElements);
    }
  });
}