@@ -6,7 +6,6 @@ var destroyGraphDiv = require('../assets/destroy_graph_div');
6
6
var assertDims = require ( '../assets/assert_dims' ) ;
7
7
var assertStyle = require ( '../assets/assert_style' ) ;
8
8
9
-
10
9
describe ( 'groupby' , function ( ) {
11
10
12
11
describe ( 'one-to-many transforms:' , function ( ) {
@@ -19,7 +18,10 @@ describe('groupby', function() {
19
18
transforms : [ {
20
19
type : 'groupby' ,
21
20
groups : [ 'a' , 'a' , 'b' , 'a' , 'b' , 'b' , 'a' ] ,
22
- style : { a : { marker : { color : 'red' } } , b : { marker : { color : 'blue' } } }
21
+ styles : [
22
+ { target : 'a' , value : { marker : { color : 'red' } } } ,
23
+ { target : 'b' , value : { marker : { color : 'blue' } } }
24
+ ]
23
25
} ]
24
26
} ] ;
25
27
@@ -30,7 +32,10 @@ describe('groupby', function() {
30
32
transforms : [ {
31
33
type : 'groupby' ,
32
34
groups : [ 'b' , 'a' , 'b' , 'b' , 'b' , 'a' , 'a' ] ,
33
- style : { a : { marker : { color : 'green' } } , b : { marker : { color : 'black' } } }
35
+ styles : [
36
+ { target : 'a' , value : { marker : { color : 'green' } } } ,
37
+ { target : 'b' , value : { marker : { color : 'black' } } }
38
+ ]
34
39
} ]
35
40
} ] ;
36
41
@@ -58,6 +63,58 @@ describe('groupby', function() {
58
63
} ) ;
59
64
} ) ;
60
65
66
+ it ( 'Accepts deprecated object notation for styles' , function ( done ) {
67
+ var oldStyleMockData = [ {
68
+ mode : 'markers' ,
69
+ x : [ 1 , - 1 , - 2 , 0 , 1 , 2 , 3 ] ,
70
+ y : [ 1 , 2 , 3 , 1 , 2 , 3 , 1 ] ,
71
+ transforms : [ {
72
+ type : 'groupby' ,
73
+ groups : [ 'a' , 'a' , 'b' , 'a' , 'b' , 'b' , 'a' ] ,
74
+ styles : {
75
+ a : { marker : { color : 'red' } } ,
76
+ b : { marker : { color : 'blue' } }
77
+ }
78
+ } ]
79
+ } ] ;
80
+ var data = Lib . extendDeep ( [ ] , oldStyleMockData ) ;
81
+ data [ 0 ] . marker = { size : 20 } ;
82
+
83
+ var gd = createGraphDiv ( ) ;
84
+ var dims = [ 4 , 3 ] ;
85
+
86
+ Plotly . plot ( gd , data ) . then ( function ( ) {
87
+ assertStyle ( dims ,
88
+ [ 'rgb(255, 0, 0)' , 'rgb(0, 0, 255)' ] ,
89
+ [ 1 , 1 ]
90
+ ) ;
91
+
92
+ return Plotly . restyle ( gd , 'marker.opacity' , 0.4 ) ;
93
+ } ) . then ( function ( ) {
94
+ assertStyle ( dims ,
95
+ [ 'rgb(255, 0, 0)' , 'rgb(0, 0, 255)' ] ,
96
+ [ 0.4 , 0.4 ]
97
+ ) ;
98
+
99
+ expect ( gd . _fullData [ 0 ] . marker . opacity ) . toEqual ( 0.4 ) ;
100
+ expect ( gd . _fullData [ 1 ] . marker . opacity ) . toEqual ( 0.4 ) ;
101
+
102
+ return Plotly . restyle ( gd , 'marker.opacity' , 1 ) ;
103
+ } ) . then ( function ( ) {
104
+ assertStyle ( dims ,
105
+ [ 'rgb(255, 0, 0)' , 'rgb(0, 0, 255)' ] ,
106
+ [ 1 , 1 ]
107
+ ) ;
108
+
109
+ expect ( gd . _fullData [ 0 ] . marker . opacity ) . toEqual ( 1 ) ;
110
+ expect ( gd . _fullData [ 1 ] . marker . opacity ) . toEqual ( 1 ) ;
111
+ } ) . then ( done ) ;
112
+
113
+ // The final test for restyle updates using deprecated syntax
114
+ // is ommitted since old style syntax is *only* sanitized on
115
+ // initial plot, *not* on restyle.
116
+ } ) ;
117
+
61
118
it ( 'Plotly.restyle should work' , function ( done ) {
62
119
var data = Lib . extendDeep ( [ ] , mockData0 ) ;
63
120
data [ 0 ] . marker = { size : 20 } ;
@@ -92,7 +149,10 @@ describe('groupby', function() {
92
149
expect ( gd . _fullData [ 1 ] . marker . opacity ) . toEqual ( 1 ) ;
93
150
94
151
return Plotly . restyle ( gd , {
95
- 'transforms[0].style' : { a : { marker : { color : 'green' } } , b : { marker : { color : 'red' } } } ,
152
+ 'transforms[0].styles' : [ [
153
+ { target : 'a' , value : { marker : { color : 'green' } } } ,
154
+ { target : 'b' , value : { marker : { color : 'red' } } }
155
+ ] ] ,
96
156
'marker.opacity' : 0.4
97
157
} ) ;
98
158
} ) . then ( function ( ) {
@@ -192,7 +252,10 @@ describe('groupby', function() {
192
252
transforms : [ {
193
253
type : 'groupby' ,
194
254
groups : [ 'a' , 'a' , 'b' , 'a' , 'b' , 'b' , 'a' ] ,
195
- style : { a : { marker : { color : 'red' } } , b : { marker : { color : 'blue' } } }
255
+ styles : [
256
+ { target : 'a' , value : { marker : { color : 'red' } } } ,
257
+ { target : 'b' , value : { marker : { color : 'blue' } } }
258
+ ]
196
259
} ]
197
260
} ] ;
198
261
@@ -387,7 +450,10 @@ describe('groupby', function() {
387
450
transforms : [ {
388
451
type : 'groupby' ,
389
452
groups : [ 'a' , 'a' , 'b' , 'a' , 'b' , 'b' , 'a' ] ,
390
- style : { a : { marker : { color : 'red' } } , b : { marker : { color : 'blue' } } }
453
+ styles : [
454
+ { target : 'a' , value : { marker : { color : 'red' } } } ,
455
+ { target : 'b' , value : { marker : { color : 'blue' } } }
456
+ ]
391
457
} ]
392
458
} ] ;
393
459
@@ -401,17 +467,20 @@ describe('groupby', function() {
401
467
transforms : [ {
402
468
type : 'groupby' ,
403
469
groups : [ 'a' , 'a' , 'b' , 'a' , 'b' , 'b' , 'a' ] ,
404
- style : {
405
- a : {
470
+ styles : [ {
471
+ target : 'a' ,
472
+ value : {
406
473
marker : {
407
474
color : 'orange' ,
408
475
size : 20 ,
409
476
line : {
410
477
color : 'red'
411
478
}
412
479
}
413
- } ,
414
- b : {
480
+ }
481
+ } , {
482
+ target : 'b' ,
483
+ value : {
415
484
mode : 'markers+lines' , // heterogeonos attributes are OK: group 'a' doesn't need to define this
416
485
marker : {
417
486
color : 'cyan' ,
@@ -426,7 +495,7 @@ describe('groupby', function() {
426
495
color : 'purple'
427
496
}
428
497
}
429
- }
498
+ } ]
430
499
} ]
431
500
} ] ;
432
501
@@ -447,11 +516,14 @@ describe('groupby', function() {
447
516
transforms : [ {
448
517
type : 'groupby' ,
449
518
groups : [ 'a' , 'a' , 'b' , 'a' , 'b' , 'b' , 'a' ] ,
450
- style : {
451
- a : { marker : { size : 30 } } ,
519
+ styles : [ {
520
+ target : 'a' ,
521
+ value : { marker : { size : 30 } }
522
+ } , {
452
523
// override general color:
453
- b : { marker : { size : 15 , line : { color : 'yellow' } } , line : { color : 'purple' } }
454
- }
524
+ target : 'b' ,
525
+ value : { marker : { size : 15 , line : { color : 'yellow' } } , line : { color : 'purple' } }
526
+ } ]
455
527
} ]
456
528
} ] ;
457
529
@@ -464,7 +536,7 @@ describe('groupby', function() {
464
536
transforms : [ {
465
537
type : 'groupby' ,
466
538
groups : [ 'a' , 'a' , 'b' , 'a' , 'b' , 'b' , 'a' ] ,
467
- style : { /* can be empty, or of partial group id coverage */ }
539
+ styles : [ /* can be empty, or of partial group id coverage */ ]
468
540
} ]
469
541
} ] ;
470
542
@@ -548,7 +620,10 @@ describe('groupby', function() {
548
620
transforms : [ {
549
621
type : 'groupby' ,
550
622
// groups: ['a', 'a', 'b', 'a', 'b', 'b', 'a'],
551
- style : { a : { marker : { color : 'red' } } , b : { marker : { color : 'blue' } } }
623
+ styles : [
624
+ { target : 'a' , value : { marker : { color : 'red' } } } ,
625
+ { target : 'b' , value : { marker : { color : 'blue' } } }
626
+ ]
552
627
} ]
553
628
} ] ;
554
629
@@ -561,7 +636,10 @@ describe('groupby', function() {
561
636
transforms : [ {
562
637
type : 'groupby' ,
563
638
groups : [ ] ,
564
- style : { a : { marker : { color : 'red' } } , b : { marker : { color : 'blue' } } }
639
+ styles : [
640
+ { target : 'a' , value : { marker : { color : 'red' } } } ,
641
+ { target : 'b' , value : { marker : { color : 'blue' } } }
642
+ ]
565
643
} ]
566
644
} ] ;
567
645
@@ -574,7 +652,10 @@ describe('groupby', function() {
574
652
transforms : [ {
575
653
type : 'groupby' ,
576
654
groups : null ,
577
- style : { a : { marker : { color : 'red' } } , b : { marker : { color : 'blue' } } }
655
+ styles : [
656
+ { target : 'a' , value : { marker : { color : 'red' } } } ,
657
+ { target : 'b' , value : { marker : { color : 'blue' } } }
658
+ ]
578
659
} ]
579
660
} ] ;
580
661
0 commit comments