Skip to content

Commit

Permalink
make trace uid accept numbers
Browse files Browse the repository at this point in the history
  • Loading branch information
etpinard committed Jan 10, 2019
1 parent c087b0a commit 4ef048f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/plots/plots.js
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,10 @@ function getTraceUids(oldFullData, newData) {
}

for(i = 0; i < len; i++) {
if(tryUid(newData[i].uid, i)) continue;
var newUid = newData[i].uid;
if(typeof newUid === 'number') newUid = String(newUid);

if(tryUid(newUid, i)) continue;
if(i < oldLen && tryUid(oldFullInput[i].uid, i)) continue;
setUid(Lib.randstr(seenUids), i);
}
Expand Down
20 changes: 20 additions & 0 deletions test/jasmine/tests/plots_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,26 @@ describe('Test Plots', function() {

testSanitizeMarginsHasBeenCalledOnlyOnce(gd);
});

it('should accept trace uids as non-empty strings or numbers', function() {
var gd = {
data: [{}, {uid: false}, {uid: 'my-id'}, {uid: ''}, {uid: 0}, {uid: 2}]
};
supplyAllDefaults(gd);

var traceUids = gd._fullLayout._traceUids;
expect(traceUids.length).toBe(6, '# of trace uids');
expect(traceUids[2]).toBe('my-id');
expect(traceUids[4]).toBe('0');
expect(traceUids[5]).toBe('2');

var indicesOfRandomUid = [0, 1, 3];
indicesOfRandomUid.forEach(function(ind) {
var msg = 'fullData[' + ind + '].uid';
expect(typeof traceUids[ind]).toBe('string', msg + 'is a string');
expect(traceUids[ind].length).toBe(6, msg + 'is of length 6');
});
});
});

describe('Plots.supplyLayoutGlobalDefaults should', function() {
Expand Down

0 comments on commit 4ef048f

Please sign in to comment.