[Plot] Wait for width before loading (#1975)

Plot waits for element to have width before loading.  Otherwise,
it may make a minmax request with an invalid size parameter.

Fixes https://github.com/nasa/openmct/issues/1974
This commit is contained in:
Pete Richards 2018-04-03 15:03:35 -07:00 committed by Andrew Henry
parent 1a23f2b390
commit fa7298a752

View File

@ -82,6 +82,10 @@ define([
};
PlotController.prototype.loadSeriesData = function (series) {
if (this.$element[0].offsetWidth === 0) {
this.scheduleLoad(series);
return;
}
this.startLoading();
var options = {
size: this.$element[0].offsetWidth,
@ -92,6 +96,26 @@ define([
.then(this.stopLoading.bind(this));
};
PlotController.prototype.scheduleLoad = function (series) {
if (!this.scheduledLoads) {
this.startLoading();
this.scheduledLoads = [];
this.checkForSize = setInterval(function () {
if (this.$element[0].offsetWidth === 0) {
return;
}
this.stopLoading();
this.scheduledLoads.forEach(this.loadSeriesData, this);
delete this.scheduledLoads;
clearInterval(this.checkForSize);
delete this.checkForSize;
}.bind(this));
}
if (this.scheduledLoads.indexOf(series) === -1) {
this.scheduledLoads.push(series);
}
};
PlotController.prototype.addSeries = function (series) {
this.listenTo(series, 'change:yKey', function () {
this.loadSeriesData(series);
@ -126,6 +150,10 @@ define([
PlotController.prototype.destroy = function () {
configStore.untrack(this.config.id);
this.stopListening();
if (this.checkForSize) {
clearInterval(this.checkForSize);
delete this.checkForSize;
}
};
PlotController.prototype.loadMoreData = function (range, purge) {