Skip to content

Commit 8c8b8d1

Browse files
committed
fix(chartjs): lost customTooltips on update
1 parent 066ef6a commit 8c8b8d1

File tree

1 file changed

+24
-3
lines changed

1 file changed

+24
-3
lines changed

projects/coreui-angular-chartjs/src/lib/chartjs.component.ts

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -182,12 +182,13 @@ export class ChartjsComponent implements IChartjs, AfterViewInit, OnDestroy, OnC
182182
return;
183183
}
184184

185-
if (this.options) {
186-
this.chart.options = { ...this.options };
187-
}
188185

189186
const config = this.chartConfig();
190187

188+
if (this.options) {
189+
Object.assign(this.chart.options, config.options);
190+
}
191+
191192
if (!this.chart.config.data) {
192193
this.chart.config.data = { ...config.data };
193194
this.chartUpdateOutsideAngular();
@@ -222,11 +223,31 @@ export class ChartjsComponent implements IChartjs, AfterViewInit, OnDestroy, OnC
222223
}
223224

224225
private chartConfig() {
226+
this.chartCustomTooltips();
225227
return {
226228
data: this.chartDataConfig(),
227229
options: this.options as ChartOptions,
228230
plugins: this.plugins,
229231
type: this.type
230232
};
231233
}
234+
235+
private chartCustomTooltips() {
236+
if (this.customTooltips) {
237+
const options = this.options
238+
this.options = {
239+
...options,
240+
plugins: {
241+
...options?.plugins,
242+
tooltip: {
243+
...options?.plugins?.tooltip,
244+
enabled: false,
245+
mode: 'index',
246+
position: 'nearest',
247+
external: cuiCustomTooltips
248+
}
249+
}
250+
};
251+
};
252+
};
232253
}

0 commit comments

Comments
 (0)