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

Function getUniqueInfo

src/traces/parcats/calc.js:391–437  ·  view source on GitHub ↗

* Compute unique value information for an array * * IMPORTANT: Note that values are considered unique * if their string representations are unique. * * @param {Array} values * @param {Array|undefined} uniqueValues * Array of expected unique values. The uniqueValues property of the resulting

(values, uniqueValues)

Source from the content-addressed store, hash-verified

389 * @return {UniqueInfo}
390 */
391function getUniqueInfo(values, uniqueValues) {
392 // Initialize uniqueValues if not specified
393 if(uniqueValues === undefined || uniqueValues === null) {
394 uniqueValues = [];
395 } else {
396 // Shallow copy so append below doesn't alter input array
397 uniqueValues = uniqueValues.map(function(e) {return e;});
398 }
399
400 // Initialize Variables
401 var uniqueValueCounts = {};
402 var uniqueValueInds = {};
403 var inds = [];
404
405 // Initialize uniqueValueCounts and
406 uniqueValues.forEach(function(uniqueVal, valInd) {
407 uniqueValueCounts[uniqueVal] = 0;
408 uniqueValueInds[uniqueVal] = valInd;
409 });
410
411 // Compute the necessary unique info in a single pass
412 for(var i = 0; i < values.length; i++) {
413 var item = values[i];
414 var itemInd;
415
416 if(uniqueValueCounts[item] === undefined) {
417 // This item has a previously unseen value
418 uniqueValueCounts[item] = 1;
419 itemInd = uniqueValues.push(item) - 1;
420 uniqueValueInds[item] = itemInd;
421 } else {
422 // Increment count for this item
423 uniqueValueCounts[item]++;
424 itemInd = uniqueValueInds[item];
425 }
426 inds.push(itemInd);
427 }
428
429 // Build UniqueInfo
430 var uniqueCounts = uniqueValues.map(function(v) { return uniqueValueCounts[v]; });
431
432 return {
433 uniqueValues: uniqueValues,
434 uniqueCounts: uniqueCounts,
435 inds: inds
436 };
437}
438
439
440/**

Callers 1

calc.jsFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…