@@ -1447,29 +1447,88 @@ describe('Activate and edit editable shapes', function() {
1447
1447
layout : {
1448
1448
shapes : [
1449
1449
{
1450
+ editable : false ,
1450
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 ,
1451
1465
x1 : 2.5 ,
1452
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 ,
1453
1480
y1 : 2.5 ,
1454
- fillcolor : 'blue'
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
+ }
1455
1496
}
1456
1497
]
1457
1498
}
1458
1499
} )
1459
1500
1460
1501
. then ( function ( ) {
1461
1502
var el = Plotly . d3 . selectAll ( '.shapelayer path' ) [ 0 ] [ 0 ] ;
1462
- var pointerEvents = el . style [ 'pointer-events' ] ;
1463
- expect ( pointerEvents ) . not . toBe ( 'all' ) ;
1464
- expect ( pointerEvents ) . not . toBe ( 'stroke' ) ;
1465
- expect ( pointerEvents ) . toBe ( '' ) ;
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
1466
1525
} )
1467
1526
1468
1527
. catch ( failTest )
1469
1528
. then ( done ) ;
1470
1529
} ) ;
1471
1530
1472
- it ( 'should provide invisible border & set pointer-events to "stroke" for editable shapes i.e. to allow shape activation' , function ( done ) {
1531
+ it ( 'should provide invisible border & set pointer-events (depending on fill transparency) for editable shapes i.e. to allow shape activation' , function ( done ) {
1473
1532
Plotly . newPlot ( gd , {
1474
1533
data : [ {
1475
1534
mode : 'markers' ,
@@ -1481,15 +1540,50 @@ describe('Activate and edit editable shapes', function() {
1481
1540
{
1482
1541
editable : true ,
1483
1542
x0 : 1.5 ,
1484
- x1 : 2.5 ,
1543
+ x1 : 2 ,
1485
1544
y0 : 1.5 ,
1486
- y1 : 2.5 ,
1545
+ y1 : 2 ,
1546
+ opacity : 0.5 ,
1487
1547
fillcolor : 'blue' ,
1488
1548
line : {
1489
1549
width : 0 ,
1490
1550
dash : 'dash' ,
1491
1551
color : 'black'
1492
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
+ }
1493
1587
}
1494
1588
]
1495
1589
}
@@ -1501,6 +1595,24 @@ describe('Activate and edit editable shapes', function() {
1501
1595
expect ( el . style . stroke ) . toBe ( 'rgb(0, 0, 0)' ) ; // no color
1502
1596
expect ( el . style [ 'stroke-opacity' ] ) . toBe ( '0' ) ; // invisible
1503
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
1504
1616
} )
1505
1617
1506
1618
. catch ( failTest )
0 commit comments