Skip to content

Commit 62aeefb

Browse files
committed
[pof] add 'cumulative' histogram 'mode' for CDF
1 parent c130932 commit 62aeefb

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

src/traces/histogram/attributes.js

+10
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,16 @@ module.exports = {
7171
].join(' ')
7272
},
7373

74+
mode: {
75+
valType: 'enumerated',
76+
values: ['density', 'cumulative'],
77+
dflt: 'density',
78+
role: 'info',
79+
description: [
80+
''
81+
].join('')
82+
},
83+
7484
autobinx: {
7585
valType: 'boolean',
7686
dflt: null,

src/traces/histogram/calc.js

+9
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ module.exports = function calc(gd, trace) {
3838

3939
// prepare the raw data
4040
var pos0 = pa.makeCalcdata(trace, maindata);
41+
4142
// calculate the bins
4243
if((trace['autobin' + maindata] !== false) || !(maindata + 'bins' in trace)) {
4344
trace[maindata + 'bins'] = Axes.autoBin(pos0, pa, trace['nbins' + maindata]);
@@ -112,6 +113,8 @@ module.exports = function calc(gd, trace) {
112113
// average and/or normalize the data, if needed
113114
if(doavg) total = doAvg(size, counts);
114115
if(normfunc) normfunc(size, total, inc);
116+
if(trace.mode === 'cumulative') cdf(size);
117+
115118

116119
var serieslen = Math.min(pos.length, size.length),
117120
cd = [],
@@ -140,3 +143,9 @@ module.exports = function calc(gd, trace) {
140143

141144
return cd;
142145
};
146+
147+
function cdf(size) {
148+
for(var i = 1; i < size.length; i++) {
149+
size[i] += size[i - 1];
150+
}
151+
}

src/traces/histogram/defaults.js

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
2626
var x = coerce('x'),
2727
y = coerce('y');
2828

29+
coerce('mode');
2930
coerce('text');
3031

3132
var orientation = coerce('orientation', (y && !x) ? 'h' : 'v'),

0 commit comments

Comments
 (0)