Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent charts from rendering twice #8371

Merged
merged 3 commits into from
Sep 22, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/ui/public/vislib/lib/resize_checker.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,10 @@ export default function ResizeCheckerFactory(Private, Notifier) {
}, ms));
};

ResizeChecker.prototype.stopSchedule = function () {
clearTimeout(this._timerId);
};

/**
* Signal that the ResizeChecker should shutdown.
*
Expand Down
10 changes: 9 additions & 1 deletion src/ui/public/vislib/vis.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export default function VisFactory(Private) {
}

this.handler = handlerTypes[chartType](this) || handlerTypes.column(this);
this._runOnHandler('render');
this._runWithoutResizeChecker('render');
};

/**
Expand All @@ -86,6 +86,14 @@ export default function VisFactory(Private) {
}
};

_runWithoutResizeChecker(method) {
this.resizeChecker.stopSchedule();
this._runOnHandler(method);
this.resizeChecker.saveSize();
this.resizeChecker.saveDirty(false);
this.resizeChecker.continueSchedule();
}

_runOnHandler(method) {
try {
this.handler[method]();
Expand Down
9 changes: 5 additions & 4 deletions src/ui/public/vislib_vis_type/__tests__/_vislib_renderbot.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,11 @@ describe('renderbot', function exportWrapper() {
let buildStub = sinon.stub(renderbot, 'buildChartData', _.constant(football));
let renderStub = sinon.stub(renderbot.vislibVis, 'render');

renderbot.render('flat data', persistedState);
expect(renderStub.callCount).to.be(1);
expect(buildStub.callCount).to.be(1);
expect(renderStub.firstCall.args[0]).to.be(football);
return renderbot.render('flat data', persistedState).then(() => {
expect(renderStub.callCount).to.be(1);
expect(buildStub.callCount).to.be(1);
expect(renderStub.firstCall.args[0]).to.be(football);
});
});
});

Expand Down
7 changes: 6 additions & 1 deletion src/ui/public/vislib_vis_type/vislib_renderbot.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,12 @@ module.exports = function VislibRenderbotFactory(Private) {
VislibRenderbot.prototype.buildChartData = buildChartData;
VislibRenderbot.prototype.render = function (esResponse) {
this.chartData = this.buildChartData(esResponse);
this.vislibVis.render(this.chartData, this.uiState);
// to allow legend to render first (wait for angular digest cycle to complete)
return new Promise((resolve, reject) => {
setTimeout(() => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should use $scope.$evalAsync() so that we can be sure that angular has time to finish it's digest, and so that it runs one after we are done.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

renderbot is non-angular library so it doesnt use scope ... do you think its a good idea to introduce it ? i kinda like it to be a separate thing.

resolve(this.vislibVis.render(this.chartData, this.uiState));
});
});
};

VislibRenderbot.prototype.destroy = function () {
Expand Down