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

Function calc

src/traces/histogram/calc.js:18–231  ·  view source on GitHub ↗
(gd, trace)

Source from the content-addressed store, hash-verified

16var getBinSpanLabelRound = require('./bin_label_vals');
17
18function calc(gd, trace) {
19 var pos = [];
20 var size = [];
21 var isHorizontal = trace.orientation === 'h';
22 var pa = Axes.getFromId(gd, isHorizontal ? trace.yaxis : trace.xaxis);
23 var mainData = isHorizontal ? 'y' : 'x';
24 var counterData = {x: 'y', y: 'x'}[mainData];
25 var calendar = trace[mainData + 'calendar'];
26 var cumulativeSpec = trace.cumulative;
27 var i;
28
29 var binsAndPos = calcAllAutoBins(gd, trace, pa, mainData);
30 var binSpec = binsAndPos[0];
31 var pos0 = binsAndPos[1];
32
33 var nonuniformBins = typeof binSpec.size === 'string';
34 var binEdges = [];
35 var bins = nonuniformBins ? binEdges : binSpec;
36 // make the empty bin array
37 var inc = [];
38 var counts = [];
39 var inputPoints = [];
40 var total = 0;
41 var norm = trace.histnorm;
42 var func = trace.histfunc;
43 var densityNorm = norm.indexOf('density') !== -1;
44 var i2, binEnd, n;
45
46 if(cumulativeSpec.enabled && densityNorm) {
47 // we treat "cumulative" like it means "integral" if you use a density norm,
48 // which in the end means it's the same as without "density"
49 norm = norm.replace(/ ?density$/, '');
50 densityNorm = false;
51 }
52
53 var extremeFunc = func === 'max' || func === 'min';
54 var sizeInit = extremeFunc ? null : 0;
55 var binFunc = binFunctions.count;
56 var normFunc = normFunctions[norm];
57 var isAvg = false;
58 var pr2c = function(v) { return pa.r2c(v, 0, calendar); };
59 var rawCounterData;
60
61 if(Lib.isArrayOrTypedArray(trace[counterData]) && func !== 'count') {
62 rawCounterData = trace[counterData];
63 isAvg = func === 'avg';
64 binFunc = binFunctions[func];
65 }
66
67 // create the bins (and any extra arrays needed)
68 // assume more than 1e6 bins is an error, so we don't crash the browser
69 i = pr2c(binSpec.start);
70
71 // decrease end a little in case of rounding errors
72 binEnd = pr2c(binSpec.end) + (i - Axes.tickIncrement(i, binSpec.size, false, calendar)) / 1e6;
73
74 while(i < binEnd && pos.length < 1e6) {
75 i2 = Axes.tickIncrement(i, binSpec.size, false, calendar);

Callers

nothing calls this directly

Calls 5

calcAllAutoBinsFunction · 0.85
pr2cFunction · 0.85
cdfFunction · 0.85
hasColorscaleFunction · 0.85
arraysToCalcdataFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…