-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
Conversation
no @thomasneirynck it is related, but not the same. everytime visualization is rendered its done so twice. first normal render then resize_checker finds out that the size of chart changed (becase before divs height was 0 and now its actual chart height or because legend appeared) and rerenders it again. it doesn't depend on changing any options (the other two issues seem to be problems when chart is rerendered after changing option when that is not needed ) |
@@ -46,7 +46,10 @@ 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 | |||
setTimeout(() => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i don't really like this (and its breaking tests). would returning a promise here be a good idea ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you create a "legend rendered" event and listen for it? Or if render
directly modifies the DOM, perhaps you could listen to for the DOM modification event that adds the legend? I've never really looked at the Renderbot code, so I'm probably not a ton of help here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
legend is waiting for renderbot.chartData to be available. once thats done it'll render in the next digest cycle so its sufficient for renderbot to just wait here after it makes chartData available
expect(renderStub.callCount).to.be(1); | ||
expect(buildStub.callCount).to.be(1); | ||
expect(renderStub.firstCall.args[0]).to.be(football); | ||
renderbot.render('flat data', persistedState).then(() => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you need to return the promise here, or the assertions won't fail the test.
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(() => { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
@@ -64,8 +64,12 @@ export default function VisFactory(Private) { | |||
uiState.on('change', this._uiStateChangeHandler = () => this.render(this.data, this.uiState)); | |||
} | |||
|
|||
this.resizeChecker.stopSchedule(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a pretty serious collection of steps. What do you think about naming it something and adding it as a method to the ResizeChecker
.
Maybe something like:
ResizeChecker.prototype.changeWithoutTriggering = function(block) {
// prevent checking while the block runs
this.stopSchedule();
// run the external code that will cause the size to change
block();
// save the new size, without emitting a change, and restart the schedule
this.saveSize();
this.saveDirty(false);
this.continueSchedule();
};
Which would be used as:
this.resizeChecker.changeWithoutTriggering(() => {
this.handler = handlerTypes[chartType](this) || handlerTypes.column(this);
this._runOnHandler('render');
})
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what do you think about adding function to the vislib class ? (take a look at latest commit) ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like it
LGTM. I like the improvement! |
--------- **Commit 1:** fixing charts to not render twice * Original sha: f7f0f12 * Authored by ppisljar <[email protected]> on 2016-09-20T08:55:55Z **Commit 2:** fixing tests * Original sha: 40234e8 * Authored by ppisljar <[email protected]> on 2016-09-21T07:21:01Z **Commit 3:** fixing based on Spencers comments * Original sha: cdad772 * Authored by ppisljar <[email protected]> on 2016-09-21T19:41:57Z
--------- **Commit 1:** fixing charts to not render twice * Original sha: f7f0f12 * Authored by ppisljar <[email protected]> on 2016-09-20T08:55:55Z **Commit 2:** fixing tests * Original sha: 40234e8 * Authored by ppisljar <[email protected]> on 2016-09-21T07:21:01Z **Commit 3:** fixing based on Spencers comments * Original sha: cdad772 * Authored by ppisljar <[email protected]> on 2016-09-21T19:41:57Z (cherry picked from commit 61d487c)
--------- **Commit 1:** fixing charts to not render twice * Original sha: d386bf04d6899d2d2c884504fd931342e59668be [formerly f7f0f12] * Authored by ppisljar <[email protected]> on 2016-09-20T08:55:55Z **Commit 2:** fixing tests * Original sha: 9eb6e1c53602065bc5b5b39c278876852c1cb672 [formerly 40234e8] * Authored by ppisljar <[email protected]> on 2016-09-21T07:21:01Z **Commit 3:** fixing based on Spencers comments * Original sha: a876c212643aad14444e514a4b38fe67b73ee1d9 [formerly cdad772] * Authored by ppisljar <[email protected]> on 2016-09-21T19:41:57Z Former-commit-id: 61d487c
[backport] PR elastic#8371 to 5.x Former-commit-id: 411db1f
Charts in kibana (pie and point charts) render twice. There are two problems: