@@ -946,106 +946,130 @@ describe('Draw new shapes to layout', function() {
946
946
} ) ;
947
947
} ) ;
948
948
949
- describe ( 'Activate and deactivate shapes to edit ' , function ( ) {
949
+ describe ( 'Activate and edit editable shapes ' , function ( ) {
950
950
var fig = {
951
- data : [ { x : [ 0 , 50 ] , y : [ 0 , 50 ] } ] ,
952
- layout : {
953
- width : 800 ,
954
- height : 600 ,
955
- margin : {
956
- t : 100 ,
957
- b : 50 ,
958
- l : 100 ,
959
- r : 50
951
+ 'data' : [
952
+ {
953
+ 'x' : [
954
+ 0 ,
955
+ 50
956
+ ] ,
957
+ 'y' : [
958
+ 0 ,
959
+ 50
960
+ ]
961
+ }
962
+ ] ,
963
+ 'layout' : {
964
+ 'width' : 800 ,
965
+ 'height' : 600 ,
966
+ 'margin' : {
967
+ 't' : 100 ,
968
+ 'b' : 50 ,
969
+ 'l' : 100 ,
970
+ 'r' : 50
960
971
} ,
961
-
962
- yaxis : {
963
- autorange : 'reversed'
972
+ 'yaxis' : {
973
+ 'autorange' : 'reversed'
964
974
} ,
965
-
966
- template : {
967
- layout : {
968
- shapes : [ {
969
- name : 'myPath' ,
970
- editable : true ,
971
- layer : 'below' ,
972
- line : { width : 0 } ,
973
- fillcolor : 'gray' ,
974
- opacity : 0.5 ,
975
- xref : 'paper' ,
976
- yref : 'paper' ,
977
- path : 'M0.5,0.3C0.5,0.9 0.9,0.9 0.9,0.3C0.9,0.1 0.5,0.1 0.5,0.3ZM0.6,0.4C0.6,0.5 0.66,0.5 0.66,0.4ZM0.74,0.4C0.74,0.5 0.8,0.5 0.8,0.4ZM0.6,0.3C0.63,0.2 0.77,0.2 0.8,0.3Z'
978
- } ]
975
+ 'template' : {
976
+ 'layout' : {
977
+ 'shapes' : [
978
+ {
979
+ 'name' : 'myPath' ,
980
+ 'editable' : true ,
981
+ 'layer' : 'below' ,
982
+ 'line' : {
983
+ 'width' : 0
984
+ } ,
985
+ 'fillcolor' : 'gray' ,
986
+ 'opacity' : 0.5 ,
987
+ 'xref' : 'paper' ,
988
+ 'yref' : 'paper' ,
989
+ 'path' : 'M0.5,0.3C0.5,0.9 0.9,0.9 0.9,0.3C0.9,0.1 0.5,0.1 0.5,0.3ZM0.6,0.4C0.6,0.5 0.66,0.5 0.66,0.4ZM0.74,0.4C0.74,0.5 0.8,0.5 0.8,0.4ZM0.6,0.3C0.63,0.2 0.77,0.2 0.8,0.3Z'
990
+ }
991
+ ]
979
992
}
980
993
} ,
981
- shapes : [
994
+ ' shapes' : [
982
995
{
983
- editable : true ,
984
- layer : 'below' ,
985
- type : 'rect' ,
986
- line : { width : 5 } ,
987
- fillcolor : 'red' ,
988
- opacity : 0.5 ,
989
- xref : 'xaxis' ,
990
- yref : 'yaxis' ,
991
- y0 : 25 ,
992
- y1 : 75 ,
993
- x0 : 25 ,
994
- x1 : 75
996
+ 'editable' : true ,
997
+ 'layer' : 'below' ,
998
+ 'type' : 'rect' ,
999
+ 'line' : {
1000
+ 'width' : 5
1001
+ } ,
1002
+ 'fillcolor' : 'red' ,
1003
+ 'opacity' : 0.5 ,
1004
+ 'xref' : 'xaxis' ,
1005
+ 'yref' : 'yaxis' ,
1006
+ 'x0' : 25 ,
1007
+ 'y0' : 25 ,
1008
+ 'x1' : 75 ,
1009
+ 'y1' : 75
995
1010
} ,
996
1011
{
997
- editable : true ,
998
- layer : 'top' ,
999
- type : 'circle' ,
1000
- line : { width : 5 } ,
1001
- fillcolor : 'green' ,
1002
- opacity : 0.5 ,
1003
- xref : 'xaxis' ,
1004
- yref : 'yaxis' ,
1005
- y0 : 25 ,
1006
- y1 : 75 ,
1007
- x0 : 125 ,
1008
- x1 : 175
1012
+ 'editable' : true ,
1013
+ 'layer' : 'top' ,
1014
+ 'type' : 'circle' ,
1015
+ 'line' : {
1016
+ 'width' : 5
1017
+ } ,
1018
+ 'fillcolor' : 'green' ,
1019
+ 'opacity' : 0.5 ,
1020
+ 'xref' : 'xaxis' ,
1021
+ 'yref' : 'yaxis' ,
1022
+ 'x0' : 125 ,
1023
+ 'y0' : 25 ,
1024
+ 'x1' : 175 ,
1025
+ 'y1' : 75
1009
1026
} ,
1010
1027
{
1011
- editable : true ,
1012
- line : { width : 5 } ,
1013
- fillcolor : 'blue' ,
1014
- path : 'M250,25L225,75L275,75Z'
1028
+ 'editable' : true ,
1029
+ 'line' : {
1030
+ 'width' : 5
1031
+ } ,
1032
+ 'fillcolor' : 'blue' ,
1033
+ 'path' : 'M250,25L225,75L275,75Z'
1015
1034
} ,
1016
1035
{
1017
- editable : true ,
1018
- line : { width : 15 } ,
1019
- path : 'M250,225L225,275L275,275'
1036
+ 'editable' : true ,
1037
+ 'line' : {
1038
+ 'width' : 15
1039
+ } ,
1040
+ 'path' : 'M250,225L225,275L275,275'
1020
1041
} ,
1021
1042
{
1022
- editable : true ,
1023
- layer : 'below' ,
1024
- path : 'M320,100C390,180 290,180 360,100Z' ,
1025
- fillcolor : 'rgba(0,127,127,0.5)' ,
1026
- line : { width : 5 }
1043
+ 'editable' : true ,
1044
+ 'layer' : 'below' ,
1045
+ 'path' : 'M320,100C390,180 290,180 360,100Z' ,
1046
+ 'fillcolor' : 'rgba(0,127,127,0.5)' ,
1047
+ 'line' : {
1048
+ 'width' : 5
1049
+ }
1027
1050
} ,
1028
1051
{
1029
- editable : true ,
1030
- line : {
1031
- width : 5 ,
1032
- color : 'orange'
1052
+ ' editable' : true ,
1053
+ ' line' : {
1054
+ ' width' : 5 ,
1055
+ ' color' : 'orange'
1033
1056
} ,
1034
- fillcolor : 'rgba(127,255,127,0.5)' ,
1035
- path : 'M0,100V200H50L0,300Q100,300 100,200T150,200C100,300 200,300 200,200S150,200 150,100Z'
1057
+ ' fillcolor' : 'rgba(127,255,127,0.5)' ,
1058
+ ' path' : 'M0,100V200H50L0,300Q100,300 100,200T150,200C100,300 200,300 200,200S150,200 150,100Z'
1036
1059
} ,
1037
1060
{
1038
- editable : true ,
1039
- line : { width : 2 } ,
1040
- fillcolor : 'yellow' ,
1041
-
1042
- path : 'M300,70C300,10 380,10 380,70C380,90 300,90 300,70ZM320,60C320,50 332,50 332,60ZM348,60C348,50 360,50 360,60ZM320,70C326,80 354,80 360,70Z'
1061
+ 'editable' : true ,
1062
+ 'line' : {
1063
+ 'width' : 2
1064
+ } ,
1065
+ 'fillcolor' : 'yellow' ,
1066
+ 'path' : 'M300,70C300,10 380,10 380,70C380,90 300,90 300,70ZM320,60C320,50 332,50 332,60ZM348,60C348,50 360,50 360,60ZM320,70C326,80 354,80 360,70Z'
1043
1067
}
1044
1068
]
1045
1069
} ,
1046
- config : {
1047
- editable : false ,
1048
- modeBarButtonsToAdd : [
1070
+ ' config' : {
1071
+ ' editable' : false ,
1072
+ ' modeBarButtonsToAdd' : [
1049
1073
'drawline' ,
1050
1074
'drawopenpath' ,
1051
1075
'drawclosedpath' ,
@@ -1065,8 +1089,8 @@ describe('Activate and deactivate shapes to edit', function() {
1065
1089
afterEach ( destroyGraphDiv ) ;
1066
1090
1067
1091
[ 'mouse' ] . forEach ( function ( device ) {
1068
- it ( '@flaky activate and edit editable shapes using' + device , function ( done ) {
1069
- var i ;
1092
+ it ( '@flaky reactangle using' + device , function ( done ) {
1093
+ var i = 0 ; // shape index
1070
1094
1071
1095
Plotly . newPlot ( gd , {
1072
1096
data : fig . data ,
@@ -1077,8 +1101,6 @@ describe('Activate and deactivate shapes to edit', function() {
1077
1101
// shape between 175, 160 and 255, 230
1078
1102
. then ( function ( ) { click ( 200 , 160 ) ; } ) // activate shape
1079
1103
. then ( function ( ) {
1080
- i = 0 ; // test first shape i.e. case of rectangle
1081
-
1082
1104
var id = gd . _fullLayout . _activeShapeIndex ;
1083
1105
expect ( id ) . toEqual ( i , 'activate shape by clicking border' ) ;
1084
1106
@@ -1198,11 +1220,22 @@ describe('Activate and deactivate shapes to edit', function() {
1198
1220
expect ( id ) . toEqual ( undefined , 'deactivate shape by clicking inside' ) ;
1199
1221
} )
1200
1222
1223
+ . catch ( failTest )
1224
+ . then ( done ) ;
1225
+ } ) ;
1226
+
1227
+ it ( '@flaky circle using' + device , function ( done ) {
1228
+ var i = 1 ; // shape index
1229
+
1230
+ Plotly . newPlot ( gd , {
1231
+ data : fig . data ,
1232
+ layout : fig . layout ,
1233
+ config : fig . config
1234
+ } )
1235
+
1201
1236
// next shape
1202
1237
. then ( function ( ) { click ( 355 , 225 ) ; } ) // activate shape
1203
1238
. then ( function ( ) {
1204
- i = 1 ; // test second shape i.e. case of circle
1205
-
1206
1239
var id = gd . _fullLayout . _activeShapeIndex ;
1207
1240
expect ( id ) . toEqual ( i , 'activate shape by clicking border' ) ;
1208
1241
@@ -1244,11 +1277,22 @@ describe('Activate and deactivate shapes to edit', function() {
1244
1277
} ) ;
1245
1278
} )
1246
1279
1280
+ . catch ( failTest )
1281
+ . then ( done ) ;
1282
+ } ) ;
1283
+
1284
+ it ( '@flaky closed-path using' + device , function ( done ) {
1285
+ var i = 2 ; // shape index
1286
+
1287
+ Plotly . newPlot ( gd , {
1288
+ data : fig . data ,
1289
+ layout : fig . layout ,
1290
+ config : fig . config
1291
+ } )
1292
+
1247
1293
// next shape
1248
1294
. then ( function ( ) { click ( 500 , 225 ) ; } ) // activate shape
1249
1295
. then ( function ( ) {
1250
- i = 2 ; // test third shape i.e. case of closed-path
1251
-
1252
1296
var id = gd . _fullLayout . _activeShapeIndex ;
1253
1297
expect ( id ) . toEqual ( i , 'activate shape by clicking border' ) ;
1254
1298
@@ -1278,11 +1322,22 @@ describe('Activate and deactivate shapes to edit', function() {
1278
1322
assertPos ( obj . path , 'M250,25L225,75L275,75Z' ) ;
1279
1323
} )
1280
1324
1325
+ . catch ( failTest )
1326
+ . then ( done ) ;
1327
+ } ) ;
1328
+
1329
+ it ( '@flaky bezier curves using' + device , function ( done ) {
1330
+ var i = 5 ; // shape index
1331
+
1332
+ Plotly . newPlot ( gd , {
1333
+ data : fig . data ,
1334
+ layout : fig . layout ,
1335
+ config : fig . config
1336
+ } )
1337
+
1281
1338
// next shape
1282
1339
. then ( function ( ) { click ( 300 , 266 ) ; } ) // activate shape
1283
1340
. then ( function ( ) {
1284
- i = 5 ; // test case of bezier curves
1285
-
1286
1341
var id = gd . _fullLayout . _activeShapeIndex ;
1287
1342
expect ( id ) . toEqual ( i , 'activate shape by clicking border' ) ;
1288
1343
@@ -1312,11 +1367,21 @@ describe('Activate and deactivate shapes to edit', function() {
1312
1367
assertPos ( obj . path , 'M0,100.00237388724034L0,199.99762611275966L50.00310077519379,199.99762611275966L0,300Q100,300,100,199.9976261127597T150.0031007751938,199.99762611275966C100,300,200,300,200,199.99762611275966S150.0031007751938,199.99762611275966,150.0031007751938,100.00237388724034Z' ) ;
1313
1368
} )
1314
1369
1315
- // next shape
1370
+ . catch ( failTest )
1371
+ . then ( done ) ;
1372
+ } ) ;
1373
+
1374
+ it ( '@flaky multi-cell path using' + device , function ( done ) {
1375
+ var i = 6 ; // shape index
1376
+
1377
+ Plotly . newPlot ( gd , {
1378
+ data : fig . data ,
1379
+ layout : fig . layout ,
1380
+ config : fig . config
1381
+ } )
1382
+
1316
1383
. then ( function ( ) { click ( 627 , 193 ) ; } ) // activate shape
1317
1384
. then ( function ( ) {
1318
- i = 6 ; // test case of multi-cell path
1319
-
1320
1385
var id = gd . _fullLayout . _activeShapeIndex ;
1321
1386
expect ( id ) . toEqual ( i , 'activate shape by clicking border' ) ;
1322
1387
@@ -1325,17 +1390,17 @@ describe('Activate and deactivate shapes to edit', function() {
1325
1390
print ( obj ) ;
1326
1391
assertPos ( obj . path , 'M300,70C300,10 380,10 380,70C380,90 300,90 300,70ZM320,60C320,50 332,50 332,60ZM348,60C348,50 360,50 360,60ZM320,70C326,80 354,80 360,70Z' ) ;
1327
1392
} )
1328
- . then ( function ( ) { drag ( [ [ 717 , 225 ] , [ 725 , 230 ] ] ) ; } ) // move vertex
1393
+ . then ( function ( ) { drag ( [ [ 717 , 225 ] , [ 700 , 250 ] ] ) ; } ) // move vertex
1329
1394
. then ( function ( ) {
1330
1395
var id = gd . _fullLayout . _activeShapeIndex ;
1331
1396
expect ( id ) . toEqual ( i , 'keep shape active after drag corner' ) ;
1332
1397
1333
1398
var shapes = gd . _fullLayout . shapes ;
1334
1399
var obj = shapes [ id ] . _input ;
1335
1400
print ( obj ) ;
1336
- assertPos ( obj . path , 'M300,69.99881305637984C300,9.998813056379817,380,9.998813056379817,380,69.99881305637984C380,90.00356083086054,300,90.00356083086054,300,69.99881305637984ZM320,60.00000000000001C320,50.00118694362017,332,50.00118694362017,332,60.00000000000001ZM348,60.00000000000001C348,50.00118694362017,360,50.00118694362017,360,60.00000000000001ZM320,69.99881305637984C326.0031007751938,79.99762611275966,354.0031007751938,79.99762611275966,364.9612403100775,69.99881305637984Z ' ) ;
1401
+ assertPos ( obj . path , 'M300,69.99881305637984C300,9.998813056379817,380,9.998813056379817,380,69.99881305637984C380,90.00356083086054,300,90.00356083086054,300,69.99881305637984ZM320,60.00000000000001C320,50.00118694362017,332,50.00118694362017,332,60.00000000000001ZM348,60.00000000000001C348,50.00118694362017,360,50.00118694362017,360,60.00000000000001ZM320,69.99881305637984C326.0031007751938,79.99762611275966,354.0031007751938,79.99762611275966,349.4573643410853,87.80296735905047Z ' ) ;
1337
1402
} )
1338
- . then ( function ( ) { drag ( [ [ 725 , 230 ] , [ 717 , 225 ] ] ) ; } ) // move vertex back
1403
+ . then ( function ( ) { drag ( [ [ 700 , 250 ] , [ 717 , 225 ] ] ) ; } ) // move vertex back
1339
1404
. then ( function ( ) {
1340
1405
var id = gd . _fullLayout . _activeShapeIndex ;
1341
1406
expect ( id ) . toEqual ( i , 'keep shape active after drag corner' ) ;
@@ -1345,6 +1410,7 @@ describe('Activate and deactivate shapes to edit', function() {
1345
1410
print ( obj ) ;
1346
1411
assertPos ( obj . path , 'M300,70C300,10 380,10 380,70C380,90 300,90 300,70ZM320,60C320,50 332,50 332,60ZM348,60C348,50 360,50 360,60ZM320,70C326,80 354,80 360,70Z' ) ;
1347
1412
} )
1413
+
1348
1414
// erase shape
1349
1415
. then ( function ( ) {
1350
1416
expect ( gd . _fullLayout . shapes . length ) . toEqual ( 8 ) ;
0 commit comments