@@ -7,8 +7,6 @@ var Drawing = require('@src/components/drawing');
7
7
8
8
var Axes = require ( '@src/plots/cartesian/axes' ) ;
9
9
10
- var click = require ( '../assets/click' ) ;
11
- var DBLCLICKDELAY = require ( '../../../src/constants/interactions' ) . DBLCLICKDELAY ;
12
10
var createGraphDiv = require ( '../assets/create_graph_div' ) ;
13
11
var destroyGraphDiv = require ( '../assets/destroy_graph_div' ) ;
14
12
var failTest = require ( '../assets/fail_test' ) ;
@@ -213,17 +211,27 @@ describe('waterfall calc / crossTraceCalc', function() {
213
211
var gd = mockWaterfallPlot ( [ {
214
212
y : [ 2 , 1 , 2 ]
215
213
} , {
216
- y : [ 3 , 1 , 2 ]
214
+ y : [ 3 , 1 , null , 2 , null ] ,
215
+ measure : [ 'absolute' , 'relative' , 'total' , 'relative' , 'total' ]
217
216
} ] , {
218
217
waterfallmode : 'overlay'
219
218
} ) ;
220
219
221
220
var cd = gd . calcdata ;
222
- assertPointField ( cd , 'x' , [ [ 0 , 1 , 2 ] , [ 0 , 1 , 2 ] ] ) ;
223
- assertPointField ( cd , 'y' , [ [ 2 , 3 , 5 ] , [ 3 , 4 , 6 ] ] ) ;
224
- assertPointField ( cd , 'b' , [ [ 0 , 0 , 0 ] , [ 0 , 0 , 0 ] ] ) ;
225
- assertPointField ( cd , 's' , [ [ 2 , 3 , 5 ] , [ 3 , 4 , 6 ] ] ) ;
226
- assertPointField ( cd , 'p' , [ [ 0 , 1 , 2 ] , [ 0 , 1 , 2 ] ] ) ;
221
+ assertPointField ( cd , 'w' , [ [ 0.8 , 0.8 , 0.8 ] , [ 0.8 , 0.8 , 0.8 , 0.8 , 0.8 ] ] ) ;
222
+ assertPointField ( cd , 'x' , [ [ 0 , 1 , 2 ] , [ 0 , 1 , 2 , 3 , 4 ] ] ) ;
223
+ assertPointField ( cd , 'y' , [ [ 2 , 3 , 5 ] , [ 3 , 4 , 4 , 6 , 6 ] ] ) ;
224
+ assertPointField ( cd , 'b' , [ [ 0 , 0 , 0 ] , [ 0 , 0 , 0 , 0 , 0 ] ] ) ;
225
+ assertPointField ( cd , 's' , [ [ 2 , 3 , 5 ] , [ 3 , 4 , 4 , 6 , 6 ] ] ) ;
226
+ assertPointField ( cd , 'p' , [ [ 0 , 1 , 2 ] , [ 0 , 1 , 2 , 3 , 4 ] ] ) ;
227
+ assertPointField ( cd , 'p0' , [ [ - 0.4 , 0.6 , 1.6 ] , [ - 0.4 , 0.6 , 1.6 , 2.6 , 3.6 ] ] ) ;
228
+ assertPointField ( cd , 'p1' , [ [ 0.4 , 1.4 , 2.4 ] , [ 0.4 , 1.4 , 2.4 , 3.4 , 4.4 ] ] ) ;
229
+ assertPointField ( cd , 's0' , [ [ 0 , 2 , 3 ] , [ 0 , 3 , 0 , 4 , 0 ] ] ) ;
230
+ assertPointField ( cd , 's1' , [ [ 2 , 3 , 5 ] , [ 3 , 4 , 4 , 6 , 6 ] ] ) ;
231
+ assertPointField ( cd , 'isSum' , [ [ false , false , false ] , [ true , false , true , false , true ] ] ) ;
232
+ assertPointField ( cd , 'rawS' , [ [ 2 , 1 , 2 ] , [ 3 , 1 , 0 , 2 , 0 ] ] ) ;
233
+ assertPointField ( cd , 'dir' , [ [ 'increasing' , 'increasing' , 'increasing' ] , [ 'totals' , 'increasing' , 'totals' , 'increasing' , 'totals' ] ] ) ;
234
+ assertPointField ( cd , 'hasTotals' , [ [ false , undefined , undefined ] , [ true , undefined , undefined , undefined , undefined ] ] ) ;
227
235
assertTraceField ( cd , 't.barwidth' , [ 0.8 , 0.8 ] ) ;
228
236
assertTraceField ( cd , 't.poffset' , [ - 0.4 , - 0.4 ] ) ;
229
237
assertTraceField ( cd , 't.bargroupwidth' , [ 0.8 , 0.8 ] ) ;
@@ -233,19 +241,29 @@ describe('waterfall calc / crossTraceCalc', function() {
233
241
var gd = mockWaterfallPlot ( [ {
234
242
y : [ 2 , 1 , 2 ]
235
243
} , {
236
- y : [ 3 , 1 , 2 ]
244
+ y : [ 3 , 1 , null , 2 , null ] ,
245
+ measure : [ 'absolute' , null , 'total' , null , 'total' ]
237
246
} ] , {
238
247
waterfallmode : 'group' ,
239
248
// asumming default waterfallgap is 0.2
240
249
waterfallgroupgap : 0.1
241
250
} ) ;
242
251
243
252
var cd = gd . calcdata ;
244
- assertPointField ( cd , 'x' , [ [ - 0.2 , 0.8 , 1.8 ] , [ 0.2 , 1.2 , 2.2 ] ] ) ;
245
- assertPointField ( cd , 'y' , [ [ 2 , 3 , 5 ] , [ 3 , 4 , 6 ] ] ) ;
246
- assertPointField ( cd , 'b' , [ [ 0 , 0 , 0 ] , [ 0 , 0 , 0 ] ] ) ;
247
- assertPointField ( cd , 's' , [ [ 2 , 3 , 5 ] , [ 3 , 4 , 6 ] ] ) ;
248
- assertPointField ( cd , 'p' , [ [ 0 , 1 , 2 ] , [ 0 , 1 , 2 ] ] ) ;
253
+ assertPointField ( cd , 'w' , [ [ 0.36 , 0.36 , 0.36 ] , [ 0.36 , 0.36 , 0.36 , 0.36 , 0.36 ] ] ) ;
254
+ assertPointField ( cd , 'x' , [ [ - 0.2 , 0.8 , 1.8 ] , [ 0.2 , 1.2 , 2.2 , 3.2 , 4.2 ] ] ) ;
255
+ assertPointField ( cd , 'y' , [ [ 2 , 3 , 5 ] , [ 3 , 4 , 4 , 6 , 6 ] ] ) ;
256
+ assertPointField ( cd , 'b' , [ [ 0 , 0 , 0 ] , [ 0 , 0 , 0 , 0 , 0 ] ] ) ;
257
+ assertPointField ( cd , 's' , [ [ 2 , 3 , 5 ] , [ 3 , 4 , 4 , 6 , 6 ] ] ) ;
258
+ assertPointField ( cd , 'p' , [ [ 0 , 1 , 2 ] , [ 0 , 1 , 2 , 3 , 4 ] ] ) ;
259
+ assertPointField ( cd , 'p0' , [ [ - 0.38 , 0.62 , 1.62 ] , [ 0.02 , 1.02 , 2.02 , 3.02 , 4.02 ] ] ) ;
260
+ assertPointField ( cd , 'p1' , [ [ - 0.02 , 0.98 , 1.98 ] , [ 0.38 , 1.38 , 2.38 , 3.38 , 4.38 ] ] ) ;
261
+ assertPointField ( cd , 's0' , [ [ 0 , 2 , 3 ] , [ 0 , 3 , 0 , 4 , 0 ] ] ) ;
262
+ assertPointField ( cd , 's1' , [ [ 2 , 3 , 5 ] , [ 3 , 4 , 4 , 6 , 6 ] ] ) ;
263
+ assertPointField ( cd , 'isSum' , [ [ false , false , false ] , [ true , false , true , false , true ] ] ) ;
264
+ assertPointField ( cd , 'rawS' , [ [ 2 , 1 , 2 ] , [ 3 , 1 , 0 , 2 , 0 ] ] ) ;
265
+ assertPointField ( cd , 'dir' , [ [ 'increasing' , 'increasing' , 'increasing' ] , [ 'totals' , 'increasing' , 'totals' , 'increasing' , 'totals' ] ] ) ;
266
+ assertPointField ( cd , 'hasTotals' , [ [ false , undefined , undefined ] , [ true , undefined , undefined , undefined , undefined ] ] ) ;
249
267
assertTraceField ( cd , 't.barwidth' , [ 0.36 , 0.36 ] ) ;
250
268
assertTraceField ( cd , 't.poffset' , [ - 0.38 , 0.02 ] ) ;
251
269
assertTraceField ( cd , 't.bargroupwidth' , [ 0.8 , 0.8 ] ) ;
@@ -617,31 +635,11 @@ describe('A waterfall plot', function() {
617
635
} ;
618
636
}
619
637
620
- function assertTextFontFamilies ( expFontFamilies ) {
621
- return function ( ) {
622
- var selection = d3 . selectAll ( WATERFALL_TEXT_SELECTOR ) ;
623
- expect ( selection . size ( ) ) . toBe ( expFontFamilies . length ) ;
624
- selection . each ( function ( d , i ) {
625
- expect ( this . style . fontFamily ) . toBe ( expFontFamilies [ i ] ) ;
626
- } ) ;
627
- } ;
628
- }
629
-
630
- function assertTextFontSizes ( expFontSizes ) {
631
- return function ( ) {
632
- var selection = d3 . selectAll ( WATERFALL_TEXT_SELECTOR ) ;
633
- expect ( selection . size ( ) ) . toBe ( expFontSizes . length ) ;
634
- selection . each ( function ( d , i ) {
635
- expect ( this . style . fontSize ) . toBe ( expFontSizes [ i ] + 'px' ) ;
636
- } ) ;
637
- } ;
638
- }
639
-
640
- it ( 'should show waterfall texts (inside case)' , function ( done ) {
638
+ it ( 'should show texts (inside case)' , function ( done ) {
641
639
var data = [ {
642
640
y : [ 10 , 20 , 30 ] ,
643
641
type : 'waterfall' ,
644
- text : [ '1' , 'Very very very very very long waterfall text' ] ,
642
+ text : [ '1' , 'Very very very very very long text' ] ,
645
643
textposition : 'inside' ,
646
644
} ] ;
647
645
var layout = { } ;
@@ -667,11 +665,11 @@ describe('A waterfall plot', function() {
667
665
. then ( done ) ;
668
666
} ) ;
669
667
670
- it ( 'should show waterfall texts (horizontal case)' , function ( done ) {
668
+ it ( 'should show texts (horizontal case)' , function ( done ) {
671
669
var data = [ {
672
670
x : [ 10 , - 20 , 30 ] ,
673
671
type : 'waterfall' ,
674
- text : [ 'Very very very very very long waterfall text' , - 20 ] ,
672
+ text : [ 'Very very very very very long text' , - 20 ] ,
675
673
textposition : 'outside' ,
676
674
} ] ;
677
675
var layout = { } ;
@@ -709,16 +707,15 @@ describe('A waterfall plot', function() {
709
707
}
710
708
} ;
711
709
712
- it ( 'should take waterfall fill opacities into account when calculating contrasting inside text colors' , function ( done ) {
710
+ it ( 'should take fill opacities into account when calculating contrasting inside text colors' , function ( done ) {
713
711
var trace = {
714
712
x : [ 5 , 10 ] ,
715
- y : [ 5 , 15 ] ,
713
+ y : [ 5 , - 15 ] ,
716
714
text : [ 'Giraffes' , 'Zebras' ] ,
717
715
type : 'waterfall' ,
718
716
textposition : 'inside' ,
719
- marker : {
720
- color : [ 'rgba(0, 0, 0, 0.2)' , 'rgba(0, 0, 0, 0.8)' ]
721
- }
717
+ increasing : { marker : { color : 'rgba(0, 0, 0, 0.2)' } } ,
718
+ decreasing : { marker : { color : 'rgba(0, 0, 0, 0.8)' } }
722
719
} ;
723
720
724
721
Plotly . plot ( gd , [ trace ] )
@@ -736,84 +733,6 @@ describe('A waterfall plot', function() {
736
733
. then ( done ) ;
737
734
} ) ;
738
735
739
- it ( 'should retain text styles throughout selecting and deselecting data points' , function ( done ) {
740
- var trace1 = {
741
- x : [ 'giraffes' , 'orangutans' , 'monkeys' ] ,
742
- y : [ 12 , 18 , 29 ] ,
743
- text : [ 12 , 18 , 29 ] ,
744
- type : 'waterfall' ,
745
- textposition : 'inside' ,
746
- textfont : {
747
- color : [ 'red' , 'orange' ] ,
748
- family : [ 'Arial' , 'serif' ] ,
749
- size : [ 8 , 24 ]
750
- } ,
751
- insidetextfont : {
752
- color : [ 'blue' ] ,
753
- family : [ 'Arial' ] ,
754
- size : [ 16 ]
755
- }
756
- } ;
757
- var trace2 = Lib . extendDeep ( { } , trace1 , { textposition : 'outside' } ) ;
758
- var layout = {
759
- waterfallmode : 'group' ,
760
- font : {
761
- family : 'Roboto' ,
762
- size : 12
763
- } ,
764
- clickmode : 'event+select'
765
- } ;
766
-
767
- Plotly . plot ( gd , [ trace1 , trace2 ] , layout )
768
- . then ( function ( ) {
769
- assertNonSelectionModeStyle ( 'before selection' ) ;
770
- } )
771
- . then ( function ( ) {
772
- return select1stWaterfall2ndTrace ( ) ;
773
- } )
774
- . then ( function ( ) {
775
- assertSelectionModeStyle ( 'in selection mode' ) ;
776
- } )
777
- . then ( function ( ) {
778
- return deselect1stWaterfall2ndTrace ( ) ;
779
- } )
780
- . then ( function ( ) {
781
- assertNonSelectionModeStyle ( 'after selection' ) ;
782
- } )
783
- . catch ( failTest )
784
- . then ( done ) ;
785
-
786
- function assertSelectionModeStyle ( label ) {
787
- var unselColor = [ 'black' , '0.2' ] ;
788
- assertTextFontColors ( [ unselColor , unselColor , unselColor , 'red' , unselColor , unselColor ] , label ) ( ) ;
789
- assertTextFontFamilies ( [ 'Arial' , 'serif' , 'Roboto' , 'Arial' , 'serif' , 'Roboto' ] ) ( ) ;
790
- assertTextFontSizes ( [ 16 , 24 , 12 , 8 , 24 , 12 ] ) ( ) ;
791
- }
792
-
793
- function assertNonSelectionModeStyle ( label ) {
794
- assertTextFontColors ( [ 'blue' , 'orange' , LIGHT , 'red' , 'orange' , DARK ] , label ) ( ) ;
795
- assertTextFontFamilies ( [ 'Arial' , 'serif' , 'Roboto' , 'Arial' , 'serif' , 'Roboto' ] ) ( ) ;
796
- assertTextFontSizes ( [ 16 , 24 , 12 , 8 , 24 , 12 ] ) ( ) ;
797
- }
798
-
799
- function select1stWaterfall2ndTrace ( ) {
800
- return new Promise ( function ( resolve ) {
801
- click ( 176 , 354 ) ;
802
- resolve ( ) ;
803
- } ) ;
804
- }
805
-
806
- function deselect1stWaterfall2ndTrace ( ) {
807
- return new Promise ( function ( resolve ) {
808
- var delayAvoidingDblClick = DBLCLICKDELAY * 1.01 ;
809
- setTimeout ( function ( ) {
810
- click ( 176 , 354 ) ;
811
- resolve ( ) ;
812
- } , delayAvoidingDblClick ) ;
813
- } ) ;
814
- }
815
- } ) ;
816
-
817
736
it ( 'should be able to restyle' , function ( done ) {
818
737
var mock = {
819
738
data : [
@@ -1294,14 +1213,14 @@ describe('waterfall hover', function() {
1294
1213
it ( 'should return the correct hover point data (case x)' , function ( ) {
1295
1214
var out = _hover ( gd , 0 , 0 , 'x' ) ;
1296
1215
1297
- expect ( out . style ) . toEqual ( [ 0 , 'rgb(255, 102, 97) ' , 0 , 13.23 ] ) ;
1216
+ expect ( out . style ) . toEqual ( [ 0 , '#3D9970 ' , 0 , 13.23 ] ) ;
1298
1217
assertPos ( out . pos , [ 11.87 , 106.8 , 52.71 , 52.71 ] ) ;
1299
1218
} ) ;
1300
1219
1301
1220
it ( 'should return the correct hover point data (case closest)' , function ( ) {
1302
1221
var out = _hover ( gd , - 0.2 , 12 , 'closest' ) ;
1303
1222
1304
- expect ( out . style ) . toEqual ( [ 0 , 'rgb(255, 102, 97) ' , 0 , 13.23 ] ) ;
1223
+ expect ( out . style ) . toEqual ( [ 0 , '#3D9970 ' , 0 , 13.23 ] ) ;
1305
1224
assertPos ( out . pos , [ 11.87 , 59.33 , 52.71 , 52.71 ] ) ;
1306
1225
} ) ;
1307
1226
} ) ;
@@ -1469,11 +1388,11 @@ describe('waterfall hover', function() {
1469
1388
} )
1470
1389
. then ( function ( ) {
1471
1390
// you can still hover over the gap (14) but the label will
1472
- // get pushed in to the waterfall
1391
+ // get pushed in to the bar
1473
1392
var out = _hover ( gd , 14 , 2 , 'x' ) ;
1474
1393
assertPos ( out . pos , [ 145 , 155 , 110 , 110 ] ) ;
1475
1394
1476
- // in closest mode you must be over the waterfall though
1395
+ // in closest mode you must be over the bar though
1477
1396
out = _hover ( gd , 14 , 2 , 'closest' ) ;
1478
1397
expect ( out ) . toBe ( false ) ;
1479
1398
0 commit comments