Skip to content

Commit 46f4cfc

Browse files
authored
Merge pull request #4024 from plotly/schema-animatable-anim-fixes
Schema animatable + anim fixes
2 parents 68f2009 + a1d1d18 commit 46f4cfc

File tree

4 files changed

+72
-2
lines changed

4 files changed

+72
-2
lines changed

src/plot_api/plot_api.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -2811,7 +2811,11 @@ function diffData(gd, oldFullData, newFullData, immutable, transition, newDataRe
28112811
var i, trace;
28122812

28132813
function getTraceValObject(parts) {
2814-
return PlotSchema.getTraceValObject(trace, parts);
2814+
var out = PlotSchema.getTraceValObject(trace, parts);
2815+
if(!trace._module.animatable && out.anim) {
2816+
out.anim = false;
2817+
}
2818+
return out;
28152819
}
28162820

28172821
var diffOpts = {

src/plot_api/plot_schema.js

+10-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
* LICENSE file in the root directory of this source tree.
77
*/
88

9-
109
'use strict';
1110

1211
var Registry = require('../registry');
@@ -504,6 +503,7 @@ function getTraceAttributes(type) {
504503
var out = {
505504
meta: _module.meta || {},
506505
categories: _module.categories || {},
506+
animatable: Boolean(_module.animatable),
507507
type: type,
508508
attributes: formatAttributes(attributes),
509509
};
@@ -516,6 +516,15 @@ function getTraceAttributes(type) {
516516
out.layoutAttributes = formatAttributes(layoutAttributes);
517517
}
518518

519+
// drop anim:true in non-animatable modules
520+
if(!_module.animatable) {
521+
exports.crawl(out, function(attr) {
522+
if(exports.isValObject(attr) && 'anim' in attr) {
523+
delete attr.anim;
524+
}
525+
});
526+
}
527+
519528
return out;
520529
}
521530

test/jasmine/bundle_tests/plotschema_test.js

+16
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,22 @@ describe('plot schema', function() {
377377
expect(traces.parcoords.attributes.hoverinfo).toBe(undefined, 'no hover attrs for parcoords');
378378
expect(traces.scatter3d.attributes.selectedpoints).toBe(undefined, 'no selectedpoints for gl3d traces');
379379
});
380+
381+
it('traces that are not animatable should not list `anim:true` attributes', function() {
382+
var notAnimatable = Object.keys(plotSchema.traces).filter(function(traceType) {
383+
return !plotSchema.traces[traceType].animatable;
384+
});
385+
386+
notAnimatable.forEach(function(traceType) {
387+
Plotly.PlotSchema.crawl(plotSchema.traces[traceType].attributes, function() {
388+
var attr = arguments[0];
389+
var astr = arguments[4];
390+
if(Plotly.PlotSchema.isValObject(attr) && 'anim' in attr) {
391+
fail('Trace module ' + traceType + ' sets *' + astr + '* with anim:true');
392+
}
393+
});
394+
});
395+
});
380396
});
381397

382398
describe('getTraceValObject', function() {

test/jasmine/tests/transition_test.js

+41
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,47 @@ describe('Plotly.react transitions:', function() {
431431
.then(done);
432432
});
433433

434+
it('should no try to transition a trace which is not *animatable:true* yet', function(done) {
435+
addSpies();
436+
437+
var trace = {
438+
type: 'bar',
439+
y: [1],
440+
marker: {line: {width: 1}}
441+
};
442+
443+
var data = [trace];
444+
var layout = {transition: {duration: 10}};
445+
446+
// sanity check that this test actually tests what was intended
447+
var Bar = Registry.modules.bar._module;
448+
if(Bar.animatable || Bar.attributes.marker.line.width.anim !== true) {
449+
fail('Test no longer tests its indented code path:' +
450+
' This test is meant to test that Plotly.react with' +
451+
' *anim:true* attributes in *animatable:false* modules' +
452+
' does not trigger Plots.transitionFromReact calls.'
453+
);
454+
}
455+
456+
Plotly.react(gd, data, layout)
457+
.then(function() {
458+
assertSpies('first draw', [
459+
[Plots, 'transitionFromReact', 0]
460+
]);
461+
})
462+
.then(function() {
463+
trace.marker.line.width = 5;
464+
return Plotly.react(gd, data, layout);
465+
})
466+
.then(function() {
467+
assertSpies('after (transition) react call', [
468+
[Plots, 'transitionFromReact', 0]
469+
]);
470+
})
471+
.catch(failTest)
472+
.then(done);
473+
});
474+
434475
it('should not try to transition when the *config* has changed', function(done) {
435476
addSpies();
436477

0 commit comments

Comments
 (0)