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

Function handleSingleValueOverlays

src/traces/histogram/calc.js:433–510  ·  view source on GitHub ↗
(gd, trace, pa, mainData, binAttr)

Source from the content-addressed store, hash-verified

431 * Returns the binSpec for the trace that sparked all this
432 */
433function handleSingleValueOverlays(gd, trace, pa, mainData, binAttr) {
434 var fullLayout = gd._fullLayout;
435 var overlaidTraceGroup = getConnectedHistograms(gd, trace);
436 var pastThisTrace = false;
437 var minSize = Infinity;
438 var singleValuedTraces = [trace];
439 var i, tracei, binOpts;
440
441 // first collect all the:
442 // - min bin size from all multi-valued traces
443 // - single-valued traces
444 for(i = 0; i < overlaidTraceGroup.length; i++) {
445 tracei = overlaidTraceGroup[i];
446
447 if(tracei === trace) {
448 pastThisTrace = true;
449 } else if(!pastThisTrace) {
450 // This trace has already had its autobins calculated, so either:
451 // - it is part of a bingroup
452 // - it is NOT a single-valued trace
453 binOpts = fullLayout._histogramBinOpts[tracei['_' + mainData + 'bingroup']];
454 minSize = Math.min(minSize, binOpts.size || tracei[binAttr].size);
455 } else {
456 var resulti = calcAllAutoBins(gd, tracei, pa, mainData, true);
457 var binSpeci = resulti[0];
458 var isSingleValued = resulti[2];
459
460 // so we can use this result when we get to tracei in the normal
461 // course of events, mark it as done and put _pos0 back
462 tracei['_' + mainData + 'autoBinFinished'] = 1;
463 tracei['_' + mainData + 'pos0'] = resulti[1];
464
465 if(isSingleValued) {
466 singleValuedTraces.push(tracei);
467 } else {
468 minSize = Math.min(minSize, binSpeci.size);
469 }
470 }
471 }
472
473 // find the real data values for each single-valued trace
474 // hunt through pos0 for the first valid value
475 var dataVals = new Array(singleValuedTraces.length);
476 for(i = 0; i < singleValuedTraces.length; i++) {
477 var pos0 = singleValuedTraces[i]['_' + mainData + 'pos0'];
478 for(var j = 0; j < pos0.length; j++) {
479 if(pos0[j] !== undefined) {
480 dataVals[i] = pos0[j];
481 break;
482 }
483 }
484 }
485
486 // are ALL traces are single-valued? use the min difference between
487 // all of their values (which defaults to 1 if there's still only one)
488 if(!isFinite(minSize)) {
489 minSize = Lib.distinctVals(dataVals).minDiff;
490 }

Callers 1

calcAllAutoBinsFunction · 0.85

Calls 2

getConnectedHistogramsFunction · 0.85
calcAllAutoBinsFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…