Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions api-goldens/charts-ng/common/index.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -262,8 +262,6 @@ export class SiChartBaseComponent implements AfterViewInit, OnChanges, OnInit, O
readonly pointer: _angular_core.OutputEmitterRef<AxisPointerEvent>;
refreshSeries(isLive?: boolean, dzToSet?: DataZoomRange): void;
readonly renderer: _angular_core.InputSignal<"canvas" | "svg">;
// @deprecated
resetChart(): void;
resize(): void;
readonly selectedItem: _angular_core.InputSignal<SelectedLegendItem>;
readonly selectionChanged: _angular_core.OutputEmitterRef<any>;
Expand Down
29 changes: 1 addition & 28 deletions projects/charts-ng/common/si-chart-base.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -386,8 +386,7 @@
this.actualOptions.color = changes.options.previousValue.color;
}
if (changes.theme || changes.renderer) {
// need to completely redo the chart for the theme change to take effect
return this.resetChart();
return this.themeSwitch();
}
Comment on lines 388 to 390

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

critical

This change introduces a regression. While themeSwitch() is the correct, more efficient approach for theme changes, it does not handle renderer changes. The chart's renderer can only be set during initialization (echarts.init). The themeSwitch() method does not re-initialize the chart, so changing the renderer input will have no effect.

The previous implementation using resetChart() was correct for renderer changes because it disposed and re-created the chart instance. The logic from resetChart() is still needed for this case.

I suggest splitting the condition to handle renderer changes by re-creating the chart (using the logic from the old resetChart method), and theme-only changes by calling themeSwitch().

    if (changes.renderer) {
      // Re-create the chart to apply the new renderer
      this.applyTheme();

      if (!this.actualOptions) {
        return;
      }

      this.disposeChart();
      this.applyPalette();
      const addOpts = this.additionalOptions();
      if (addOpts?.palette) {
        echarts.util.merge(this.actualOptions.palette, addOpts.palette, true);
      }
      this.themeChanged();
      this.applyStyles();
      this.applyTitles();
      this.ngAfterViewInit(true);
      this.cdRef.markForCheck();
    } else if (changes.theme) {
      this.themeSwitch();
    }


let updates = 0;
Expand Down Expand Up @@ -612,32 +611,6 @@
this.cdRef.markForCheck();
}

/**
* Re-render the whole chart.
* @deprecated The method is deprecated and should not be used directly by the consumer.
*/
resetChart(): void {
this.applyTheme();

if (!this.actualOptions) {
// this can happen if the SiThemeService fires the theme switch when the chart is not
// yet completely initialized
return;
}

this.disposeChart();
this.applyPalette();
const addOpts = this.additionalOptions();
if (addOpts?.palette) {
echarts.util.merge(this.actualOptions.palette, addOpts.palette, true);
}
this.themeChanged();
this.applyStyles();
this.applyTitles();
this.ngAfterViewInit(true); // eslint-disable-line @angular-eslint/no-lifecycle-call
this.cdRef.markForCheck();
}

protected handleLegendClick(legend: CustomLegendItem): void {
this.doToggleSeriesVisibility(legend.name, legend.selected, legend);
this.cdRef.markForCheck();
Expand Down Expand Up @@ -817,7 +790,7 @@
? this.getThemeCustomValue(['externalZoomSlider', 'grid'], {})
: this.getThemeCustomValue(['dataZoom', 'grid'], {});

if (this.showTimeRangeBar()) {

Check warning on line 793 in projects/charts-ng/common/si-chart-base.component.ts

View workflow job for this annotation

GitHub Actions / test

`showTimeRangeBar` is deprecated. The input will be removed in future versions as the time range bar slot is deprecated
const timeBarOptions = this.getThemeCustomValue(['timeRangeBar'], {});
if (customOptions.height && customOptions.bottom) {
this.timeBarBottom.set(customOptions.height + customOptions.bottom);
Expand Down
Loading