@@ -247,63 +247,97 @@ describe('Test histogram', function() {
247247 } ) ;
248248
249249 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+ } ;
251254
252255 it ( 'makes the right base histogram' , function ( ) {
253256 var baseOut = _calc ( base ) ;
254257 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 } ,
259262 ] ) ;
260263 } ) ;
261264
262265 var CDFs = [
263- { p : [ 1 , 2 , 3 , 4 ] , s : [ 1 , 3 , 6 , 10 ] } ,
266+ { p : [ 2 , 7 , 12 , 17 ] , s : [ 1 , 3 , 6 , 10 ] } ,
264267 {
265268 direction : 'decreasing' ,
266- p : [ 1 , 2 , 3 , 4 ] , s : [ 10 , 9 , 7 , 4 ]
269+ p : [ 2 , 7 , 12 , 17 ] , s : [ 10 , 9 , 7 , 4 ]
267270 } ,
268271 {
269272 currentbin : 'exclude' ,
270- p : [ 2 , 3 , 4 , 5 ] , s : [ 1 , 3 , 6 , 10 ]
273+ p : [ 7 , 12 , 17 , 22 ] , s : [ 1 , 3 , 6 , 10 ]
271274 } ,
272275 {
273276 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 ]
275278 } ,
276279 {
277280 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 ]
279282 } ,
280283 {
281284 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 ]
283286 } ,
284287 {
285288 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 ]
287290 } ,
288291 {
289292 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 ]
291324 }
292325 ] ;
293326
294327 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 ,
299329 s = CDF . s ;
300330
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 ( ) {
302333 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
307341 } ) ;
308342 var out = _calc ( traceIn ) ;
309343
0 commit comments