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) { protected updateSeriesData(initial = false) {
this.total = 0; if (!this.latestChart.isDisposed()) {
this.totalText = 'N/A'; this.total = 0;
let hasValue = false; this.totalText = 'N/A';
for (const dataItem of this.dataItems) { let hasValue = false;
if (dataItem.enabled && dataItem.hasValue) { for (const dataItem of this.dataItems) {
hasValue = true; if (dataItem.enabled && dataItem.hasValue) {
this.total += dataItem.value; hasValue = true;
} this.total += dataItem.value;
if (this.settings.showLegend) { }
const legendItem = this.legendItems.find(item => item.dataKey === dataItem.dataKey); if (this.settings.showLegend) {
if (dataItem.hasValue) { const legendItem = this.legendItems.find(item => item.dataKey === dataItem.dataKey);
legendItem.hasValue = true; if (dataItem.hasValue) {
legendItem.value = formatValue(dataItem.value, this.decimals, this.units, false); legendItem.hasValue = true;
} else { legendItem.value = formatValue(dataItem.value, this.decimals, this.units, false);
legendItem.hasValue = false; } else {
legendItem.value = '--'; legendItem.hasValue = false;
legendItem.value = '--';
}
} }
} }
} if (this.settings.showTotal || this.settings.showLegend) {
if (this.settings.showTotal || this.settings.showLegend) { if (hasValue) {
if (hasValue) { this.totalText = formatValue(this.total, this.decimals, this.units, false);
this.totalText = formatValue(this.total, this.decimals, this.units, false); if (this.settings.showLegend && !this.settings.showTotal) {
if (this.settings.showLegend && !this.settings.showTotal) { this.legendItems[this.legendItems.length - 1].hasValue = true;
this.legendItems[this.legendItems.length - 1].hasValue = true; this.legendItems[this.legendItems.length - 1].value = this.totalText;
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() { 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 { private updateSeriesData(updateScale = false): void {
this.updateSeries(); if (!this.timeSeriesChart.isDisposed()) {
if (updateScale && this.updateYAxisScale(this.yAxisList)) { this.updateSeries();
this.timeSeriesChartOptions.yAxis = this.yAxisList.map(axis => axis.option); 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 { 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; const resizable = item.resize;
this.heightValue = resizable.height; if (resizable) {
this.widthValue = resizable.width; this.heightValue = resizable.height;
this.widthValue = resizable.width;
const setItemHeight = resizable.setItemHeight.bind(resizable);
const setItemWidth = resizable.setItemWidth.bind(resizable); const setItemHeight = resizable.setItemHeight.bind(resizable);
resizable.setItemHeight = (height) => { const setItemWidth = resizable.setItemWidth.bind(resizable);
setItemHeight(height); resizable.setItemHeight = (height) => {
this.heightValue = height; setItemHeight(height);
if (this.preserveAspectRatio) { this.heightValue = height;
setItemWidth(height * this.aspectRatio); if (this.preserveAspectRatio) {
} setItemWidth(height * this.aspectRatio);
}; }
resizable.setItemWidth = (width) => { };
setItemWidth(width); resizable.setItemWidth = (width) => {
this.widthValue = width; setItemWidth(width);
if (this.preserveAspectRatio) { this.widthValue = width;
setItemHeight(width / this.aspectRatio); if (this.preserveAspectRatio) {
} setItemHeight(width / this.aspectRatio);
}; }
};
Object.defineProperty(resizable, 'height', {
get: () => this.heightValue, Object.defineProperty(resizable, 'height', {
set: v => { get: () => this.heightValue,
if (this.heightValue !== v) { set: v => {
if (this.preserveAspectRatio) { if (this.heightValue !== v) {
this.widthValue = v * this.aspectRatio; if (this.preserveAspectRatio) {
this.widthValue = v * this.aspectRatio;
}
this.heightValue = v;
} }
this.heightValue = v;
} }
} });
});
Object.defineProperty(resizable, 'width', { Object.defineProperty(resizable, 'width', {
get: () => this.widthValue, get: () => this.widthValue,
set: v => { set: v => {
if (this.widthValue !== v) { if (this.widthValue !== v) {
if (this.preserveAspectRatio) { if (this.preserveAspectRatio) {
this.heightValue = v / this.aspectRatio; this.heightValue = v / this.aspectRatio;
}
this.widthValue = v;
} }
this.widthValue = v;
} }
} });
}); }
this.preserveAspectRatioApplied = true; this.preserveAspectRatioApplied = true;
} }
} }

Loading…
Cancel
Save