@@ -6,7 +6,6 @@ var destroyGraphDiv = require('../assets/destroy_graph_div');
66var assertDims = require ( '../assets/assert_dims' ) ;
77var assertStyle = require ( '../assets/assert_style' ) ;
88
9-
109describe ( 'groupby' , function ( ) {
1110
1211 describe ( 'one-to-many transforms:' , function ( ) {
@@ -19,7 +18,10 @@ describe('groupby', function() {
1918 transforms : [ {
2019 type : 'groupby' ,
2120 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+ ]
2325 } ]
2426 } ] ;
2527
@@ -30,7 +32,10 @@ describe('groupby', function() {
3032 transforms : [ {
3133 type : 'groupby' ,
3234 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+ ]
3439 } ]
3540 } ] ;
3641
@@ -58,6 +63,58 @@ describe('groupby', function() {
5863 } ) ;
5964 } ) ;
6065
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+
61118 it ( 'Plotly.restyle should work' , function ( done ) {
62119 var data = Lib . extendDeep ( [ ] , mockData0 ) ;
63120 data [ 0 ] . marker = { size : 20 } ;
@@ -92,7 +149,10 @@ describe('groupby', function() {
92149 expect ( gd . _fullData [ 1 ] . marker . opacity ) . toEqual ( 1 ) ;
93150
94151 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+ ] ] ,
96156 'marker.opacity' : 0.4
97157 } ) ;
98158 } ) . then ( function ( ) {
@@ -192,7 +252,10 @@ describe('groupby', function() {
192252 transforms : [ {
193253 type : 'groupby' ,
194254 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+ ]
196259 } ]
197260 } ] ;
198261
@@ -387,7 +450,10 @@ describe('groupby', function() {
387450 transforms : [ {
388451 type : 'groupby' ,
389452 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+ ]
391457 } ]
392458 } ] ;
393459
@@ -401,17 +467,20 @@ describe('groupby', function() {
401467 transforms : [ {
402468 type : 'groupby' ,
403469 groups : [ 'a' , 'a' , 'b' , 'a' , 'b' , 'b' , 'a' ] ,
404- style : {
405- a : {
470+ styles : [ {
471+ target : 'a' ,
472+ value : {
406473 marker : {
407474 color : 'orange' ,
408475 size : 20 ,
409476 line : {
410477 color : 'red'
411478 }
412479 }
413- } ,
414- b : {
480+ }
481+ } , {
482+ target : 'b' ,
483+ value : {
415484 mode : 'markers+lines' , // heterogeonos attributes are OK: group 'a' doesn't need to define this
416485 marker : {
417486 color : 'cyan' ,
@@ -426,7 +495,7 @@ describe('groupby', function() {
426495 color : 'purple'
427496 }
428497 }
429- }
498+ } ]
430499 } ]
431500 } ] ;
432501
@@ -447,11 +516,14 @@ describe('groupby', function() {
447516 transforms : [ {
448517 type : 'groupby' ,
449518 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+ } , {
452523 // 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+ } ]
455527 } ]
456528 } ] ;
457529
@@ -464,7 +536,7 @@ describe('groupby', function() {
464536 transforms : [ {
465537 type : 'groupby' ,
466538 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 */ ]
468540 } ]
469541 } ] ;
470542
@@ -548,7 +620,10 @@ describe('groupby', function() {
548620 transforms : [ {
549621 type : 'groupby' ,
550622 // 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+ ]
552627 } ]
553628 } ] ;
554629
@@ -561,7 +636,10 @@ describe('groupby', function() {
561636 transforms : [ {
562637 type : 'groupby' ,
563638 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+ ]
565643 } ]
566644 } ] ;
567645
@@ -574,7 +652,10 @@ describe('groupby', function() {
574652 transforms : [ {
575653 type : 'groupby' ,
576654 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+ ]
578659 } ]
579660 } ] ;
580661
0 commit comments