@@ -68,8 +68,8 @@ describe('Pie defaults', function() {
68
68
expect ( out . insidetextfont . color ) . toBe ( undefined ) ;
69
69
} ) ;
70
70
71
- it ( 'does apply textfont.color to insidetextfont.color' , function ( ) {
72
- var out = _supply ( { type : 'pie' , values : [ 1 , 2 ] , textfont : { color : 'blue' } } ) ;
71
+ it ( 'does apply textfont.color to insidetextfont.color if not set ' , function ( ) {
72
+ var out = _supply ( { type : 'pie' , values : [ 1 , 2 ] , textfont : { color : 'blue' } } , { font : { color : 'red' } } ) ;
73
73
expect ( out . insidetextfont . color ) . toBe ( 'blue' ) ;
74
74
} ) ;
75
75
} ) ;
@@ -168,7 +168,23 @@ describe('Pie traces', function() {
168
168
function _checkFontColors ( expFontColors ) {
169
169
return function ( ) {
170
170
d3 . selectAll ( SLICES_TEXT_SELECTOR ) . each ( function ( d , i ) {
171
- expect ( this . style . fill ) . toBe ( expFontColors [ i ] , i ) ;
171
+ expect ( this . style . fill ) . toBe ( expFontColors [ i ] , 'fill color of ' + i ) ;
172
+ } ) ;
173
+ } ;
174
+ }
175
+
176
+ function _checkFontFamilies ( expFontFamilies ) {
177
+ return function ( ) {
178
+ d3 . selectAll ( SLICES_TEXT_SELECTOR ) . each ( function ( d , i ) {
179
+ expect ( this . style . fontFamily ) . toBe ( expFontFamilies [ i ] , 'fontFamily of ' + i ) ;
180
+ } ) ;
181
+ } ;
182
+ }
183
+
184
+ function _checkFontSizes ( expFontSizes ) {
185
+ return function ( ) {
186
+ d3 . selectAll ( SLICES_TEXT_SELECTOR ) . each ( function ( d , i ) {
187
+ expect ( this . style . fontSize ) . toBe ( expFontSizes [ i ] + 'px' , 'fontSize of ' + i ) ;
172
188
} ) ;
173
189
} ;
174
190
}
@@ -490,6 +506,35 @@ describe('Pie traces', function() {
490
506
. then ( done ) ;
491
507
} ) ;
492
508
509
+ [
510
+ { fontAttr : 'textfont' , textposition : 'outside' } ,
511
+ { fontAttr : 'textfont' , textposition : 'inside' } ,
512
+ { fontAttr : 'outsidetextfont' , textposition : 'outside' } ,
513
+ { fontAttr : 'insidetextfont' , textposition : 'inside' }
514
+ ] . forEach ( function ( spec ) {
515
+ var desc = 'allow to specify ' + spec . fontAttr +
516
+ ' properties per individual slice (textposition ' + spec . textposition + ')' ;
517
+ it ( desc , function ( done ) {
518
+ var data = {
519
+ values : [ 3 , 2 , 1 ] ,
520
+ type : 'pie' ,
521
+ textposition : spec . textposition
522
+ } ;
523
+ data [ spec . fontAttr ] = {
524
+ color : [ 'red' , 'green' , 'blue' ] ,
525
+ family : [ 'Arial' , 'Gravitas' , 'Roboto' ] ,
526
+ size : [ 12 , 20 , 16 ]
527
+ } ;
528
+
529
+ Plotly . plot ( gd , [ data ] )
530
+ . then ( _checkFontColors ( [ rgb ( 'red' ) , rgb ( 'green' ) , rgb ( 'blue' ) ] ) )
531
+ . then ( _checkFontFamilies ( [ 'Arial' , 'Gravitas' , 'Roboto' ] ) )
532
+ . then ( _checkFontSizes ( [ 12 , 20 , 16 ] ) )
533
+ . catch ( failTest )
534
+ . then ( done ) ;
535
+ } ) ;
536
+ } ) ;
537
+
493
538
var insideTextTestsTraceDef = {
494
539
values : [ 6 , 5 , 4 , 3 , 2 , 1 ] ,
495
540
type : 'pie' ,
@@ -506,19 +551,140 @@ describe('Pie traces', function() {
506
551
} ) ;
507
552
508
553
it ( 'should use textfont.color for inside text instead of the contrasting default' , function ( done ) {
509
- var data = Lib . extendFlat ( { } , insideTextTestsTraceDef , { textfont : { color : 'red' } } ) ;
554
+ var data = Lib . extendFlat ( { } , insideTextTestsTraceDef , { textfont : { color : 'red' } } ) ;
510
555
Plotly . plot ( gd , [ data ] )
511
556
. then ( _checkFontColors ( Lib . repeat ( rgb ( 'red' ) , 6 ) ) )
512
557
. catch ( failTest )
513
558
. then ( done ) ;
514
559
} ) ;
515
560
561
+ it ( 'should use matching color from textfont.color array for inside text, contrasting otherwise' , function ( done ) {
562
+ var data = Lib . extendFlat ( { } , insideTextTestsTraceDef , { textfont : { color : [ 'red' , 'blue' ] } } ) ;
563
+ Plotly . plot ( gd , [ data ] )
564
+ . then ( _checkFontColors ( [ rgb ( 'red' ) , rgb ( 'blue' ) , LIGHT , LIGHT , DARK , LIGHT ] ) )
565
+ . catch ( failTest )
566
+ . then ( done ) ;
567
+ } ) ;
568
+
516
569
it ( 'should not use layout.font.color for inside text, but a contrasting color instead' , function ( done ) {
517
570
Plotly . plot ( gd , [ insideTextTestsTraceDef ] , { font : { color : 'green' } } )
518
571
. then ( _checkFontColors ( [ DARK , DARK , LIGHT , LIGHT , DARK , LIGHT ] ) )
519
572
. catch ( failTest )
520
573
. then ( done ) ;
521
574
} ) ;
575
+
576
+ it ( 'should use matching color from insidetextfont.color array instead of the contrasting default' , function ( done ) {
577
+ var data = Lib . extendFlat ( { } , insideTextTestsTraceDef , { textfont : { color : [ 'orange' , 'purple' ] } } ) ;
578
+ Plotly . plot ( gd , [ data ] )
579
+ . then ( _checkFontColors ( [ rgb ( 'orange' ) , rgb ( 'purple' ) , LIGHT , LIGHT , DARK , LIGHT ] ) )
580
+ . catch ( failTest )
581
+ . then ( done ) ;
582
+ } ) ;
583
+
584
+ [
585
+ { fontAttr : 'outsidetextfont' , textposition : 'outside' } ,
586
+ { fontAttr : 'insidetextfont' , textposition : 'inside' }
587
+ ] . forEach ( function ( spec ) {
588
+ it ( 'should fall back to textfont scalar values if ' + spec . fontAttr + ' value ' +
589
+ 'arrays don\'t cover all slices' , function ( done ) {
590
+ var data = Lib . extendFlat ( { } , insideTextTestsTraceDef , {
591
+ textposition : spec . textposition ,
592
+ textfont : { color : 'orange' , family : 'Gravitas' , size : 12 }
593
+ } ) ;
594
+ data [ spec . fontAttr ] = { color : [ 'blue' , 'yellow' ] , family : [ 'Arial' , 'Arial' ] , size : [ 24 , 34 ] } ;
595
+
596
+ var orange = rgb ( 'orange' ) ;
597
+ Plotly . plot ( gd , [ data ] )
598
+ . then ( _checkFontColors ( [ rgb ( 'blue' ) , rgb ( 'yellow' ) , orange , orange , orange , orange ] ) )
599
+ . then ( _checkFontFamilies ( [ 'Arial' , 'Arial' , 'Gravitas' , 'Gravitas' , 'Gravitas' , 'Gravitas' ] ) )
600
+ . then ( _checkFontSizes ( [ 24 , 34 , 12 , 12 , 12 , 12 ] ) )
601
+ . catch ( failTest )
602
+ . then ( done ) ;
603
+ } ) ;
604
+ } ) ;
605
+
606
+ it ( 'should fall back to textfont array values and layout.font scalar (except color)' +
607
+ ' values for inside text' , function ( done ) {
608
+ var layout = { font : { color : 'orange' , family : 'serif' , size : 16 } } ;
609
+ var data = Lib . extendFlat ( { } , insideTextTestsTraceDef , {
610
+ textfont : {
611
+ color : [ 'blue' , 'blue' ] , family : [ 'Arial' , 'Arial' ] , size : [ 18 , 18 ]
612
+ } ,
613
+ insidetextfont : {
614
+ color : [ 'purple' ] , family : [ 'Roboto' ] , size : [ 24 ]
615
+ }
616
+ } ) ;
617
+
618
+ Plotly . plot ( gd , [ data ] , layout )
619
+ . then ( _checkFontColors ( [ rgb ( 'purple' ) , rgb ( 'blue' ) , LIGHT , LIGHT , DARK , LIGHT ] ) )
620
+ . then ( _checkFontFamilies ( [ 'Roboto' , 'Arial' , 'serif' , 'serif' , 'serif' , 'serif' ] ) )
621
+ . then ( _checkFontSizes ( [ 24 , 18 , 16 , 16 , 16 , 16 ] ) )
622
+ . catch ( failTest )
623
+ . then ( done ) ;
624
+ } ) ;
625
+
626
+ it ( 'should fall back to textfont array values and layout.font scalar' +
627
+ ' values for outside text' , function ( done ) {
628
+ var layout = { font : { color : 'orange' , family : 'serif' , size : 16 } } ;
629
+ var data = Lib . extendFlat ( { } , insideTextTestsTraceDef , {
630
+ textposition : 'outside' ,
631
+ textfont : {
632
+ color : [ 'blue' , 'blue' ] , family : [ 'Arial' , 'Arial' ] , size : [ 18 , 18 ]
633
+ } ,
634
+ outsidetextfont : {
635
+ color : [ 'purple' ] , family : [ 'Roboto' ] , size : [ 24 ]
636
+ }
637
+ } ) ;
638
+
639
+ var orange = rgb ( 'orange' ) ;
640
+ Plotly . plot ( gd , [ data ] , layout )
641
+ . then ( _checkFontColors ( [ rgb ( 'purple' ) , rgb ( 'blue' ) , orange , orange , orange , orange ] ) )
642
+ . then ( _checkFontFamilies ( [ 'Roboto' , 'Arial' , 'serif' , 'serif' , 'serif' , 'serif' ] ) )
643
+ . then ( _checkFontSizes ( [ 24 , 18 , 16 , 16 , 16 , 16 ] ) )
644
+ . catch ( failTest )
645
+ . then ( done ) ;
646
+ } ) ;
647
+
648
+ [
649
+ { fontAttr : 'textfont' } ,
650
+ { fontAttr : 'insidetextfont' }
651
+ ] . forEach ( function ( spec ) {
652
+ it ( 'should fall back to layout.font scalar values for inside text (except color) if ' + spec . fontAttr + ' value ' +
653
+ 'arrays don\'t cover all slices' , function ( done ) {
654
+ var layout = { font : { color : 'orange' , family : 'serif' , size : 16 } } ;
655
+ var data = Lib . extendFlat ( { } , insideTextTestsTraceDef ) ;
656
+ data . textposition = 'inside' ;
657
+ data [ spec . fontAttr ] = { color : [ 'blue' , 'yellow' ] , family : [ 'Arial' , 'Arial' ] , size : [ 24 , 34 ] } ;
658
+
659
+ Plotly . plot ( gd , [ data ] , layout )
660
+ . then ( _checkFontColors ( [ rgb ( 'blue' ) , rgb ( 'yellow' ) , LIGHT , LIGHT , DARK , LIGHT ] ) )
661
+ . then ( _checkFontFamilies ( [ 'Arial' , 'Arial' , 'serif' , 'serif' , 'serif' , 'serif' ] ) )
662
+ . then ( _checkFontSizes ( [ 24 , 34 , 16 , 16 , 16 , 16 ] ) )
663
+ . catch ( failTest )
664
+ . then ( done ) ;
665
+ } ) ;
666
+ } ) ;
667
+
668
+ [
669
+ { fontAttr : 'textfont' } ,
670
+ { fontAttr : 'outsidetextfont' }
671
+ ] . forEach ( function ( spec ) {
672
+ it ( 'should fall back to layout.font scalar values for outside text if ' + spec . fontAttr + ' value ' +
673
+ 'arrays don\'t cover all slices' , function ( done ) {
674
+ var layout = { font : { color : 'orange' , family : 'serif' , size : 16 } } ;
675
+ var data = Lib . extendFlat ( { } , insideTextTestsTraceDef ) ;
676
+ data . textposition = 'outside' ;
677
+ data [ spec . fontAttr ] = { color : [ 'blue' , 'yellow' ] , family : [ 'Arial' , 'Arial' ] , size : [ 24 , 34 ] } ;
678
+
679
+ var orange = rgb ( 'orange' ) ;
680
+ Plotly . plot ( gd , [ data ] , layout )
681
+ . then ( _checkFontColors ( [ rgb ( 'blue' ) , rgb ( 'yellow' ) , orange , orange , orange , orange ] ) )
682
+ . then ( _checkFontFamilies ( [ 'Arial' , 'Arial' , 'serif' , 'serif' , 'serif' , 'serif' ] ) )
683
+ . then ( _checkFontSizes ( [ 24 , 34 , 16 , 16 , 16 , 16 ] ) )
684
+ . catch ( failTest )
685
+ . then ( done ) ;
686
+ } ) ;
687
+ } ) ;
522
688
} ) ;
523
689
524
690
describe ( 'pie hovering' , function ( ) {
0 commit comments