fix problems with low result count breaking insights (#1052)

This commit is contained in:
Anthony Dresser
2018-04-06 15:54:43 -07:00
committed by Karl Burtram
parent 86748e6d69
commit bec8e72688
2 changed files with 24 additions and 5 deletions

View File

@@ -111,7 +111,6 @@ export abstract class ChartInsight extends Disposable implements IInsightsView {
protected abstract get chartType(): ChartType;
constructor(
@Inject(forwardRef(() => ChangeDetectorRef)) private _changeRef: ChangeDetectorRef,
@Inject(forwardRef(() => ElementRef)) private _el: ElementRef,
@@ -127,7 +126,6 @@ export abstract class ChartInsight extends Disposable implements IInsightsView {
// This is because chart.js doesn't auto-update anything other than dataset when re-rendering so defaults are used
// hence it's easier to not render until ready
this.options = mixin(this.options, { maintainAspectRatio: false });
this._isDataAvailable = true;
this._changeRef.detectChanges();
TelemetryUtils.addTelemetry(this._bootstrapService.telemetryService, TelemetryKeys.ChartCreated, { type: this.chartType });
}
@@ -178,6 +176,9 @@ export abstract class ChartInsight extends Disposable implements IInsightsView {
unmemoize(this, 'chartData');
unmemoize(this, 'labels');
this._data = data;
if (isValidData(data)) {
this._isDataAvailable = true;
}
this._changeRef.detectChanges();
}
@@ -226,14 +227,14 @@ export abstract class ChartInsight extends Disposable implements IInsightsView {
data: this._data.rows.map(row => Number(row[i])),
label: this._data.columns[i]
};
}).slice(1);
});
} else {
return this._data.rows[0].map((row, i) => {
return {
data: this._data.rows.map(row => Number(row[i])),
label: 'Series' + i
};
}).slice(1);
});
}
}
}
@@ -284,3 +285,19 @@ export abstract class ChartInsight extends Disposable implements IInsightsView {
this.options = mixin(this.options, options);
}
}
function isValidData(data: IInsightData): boolean {
if (types.isUndefinedOrNull(data)) {
return false;
}
if (types.isUndefinedOrNull(data.columns)) {
return false;
}
if (types.isUndefinedOrNull(data.rows)) {
return false;
}
return true;
}

View File

@@ -351,7 +351,9 @@ export class ChartViewerComponent implements OnInit, OnDestroy, IChartViewAction
this.componentHost.viewContainerRef.clear();
let componentRef = this.componentHost.viewContainerRef.createComponent(componentFactory);
this._chartComponent = <ChartInsight>componentRef.instance;
this._chartComponent.setConfig(this._chartConfig);
if (this._chartComponent.setConfig) {
this._chartComponent.setConfig(this._chartConfig);
}
this._chartComponent.data = this._executeResult;
this._chartComponent.options = mixin(this._chartComponent.options, { animation: { duration: 0 } });
if (this._chartComponent.init) {