MCPcopy Index your code
hub / github.com/plotly/plotly.js / getTraceUids

Function getTraceUids

src/plots/plots.js:559–594  ·  view source on GitHub ↗

* Create a list of uid strings satisfying (in this order of importance): * 1. all unique, all strings * 2. matches input uids if provided * 3. matches previous data uids

(oldFullData, newData)

Source from the content-addressed store, hash-verified

557 * 3. matches previous data uids
558 */
559function getTraceUids(oldFullData, newData) {
560 var len = newData.length;
561 var oldFullInput = [];
562 var i, prevFullInput;
563 for(i = 0; i < oldFullData.length; i++) {
564 var thisFullInput = oldFullData[i]._fullInput;
565 if(thisFullInput !== prevFullInput) oldFullInput.push(thisFullInput);
566 prevFullInput = thisFullInput;
567 }
568 var oldLen = oldFullInput.length;
569 var out = new Array(len);
570 var seenUids = {};
571
572 function setUid(uid, i) {
573 out[i] = uid;
574 seenUids[uid] = 1;
575 }
576
577 function tryUid(uid, i) {
578 if(uid && typeof uid === 'string' && !seenUids[uid]) {
579 setUid(uid, i);
580 return true;
581 }
582 }
583
584 for(i = 0; i < len; i++) {
585 var newUid = newData[i].uid;
586 if(typeof newUid === 'number') newUid = String(newUid);
587
588 if(tryUid(newUid, i)) continue;
589 if(i < oldLen && tryUid(oldFullInput[i].uid, i)) continue;
590 setUid(Lib.randstr(seenUids), i);
591 }
592
593 return out;
594}
595
596/**
597 * Make a container for collecting subplots we need to display.

Callers 1

plots.jsFile · 0.85

Calls 2

tryUidFunction · 0.85
setUidFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…