@@ -247,63 +247,97 @@ describe('Test histogram', function() {
247
247
} ) ;
248
248
249
249
describe ( 'cumulative distribution functions' , function ( ) {
250
- var base = { x : [ 1 , 2 , 3 , 4 , 2 , 3 , 4 , 3 , 4 , 4 ] } ;
250
+ var base = {
251
+ x : [ 0 , 5 , 10 , 15 , 5 , 10 , 15 , 10 , 15 , 15 ] ,
252
+ y : [ 2 , 2 , 2 , 14 , 6 , 6 , 6 , 10 , 10 , 2 ]
253
+ } ;
251
254
252
255
it ( 'makes the right base histogram' , function ( ) {
253
256
var baseOut = _calc ( base ) ;
254
257
expect ( baseOut ) . toEqual ( [
255
- { b : 0 , p : 1 , s : 1 } ,
256
- { b : 0 , p : 2 , s : 2 } ,
257
- { b : 0 , p : 3 , s : 3 } ,
258
- { b : 0 , p : 4 , s : 4 } ,
258
+ { b : 0 , p : 2 , s : 1 } ,
259
+ { b : 0 , p : 7 , s : 2 } ,
260
+ { b : 0 , p : 12 , s : 3 } ,
261
+ { b : 0 , p : 17 , s : 4 } ,
259
262
] ) ;
260
263
} ) ;
261
264
262
265
var CDFs = [
263
- { p : [ 1 , 2 , 3 , 4 ] , s : [ 1 , 3 , 6 , 10 ] } ,
266
+ { p : [ 2 , 7 , 12 , 17 ] , s : [ 1 , 3 , 6 , 10 ] } ,
264
267
{
265
268
direction : 'decreasing' ,
266
- p : [ 1 , 2 , 3 , 4 ] , s : [ 10 , 9 , 7 , 4 ]
269
+ p : [ 2 , 7 , 12 , 17 ] , s : [ 10 , 9 , 7 , 4 ]
267
270
} ,
268
271
{
269
272
currentbin : 'exclude' ,
270
- p : [ 2 , 3 , 4 , 5 ] , s : [ 1 , 3 , 6 , 10 ]
273
+ p : [ 7 , 12 , 17 , 22 ] , s : [ 1 , 3 , 6 , 10 ]
271
274
} ,
272
275
{
273
276
direction : 'decreasing' , currentbin : 'exclude' ,
274
- p : [ 0 , 1 , 2 , 3 ] , s : [ 10 , 9 , 7 , 4 ]
277
+ p : [ - 3 , 2 , 7 , 12 ] , s : [ 10 , 9 , 7 , 4 ]
275
278
} ,
276
279
{
277
280
currentbin : 'half' ,
278
- p : [ 1 , 2 , 3 , 4 , 5 ] , s : [ 0.5 , 2 , 4.5 , 8 , 10 ]
281
+ p : [ 2 , 7 , 12 , 17 , 22 ] , s : [ 0.5 , 2 , 4.5 , 8 , 10 ]
279
282
} ,
280
283
{
281
284
direction : 'decreasing' , currentbin : 'half' ,
282
- p : [ 0 , 1 , 2 , 3 , 4 ] , s : [ 10 , 9.5 , 8 , 5.5 , 2 ]
285
+ p : [ - 3 , 2 , 7 , 12 , 17 ] , s : [ 10 , 9.5 , 8 , 5.5 , 2 ]
283
286
} ,
284
287
{
285
288
direction : 'decreasing' , currentbin : 'half' , histnorm : 'percent' ,
286
- p : [ 0 , 1 , 2 , 3 , 4 ] , s : [ 100 , 95 , 80 , 55 , 20 ]
289
+ p : [ - 3 , 2 , 7 , 12 , 17 ] , s : [ 100 , 95 , 80 , 55 , 20 ]
287
290
} ,
288
291
{
289
292
currentbin : 'exclude' , histnorm : 'probability' ,
290
- p : [ 2 , 3 , 4 , 5 ] , s : [ 0.1 , 0.3 , 0.6 , 1 ]
293
+ p : [ 7 , 12 , 17 , 22 ] , s : [ 0.1 , 0.3 , 0.6 , 1 ]
294
+ } ,
295
+ {
296
+ // behaves the same as without *density*
297
+ direction : 'decreasing' , currentbin : 'half' , histnorm : 'density' ,
298
+ p : [ - 3 , 2 , 7 , 12 , 17 ] , s : [ 10 , 9.5 , 8 , 5.5 , 2 ]
299
+ } ,
300
+ {
301
+ // behaves the same as without *density*, only *probability*
302
+ direction : 'decreasing' , currentbin : 'half' , histnorm : 'probability density' ,
303
+ p : [ - 3 , 2 , 7 , 12 , 17 ] , s : [ 1 , 0.95 , 0.8 , 0.55 , 0.2 ]
304
+ } ,
305
+ {
306
+ currentbin : 'half' , histfunc : 'sum' ,
307
+ p : [ 2 , 7 , 12 , 17 , 22 ] , s : [ 1 , 6 , 19 , 44 , 60 ]
308
+ } ,
309
+ {
310
+ currentbin : 'half' , histfunc : 'sum' , histnorm : 'probability' ,
311
+ p : [ 2 , 7 , 12 , 17 , 22 ] , s : [ 0.5 / 30 , 0.1 , 9.5 / 30 , 22 / 30 , 1 ]
312
+ } ,
313
+ {
314
+ direction : 'decreasing' , currentbin : 'half' , histfunc : 'max' , histnorm : 'percent' ,
315
+ p : [ - 3 , 2 , 7 , 12 , 17 ] , s : [ 100 , 3100 / 32 , 2700 / 32 , 1900 / 32 , 700 / 32 ]
316
+ } ,
317
+ {
318
+ direction : 'decreasing' , currentbin : 'half' , histfunc : 'min' , histnorm : 'density' ,
319
+ p : [ - 3 , 2 , 7 , 12 , 17 ] , s : [ 8 , 7 , 5 , 3 , 1 ]
320
+ } ,
321
+ {
322
+ currentbin : 'exclude' , histfunc : 'avg' , histnorm : 'probability density' ,
323
+ p : [ 7 , 12 , 17 , 22 ] , s : [ 0.1 , 0.3 , 0.6 , 1 ]
291
324
}
292
325
] ;
293
326
294
327
CDFs . forEach ( function ( CDF ) {
295
- var direction = CDF . direction ,
296
- currentbin = CDF . currentbin ,
297
- histnorm = CDF . histnorm ,
298
- p = CDF . p ,
328
+ var p = CDF . p ,
299
329
s = CDF . s ;
300
330
301
- it ( 'handles direction=' + direction + ', currentbin=' + currentbin + ', histnorm=' + histnorm , function ( ) {
331
+ it ( 'handles direction=' + CDF . direction + ', currentbin=' + CDF . currentbin +
332
+ ', histnorm=' + CDF . histnorm + ', histfunc=' + CDF . histfunc , function ( ) {
302
333
var traceIn = Lib . extendFlat ( { } , base , {
303
- cumulative : true ,
304
- direction : direction ,
305
- currentbin : currentbin ,
306
- histnorm : histnorm
334
+ cumulative : {
335
+ enabled : true ,
336
+ direction : CDF . direction ,
337
+ currentbin : CDF . currentbin
338
+ } ,
339
+ histnorm : CDF . histnorm ,
340
+ histfunc : CDF . histfunc
307
341
} ) ;
308
342
var out = _calc ( traceIn ) ;
309
343
0 commit comments