Fix time series charts initialization

This commit is contained in:
Igor Kulikov 2024-03-26 18:03:54 +02:00
parent 2355ebc852
commit 79803292b6

View File

@ -139,8 +139,9 @@ export class TbTimeSeriesChart {
this.settings = mergeDeep({} as TimeSeriesChartSettings, this.settings = mergeDeep({} as TimeSeriesChartSettings,
timeSeriesChartDefaultSettings, timeSeriesChartDefaultSettings,
this.inputSettings as TimeSeriesChartSettings); this.inputSettings as TimeSeriesChartSettings);
const dashboardPageElement = this.ctx.$containerParent.parents('.tb-dashboard-page'); const $dashboardPageElement = this.ctx.$containerParent.parents('.tb-dashboard-page');
this.darkMode = this.settings.darkMode || dashboardPageElement.hasClass('dark'); const dashboardPageElement = $dashboardPageElement.length ? $($dashboardPageElement[$dashboardPageElement.length-1]) : null;
this.darkMode = this.settings.darkMode || dashboardPageElement?.hasClass('dark');
this.setupYAxes(); this.setupYAxes();
this.setupData(); this.setupData();
this.setupThresholds(); this.setupThresholds();
@ -154,8 +155,9 @@ export class TbTimeSeriesChart {
}); });
this.shapeResize$.observe(this.chartElement); this.shapeResize$.observe(this.chartElement);
} }
if (dashboardPageElement) {
this.darkModeObserver = new MutationObserver(mutations => { this.darkModeObserver = new MutationObserver(mutations => {
for(let mutation of mutations) { for (const mutation of mutations) {
if (mutation.type === 'attributes' && mutation.attributeName === 'class') { if (mutation.type === 'attributes' && mutation.attributeName === 'class') {
const darkMode = dashboardPageElement.hasClass('dark'); const darkMode = dashboardPageElement.hasClass('dark');
this.setDarkMode(darkMode); this.setDarkMode(darkMode);
@ -164,6 +166,7 @@ export class TbTimeSeriesChart {
}); });
this.darkModeObserver.observe(dashboardPageElement[0], {attributes: true}); this.darkModeObserver.observe(dashboardPageElement[0], {attributes: true});
} }
}
public update(): void { public update(): void {
for (const item of this.dataItems) { for (const item of this.dataItems) {
@ -269,7 +272,7 @@ export class TbTimeSeriesChart {
} }
this.yMinSubject.complete(); this.yMinSubject.complete();
this.yMaxSubject.complete(); this.yMaxSubject.complete();
this.darkModeObserver.disconnect(); this.darkModeObserver?.disconnect();
} }
public resize(): void { public resize(): void {