@@ -9,19 +9,22 @@ var click = require('../assets/click');
9
9
var getClientPosition = require ( '../assets/get_client_position' ) ;
10
10
var mouseEvent = require ( '../assets/mouse_event' ) ;
11
11
var supplyAllDefaults = require ( '../assets/supply_defaults' ) ;
12
+ var color = require ( '../../../src/components/color' ) ;
13
+ var rgb = color . rgb ;
12
14
13
15
var customAssertions = require ( '../assets/custom_assertions' ) ;
14
16
var assertHoverLabelStyle = customAssertions . assertHoverLabelStyle ;
15
17
var assertHoverLabelContent = customAssertions . assertHoverLabelContent ;
16
18
17
19
var SLICES_SELECTOR = '.slice path' ;
20
+ var SLICES_TEXT_SELECTOR = '.pielayer text.slicetext' ;
18
21
var LEGEND_ENTRIES_SELECTOR = '.legendpoints path' ;
19
22
20
23
describe ( 'Pie defaults' , function ( ) {
21
- function _supply ( trace ) {
24
+ function _supply ( trace , layout ) {
22
25
var gd = {
23
26
data : [ trace ] ,
24
- layout : { }
27
+ layout : layout || { }
25
28
} ;
26
29
27
30
supplyAllDefaults ( gd ) ;
@@ -59,11 +62,24 @@ describe('Pie defaults', function() {
59
62
out = _supply ( { type : 'pie' , labels : [ 'A' , 'B' ] , values : [ ] } ) ;
60
63
expect ( out . visible ) . toBe ( false ) ;
61
64
} ) ;
65
+
66
+ it ( 'does not apply layout.font.color to insidetextfont.color (it\'ll be contrasting instead)' , function ( ) {
67
+ var out = _supply ( { type : 'pie' , values : [ 1 , 2 ] } , { font : { color : 'blue' } } ) ;
68
+ expect ( out . insidetextfont . color ) . toBe ( undefined ) ;
69
+ } ) ;
70
+
71
+ it ( 'does apply textfont.color to insidetextfont.color' , function ( ) {
72
+ var out = _supply ( { type : 'pie' , values : [ 1 , 2 ] , textfont : { color : 'blue' } } ) ;
73
+ expect ( out . insidetextfont . color ) . toBe ( 'blue' ) ;
74
+ } ) ;
62
75
} ) ;
63
76
64
77
describe ( 'Pie traces' , function ( ) {
65
78
'use strict' ;
66
79
80
+ var DARK = color . rgb ( '#444' ) ;
81
+ var LIGHT = color . rgb ( '#fff' ) ;
82
+
67
83
var gd ;
68
84
69
85
beforeEach ( function ( ) { gd = createGraphDiv ( ) ; } ) ;
@@ -149,6 +165,14 @@ describe('Pie traces', function() {
149
165
} ;
150
166
}
151
167
168
+ function _checkFontColors ( expFontColors ) {
169
+ return function ( ) {
170
+ d3 . selectAll ( SLICES_TEXT_SELECTOR ) . each ( function ( d , i ) {
171
+ expect ( this . style . fill ) . toBe ( expFontColors [ i ] , i ) ;
172
+ } ) ;
173
+ } ;
174
+ }
175
+
152
176
it ( 'propagate explicit colors to the same labels in earlier OR later traces' , function ( done ) {
153
177
var data1 = [
154
178
{ type : 'pie' , values : [ 3 , 2 ] , marker : { colors : [ 'red' , 'black' ] } , domain : { x : [ 0.5 , 1 ] } } ,
@@ -465,6 +489,36 @@ describe('Pie traces', function() {
465
489
. catch ( failTest )
466
490
. then ( done ) ;
467
491
} ) ;
492
+
493
+ var insideTextTestsTraceDef = {
494
+ values : [ 6 , 5 , 4 , 3 , 2 , 1 ] ,
495
+ type : 'pie' ,
496
+ marker : {
497
+ colors : [ '#ee1' , '#eee' , '#333' , '#9467bd' , '#dda' , '#922' ] ,
498
+ }
499
+ } ;
500
+
501
+ it ( 'should use inside text colors contrasting to slice colors by default' , function ( done ) {
502
+ Plotly . plot ( gd , [ insideTextTestsTraceDef ] )
503
+ . then ( _checkFontColors ( [ DARK , DARK , LIGHT , LIGHT , DARK , LIGHT ] ) )
504
+ . catch ( failTest )
505
+ . then ( done ) ;
506
+ } ) ;
507
+
508
+ it ( 'should use textfont.color for inside text instead of the contrasting default' , function ( done ) {
509
+ var data = Lib . extendFlat ( { } , insideTextTestsTraceDef , { textfont : { color : 'red' } } ) ;
510
+ Plotly . plot ( gd , [ data ] )
511
+ . then ( _checkFontColors ( Lib . repeat ( rgb ( 'red' ) , 6 ) ) )
512
+ . catch ( failTest )
513
+ . then ( done ) ;
514
+ } ) ;
515
+
516
+ it ( 'should not use layout.font.color for inside text, but a contrasting color instead' , function ( done ) {
517
+ Plotly . plot ( gd , [ insideTextTestsTraceDef ] , { font : { color : 'green' } } )
518
+ . then ( _checkFontColors ( [ DARK , DARK , LIGHT , LIGHT , DARK , LIGHT ] ) )
519
+ . catch ( failTest )
520
+ . then ( done ) ;
521
+ } ) ;
468
522
} ) ;
469
523
470
524
describe ( 'pie hovering' , function ( ) {
0 commit comments