@@ -9,10 +9,8 @@ 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' ) ;
13
12
var selectButton = require ( '../assets/modebar_button' ) ;
14
13
var delay = require ( '../assets/delay' ) ;
15
- var readPixel = require ( '../assets/read_pixel' ) ;
16
14
17
15
var customAssertions = require ( '../assets/custom_assertions' ) ;
18
16
var assertHoverLabelStyle = customAssertions . assertHoverLabelStyle ;
@@ -1239,21 +1237,6 @@ describe('Test removal of gl contexts', function() {
1239
1237
. then ( done ) ;
1240
1238
} ) ;
1241
1239
1242
- it ( 'Plots.cleanPlot should remove gl context from the graph div of a gl2d plot' , function ( done ) {
1243
- Plotly . plot ( gd , [ {
1244
- type : 'scattergl' ,
1245
- x : [ 1 , 2 , 3 ] ,
1246
- y : [ 2 , 1 , 3 ]
1247
- } ] )
1248
- . then ( function ( ) {
1249
- expect ( gd . _fullLayout . _plots . xy . _scene ) . toBeDefined ( ) ;
1250
- Plots . cleanPlot ( [ ] , { } , gd . _fullData , gd . _fullLayout ) ;
1251
-
1252
- expect ( gd . _fullLayout . _plots . xy . _scene ) . toBeUndefined ( ) ;
1253
- } )
1254
- . then ( done ) ;
1255
- } ) ;
1256
-
1257
1240
it ( 'Plotly.newPlot should remove gl context from the graph div of a gl3d plot' , function ( done ) {
1258
1241
var firstGlplotObject , firstGlContext , firstCanvas ;
1259
1242
@@ -1297,551 +1280,4 @@ describe('Test removal of gl contexts', function() {
1297
1280
} )
1298
1281
. then ( done ) ;
1299
1282
} ) ;
1300
-
1301
- it ( 'Plotly.newPlot should remove gl context from the graph div of a gl2d plot' , function ( done ) {
1302
- var firstGlplotObject , firstGlContext , firstCanvas ;
1303
-
1304
- Plotly . plot ( gd , [ {
1305
- type : 'scattergl' ,
1306
- x : [ 1 , 2 , 3 ] ,
1307
- y : [ 2 , 1 , 3 ]
1308
- } ] )
1309
- . then ( function ( ) {
1310
- firstGlplotObject = gd . _fullLayout . _plots . xy . _scene ;
1311
- firstGlContext = firstGlplotObject . scatter2d . gl ;
1312
- firstCanvas = firstGlContext . canvas ;
1313
-
1314
- expect ( firstGlplotObject ) . toBeDefined ( ) ;
1315
- expect ( firstGlContext ) . toBeDefined ( ) ;
1316
- expect ( firstGlContext instanceof WebGLRenderingContext ) ;
1317
-
1318
- return Plotly . newPlot ( gd , [ {
1319
- type : 'scattergl' ,
1320
- x : [ 1 , 2 , 3 ] ,
1321
- y : [ 2 , 1 , 3 ]
1322
- } ] , { } ) ;
1323
- } )
1324
- . then ( function ( ) {
1325
- var secondGlplotObject = gd . _fullLayout . _plots . xy . _scene ;
1326
- var secondGlContext = secondGlplotObject . scatter2d . gl ;
1327
- var secondCanvas = secondGlContext . canvas ;
1328
-
1329
- expect ( Object . keys ( gd . _fullLayout . _plots ) . length === 1 ) ;
1330
- expect ( secondGlplotObject ) . not . toBe ( firstGlplotObject ) ;
1331
- expect ( firstGlplotObject . gl === null ) ;
1332
- expect ( secondGlContext instanceof WebGLRenderingContext ) ;
1333
- expect ( secondGlContext ) . not . toBe ( firstGlContext ) ;
1334
-
1335
- expect (
1336
- firstCanvas . parentNode === null ||
1337
- firstCanvas !== secondCanvas && firstGlContext . isContextLost ( )
1338
- ) ;
1339
- } )
1340
- . then ( done ) ;
1341
- } ) ;
1342
- } ) ;
1343
-
1344
- describe ( 'Test gl plot side effects' , function ( ) {
1345
- var gd ;
1346
-
1347
- beforeEach ( function ( ) {
1348
- gd = createGraphDiv ( ) ;
1349
- } ) ;
1350
-
1351
- afterEach ( function ( ) {
1352
- Plotly . purge ( gd ) ;
1353
- destroyGraphDiv ( ) ;
1354
- } ) ;
1355
-
1356
- it ( 'should not draw the rangeslider' , function ( done ) {
1357
- var data = [ {
1358
- x : [ 1 , 2 , 3 ] ,
1359
- y : [ 2 , 3 , 4 ] ,
1360
- type : 'scattergl'
1361
- } , {
1362
- x : [ 1 , 2 , 3 ] ,
1363
- y : [ 2 , 3 , 4 ] ,
1364
- type : 'scatter'
1365
- } ] ;
1366
-
1367
- var layout = {
1368
- xaxis : { rangeslider : { visible : true } }
1369
- } ;
1370
-
1371
- Plotly . plot ( gd , data , layout ) . then ( function ( ) {
1372
- var rangeSlider = document . getElementsByClassName ( 'range-slider' ) [ 0 ] ;
1373
- expect ( rangeSlider ) . not . toBeDefined ( ) ;
1374
- } )
1375
- . then ( done ) ;
1376
- } ) ;
1377
-
1378
- it ( 'should be able to replot from a blank graph' , function ( done ) {
1379
-
1380
- function countCanvases ( cnt ) {
1381
- var nodes = d3 . selectAll ( 'canvas' ) ;
1382
- expect ( nodes . size ( ) ) . toEqual ( cnt ) ;
1383
- }
1384
-
1385
- var data = [ {
1386
- type : 'scattergl' ,
1387
- x : [ 1 , 2 , 3 ] ,
1388
- y : [ 2 , 1 , 2 ]
1389
- } ] ;
1390
-
1391
- Plotly . plot ( gd , [ ] )
1392
- . then ( function ( ) {
1393
- countCanvases ( 0 ) ;
1394
-
1395
- return Plotly . plot ( gd , data ) ;
1396
- } )
1397
- . then ( function ( ) {
1398
- countCanvases ( 3 ) ;
1399
-
1400
- return Plotly . purge ( gd ) ;
1401
- } )
1402
- . then ( function ( ) {
1403
- countCanvases ( 0 ) ;
1404
-
1405
- return Plotly . plot ( gd , data ) ;
1406
- } )
1407
- . then ( function ( ) {
1408
- countCanvases ( 3 ) ;
1409
-
1410
- return Plotly . deleteTraces ( gd , [ 0 ] ) ;
1411
- } )
1412
- . then ( function ( ) {
1413
- countCanvases ( 0 ) ;
1414
-
1415
- return Plotly . purge ( gd ) ;
1416
- } )
1417
- . then ( done ) ;
1418
- } ) ;
1419
-
1420
- it ( 'should be able to switch trace type' , function ( done ) {
1421
- Plotly . newPlot ( gd , [ {
1422
- type : 'parcoords' ,
1423
- x : [ 1 , 2 , 3 ] ,
1424
- y : [ 2 , 1 , 2 ] ,
1425
- dimensions : [
1426
- {
1427
- constraintrange : [ 200 , 700 ] ,
1428
- label : 'Block height' ,
1429
- values : [ 321 , 534 , 542 , 674 , 31 , 674 , 124 , 246 , 456 , 743 ]
1430
- }
1431
- ]
1432
- } ] )
1433
- . then ( function ( ) {
1434
- expect ( d3 . selectAll ( 'canvas' ) . size ( ) ) . toEqual ( 3 ) ;
1435
-
1436
- return Plotly . restyle ( gd , 'type' , 'scatter' ) ;
1437
- } )
1438
- . then ( function ( ) {
1439
- expect ( d3 . selectAll ( 'canvas' ) . size ( ) ) . toEqual ( 0 ) ;
1440
- } )
1441
- . then ( done ) ;
1442
- } ) ;
1443
- } ) ;
1444
-
1445
- describe ( 'Test gl2d plots' , function ( ) {
1446
- var gd ;
1447
-
1448
- var mock = require ( '@mocks/gl2d_10.json' ) ;
1449
-
1450
- beforeEach ( function ( ) {
1451
- jasmine . DEFAULT_TIMEOUT_INTERVAL = 4000 ;
1452
- gd = createGraphDiv ( ) ;
1453
- } ) ;
1454
-
1455
- afterEach ( function ( ) {
1456
- Plotly . purge ( gd ) ;
1457
- destroyGraphDiv ( ) ;
1458
- } ) ;
1459
-
1460
- function mouseTo ( p0 , p1 ) {
1461
- var node = d3 . select ( '.nsewdrag[data-subplot="xy"]' ) . node ( ) ;
1462
- var dx = p1 [ 0 ] - p0 [ 0 ] ;
1463
- var dy = p1 [ 1 ] - p0 [ 1 ] ;
1464
- return drag ( node , dx , dy , null , p0 [ 0 ] , p0 [ 1 ] ) ;
1465
- }
1466
-
1467
- function select ( path ) {
1468
- return new Promise ( function ( resolve ) {
1469
- gd . once ( 'plotly_selected' , resolve ) ;
1470
-
1471
- var len = path . length ;
1472
-
1473
- // do selection
1474
- Lib . clearThrottle ( ) ;
1475
- mouseEvent ( 'mousemove' , path [ 0 ] [ 0 ] , path [ 0 ] [ 1 ] ) ;
1476
- mouseEvent ( 'mousedown' , path [ 0 ] [ 0 ] , path [ 0 ] [ 1 ] ) ;
1477
-
1478
- path . slice ( 1 , len ) . forEach ( function ( pt ) {
1479
- Lib . clearThrottle ( ) ;
1480
- mouseEvent ( 'mousemove' , pt [ 0 ] , pt [ 1 ] ) ;
1481
- } ) ;
1482
-
1483
- mouseEvent ( 'mouseup' , path [ len - 1 ] [ 0 ] , path [ len - 1 ] [ 1 ] ) ;
1484
- } ) ;
1485
- }
1486
-
1487
- it ( 'should respond to drag interactions' , function ( done ) {
1488
- var _mock = Lib . extendDeep ( { } , mock ) ;
1489
-
1490
- var relayoutCallback = jasmine . createSpy ( 'relayoutCallback' ) ;
1491
-
1492
- var originalX = [ - 0.3037383177570093 , 5.303738317757009 ] ;
1493
- var originalY = [ - 0.5 , 6.1 ] ;
1494
- var newX = [ - 0.5 , 5 ] ;
1495
- var newY = [ - 1.7 , 4.95 ] ;
1496
- var precision = 1 ;
1497
-
1498
- Plotly . newPlot ( gd , _mock )
1499
- . then ( delay ( 20 ) )
1500
- . then ( function ( ) {
1501
- expect ( gd . layout . xaxis . autorange ) . toBe ( true ) ;
1502
- expect ( gd . layout . yaxis . autorange ) . toBe ( true ) ;
1503
- expect ( gd . layout . xaxis . range ) . toBeCloseToArray ( originalX , precision ) ;
1504
- expect ( gd . layout . yaxis . range ) . toBeCloseToArray ( originalY , precision ) ;
1505
-
1506
- // Switch to pan mode
1507
- var buttonPan = selectButton ( gd . _fullLayout . _modeBar , 'pan2d' ) ;
1508
- expect ( buttonPan . isActive ( ) ) . toBe ( false , 'initially, zoom is active' ) ;
1509
- buttonPan . click ( ) ;
1510
- expect ( buttonPan . isActive ( ) ) . toBe ( true , 'switched on dragmode' ) ;
1511
-
1512
- // Switching mode must not change visible range
1513
- expect ( gd . layout . xaxis . range ) . toBeCloseToArray ( originalX , precision ) ;
1514
- expect ( gd . layout . yaxis . range ) . toBeCloseToArray ( originalY , precision ) ;
1515
- } )
1516
- . then ( delay ( 200 ) )
1517
- . then ( function ( ) {
1518
- gd . on ( 'plotly_relayout' , relayoutCallback ) ;
1519
- } )
1520
- . then ( function ( ) {
1521
- // Drag scene along the X axis
1522
- return mouseTo ( [ 200 , 200 ] , [ 220 , 200 ] ) ;
1523
- } )
1524
- . then ( function ( ) {
1525
- expect ( gd . layout . xaxis . autorange ) . toBe ( false ) ;
1526
- expect ( gd . layout . yaxis . autorange ) . toBe ( false ) ;
1527
- expect ( gd . layout . xaxis . range ) . toBeCloseToArray ( newX , precision ) ;
1528
- expect ( gd . layout . yaxis . range ) . toBeCloseToArray ( originalY , precision ) ;
1529
- } )
1530
- . then ( function ( ) {
1531
- // Drag scene back along the X axis
1532
- return mouseTo ( [ 220 , 200 ] , [ 200 , 200 ] ) ;
1533
- } )
1534
- . then ( function ( ) {
1535
- expect ( gd . layout . xaxis . range ) . toBeCloseToArray ( originalX , precision ) ;
1536
- expect ( gd . layout . yaxis . range ) . toBeCloseToArray ( originalY , precision ) ;
1537
- } )
1538
- . then ( function ( ) {
1539
- // Drag scene along the Y axis
1540
- return mouseTo ( [ 200 , 200 ] , [ 200 , 150 ] ) ;
1541
- } )
1542
- . then ( function ( ) {
1543
- expect ( gd . layout . xaxis . range ) . toBeCloseToArray ( originalX , precision ) ;
1544
- expect ( gd . layout . yaxis . range ) . toBeCloseToArray ( newY , precision ) ;
1545
- } )
1546
- . then ( function ( ) {
1547
- // Drag scene back along the Y axis
1548
- return mouseTo ( [ 200 , 150 ] , [ 200 , 200 ] ) ;
1549
- } )
1550
- . then ( function ( ) {
1551
- expect ( gd . layout . xaxis . range ) . toBeCloseToArray ( originalX , precision ) ;
1552
- expect ( gd . layout . yaxis . range ) . toBeCloseToArray ( originalY , precision ) ;
1553
- } )
1554
- . then ( function ( ) {
1555
- // Drag scene along both the X and Y axis
1556
- return mouseTo ( [ 200 , 200 ] , [ 220 , 150 ] ) ;
1557
- } )
1558
- . then ( function ( ) {
1559
- expect ( gd . layout . xaxis . range ) . toBeCloseToArray ( newX , precision ) ;
1560
- expect ( gd . layout . yaxis . range ) . toBeCloseToArray ( newY , precision ) ;
1561
- } )
1562
- . then ( function ( ) {
1563
- // Drag scene back along the X and Y axis
1564
- return mouseTo ( [ 220 , 150 ] , [ 200 , 200 ] ) ;
1565
- } )
1566
- . then ( function ( ) {
1567
- expect ( gd . layout . xaxis . range ) . toBeCloseToArray ( originalX , precision ) ;
1568
- expect ( gd . layout . yaxis . range ) . toBeCloseToArray ( originalY , precision ) ;
1569
- } )
1570
- . then ( delay ( 200 ) )
1571
- . then ( function ( ) {
1572
- // callback count expectation: X and back; Y and back; XY and back
1573
- expect ( relayoutCallback ) . toHaveBeenCalledTimes ( 6 ) ;
1574
-
1575
- // a callback value structure and contents check
1576
- expect ( relayoutCallback ) . toHaveBeenCalledWith ( jasmine . objectContaining ( {
1577
- 'xaxis.range[0]' : jasmine . any ( Number ) ,
1578
- 'xaxis.range[1]' : jasmine . any ( Number ) ,
1579
- 'yaxis.range[0]' : jasmine . any ( Number ) ,
1580
- 'yaxis.range[1]' : jasmine . any ( Number )
1581
- } ) ) ;
1582
- } )
1583
- . catch ( fail )
1584
- . then ( done ) ;
1585
- } ) ;
1586
-
1587
- it ( 'should be able to toggle visibility' , function ( done ) {
1588
- var _mock = Lib . extendDeep ( { } , mock ) ;
1589
- _mock . data [ 0 ] . line . width = 5 ;
1590
-
1591
- Plotly . plot ( gd , _mock )
1592
- . then ( delay ( 20 ) )
1593
- . then ( function ( ) {
1594
- return Plotly . restyle ( gd , 'visible' , 'legendonly' ) ;
1595
- } )
1596
- . then ( function ( ) {
1597
- expect ( gd . querySelector ( '.gl-canvas-context' ) ) . toBe ( null ) ;
1598
-
1599
- return Plotly . restyle ( gd , 'visible' , true ) ;
1600
- } )
1601
- . then ( function ( ) {
1602
- expect ( readPixel ( gd . querySelector ( '.gl-canvas-context' ) , 108 , 100 ) [ 0 ] ) . not . toBe ( 0 ) ;
1603
-
1604
- return Plotly . restyle ( gd , 'visible' , false ) ;
1605
- } )
1606
- . then ( function ( ) {
1607
- expect ( gd . querySelector ( '.gl-canvas-context' ) ) . toBe ( null ) ;
1608
-
1609
- return Plotly . restyle ( gd , 'visible' , true ) ;
1610
- } )
1611
- . then ( function ( ) {
1612
- expect ( readPixel ( gd . querySelector ( '.gl-canvas-context' ) , 108 , 100 ) [ 0 ] ) . not . toBe ( 0 ) ;
1613
- } )
1614
- . catch ( fail )
1615
- . then ( done ) ;
1616
- } ) ;
1617
-
1618
- it ( 'should display selection of big number of points' , function ( done ) {
1619
- // generate large number of points
1620
- var x = [ ] , y = [ ] , n = 2e2 , N = n * n ;
1621
- for ( var i = 0 ; i < N ; i ++ ) {
1622
- x . push ( ( i % n ) / n ) ;
1623
- y . push ( i / N ) ;
1624
- }
1625
-
1626
- var mock = {
1627
- data : [ {
1628
- x : x , y : y , type : 'scattergl' , mode : 'markers'
1629
- } ] ,
1630
- layout : {
1631
- dragmode : 'select'
1632
- }
1633
- } ;
1634
-
1635
- Plotly . plot ( gd , mock )
1636
- . then ( delay ( 1000 ) )
1637
- . then ( select ( [ [ 160 , 100 ] , [ 180 , 100 ] ] ) )
1638
- . then ( delay ( 1000 ) )
1639
- . then ( function ( ) {
1640
- expect ( readPixel ( gd . querySelector ( '.gl-canvas-context' ) , 168 , 100 ) [ 3 ] ) . toBe ( 0 ) ;
1641
- expect ( readPixel ( gd . querySelector ( '.gl-canvas-context' ) , 158 , 100 ) [ 3 ] ) . not . toBe ( 0 ) ;
1642
- expect ( readPixel ( gd . querySelector ( '.gl-canvas-focus' ) , 168 , 100 ) [ 3 ] ) . not . toBe ( 0 ) ;
1643
- } )
1644
- . catch ( fail )
1645
- . then ( done ) ;
1646
- } ) ;
1647
-
1648
- it ( 'should be able to toggle from svg to gl' , function ( done ) {
1649
- Plotly . plot ( gd , [ {
1650
- y : [ 1 , 2 , 1 ] ,
1651
- } ] )
1652
- . then ( function ( ) {
1653
- expect ( countCanvases ( ) ) . toBe ( 0 ) ;
1654
- expect ( d3 . selectAll ( '.scatterlayer > .trace' ) . size ( ) ) . toBe ( 1 ) ;
1655
-
1656
- return Plotly . restyle ( gd , 'type' , 'scattergl' ) ;
1657
- } )
1658
- . then ( function ( ) {
1659
- expect ( countCanvases ( ) ) . toBe ( 3 ) ;
1660
- expect ( d3 . selectAll ( '.scatterlayer > .trace' ) . size ( ) ) . toBe ( 0 ) ;
1661
-
1662
- return Plotly . restyle ( gd , 'type' , 'scatter' ) ;
1663
- } )
1664
- . then ( function ( ) {
1665
- expect ( countCanvases ( ) ) . toBe ( 0 ) ;
1666
- expect ( d3 . selectAll ( '.scatterlayer > .trace' ) . size ( ) ) . toBe ( 1 ) ;
1667
- } )
1668
- . catch ( fail )
1669
- . then ( done ) ;
1670
- } ) ;
1671
-
1672
- it ( 'supports 1D and 2D Zoom' , function ( done ) {
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
- } )
1685
- . then ( function ( ) {
1686
- var bBox = gd . getBoundingClientRect ( ) ;
1687
- centerX = bBox . left + 200 ;
1688
- centerY = bBox . top + 200 ;
1689
-
1690
- return mouseTo ( [ centerX , centerY ] , [ centerX - 5 , centerY + 5 ] ) ;
1691
- } )
1692
- . then ( function ( ) {
1693
- // no change - too small
1694
- expect ( gd . layout . xaxis . range ) . toBeCloseToArray ( [ 0 , 16 ] , 3 ) ;
1695
- expect ( gd . layout . yaxis . range ) . toBeCloseToArray ( [ 0 , 16 ] , 3 ) ;
1696
- } )
1697
- . then ( function ( ) {
1698
- return mouseTo ( [ centerX - 50 , centerY ] , [ centerX + 50 , centerY + 50 ] ) ;
1699
- } )
1700
- . then ( function ( ) {
1701
- // 2D
1702
- expect ( gd . layout . xaxis . range ) . toBeCloseToArray ( [ 4 , 12 ] , 3 ) ;
1703
- expect ( gd . layout . yaxis . range ) . toBeCloseToArray ( [ 4 , 8 ] , 3 ) ;
1704
- } )
1705
- . then ( function ( ) {
1706
- return mouseTo ( [ centerX - 50 , centerY ] , [ centerX , centerY + 5 ] ) ;
1707
- } )
1708
- . then ( function ( ) {
1709
- // x only
1710
- expect ( gd . layout . xaxis . range ) . toBeCloseToArray ( [ 6 , 8 ] , 3 ) ;
1711
- expect ( gd . layout . yaxis . range ) . toBeCloseToArray ( [ 4 , 8 ] , 3 ) ;
1712
- } )
1713
- . then ( function ( ) {
1714
- return mouseTo ( [ centerX , centerY - 50 ] , [ centerX - 5 , centerY + 50 ] ) ;
1715
- } )
1716
- . then ( function ( ) {
1717
- // y only
1718
- expect ( gd . layout . xaxis . range ) . toBeCloseToArray ( [ 6 , 8 ] , 3 ) ;
1719
- expect ( gd . layout . yaxis . range ) . toBeCloseToArray ( [ 5 , 7 ] , 3 ) ;
1720
- } )
1721
- . catch ( fail )
1722
- . then ( done ) ;
1723
- } ) ;
1724
-
1725
- it ( 'supports axis constraints with zoom' , function ( done ) {
1726
- var centerX ;
1727
- var centerY ;
1728
-
1729
- Plotly . newPlot ( gd , [ {
1730
- type : 'scattergl' , x : [ 1 , 15 ] , y : [ 1 , 15 ]
1731
- } ] , {
1732
- width : 400 ,
1733
- height : 400 ,
1734
- margin : { t : 100 , b : 100 , l : 100 , r : 100 } ,
1735
- xaxis : { range : [ 0 , 16 ] } ,
1736
- yaxis : { range : [ 0 , 16 ] }
1737
- } )
1738
- . then ( function ( ) {
1739
- var bBox = gd . getBoundingClientRect ( ) ;
1740
- centerX = bBox . left + 200 ;
1741
- centerY = bBox . top + 200 ;
1742
-
1743
- return Plotly . relayout ( gd , {
1744
- 'yaxis.scaleanchor' : 'x' ,
1745
- 'yaxis.scaleratio' : 2
1746
- } ) ;
1747
- } )
1748
- . then ( function ( ) {
1749
- // x range is adjusted to fit constraint
1750
- expect ( gd . layout . xaxis . range ) . toBeCloseToArray ( [ - 8 , 24 ] , 3 ) ;
1751
- expect ( gd . layout . yaxis . range ) . toBeCloseToArray ( [ 0 , 16 ] , 3 ) ;
1752
- } )
1753
- . then ( function ( ) {
1754
- return mouseTo ( [ centerX , centerY ] , [ centerX - 5 , centerY + 5 ] ) ;
1755
- } )
1756
- . then ( function ( ) {
1757
- // no change - too small
1758
- expect ( gd . layout . xaxis . range ) . toBeCloseToArray ( [ - 8 , 24 ] , 3 ) ;
1759
- expect ( gd . layout . yaxis . range ) . toBeCloseToArray ( [ 0 , 16 ] , 3 ) ;
1760
- } )
1761
- . then ( function ( ) {
1762
- // now there should only be 2D zooming
1763
- // dy>>dx
1764
- return mouseTo ( [ centerX , centerY ] , [ centerX - 1 , centerY - 50 ] ) ;
1765
- } )
1766
- . then ( function ( ) {
1767
- expect ( gd . layout . xaxis . range ) . toBeCloseToArray ( [ 0 , 8 ] , 3 ) ;
1768
- expect ( gd . layout . yaxis . range ) . toBeCloseToArray ( [ 8 , 12 ] , 3 ) ;
1769
- } )
1770
- . then ( function ( ) {
1771
- return mouseTo ( [ centerX , centerY ] , [ centerX + 50 , centerY + 1 ] ) ;
1772
- } )
1773
- . then ( function ( ) {
1774
- // dx>>dy
1775
- expect ( gd . layout . xaxis . range ) . toBeCloseToArray ( [ 4 , 6 ] , 3 ) ;
1776
- expect ( gd . layout . yaxis . range ) . toBeCloseToArray ( [ 9 , 10 ] , 3 ) ;
1777
- } )
1778
- . then ( function ( ) {
1779
- return Plotly . relayout ( gd , {
1780
- 'xaxis.autorange' : true ,
1781
- 'yaxis.autorange' : true
1782
- } ) ;
1783
- } )
1784
- . then ( function ( ) {
1785
- expect ( gd . layout . xaxis . range ) . toBeCloseToArray ( [ - 7.6 , 23.6 ] , 1 ) ;
1786
- expect ( gd . layout . yaxis . range ) . toBeCloseToArray ( [ 0.2 , 15.8 ] , 1 ) ;
1787
- } )
1788
- . catch ( fail )
1789
- . then ( done ) ;
1790
- } ) ;
1791
-
1792
- it ( 'should change plot type with incomplete data' , function ( done ) {
1793
- Plotly . plot ( gd , [ { } ] ) ;
1794
- expect ( function ( ) {
1795
- Plotly . restyle ( gd , { type : 'scattergl' , x : [ [ 1 ] ] } , 0 ) ;
1796
- } ) . not . toThrow ( ) ;
1797
-
1798
- expect ( function ( ) {
1799
- Plotly . restyle ( gd , { y : [ [ 1 ] ] } , 0 ) ;
1800
- } ) . not . toThrow ( ) ;
1801
-
1802
- done ( ) ;
1803
- } ) ;
1804
-
1805
- it ( 'data-referenced annotations should update on drag' , function ( done ) {
1806
- function assertAnnotation ( xy ) {
1807
- var ann = d3 . select ( 'g.annotation-text-g' ) . select ( 'g' ) ;
1808
- var translate = Drawing . getTranslate ( ann ) ;
1809
-
1810
- expect ( translate . x ) . toBeWithin ( xy [ 0 ] , 8 ) ;
1811
- expect ( translate . y ) . toBeWithin ( xy [ 1 ] , 8 ) ;
1812
- }
1813
-
1814
- Plotly . newPlot ( gd , [ {
1815
- type : 'scattergl' ,
1816
- x : [ 1 , 2 , 3 ] ,
1817
- y : [ 2 , 1 , 2 ]
1818
- } ] , {
1819
- annotations : [ {
1820
- x : 2 ,
1821
- y : 1 ,
1822
- text : 'text'
1823
- } ] ,
1824
- dragmode : 'pan'
1825
- } )
1826
- . then ( function ( ) {
1827
- assertAnnotation ( [ 327 , 312 ] ) ;
1828
- } )
1829
- . then ( function ( ) {
1830
- return mouseTo ( [ 250 , 200 ] , [ 200 , 150 ] ) ;
1831
- } )
1832
- . then ( function ( ) {
1833
- assertAnnotation ( [ 277 , 262 ] ) ;
1834
- } )
1835
- . then ( function ( ) {
1836
- return Plotly . relayout ( gd , {
1837
- 'xaxis.range' : [ 1.5 , 2.5 ] ,
1838
- 'yaxis.range' : [ 1 , 1.5 ]
1839
- } ) ;
1840
- } )
1841
- . then ( function ( ) {
1842
- assertAnnotation ( [ 327 , 331 ] ) ;
1843
- } )
1844
- . catch ( fail )
1845
- . then ( done ) ;
1846
- } ) ;
1847
1283
} ) ;
0 commit comments