Skip to content

Commit

Permalink
Refactored determining rendering performance. Fixed tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
alexanderby committed Mar 23, 2017
1 parent 6c3876e commit 1779bc7
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 18 deletions.
34 changes: 18 additions & 16 deletions src/charts/tau.plot.js
Original file line number Diff line number Diff line change
Expand Up @@ -455,22 +455,7 @@ export class Plot extends Emitter {
this._liveSpec.sources = this.getDataSources();
this._liveSpec.settings = this.configGPL.settings;

// Determine if it's better to draw chart without animation
this._liveSpec.settings.initialAnimationSpeed = (
this._liveSpec.settings.initialAnimationSpeed ||
this._liveSpec.settings.animationSpeed);
const animationSpeed = (this._liveSpec.settings.experimentalShouldAnimate(
this._liveSpec.sources,
this._liveSpec.settings
) ? this._liveSpec.settings.initialAnimationSpeed : 0);
this._liveSpec.settings.animationSpeed = animationSpeed;
const setUnitAnimation = (u) => {
u.guide.animationSpeed = animationSpeed;
if (u.units) {
u.units.forEach(setUnitAnimation);
}
};
setUnitAnimation(this._liveSpec.unit);
this._experimentalSetupAnimationSpeed(this._liveSpec);

if (this.isEmptySources(this._liveSpec.sources)) {
return null;
Expand All @@ -487,6 +472,23 @@ export class Plot extends Emitter {
return this._liveSpec;
}

_experimentalSetupAnimationSpeed(spec) {
// Determine if it's better to draw chart without animation
spec.settings.initialAnimationSpeed = (
spec.settings.initialAnimationSpeed ||
spec.settings.animationSpeed);
const animationSpeed = (spec.settings.experimentalShouldAnimate(spec) ? spec.settings.initialAnimationSpeed : 0);
spec.settings.animationSpeed = animationSpeed;
const setUnitAnimation = (u) => {
u.guide = (u.guide || {});
u.guide.animationSpeed = animationSpeed;
if (u.units) {
u.units.forEach(setUnitAnimation);
}
};
setUnitAnimation(spec.unit);
}

_createGPL(liveSpec) {
var gpl = new GPL(liveSpec, this.getScaleFactory(), unitsRegistry, GrammarRegistry);
var structure = gpl.unfoldStructure();
Expand Down
4 changes: 2 additions & 2 deletions src/tau.charts.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ var api = {
syncRenderingInterval: 50,
syncPointerEvents: false,
handleRenderingErrors: true,
experimentalShouldAnimate: (sources, settings) => {
experimentalShouldAnimate: (spec) => {
const div = document.createElement('div');
div.style.position = 'absolute';
div.style.visibility = 'hidden';
Expand Down Expand Up @@ -128,7 +128,7 @@ var api = {
}
const duration = (performance.now() - start);
document.body.removeChild(div);
return (sources['/'].data.length * duration < 500);
return (spec.sources['/'].data.length * duration < 500);
},

defaultNiceColor: true,
Expand Down
1 change: 1 addition & 0 deletions test/utils/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ define(function (require) {
height: 10
};
},
experimentalShouldAnimate: () => true,

fitModel: null, // 'entire-view',
layoutEngine: '', // 'EXTRACT'
Expand Down

0 comments on commit 1779bc7

Please sign in to comment.