Browse Source

UI: Minor fixes.

pull/13033/head
Igor Kulikov 1 year ago
parent
commit
dedf3db928
  1. 60
      ui-ngx/src/app/modules/home/components/widget/lib/chart/latest-chart.ts
  2. 12
      ui-ngx/src/app/modules/home/components/widget/lib/chart/time-series-chart.ts
  3. 78
      ui-ngx/src/app/modules/home/models/dashboard-component.models.ts

60
ui-ngx/src/app/modules/home/components/widget/lib/chart/latest-chart.ts

@ -223,40 +223,42 @@ export abstract class TbLatestChart<S extends LatestChartSettings> {
}
protected updateSeriesData(initial = false) {
this.total = 0;
this.totalText = 'N/A';
let hasValue = false;
for (const dataItem of this.dataItems) {
if (dataItem.enabled && dataItem.hasValue) {
hasValue = true;
this.total += dataItem.value;
}
if (this.settings.showLegend) {
const legendItem = this.legendItems.find(item => item.dataKey === dataItem.dataKey);
if (dataItem.hasValue) {
legendItem.hasValue = true;
legendItem.value = formatValue(dataItem.value, this.decimals, this.units, false);
} else {
legendItem.hasValue = false;
legendItem.value = '--';
if (!this.latestChart.isDisposed()) {
this.total = 0;
this.totalText = 'N/A';
let hasValue = false;
for (const dataItem of this.dataItems) {
if (dataItem.enabled && dataItem.hasValue) {
hasValue = true;
this.total += dataItem.value;
}
if (this.settings.showLegend) {
const legendItem = this.legendItems.find(item => item.dataKey === dataItem.dataKey);
if (dataItem.hasValue) {
legendItem.hasValue = true;
legendItem.value = formatValue(dataItem.value, this.decimals, this.units, false);
} else {
legendItem.hasValue = false;
legendItem.value = '--';
}
}
}
}
if (this.settings.showTotal || this.settings.showLegend) {
if (hasValue) {
this.totalText = formatValue(this.total, this.decimals, this.units, false);
if (this.settings.showLegend && !this.settings.showTotal) {
this.legendItems[this.legendItems.length - 1].hasValue = true;
this.legendItems[this.legendItems.length - 1].value = this.totalText;
if (this.settings.showTotal || this.settings.showLegend) {
if (hasValue) {
this.totalText = formatValue(this.total, this.decimals, this.units, false);
if (this.settings.showLegend && !this.settings.showTotal) {
this.legendItems[this.legendItems.length - 1].hasValue = true;
this.legendItems[this.legendItems.length - 1].value = this.totalText;
}
} else if (this.settings.showLegend && !this.settings.showTotal) {
this.legendItems[this.legendItems.length - 1].hasValue = false;
this.legendItems[this.legendItems.length - 1].value = '--';
}
} else if (this.settings.showLegend && !this.settings.showTotal) {
this.legendItems[this.legendItems.length - 1].hasValue = false;
this.legendItems[this.legendItems.length - 1].value = '--';
}
this.doUpdateSeriesData();
this.latestChart.setOption(this.latestChartOption);
this.afterUpdateSeriesData(initial);
}
this.doUpdateSeriesData();
this.latestChart.setOption(this.latestChartOption);
this.afterUpdateSeriesData(initial);
}
private drawChart() {

12
ui-ngx/src/app/modules/home/components/widget/lib/chart/time-series-chart.ts

@ -690,12 +690,14 @@ export class TbTimeSeriesChart {
}
private updateSeriesData(updateScale = false): void {
this.updateSeries();
if (updateScale && this.updateYAxisScale(this.yAxisList)) {
this.timeSeriesChartOptions.yAxis = this.yAxisList.map(axis => axis.option);
if (!this.timeSeriesChart.isDisposed()) {
this.updateSeries();
if (updateScale && this.updateYAxisScale(this.yAxisList)) {
this.timeSeriesChartOptions.yAxis = this.yAxisList.map(axis => axis.option);
}
this.timeSeriesChart.setOption(this.timeSeriesChartOptions);
this.updateAxes();
}
this.timeSeriesChart.setOption(this.timeSeriesChartOptions);
this.updateAxes();
}
private updateSeries(): void {

78
ui-ngx/src/app/modules/home/models/dashboard-component.models.ts

@ -468,49 +468,51 @@ export class DashboardWidget implements GridsterItem, IDashboardWidget {
const resizable = item.resize;
this.heightValue = resizable.height;
this.widthValue = resizable.width;
const setItemHeight = resizable.setItemHeight.bind(resizable);
const setItemWidth = resizable.setItemWidth.bind(resizable);
resizable.setItemHeight = (height) => {
setItemHeight(height);
this.heightValue = height;
if (this.preserveAspectRatio) {
setItemWidth(height * this.aspectRatio);
}
};
resizable.setItemWidth = (width) => {
setItemWidth(width);
this.widthValue = width;
if (this.preserveAspectRatio) {
setItemHeight(width / this.aspectRatio);
}
};
Object.defineProperty(resizable, 'height', {
get: () => this.heightValue,
set: v => {
if (this.heightValue !== v) {
if (this.preserveAspectRatio) {
this.widthValue = v * this.aspectRatio;
if (resizable) {
this.heightValue = resizable.height;
this.widthValue = resizable.width;
const setItemHeight = resizable.setItemHeight.bind(resizable);
const setItemWidth = resizable.setItemWidth.bind(resizable);
resizable.setItemHeight = (height) => {
setItemHeight(height);
this.heightValue = height;
if (this.preserveAspectRatio) {
setItemWidth(height * this.aspectRatio);
}
};
resizable.setItemWidth = (width) => {
setItemWidth(width);
this.widthValue = width;
if (this.preserveAspectRatio) {
setItemHeight(width / this.aspectRatio);
}
};
Object.defineProperty(resizable, 'height', {
get: () => this.heightValue,
set: v => {
if (this.heightValue !== v) {
if (this.preserveAspectRatio) {
this.widthValue = v * this.aspectRatio;
}
this.heightValue = v;
}
this.heightValue = v;
}
}
});
});
Object.defineProperty(resizable, 'width', {
get: () => this.widthValue,
set: v => {
if (this.widthValue !== v) {
if (this.preserveAspectRatio) {
this.heightValue = v / this.aspectRatio;
Object.defineProperty(resizable, 'width', {
get: () => this.widthValue,
set: v => {
if (this.widthValue !== v) {
if (this.preserveAspectRatio) {
this.heightValue = v / this.aspectRatio;
}
this.widthValue = v;
}
this.widthValue = v;
}
}
});
});
}
this.preserveAspectRatioApplied = true;
}
}

Loading…
Cancel
Save