-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Minor changes to animation code ahead of the array animation fix #2313
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
Changes from all commits
09924a6
6efb0a7
6d4c86b
1fb2ed1
a666251
b1e538d
1ccf35c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1779,7 +1779,7 @@ plots.graphJson = function(gd, dataonly, mode, output, useDefaults) { | |
plots.modifyFrames = function(gd, operations) { | ||
var i, op, frame; | ||
var _frames = gd._transitionData._frames; | ||
var _hash = gd._transitionData._frameHash; | ||
var _frameHash = gd._transitionData._frameHash; | ||
|
||
for(i = 0; i < operations.length; i++) { | ||
op = operations[i]; | ||
|
@@ -1788,32 +1788,32 @@ plots.modifyFrames = function(gd, operations) { | |
// No reason this couldn't exist, but is currently unused/untested: | ||
/* case 'rename': | ||
frame = _frames[op.index]; | ||
delete _hash[frame.name]; | ||
_hash[op.name] = frame; | ||
delete _frameHash[frame.name]; | ||
_frameHash[op.name] = frame; | ||
frame.name = op.name; | ||
break;*/ | ||
case 'replace': | ||
frame = op.value; | ||
var oldName = (_frames[op.index] || {}).name; | ||
var newName = frame.name; | ||
_frames[op.index] = _hash[newName] = frame; | ||
_frames[op.index] = _frameHash[newName] = frame; | ||
|
||
if(newName !== oldName) { | ||
// If name has changed in addition to replacement, then update | ||
// the lookup table: | ||
delete _hash[oldName]; | ||
_hash[newName] = frame; | ||
delete _frameHash[oldName]; | ||
_frameHash[newName] = frame; | ||
} | ||
|
||
break; | ||
case 'insert': | ||
frame = op.value; | ||
_hash[frame.name] = frame; | ||
_frameHash[frame.name] = frame; | ||
_frames.splice(op.index, 0, frame); | ||
break; | ||
case 'delete': | ||
frame = _frames[op.index]; | ||
delete _hash[frame.name]; | ||
delete _frameHash[frame.name]; | ||
_frames.splice(op.index, 1); | ||
break; | ||
} | ||
|
@@ -2252,14 +2252,6 @@ plots.transition = function(gd, data, layout, traces, frameOpts, transitionOpts) | |
var module = contFull._module; | ||
|
||
if(!module) continue; | ||
|
||
if(!module.animatable) { | ||
var thisUpdate = {}; | ||
|
||
for(var ai in data[i]) { | ||
thisUpdate[ai] = [data[i][ai]]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Strange. I wonder what Ricky had in mind here. Good catch 👌 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could've been just some initial logic that remained there. |
||
} | ||
} | ||
} | ||
|
||
var seq = [plots.previousPromises, interruptPreviousTransitions, prepareTransitions, plots.rehover, executeTransitions]; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,6 +37,44 @@ describe('Test frame api', function() { | |
}); | ||
|
||
describe('#addFrames', function() { | ||
|
||
it('issues a warning if a number-named frame would overwrite a frame', function(done) { | ||
var warnings = []; | ||
spyOn(Lib, 'warn').and.callFake(function(msg) { | ||
warnings.push(msg); | ||
}); | ||
|
||
// Test with both multiframe additions and repeated `addFrames` calls - both should count toward the warn limit | ||
Plotly.addFrames(gd, [ | ||
{name: 8, data: [{x: [8, 7, 6]}]}, | ||
{name: 8888, data: [{x: [8, 7, 6]}]}, | ||
{name: 8, data: [{x: [8, 7, 6]}]}, | ||
{name: '8', data: [{x: [8, 7, 6]}]} | ||
]) | ||
.then(function() { | ||
// so far, two warnings | ||
expect(Lib.warn.calls.count()).toEqual(2); | ||
expect(warnings[0]).toMatch(/^addFrames.*overwriting/); | ||
return Plotly.addFrames(gd, [{name: 8, data: [{x: [3, 2, 1]}]}]); | ||
}) | ||
.then(function() {return Plotly.addFrames(gd, [{name: 8, data: [{x: [3, 2, 1]}]}]);}) | ||
.then(function() {return Plotly.addFrames(gd, [{name: 8, data: [{x: [3, 2, 1]}]}]);}) | ||
.then(function() { | ||
// so far, 5 + 1 warnings | ||
expect(Lib.warn.calls.count()).toEqual(5 + 1); | ||
expect(warnings[5]).toMatch(/^addFrames.*suppressed/); | ||
return Plotly.addFrames(gd, [{name: 8, data: [{x: [3, 2, 1]}]}]); | ||
}) | ||
.then(function() {return Plotly.addFrames(gd, [{name: 8, data: [{x: [3, 2, 1]}]}]);}) | ||
.then(function() {return Plotly.addFrames(gd, [{name: 8, data: [{x: [3, 2, 1]}]}]);}) | ||
.then(function() {return Plotly.addFrames(gd, [{name: 8, data: [{x: [3, 2, 1]}]}]);}) | ||
.then(function() {return Plotly.addFrames(gd, [{name: 8, data: [{x: [3, 2, 1]}]}]);}) | ||
.then(function() { | ||
// Five (`var numericNameWarningCountLimit = 5`) warnings and one warning saying that there won't be more warnings | ||
expect(Lib.warn.calls.count()).toEqual(5 + 1); | ||
}).catch(fail).then(done); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Excellent test. Thanks! |
||
}); | ||
|
||
it('treats an undefined list as a noop', function(done) { | ||
Plotly.addFrames(gd, undefined).then(function() { | ||
expect(Object.keys(h)).toEqual([]); | ||
|
@@ -102,20 +140,6 @@ describe('Test frame api', function() { | |
}).catch(fail).then(done); | ||
}); | ||
|
||
it('issues a warning if a number-named frame would overwrite a frame', function(done) { | ||
var warnings = []; | ||
spyOn(Lib, 'warn').and.callFake(function(msg) { | ||
warnings.push(msg); | ||
}); | ||
|
||
Plotly.addFrames(gd, [{name: 2}]).then(function() { | ||
return Plotly.addFrames(gd, [{name: 2, layout: {foo: 'bar'}}]); | ||
}).then(function() { | ||
expect(warnings.length).toEqual(1); | ||
expect(warnings[0]).toMatch(/overwriting/); | ||
}).catch(fail).then(done); | ||
}); | ||
|
||
it('avoids name collisions', function(done) { | ||
Plotly.addFrames(gd, [{name: 'frame 0'}, {name: 'frame 2'}]).then(function() { | ||
expect(f).toEqual([{name: 'frame 0'}, {name: 'frame 2'}]); | ||
|
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.
Why
===
instead of>
?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.
Explanation of 1st commit: it looked to me as though
Lib.warn
continued to be invoked past the 5 warnings, because I didn't see an actual condition that'd bypass this code path, so I added an extra condition in theif
line. With the commit, ifnumericNameWarningCount >= numericNameWarningCountLimit
then it doesn't descend in theif
, so it won't warn there anymore. The condition for raising the "Too many warnings" is an equality check, becausenumericNameWarningCount
is initially 0 but gets incremented past the condition check ie. before this check. IfnumericNameWarningCount
is 5 here, then we've been through this conditional branch 5 times (withnumericNameWarningCount
values 1, 2, 3, 4, 5); we emit the "too many warning" things and won't come into this conditional branch again. Hope I got it right but maybe you're seeing an off-by-one error?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.
Ok. That makes sense. Can we add a test for this? Using jasmine
spyOn(Lib, 'warn')
should make this task relatively easy.