@@ -415,6 +415,18 @@ describe('finance charts updates:', function() {
415
415
destroyGraphDiv ( ) ;
416
416
} ) ;
417
417
418
+ function countScatterTraces ( ) {
419
+ return d3 . select ( 'g.cartesianlayer' ) . selectAll ( 'g.trace.scatter' ) . size ( ) ;
420
+ }
421
+
422
+ function countBoxTraces ( ) {
423
+ return d3 . select ( 'g.cartesianlayer' ) . selectAll ( 'g.trace.boxes' ) . size ( ) ;
424
+ }
425
+
426
+ function countRangeSliders ( ) {
427
+ return d3 . select ( 'g.rangeslider-rangeplot' ) . size ( ) ;
428
+ }
429
+
418
430
it ( 'Plotly.restyle should work' , function ( done ) {
419
431
var trace0 = Lib . extendDeep ( { } , mock0 , { type : 'ohlc' } ) ;
420
432
@@ -452,23 +464,156 @@ describe('finance charts updates:', function() {
452
464
453
465
} ) ;
454
466
467
+ it ( 'should be able to toggle visibility' , function ( done ) {
468
+ var data = [
469
+ Lib . extendDeep ( { } , mock0 , { type : 'ohlc' } ) ,
470
+ Lib . extendDeep ( { } , mock0 , { type : 'candlestick' } ) ,
471
+ ] ;
472
+
473
+ Plotly . plot ( gd , data ) . then ( function ( ) {
474
+ expect ( countScatterTraces ( ) ) . toEqual ( 2 ) ;
475
+ expect ( countBoxTraces ( ) ) . toEqual ( 2 ) ;
476
+
477
+ return Plotly . restyle ( gd , 'visible' , false ) ;
478
+ } )
479
+ . then ( function ( ) {
480
+ expect ( countScatterTraces ( ) ) . toEqual ( 0 ) ;
481
+ expect ( countBoxTraces ( ) ) . toEqual ( 0 ) ;
482
+
483
+ return Plotly . restyle ( gd , 'visible' , 'legendonly' , [ 1 ] ) ;
484
+ } )
485
+ . then ( function ( ) {
486
+ expect ( countScatterTraces ( ) ) . toEqual ( 0 ) ;
487
+ expect ( countBoxTraces ( ) ) . toEqual ( 0 ) ;
488
+
489
+ return Plotly . restyle ( gd , 'visible' , true , [ 1 ] ) ;
490
+ } )
491
+ . then ( function ( ) {
492
+ expect ( countScatterTraces ( ) ) . toEqual ( 0 ) ;
493
+ expect ( countBoxTraces ( ) ) . toEqual ( 2 ) ;
494
+
495
+ return Plotly . restyle ( gd , 'visible' , true , [ 0 ] ) ;
496
+ } )
497
+ . then ( function ( ) {
498
+ expect ( countScatterTraces ( ) ) . toEqual ( 2 ) ;
499
+ expect ( countBoxTraces ( ) ) . toEqual ( 2 ) ;
500
+
501
+ return Plotly . restyle ( gd , 'visible' , 'legendonly' , [ 0 ] ) ;
502
+ } )
503
+ . then ( function ( ) {
504
+ expect ( countScatterTraces ( ) ) . toEqual ( 0 ) ;
505
+ expect ( countBoxTraces ( ) ) . toEqual ( 2 ) ;
506
+
507
+ return Plotly . restyle ( gd , 'visible' , true ) ;
508
+ } )
509
+ . then ( function ( ) {
510
+ expect ( countScatterTraces ( ) ) . toEqual ( 2 ) ;
511
+ expect ( countBoxTraces ( ) ) . toEqual ( 2 ) ;
512
+
513
+ done ( ) ;
514
+ } ) ;
515
+ } ) ;
516
+
455
517
it ( 'Plotly.relayout should work' , function ( done ) {
456
518
var trace0 = Lib . extendDeep ( { } , mock0 , { type : 'ohlc' } ) ;
457
519
458
520
Plotly . plot ( gd , [ trace0 ] ) . then ( function ( ) {
521
+ expect ( countRangeSliders ( ) ) . toEqual ( 1 ) ;
522
+
523
+ return Plotly . relayout ( gd , 'xaxis.rangeslider.visible' , false ) ;
524
+ } )
525
+ . then ( function ( ) {
526
+ expect ( countRangeSliders ( ) ) . toEqual ( 0 ) ;
459
527
460
528
done ( ) ;
461
529
} ) ;
462
530
463
531
} ) ;
464
532
465
533
it ( 'Plotly.extendTraces should work' , function ( done ) {
534
+ var data = [
535
+ Lib . extendDeep ( { } , mock0 , { type : 'ohlc' } ) ,
536
+ Lib . extendDeep ( { } , mock0 , { type : 'candlestick' } ) ,
537
+ ] ;
538
+
539
+ // ohlc have 7 calc pts per 'x' coords
540
+
541
+ Plotly . plot ( gd , data ) . then ( function ( ) {
542
+ expect ( gd . calcdata [ 0 ] . length ) . toEqual ( 28 ) ;
543
+ expect ( gd . calcdata [ 1 ] . length ) . toEqual ( 28 ) ;
544
+ expect ( gd . calcdata [ 2 ] . length ) . toEqual ( 4 ) ;
545
+ expect ( gd . calcdata [ 3 ] . length ) . toEqual ( 4 ) ;
546
+
547
+ return Plotly . extendTraces ( gd , {
548
+ open : [ [ 34 , 35 ] ] ,
549
+ high : [ [ 40 , 41 ] ] ,
550
+ low : [ [ 32 , 33 ] ] ,
551
+ close : [ [ 38 , 39 ] ]
552
+ } , [ 1 ] ) ;
553
+ } )
554
+ . then ( function ( ) {
555
+ expect ( gd . calcdata [ 0 ] . length ) . toEqual ( 28 ) ;
556
+ expect ( gd . calcdata [ 1 ] . length ) . toEqual ( 28 ) ;
557
+ expect ( gd . calcdata [ 2 ] . length ) . toEqual ( 6 ) ;
558
+ expect ( gd . calcdata [ 3 ] . length ) . toEqual ( 4 ) ;
559
+
560
+ return Plotly . extendTraces ( gd , {
561
+ open : [ [ 34 , 35 ] ] ,
562
+ high : [ [ 40 , 41 ] ] ,
563
+ low : [ [ 32 , 33 ] ] ,
564
+ close : [ [ 38 , 39 ] ]
565
+ } , [ 0 ] ) ;
566
+ } )
567
+ . then ( function ( ) {
568
+ expect ( gd . calcdata [ 0 ] . length ) . toEqual ( 42 ) ;
569
+ expect ( gd . calcdata [ 1 ] . length ) . toEqual ( 28 ) ;
570
+ expect ( gd . calcdata [ 2 ] . length ) . toEqual ( 6 ) ;
571
+ expect ( gd . calcdata [ 3 ] . length ) . toEqual ( 4 ) ;
466
572
467
- done ( ) ;
573
+ done ( ) ;
574
+ } ) ;
468
575
} ) ;
469
576
470
- it ( 'Plotly.deleteTraces should work' , function ( done ) {
471
- done ( ) ;
577
+ it ( 'Plotly.deleteTraces / addTraces should work' , function ( done ) {
578
+ var data = [
579
+ Lib . extendDeep ( { } , mock0 , { type : 'ohlc' } ) ,
580
+ Lib . extendDeep ( { } , mock0 , { type : 'candlestick' } ) ,
581
+ ] ;
582
+
583
+ Plotly . plot ( gd , data ) . then ( function ( ) {
584
+ expect ( countScatterTraces ( ) ) . toEqual ( 2 ) ;
585
+ expect ( countBoxTraces ( ) ) . toEqual ( 2 ) ;
586
+
587
+ return Plotly . deleteTraces ( gd , [ 1 ] ) ;
588
+ } )
589
+ . then ( function ( ) {
590
+ expect ( countScatterTraces ( ) ) . toEqual ( 2 ) ;
591
+ expect ( countBoxTraces ( ) ) . toEqual ( 0 ) ;
592
+
593
+ return Plotly . deleteTraces ( gd , [ 0 ] ) ;
594
+ } )
595
+ . then ( function ( ) {
596
+ expect ( countScatterTraces ( ) ) . toEqual ( 0 ) ;
597
+ expect ( countBoxTraces ( ) ) . toEqual ( 0 ) ;
598
+
599
+ var trace = Lib . extendDeep ( { } , mock0 , { type : 'candlestick' } ) ;
600
+
601
+ return Plotly . addTraces ( gd , [ trace ] ) ;
602
+ } )
603
+ . then ( function ( ) {
604
+ expect ( countScatterTraces ( ) ) . toEqual ( 0 ) ;
605
+ expect ( countBoxTraces ( ) ) . toEqual ( 2 ) ;
606
+
607
+ var trace = Lib . extendDeep ( { } , mock0 , { type : 'ohlc' } ) ;
608
+
609
+ return Plotly . addTraces ( gd , [ trace ] ) ;
610
+ } )
611
+ . then ( function ( ) {
612
+ expect ( countScatterTraces ( ) ) . toEqual ( 2 ) ;
613
+ expect ( countBoxTraces ( ) ) . toEqual ( 2 ) ;
614
+
615
+ done ( ) ;
616
+ } ) ;
472
617
} ) ;
473
618
474
619
it ( 'legend *editable: true* interactions should work' , function ( done ) {
0 commit comments