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

Function cdf

src/traces/histogram/calc.js:540–586  ·  view source on GitHub ↗
(size, direction, currentBin)

Source from the content-addressed store, hash-verified

538}
539
540function cdf(size, direction, currentBin) {
541 var i, vi, prevSum;
542
543 function firstHalfPoint(i) {
544 prevSum = size[i];
545 size[i] /= 2;
546 }
547
548 function nextHalfPoint(i) {
549 vi = size[i];
550 size[i] = prevSum + vi / 2;
551 prevSum += vi;
552 }
553
554 if(currentBin === 'half') {
555 if(direction === 'increasing') {
556 firstHalfPoint(0);
557 for(i = 1; i < size.length; i++) {
558 nextHalfPoint(i);
559 }
560 } else {
561 firstHalfPoint(size.length - 1);
562 for(i = size.length - 2; i >= 0; i--) {
563 nextHalfPoint(i);
564 }
565 }
566 } else if(direction === 'increasing') {
567 for(i = 1; i < size.length; i++) {
568 size[i] += size[i - 1];
569 }
570
571 // 'exclude' is identical to 'include' just shifted one bin over
572 if(currentBin === 'exclude') {
573 size.unshift(0);
574 size.pop();
575 }
576 } else {
577 for(i = size.length - 2; i >= 0; i--) {
578 size[i] += size[i + 1];
579 }
580
581 if(currentBin === 'exclude') {
582 size.push(0);
583 size.shift();
584 }
585 }
586}
587
588module.exports = {
589 calc: calc,

Callers 1

calcFunction · 0.85

Calls 2

firstHalfPointFunction · 0.85
nextHalfPointFunction · 0.85

Tested by

no test coverage detected