Skip to content

Commit 14f4874

Browse files
committed
Prevent crazy excessive warnings, just in case
1 parent f0ff634 commit 14f4874

File tree

3 files changed

+29
-17
lines changed

3 files changed

+29
-17
lines changed

src/plot_api/plot_api.js

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2528,7 +2528,7 @@ Plotly.animate = function(gd, frameOrGroupNameOrFrameList, animationOpts) {
25282528
Plotly.addFrames = function(gd, frameList, indices) {
25292529
gd = helpers.getGraphDiv(gd);
25302530

2531-
var hasBeenWarnedAboutNumericNames = false;
2531+
var numericNameWarningCount = 0;
25322532

25332533
if(frameList === null || frameList === undefined) {
25342534
return Promise.resolve();
@@ -2563,8 +2563,20 @@ Plotly.addFrames = function(gd, frameList, indices) {
25632563
var name = (_hash[frameList[i].name] || {}).name;
25642564
var newName = frameList[i].name;
25652565

2566-
if (name && newName && typeof newName === 'number' && _hash[name]) {
2567-
Lib.warn('addFrames: overwriting frame "' + _hash[name].name + '" with a frame whose name of type "number" also equates to "' + name + '". This is valid but may potentially lead to unexpected behavior since all plotly.js frame names are stored internally as strings.');
2566+
if(name && newName && typeof newName === 'number' && _hash[name]) {
2567+
numericNameWarningCount++;
2568+
2569+
Lib.warn('addFrames: overwriting frame "' + _hash[name].name +
2570+
'" with a frame whose name of type "number" also equates to "' +
2571+
name + '". This is valid but may potentially lead to unexpected ' +
2572+
'behavior since all plotly.js frame names are stored internally ' +
2573+
'as strings.');
2574+
2575+
if(numericNameWarningCount > 5) {
2576+
Lib.warn('addFrames: This API call has yielded too many warnings. ' +
2577+
'For the rest of this call, further warnings about numeric frame ' +
2578+
'names will be suppressed.');
2579+
}
25682580
}
25692581

25702582
insertions.push({
@@ -2587,7 +2599,7 @@ Plotly.addFrames = function(gd, frameList, indices) {
25872599
for(i = insertions.length - 1; i >= 0; i--) {
25882600
frame = insertions[i].frame;
25892601

2590-
if (typeof frame.name === 'number') {
2602+
if(typeof frame.name === 'number') {
25912603
Lib.warn('Warning: addFrames accepts frames with numeric names, but the numbers are' +
25922604
'implicitly cast to strings');
25932605

src/plots/plots.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1484,8 +1484,8 @@ plots.computeFrame = function(gd, frameName) {
14841484
// properly cast to strings. We really just want to ensure here that this
14851485
// 1) doesn't fail, and
14861486
// 2) doens't give an incorrect answer (which String(frameName) would)
1487-
if (!frameName) {
1488-
throw new Error('computeFrame must be given a string frame name')
1487+
if(!frameName) {
1488+
throw new Error('computeFrame must be given a string frame name');
14891489
}
14901490

14911491
var framePtr = frameLookup[frameName.toString()];

test/jasmine/tests/frame_api_test.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -74,36 +74,36 @@ describe('Test frame api', function() {
7474
});
7575

7676
it('creates multiple unnamed frames in series', function(done) {
77-
Plotly.addFrames(gd, [{}]).then(function () {
78-
return Plotly.addFrames(gd, [{}])
77+
Plotly.addFrames(gd, [{}]).then(function() {
78+
return Plotly.addFrames(gd, [{}]);
7979
}).then(function() {
8080
expect(f).toEqual([{name: 'frame 0'}, {name: 'frame 1'}]);
8181
}).catch(fail).then(done);
8282
});
8383

84-
it('casts number names to strings on insertion', function (done) {
85-
Plotly.addFrames(gd, [{name: 2}]).then(function () {
84+
it('casts number names to strings on insertion', function(done) {
85+
Plotly.addFrames(gd, [{name: 2}]).then(function() {
8686
expect(f).toEqual([{name: '2'}]);
8787
}).catch(fail).then(done);
8888
});
8989

90-
it('updates frames referenced by number', function (done) {
91-
Plotly.addFrames(gd, [{name: 2}]).then(function () {
90+
it('updates frames referenced by number', function(done) {
91+
Plotly.addFrames(gd, [{name: 2}]).then(function() {
9292
return Plotly.addFrames(gd, [{name: 2, layout: {foo: 'bar'}}]);
93-
}).then(function () {
93+
}).then(function() {
9494
expect(f).toEqual([{name: '2', layout: {foo: 'bar'}}]);
9595
}).catch(fail).then(done);
9696
});
9797

98-
it('issues a warning if a number-named frame would overwrite a frame', function (done) {
98+
it('issues a warning if a number-named frame would overwrite a frame', function(done) {
9999
var warnings = [];
100-
spyOn(Lib, 'warn').and.callFake(function (msg){
100+
spyOn(Lib, 'warn').and.callFake(function(msg) {
101101
warnings.push(msg);
102102
});
103103

104-
Plotly.addFrames(gd, [{name: 2}]).then(function () {
104+
Plotly.addFrames(gd, [{name: 2}]).then(function() {
105105
return Plotly.addFrames(gd, [{name: 2, layout: {foo: 'bar'}}]);
106-
}).then(function () {
106+
}).then(function() {
107107
expect(warnings.length).toEqual(1);
108108
expect(warnings[0]).toMatch(/overwriting/);
109109
}).catch(fail).then(done);

0 commit comments

Comments
 (0)