@@ -1089,7 +1089,7 @@ describe('Activate and edit editable shapes', function() {
1089
1089
afterEach ( destroyGraphDiv ) ;
1090
1090
1091
1091
[ 'mouse' ] . forEach ( function ( device ) {
1092
- it ( '@flaky reactangle using' + device , function ( done ) {
1092
+ it ( '@flaky reactangle using ' + device , function ( done ) {
1093
1093
var i = 0 ; // shape index
1094
1094
1095
1095
Plotly . newPlot ( gd , {
@@ -1224,7 +1224,7 @@ describe('Activate and edit editable shapes', function() {
1224
1224
. then ( done ) ;
1225
1225
} ) ;
1226
1226
1227
- it ( '@flaky circle using' + device , function ( done ) {
1227
+ it ( '@flaky circle using ' + device , function ( done ) {
1228
1228
var i = 1 ; // shape index
1229
1229
1230
1230
Plotly . newPlot ( gd , {
@@ -1281,7 +1281,7 @@ describe('Activate and edit editable shapes', function() {
1281
1281
. then ( done ) ;
1282
1282
} ) ;
1283
1283
1284
- it ( '@flaky closed-path using' + device , function ( done ) {
1284
+ it ( '@flaky closed-path using ' + device , function ( done ) {
1285
1285
var i = 2 ; // shape index
1286
1286
1287
1287
Plotly . newPlot ( gd , {
@@ -1326,7 +1326,7 @@ describe('Activate and edit editable shapes', function() {
1326
1326
. then ( done ) ;
1327
1327
} ) ;
1328
1328
1329
- it ( '@flaky bezier curves using' + device , function ( done ) {
1329
+ it ( '@flaky bezier curves using ' + device , function ( done ) {
1330
1330
var i = 5 ; // shape index
1331
1331
1332
1332
Plotly . newPlot ( gd , {
@@ -1371,7 +1371,7 @@ describe('Activate and edit editable shapes', function() {
1371
1371
. then ( done ) ;
1372
1372
} ) ;
1373
1373
1374
- it ( '@flaky multi-cell path using' + device , function ( done ) {
1374
+ it ( '@flaky multi-cell path using ' + device , function ( done ) {
1375
1375
var i = 6 ; // shape index
1376
1376
1377
1377
Plotly . newPlot ( gd , {
@@ -1426,3 +1426,236 @@ describe('Activate and edit editable shapes', function() {
1426
1426
} ) ;
1427
1427
} ) ;
1428
1428
} ) ;
1429
+
1430
+
1431
+ describe ( 'Activate and edit editable shapes' , function ( ) {
1432
+ var gd ;
1433
+
1434
+ beforeEach ( function ( ) {
1435
+ gd = createGraphDiv ( ) ;
1436
+ } ) ;
1437
+
1438
+ afterEach ( destroyGraphDiv ) ;
1439
+
1440
+ it ( 'should not set pointer-events for non-editable shapes i.e. to allow pan/zoom/hover work inside shapes' , function ( done ) {
1441
+ Plotly . newPlot ( gd , {
1442
+ data : [ {
1443
+ mode : 'markers' ,
1444
+ x : [ 1 , 3 , 3 ] ,
1445
+ y : [ 2 , 1 , 3 ]
1446
+ } ] ,
1447
+ layout : {
1448
+ shapes : [
1449
+ {
1450
+ editable : false ,
1451
+ x0 : 1.5 ,
1452
+ x1 : 2 ,
1453
+ y0 : 1.5 ,
1454
+ y1 : 2 ,
1455
+ opacity : 0.5 ,
1456
+ fillcolor : 'blue' ,
1457
+ line : {
1458
+ width : 0 ,
1459
+ dash : 'dash' ,
1460
+ color : 'black'
1461
+ }
1462
+ } , {
1463
+ editable : false ,
1464
+ x0 : 2 ,
1465
+ x1 : 2.5 ,
1466
+ y0 : 1.5 ,
1467
+ y1 : 2 ,
1468
+ opacity : 0.7 ,
1469
+ fillcolor : 'rgba(255,0,0,0.7)' , // N.B. 0.7 * 0.7 = 0.49 <= 0.5 is quite transparent
1470
+ line : {
1471
+ width : 0 ,
1472
+ dash : 'dash' ,
1473
+ color : 'black'
1474
+ }
1475
+ } , {
1476
+ editable : false ,
1477
+ x0 : 1.5 ,
1478
+ x1 : 2 ,
1479
+ y0 : 2 ,
1480
+ y1 : 2.5 ,
1481
+ fillcolor : 'red' ,
1482
+ line : {
1483
+ width : 3 ,
1484
+ dash : 'dash' ,
1485
+ color : 'green'
1486
+ }
1487
+ } , {
1488
+ editable : false ,
1489
+ path : 'M2,2H2.5,V2.5' , // open path
1490
+ fillcolor : 'rgba(0,0,0,0)' ,
1491
+ line : {
1492
+ width : 3 ,
1493
+ dash : 'dash' ,
1494
+ color : 'green'
1495
+ }
1496
+ }
1497
+ ]
1498
+ }
1499
+ } )
1500
+
1501
+ . then ( function ( ) {
1502
+ var el = Plotly . d3 . selectAll ( '.shapelayer path' ) [ 0 ] [ 0 ] ;
1503
+ expect ( el . style [ 'pointer-events' ] ) . toBe ( '' ) ;
1504
+ expect ( el . style . stroke ) . toBe ( 'rgb(0, 0, 0)' ) ; // no color
1505
+ expect ( el . style [ 'stroke-opacity' ] ) . toBe ( '0' ) ; // invisible
1506
+ expect ( el . style [ 'stroke-width' ] ) . toBe ( '0px' ) ; // no pixel
1507
+
1508
+ el = Plotly . d3 . selectAll ( '.shapelayer path' ) [ 0 ] [ 1 ] ;
1509
+ expect ( el . style [ 'pointer-events' ] ) . toBe ( '' ) ;
1510
+ expect ( el . style . stroke ) . toBe ( 'rgb(0, 0, 0)' ) ; // no color
1511
+ expect ( el . style [ 'stroke-opacity' ] ) . toBe ( '0' ) ; // invisible
1512
+ expect ( el . style [ 'stroke-width' ] ) . toBe ( '0px' ) ; // no pixel
1513
+
1514
+ el = Plotly . d3 . selectAll ( '.shapelayer path' ) [ 0 ] [ 2 ] ;
1515
+ expect ( el . style [ 'pointer-events' ] ) . toBe ( '' ) ;
1516
+ expect ( el . style . stroke ) . toBe ( 'rgb(0, 128, 0)' ) ; // custom color
1517
+ expect ( el . style [ 'stroke-opacity' ] ) . toBe ( '1' ) ; // visible
1518
+ expect ( el . style [ 'stroke-width' ] ) . toBe ( '3px' ) ; // custom pixel
1519
+
1520
+ el = Plotly . d3 . selectAll ( '.shapelayer path' ) [ 0 ] [ 3 ] ;
1521
+ expect ( el . style [ 'pointer-events' ] ) . toBe ( '' ) ;
1522
+ expect ( el . style . stroke ) . toBe ( 'rgb(0, 128, 0)' ) ; // custom color
1523
+ expect ( el . style [ 'stroke-opacity' ] ) . toBe ( '1' ) ; // visible
1524
+ expect ( el . style [ 'stroke-width' ] ) . toBe ( '3px' ) ; // custom pixel
1525
+ } )
1526
+
1527
+ . catch ( failTest )
1528
+ . then ( done ) ;
1529
+ } ) ;
1530
+
1531
+ it ( 'should provide invisible border & set pointer-events (depending on fill transparency) for editable shapes i.e. to allow shape activation' , function ( done ) {
1532
+ Plotly . newPlot ( gd , {
1533
+ data : [ {
1534
+ mode : 'markers' ,
1535
+ x : [ 1 , 3 , 3 ] ,
1536
+ y : [ 2 , 1 , 3 ]
1537
+ } ] ,
1538
+ layout : {
1539
+ shapes : [
1540
+ {
1541
+ editable : true ,
1542
+ x0 : 1.5 ,
1543
+ x1 : 2 ,
1544
+ y0 : 1.5 ,
1545
+ y1 : 2 ,
1546
+ opacity : 0.5 ,
1547
+ fillcolor : 'blue' ,
1548
+ line : {
1549
+ width : 0 ,
1550
+ dash : 'dash' ,
1551
+ color : 'black'
1552
+ }
1553
+ } , {
1554
+ editable : true ,
1555
+ x0 : 2 ,
1556
+ x1 : 2.5 ,
1557
+ y0 : 1.5 ,
1558
+ y1 : 2 ,
1559
+ opacity : 0.7 ,
1560
+ fillcolor : 'rgba(255,0,0,0.7)' , // N.B. 0.7 * 0.7 = 0.49 <= 0.5 is quite transparent
1561
+ line : {
1562
+ width : 0 ,
1563
+ dash : 'dash' ,
1564
+ color : 'black'
1565
+ }
1566
+ } , {
1567
+ editable : true ,
1568
+ x0 : 1.5 ,
1569
+ x1 : 2 ,
1570
+ y0 : 2 ,
1571
+ y1 : 2.5 ,
1572
+ fillcolor : 'red' ,
1573
+ line : {
1574
+ width : 3 ,
1575
+ dash : 'dash' ,
1576
+ color : 'green'
1577
+ }
1578
+ } , {
1579
+ editable : true ,
1580
+ path : 'M2,2H2.5,V2.5' , // open path
1581
+ fillcolor : 'rgba(0,0,0,0)' ,
1582
+ line : {
1583
+ width : 3 ,
1584
+ dash : 'dash' ,
1585
+ color : 'green'
1586
+ }
1587
+ }
1588
+ ]
1589
+ }
1590
+ } )
1591
+
1592
+ . then ( function ( ) {
1593
+ var el = Plotly . d3 . selectAll ( '.shapelayer path' ) [ 0 ] [ 0 ] ;
1594
+ expect ( el . style [ 'pointer-events' ] ) . toBe ( 'stroke' ) ;
1595
+ expect ( el . style . stroke ) . toBe ( 'rgb(0, 0, 0)' ) ; // no color
1596
+ expect ( el . style [ 'stroke-opacity' ] ) . toBe ( '0' ) ; // invisible
1597
+ expect ( el . style [ 'stroke-width' ] ) . toBe ( '5px' ) ; // some pixels to activate shape
1598
+
1599
+ el = Plotly . d3 . selectAll ( '.shapelayer path' ) [ 0 ] [ 1 ] ;
1600
+ expect ( el . style [ 'pointer-events' ] ) . toBe ( 'stroke' ) ;
1601
+ expect ( el . style . stroke ) . toBe ( 'rgb(0, 0, 0)' ) ; // no color
1602
+ expect ( el . style [ 'stroke-opacity' ] ) . toBe ( '0' ) ; // invisible
1603
+ expect ( el . style [ 'stroke-width' ] ) . toBe ( '5px' ) ; // some pixels to activate shape
1604
+
1605
+ el = Plotly . d3 . selectAll ( '.shapelayer path' ) [ 0 ] [ 2 ] ;
1606
+ expect ( el . style [ 'pointer-events' ] ) . toBe ( 'all' ) ;
1607
+ expect ( el . style . stroke ) . toBe ( 'rgb(0, 128, 0)' ) ; // custom color
1608
+ expect ( el . style [ 'stroke-opacity' ] ) . toBe ( '1' ) ; // visible
1609
+ expect ( el . style [ 'stroke-width' ] ) . toBe ( '3px' ) ; // custom pixel
1610
+
1611
+ el = Plotly . d3 . selectAll ( '.shapelayer path' ) [ 0 ] [ 3 ] ;
1612
+ expect ( el . style [ 'pointer-events' ] ) . toBe ( 'stroke' ) ;
1613
+ expect ( el . style . stroke ) . toBe ( 'rgb(0, 128, 0)' ) ; // custom color
1614
+ expect ( el . style [ 'stroke-opacity' ] ) . toBe ( '1' ) ; // visible
1615
+ expect ( el . style [ 'stroke-width' ] ) . toBe ( '3px' ) ; // custom pixel
1616
+ } )
1617
+
1618
+ . catch ( failTest )
1619
+ . then ( done ) ;
1620
+ } ) ;
1621
+
1622
+ it ( 'should not provide invisible border & set pointer-events to "stroke" for shapes made editable via config' , function ( done ) {
1623
+ Plotly . newPlot ( gd , {
1624
+ data : [ {
1625
+ mode : 'markers' ,
1626
+ x : [ 1 , 3 , 3 ] ,
1627
+ y : [ 2 , 1 , 3 ]
1628
+ } ] ,
1629
+ layout : {
1630
+ shapes : [
1631
+ {
1632
+ x0 : 1.5 ,
1633
+ x1 : 2.5 ,
1634
+ y0 : 1.5 ,
1635
+ y1 : 2.5 ,
1636
+ fillcolor : 'blue' ,
1637
+ line : {
1638
+ width : 0 ,
1639
+ dash : 'dash' ,
1640
+ color : 'black'
1641
+ }
1642
+ }
1643
+ ]
1644
+ } ,
1645
+ config : {
1646
+ editable : true
1647
+ }
1648
+ } )
1649
+
1650
+ . then ( function ( ) {
1651
+ var el = Plotly . d3 . selectAll ( '.shapelayer path' ) [ 0 ] [ 0 ] ;
1652
+ expect ( el . style [ 'pointer-events' ] ) . toBe ( 'all' ) ;
1653
+ expect ( el . style . stroke ) . toBe ( 'rgb(0, 0, 0)' ) ; // no color
1654
+ expect ( el . style [ 'stroke-opacity' ] ) . toBe ( '0' ) ; // invisible
1655
+ expect ( el . style [ 'stroke-width' ] ) . toBe ( '0px' ) ; // no extra pixels
1656
+ } )
1657
+
1658
+ . catch ( failTest )
1659
+ . then ( done ) ;
1660
+ } ) ;
1661
+ } ) ;
0 commit comments