updateCommonChart method

void updateCommonChart(
  1. BaseChart<D> chart,
  2. BaseChart<D>? oldWidget,
  3. BaseChartState<D> chartState
)

Updates the common.BaseChart based on changes in the widget properties.

This method is called when the chart widget is updated, allowing the chart to be reconfigured based on the new widget properties.

chart The common.BaseChart instance to update. oldWidget The previous BaseChart widget, if any. chartState The current BaseChartState instance.

Implementation

void updateCommonChart(
  common.BaseChart<D> chart,
  BaseChart<D>? oldWidget,
  BaseChartState<D> chartState,
) {
  common.Performance.time('chartsUpdateRenderers');
  // Set default renderer if one was provided.
  if (defaultRenderer != null &&
      defaultRenderer != oldWidget?.defaultRenderer) {
    chart.defaultRenderer = defaultRenderer!.build();
    chartState.markChartDirty();
  }

  // Add custom series renderers if any were provided.
  if (customSeriesRenderers != null) {
    // TODO: This logic does not remove old renderers and
    // shouldn't require the series configs to remain in the same order.
    for (var i = 0; i < customSeriesRenderers!.length; i++) {
      if (oldWidget == null ||
          (oldWidget.customSeriesRenderers != null &&
              i > oldWidget.customSeriesRenderers!.length) ||
          customSeriesRenderers![i] != oldWidget.customSeriesRenderers![i]) {
        chart.addSeriesRenderer(customSeriesRenderers![i].build());
        chartState.markChartDirty();
      }
    }
  }
  common.Performance.timeEnd('chartsUpdateRenderers');

  common.Performance.time('chartsUpdateBehaviors');
  _updateBehaviors(chart, chartState);
  common.Performance.timeEnd('chartsUpdateBehaviors');

  _updateSelectionModel(chart, chartState);

  chart.transition = animate ? animationDuration : Duration.zero;
}