Skip to content

Commit 7aca3c4

Browse files
committed
Add additional casting
1 parent 14f4874 commit 7aca3c4

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

src/plot_api/plot_api.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2327,7 +2327,11 @@ Plotly.animate = function(gd, frameOrGroupNameOrFrameList, animationOpts) {
23272327
var newFrame = trans._currentFrame = trans._frameQueue.shift();
23282328

23292329
if(newFrame) {
2330-
gd._fullLayout._currentFrame = newFrame.name;
2330+
// Since it's sometimes necessary to do deep digging into frame data,
2331+
// we'll consider it not 100% impossible for nulls or numbers to sneak through,
2332+
// so check when casting the name, just to be absolutely certain:
2333+
var stringName = newFrame.name ? newFrame.name.toString() : null;
2334+
gd._fullLayout._currentFrame = stringName;
23312335

23322336
trans._lastFrameAt = Date.now();
23332337
trans._timeToNext = newFrame.frameOpts.duration;
@@ -2349,7 +2353,7 @@ Plotly.animate = function(gd, frameOrGroupNameOrFrameList, animationOpts) {
23492353
});
23502354

23512355
gd.emit('plotly_animatingframe', {
2352-
name: newFrame.name,
2356+
name: stringName,
23532357
frame: newFrame.frame,
23542358
animation: {
23552359
frame: newFrame.frameOpts,

test/jasmine/tests/command_test.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,12 @@ describe('Plots.computeAPICommandBindings', function() {
444444
expect(result).toEqual([{type: 'layout', prop: '_currentFrame', value: 'framename'}]);
445445
});
446446

447+
it('treats numeric frame names as strings', function() {
448+
var result = Plots.computeAPICommandBindings(gd, 'animate', [[8]]);
449+
450+
expect(result).toEqual([{type: 'layout', prop: '_currentFrame', value: '8'}]);
451+
});
452+
447453
it('binds to nothing for a multi-frame animate command', function() {
448454
var result = Plots.computeAPICommandBindings(gd, 'animate', [['frame1', 'frame2']]);
449455

0 commit comments

Comments
 (0)