Skip to content

Commit 4ef048f

Browse files
committed
make trace uid accept numbers
1 parent c087b0a commit 4ef048f

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

src/plots/plots.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -563,7 +563,10 @@ function getTraceUids(oldFullData, newData) {
563563
}
564564

565565
for(i = 0; i < len; i++) {
566-
if(tryUid(newData[i].uid, i)) continue;
566+
var newUid = newData[i].uid;
567+
if(typeof newUid === 'number') newUid = String(newUid);
568+
569+
if(tryUid(newUid, i)) continue;
567570
if(i < oldLen && tryUid(oldFullInput[i].uid, i)) continue;
568571
setUid(Lib.randstr(seenUids), i);
569572
}

test/jasmine/tests/plots_test.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,26 @@ describe('Test Plots', function() {
153153

154154
testSanitizeMarginsHasBeenCalledOnlyOnce(gd);
155155
});
156+
157+
it('should accept trace uids as non-empty strings or numbers', function() {
158+
var gd = {
159+
data: [{}, {uid: false}, {uid: 'my-id'}, {uid: ''}, {uid: 0}, {uid: 2}]
160+
};
161+
supplyAllDefaults(gd);
162+
163+
var traceUids = gd._fullLayout._traceUids;
164+
expect(traceUids.length).toBe(6, '# of trace uids');
165+
expect(traceUids[2]).toBe('my-id');
166+
expect(traceUids[4]).toBe('0');
167+
expect(traceUids[5]).toBe('2');
168+
169+
var indicesOfRandomUid = [0, 1, 3];
170+
indicesOfRandomUid.forEach(function(ind) {
171+
var msg = 'fullData[' + ind + '].uid';
172+
expect(typeof traceUids[ind]).toBe('string', msg + 'is a string');
173+
expect(traceUids[ind].length).toBe(6, msg + 'is of length 6');
174+
});
175+
});
156176
});
157177

158178
describe('Plots.supplyLayoutGlobalDefaults should', function() {

0 commit comments

Comments
 (0)