@@ -9,6 +9,7 @@ var createGraphDiv = require('../assets/create_graph_div');
9
9
var destroyGraphDiv = require ( '../assets/destroy_graph_div' ) ;
10
10
var fail = require ( '../assets/fail_test' ) ;
11
11
var mouseEvent = require ( '../assets/mouse_event' ) ;
12
+ var drag = require ( '../assets/drag' ) ;
12
13
var selectButton = require ( '../assets/modebar_button' ) ;
13
14
var delay = require ( '../assets/delay' ) ;
14
15
var readPixel = require ( '../assets/read_pixel' ) ;
@@ -1445,8 +1446,8 @@ describe('Test gl2d plots', function() {
1445
1446
var mock = require ( '@mocks/gl2d_10.json' ) ;
1446
1447
1447
1448
beforeEach ( function ( ) {
1449
+ jasmine . DEFAULT_TIMEOUT_INTERVAL = 5000 ;
1448
1450
gd = createGraphDiv ( ) ;
1449
- jasmine . DEFAULT_TIMEOUT_INTERVAL = 3000 ;
1450
1451
} ) ;
1451
1452
1452
1453
afterEach ( function ( ) {
@@ -1455,10 +1456,10 @@ describe('Test gl2d plots', function() {
1455
1456
} ) ;
1456
1457
1457
1458
function mouseTo ( p0 , p1 ) {
1458
- mouseEvent ( 'mousemove' , p0 [ 0 ] , p0 [ 1 ] ) ;
1459
- mouseEvent ( 'mousedown' , p0 [ 0 ] , p0 [ 1 ] , { buttons : 1 } ) ;
1460
- mouseEvent ( 'mousemove' , p1 [ 0 ] , p1 [ 1 ] , { buttons : 1 } ) ;
1461
- mouseEvent ( 'mouseup' , p1 [ 0 ] , p1 [ 1 ] ) ;
1459
+ var node = d3 . select ( '.nsewdrag[data-subplot="xy"]' ) . node ( ) ;
1460
+ var dx = p1 [ 0 ] - p0 [ 0 ] ;
1461
+ var dy = p1 [ 1 ] - p0 [ 1 ] ;
1462
+ return drag ( node , dx , dy , null , p0 [ 0 ] , p0 [ 1 ] ) ;
1462
1463
}
1463
1464
1464
1465
it ( 'should respond to drag interactions' , function ( done ) {
@@ -1472,7 +1473,7 @@ describe('Test gl2d plots', function() {
1472
1473
var newY = [ - 1.7 , 4.95 ] ;
1473
1474
var precision = 1 ;
1474
1475
1475
- Plotly . plot ( gd , _mock )
1476
+ Plotly . newPlot ( gd , _mock )
1476
1477
. then ( delay ( 20 ) )
1477
1478
. then ( function ( ) {
1478
1479
expect ( gd . layout . xaxis . autorange ) . toBe ( true ) ;
@@ -1493,43 +1494,54 @@ describe('Test gl2d plots', function() {
1493
1494
. then ( delay ( 200 ) )
1494
1495
. then ( function ( ) {
1495
1496
gd . on ( 'plotly_relayout' , relayoutCallback ) ;
1496
-
1497
+ } )
1498
+ . then ( function ( ) {
1497
1499
// Drag scene along the X axis
1498
- mouseTo ( [ 200 , 200 ] , [ 220 , 200 ] ) ;
1499
-
1500
+ return mouseTo ( [ 200 , 200 ] , [ 220 , 200 ] ) ;
1501
+ } )
1502
+ . then ( function ( ) {
1500
1503
expect ( gd . layout . xaxis . autorange ) . toBe ( false ) ;
1501
1504
expect ( gd . layout . yaxis . autorange ) . toBe ( false ) ;
1502
-
1503
1505
expect ( gd . layout . xaxis . range ) . toBeCloseToArray ( newX , precision ) ;
1504
1506
expect ( gd . layout . yaxis . range ) . toBeCloseToArray ( originalY , precision ) ;
1505
-
1507
+ } )
1508
+ . then ( function ( ) {
1506
1509
// Drag scene back along the X axis
1507
- mouseTo ( [ 220 , 200 ] , [ 200 , 200 ] ) ;
1508
-
1510
+ return mouseTo ( [ 220 , 200 ] , [ 200 , 200 ] ) ;
1511
+ } )
1512
+ . then ( function ( ) {
1509
1513
expect ( gd . layout . xaxis . range ) . toBeCloseToArray ( originalX , precision ) ;
1510
1514
expect ( gd . layout . yaxis . range ) . toBeCloseToArray ( originalY , precision ) ;
1511
-
1515
+ } )
1516
+ . then ( function ( ) {
1512
1517
// Drag scene along the Y axis
1513
- mouseTo ( [ 200 , 200 ] , [ 200 , 150 ] ) ;
1514
-
1518
+ return mouseTo ( [ 200 , 200 ] , [ 200 , 150 ] ) ;
1519
+ } )
1520
+ . then ( function ( ) {
1515
1521
expect ( gd . layout . xaxis . range ) . toBeCloseToArray ( originalX , precision ) ;
1516
1522
expect ( gd . layout . yaxis . range ) . toBeCloseToArray ( newY , precision ) ;
1517
-
1523
+ } )
1524
+ . then ( function ( ) {
1518
1525
// Drag scene back along the Y axis
1519
- mouseTo ( [ 200 , 150 ] , [ 200 , 200 ] ) ;
1520
-
1526
+ return mouseTo ( [ 200 , 150 ] , [ 200 , 200 ] ) ;
1527
+ } )
1528
+ . then ( function ( ) {
1521
1529
expect ( gd . layout . xaxis . range ) . toBeCloseToArray ( originalX , precision ) ;
1522
1530
expect ( gd . layout . yaxis . range ) . toBeCloseToArray ( originalY , precision ) ;
1523
-
1531
+ } )
1532
+ . then ( function ( ) {
1524
1533
// Drag scene along both the X and Y axis
1525
- mouseTo ( [ 200 , 200 ] , [ 220 , 150 ] ) ;
1526
-
1534
+ return mouseTo ( [ 200 , 200 ] , [ 220 , 150 ] ) ;
1535
+ } )
1536
+ . then ( function ( ) {
1527
1537
expect ( gd . layout . xaxis . range ) . toBeCloseToArray ( newX , precision ) ;
1528
1538
expect ( gd . layout . yaxis . range ) . toBeCloseToArray ( newY , precision ) ;
1529
-
1539
+ } )
1540
+ . then ( function ( ) {
1530
1541
// Drag scene back along the X and Y axis
1531
- mouseTo ( [ 220 , 150 ] , [ 200 , 200 ] ) ;
1532
-
1542
+ return mouseTo ( [ 220 , 150 ] , [ 200 , 200 ] ) ;
1543
+ } )
1544
+ . then ( function ( ) {
1533
1545
expect ( gd . layout . xaxis . range ) . toBeCloseToArray ( originalX , precision ) ;
1534
1546
expect ( gd . layout . yaxis . range ) . toBeCloseToArray ( originalY , precision ) ;
1535
1547
} )
@@ -1546,6 +1558,7 @@ describe('Test gl2d plots', function() {
1546
1558
'yaxis.range[1]' : jasmine . any ( Number )
1547
1559
} ) ) ;
1548
1560
} )
1561
+ . catch ( fail )
1549
1562
. then ( done ) ;
1550
1563
} ) ;
1551
1564
@@ -1604,39 +1617,51 @@ describe('Test gl2d plots', function() {
1604
1617
} ) ;
1605
1618
1606
1619
it ( 'supports 1D and 2D Zoom' , function ( done ) {
1607
- var centerX , centerY ;
1608
- Plotly . newPlot ( gd ,
1609
- [ { type : 'scattergl' , x : [ 1 , 15 ] , y : [ 1 , 15 ] } ] ,
1610
- {
1611
- width : 400 ,
1612
- height : 400 ,
1613
- margin : { t : 100 , b : 100 , l : 100 , r : 100 } ,
1614
- xaxis : { range : [ 0 , 16 ] } ,
1615
- yaxis : { range : [ 0 , 16 ] }
1616
- }
1617
- )
1620
+ var centerX ;
1621
+ var centerY ;
1622
+
1623
+ Plotly . newPlot ( gd , [ {
1624
+ type : 'scattergl' , x : [ 1 , 15 ] , y : [ 1 , 15 ]
1625
+ } ] , {
1626
+ width : 400 ,
1627
+ height : 400 ,
1628
+ margin : { t : 100 , b : 100 , l : 100 , r : 100 } ,
1629
+ xaxis : { range : [ 0 , 16 ] } ,
1630
+ yaxis : { range : [ 0 , 16 ] }
1631
+ } )
1618
1632
. then ( function ( ) {
1619
1633
var bBox = gd . getBoundingClientRect ( ) ;
1620
1634
centerX = bBox . left + 200 ;
1621
1635
centerY = bBox . top + 200 ;
1622
1636
1637
+ return mouseTo ( [ centerX , centerY ] , [ centerX - 5 , centerY + 5 ] ) ;
1638
+ } )
1639
+ . then ( function ( ) {
1623
1640
// no change - too small
1624
- mouseTo ( [ centerX , centerY ] , [ centerX - 5 , centerY + 5 ] ) ;
1625
1641
expect ( gd . layout . xaxis . range ) . toBeCloseToArray ( [ 0 , 16 ] , 3 ) ;
1626
1642
expect ( gd . layout . yaxis . range ) . toBeCloseToArray ( [ 0 , 16 ] , 3 ) ;
1627
-
1643
+ } )
1644
+ . then ( function ( ) {
1645
+ return mouseTo ( [ centerX - 50 , centerY ] , [ centerX + 50 , centerY + 50 ] ) ;
1646
+ } )
1647
+ . then ( function ( ) {
1628
1648
// 2D
1629
- mouseTo ( [ centerX - 50 , centerY ] , [ centerX + 50 , centerY + 50 ] ) ;
1630
1649
expect ( gd . layout . xaxis . range ) . toBeCloseToArray ( [ 4 , 12 ] , 3 ) ;
1631
1650
expect ( gd . layout . yaxis . range ) . toBeCloseToArray ( [ 4 , 8 ] , 3 ) ;
1632
-
1651
+ } )
1652
+ . then ( function ( ) {
1653
+ return mouseTo ( [ centerX - 50 , centerY ] , [ centerX , centerY + 5 ] ) ;
1654
+ } )
1655
+ . then ( function ( ) {
1633
1656
// x only
1634
- mouseTo ( [ centerX - 50 , centerY ] , [ centerX , centerY + 5 ] ) ;
1635
1657
expect ( gd . layout . xaxis . range ) . toBeCloseToArray ( [ 6 , 8 ] , 3 ) ;
1636
1658
expect ( gd . layout . yaxis . range ) . toBeCloseToArray ( [ 4 , 8 ] , 3 ) ;
1637
-
1659
+ } )
1660
+ . then ( function ( ) {
1661
+ return mouseTo ( [ centerX , centerY - 50 ] , [ centerX - 5 , centerY + 50 ] ) ;
1662
+ } )
1663
+ . then ( function ( ) {
1638
1664
// y only
1639
- mouseTo ( [ centerX , centerY - 50 ] , [ centerX - 5 , centerY + 50 ] ) ;
1640
1665
expect ( gd . layout . xaxis . range ) . toBeCloseToArray ( [ 6 , 8 ] , 3 ) ;
1641
1666
expect ( gd . layout . yaxis . range ) . toBeCloseToArray ( [ 5 , 7 ] , 3 ) ;
1642
1667
} )
@@ -1645,17 +1670,18 @@ describe('Test gl2d plots', function() {
1645
1670
} ) ;
1646
1671
1647
1672
it ( 'supports axis constraints with zoom' , function ( done ) {
1648
- var centerX , centerY ;
1649
- Plotly . newPlot ( gd ,
1650
- [ { type : 'scattergl' , x : [ 1 , 15 ] , y : [ 1 , 15 ] } ] ,
1651
- {
1652
- width : 400 ,
1653
- height : 400 ,
1654
- margin : { t : 100 , b : 100 , l : 100 , r : 100 } ,
1655
- xaxis : { range : [ 0 , 16 ] } ,
1656
- yaxis : { range : [ 0 , 16 ] }
1657
- }
1658
- )
1673
+ var centerX ;
1674
+ var centerY ;
1675
+
1676
+ Plotly . newPlot ( gd , [ {
1677
+ type : 'scattergl' , x : [ 1 , 15 ] , y : [ 1 , 15 ]
1678
+ } ] , {
1679
+ width : 400 ,
1680
+ height : 400 ,
1681
+ margin : { t : 100 , b : 100 , l : 100 , r : 100 } ,
1682
+ xaxis : { range : [ 0 , 16 ] } ,
1683
+ yaxis : { range : [ 0 , 16 ] }
1684
+ } )
1659
1685
. then ( function ( ) {
1660
1686
var bBox = gd . getBoundingClientRect ( ) ;
1661
1687
centerX = bBox . left + 200 ;
@@ -1670,23 +1696,33 @@ describe('Test gl2d plots', function() {
1670
1696
// x range is adjusted to fit constraint
1671
1697
expect ( gd . layout . xaxis . range ) . toBeCloseToArray ( [ - 8 , 24 ] , 3 ) ;
1672
1698
expect ( gd . layout . yaxis . range ) . toBeCloseToArray ( [ 0 , 16 ] , 3 ) ;
1673
-
1699
+ } )
1700
+ . then ( function ( ) {
1701
+ return mouseTo ( [ centerX , centerY ] , [ centerX - 5 , centerY + 5 ] ) ;
1702
+ } )
1703
+ . then ( function ( ) {
1674
1704
// no change - too small
1675
- mouseTo ( [ centerX , centerY ] , [ centerX - 5 , centerY + 5 ] ) ;
1676
1705
expect ( gd . layout . xaxis . range ) . toBeCloseToArray ( [ - 8 , 24 ] , 3 ) ;
1677
1706
expect ( gd . layout . yaxis . range ) . toBeCloseToArray ( [ 0 , 16 ] , 3 ) ;
1678
-
1707
+ } )
1708
+ . then ( function ( ) {
1679
1709
// now there should only be 2D zooming
1680
1710
// dy>>dx
1681
- mouseTo ( [ centerX , centerY ] , [ centerX - 1 , centerY - 50 ] ) ;
1711
+ return mouseTo ( [ centerX , centerY ] , [ centerX - 1 , centerY - 50 ] ) ;
1712
+ } )
1713
+ . then ( function ( ) {
1682
1714
expect ( gd . layout . xaxis . range ) . toBeCloseToArray ( [ 0 , 8 ] , 3 ) ;
1683
1715
expect ( gd . layout . yaxis . range ) . toBeCloseToArray ( [ 8 , 12 ] , 3 ) ;
1684
-
1716
+ } )
1717
+ . then ( function ( ) {
1718
+ return mouseTo ( [ centerX , centerY ] , [ centerX + 50 , centerY + 1 ] ) ;
1719
+ } )
1720
+ . then ( function ( ) {
1685
1721
// dx>>dy
1686
- mouseTo ( [ centerX , centerY ] , [ centerX + 50 , centerY + 1 ] ) ;
1687
1722
expect ( gd . layout . xaxis . range ) . toBeCloseToArray ( [ 4 , 6 ] , 3 ) ;
1688
1723
expect ( gd . layout . yaxis . range ) . toBeCloseToArray ( [ 9 , 10 ] , 3 ) ;
1689
-
1724
+ } )
1725
+ . then ( function ( ) {
1690
1726
return Plotly . relayout ( gd , {
1691
1727
'xaxis.autorange' : true ,
1692
1728
'yaxis.autorange' : true
@@ -1712,28 +1748,8 @@ describe('Test gl2d plots', function() {
1712
1748
1713
1749
done ( ) ;
1714
1750
} ) ;
1715
- } ) ;
1716
-
1717
- describe ( 'Test gl2d interactions' , function ( ) {
1718
- var gd ;
1719
-
1720
- beforeEach ( function ( ) {
1721
- gd = createGraphDiv ( ) ;
1722
- } ) ;
1723
-
1724
- afterEach ( function ( ) {
1725
- Plotly . purge ( gd ) ;
1726
- destroyGraphDiv ( ) ;
1727
- } ) ;
1728
1751
1729
1752
it ( 'data-referenced annotations should update on drag' , function ( done ) {
1730
- function drag ( start , end ) {
1731
- mouseEvent ( 'mousemove' , start [ 0 ] , start [ 1 ] ) ;
1732
- mouseEvent ( 'mousedown' , start [ 0 ] , start [ 1 ] , { buttons : 1 } ) ;
1733
- mouseEvent ( 'mousemove' , end [ 0 ] , end [ 1 ] , { buttons : 1 } ) ;
1734
- mouseEvent ( 'mouseup' , end [ 0 ] , end [ 1 ] ) ;
1735
- }
1736
-
1737
1753
function assertAnnotation ( xy ) {
1738
1754
var ann = d3 . select ( 'g.annotation-text-g' ) . select ( 'g' ) ;
1739
1755
var translate = Drawing . getTranslate ( ann ) ;
@@ -1742,7 +1758,7 @@ describe('Test gl2d interactions', function() {
1742
1758
expect ( translate . y ) . toBeWithin ( xy [ 1 ] , 8 ) ;
1743
1759
}
1744
1760
1745
- Plotly . plot ( gd , [ {
1761
+ Plotly . newPlot ( gd , [ {
1746
1762
type : 'scattergl' ,
1747
1763
x : [ 1 , 2 , 3 ] ,
1748
1764
y : [ 2 , 1 , 2 ]
@@ -1756,10 +1772,14 @@ describe('Test gl2d interactions', function() {
1756
1772
} )
1757
1773
. then ( function ( ) {
1758
1774
assertAnnotation ( [ 327 , 312 ] ) ;
1759
-
1760
- drag ( [ 250 , 200 ] , [ 200 , 150 ] ) ;
1775
+ } )
1776
+ . then ( function ( ) {
1777
+ return mouseTo ( [ 250 , 200 ] , [ 200 , 150 ] ) ;
1778
+ } )
1779
+ . then ( function ( ) {
1761
1780
assertAnnotation ( [ 277 , 262 ] ) ;
1762
-
1781
+ } )
1782
+ . then ( function ( ) {
1763
1783
return Plotly . relayout ( gd , {
1764
1784
'xaxis.range' : [ 1.5 , 2.5 ] ,
1765
1785
'yaxis.range' : [ 1 , 1.5 ]
@@ -1768,6 +1788,7 @@ describe('Test gl2d interactions', function() {
1768
1788
. then ( function ( ) {
1769
1789
assertAnnotation ( [ 327 , 331 ] ) ;
1770
1790
} )
1791
+ . catch ( fail )
1771
1792
. then ( done ) ;
1772
1793
} ) ;
1773
1794
} ) ;
0 commit comments