@@ -1623,8 +1623,17 @@ describe('Polar plots with css transforms', function() {
1623
1623
}
1624
1624
1625
1625
function recalculateInverse ( gd ) {
1626
- var inverse = Lib . inverseTransformMatrix ( Lib . getFullTransformMatrix ( gd ) ) ;
1627
- gd . _fullLayout . _inverseTransform = inverse ;
1626
+ var m = Lib . inverseTransformMatrix ( Lib . getFullTransformMatrix ( gd ) ) ;
1627
+ gd . _fullLayout . _inverseTransform = m ;
1628
+ gd . _fullLayout . _inverseScaleX = Math . sqrt ( m [ 0 ] [ 0 ] * m [ 0 ] [ 0 ] + m [ 0 ] [ 1 ] * m [ 0 ] [ 1 ] + m [ 0 ] [ 2 ] * m [ 0 ] [ 2 ] ) ;
1629
+ gd . _fullLayout . _inverseScaleY = Math . sqrt ( m [ 1 ] [ 0 ] * m [ 1 ] [ 0 ] + m [ 1 ] [ 1 ] * m [ 1 ] [ 1 ] + m [ 1 ] [ 2 ] * m [ 1 ] [ 2 ] ) ;
1630
+ }
1631
+
1632
+
1633
+ function _drag ( start , dp ) {
1634
+ var node = d3 . select ( '.polar > .draglayer > .maindrag' ) . node ( ) ;
1635
+ var localStart = _getLocalPos ( gd , start ) ;
1636
+ return drag ( { node : node , dpos : dp , pos0 : localStart } ) ;
1628
1637
}
1629
1638
1630
1639
function _hover ( pos ) {
@@ -1643,6 +1652,15 @@ describe('Polar plots with css transforms', function() {
1643
1652
} ) ;
1644
1653
}
1645
1654
1655
+ function _getVisiblePointsData ( gd ) {
1656
+ return Array . from (
1657
+ document . querySelectorAll ( '.point' ) . entries ( ) ,
1658
+ ( [ key , value ] ) => value ,
1659
+ )
1660
+ . filter ( e => window . getComputedStyle ( e ) . display !== 'none' )
1661
+ . map ( e => e . __data__ ) ;
1662
+ }
1663
+
1646
1664
var rVals = [ 100 , 50 , 50 , 100 ] ;
1647
1665
var thetaVals = [ 135 , 135 , 315 , 315 ] ;
1648
1666
var plotSize = [ 400 , 400 ] ;
@@ -1666,7 +1684,7 @@ describe('Polar plots with css transforms', function() {
1666
1684
var transforms = [ 'scale(0.5)' ] ;
1667
1685
1668
1686
transforms . forEach ( function ( transform ) {
1669
- it ( '@transform_test @alex_test hover behaves correctly after css transform: ' + transform , function ( done ) {
1687
+ it ( 'hover behaves correctly after css transform: ' + transform , function ( done ) {
1670
1688
var hoverEvents = { } ;
1671
1689
1672
1690
Plotly . plot ( gd , Lib . extendDeep ( { } , mock ) )
@@ -1689,5 +1707,51 @@ describe('Polar plots with css transforms', function() {
1689
1707
. catch ( failTest )
1690
1708
. then ( done ) ;
1691
1709
} ) ;
1710
+
1711
+ it ( `drag-zoom behaves correctly after css transform: ${ transform } ` , function ( done ) {
1712
+
1713
+ Plotly . plot ( gd , Lib . extendDeep ( { } , mock ) )
1714
+ . then ( function ( ) {
1715
+ transformPlot ( gd , transform ) ;
1716
+ recalculateInverse ( gd ) ;
1717
+ } )
1718
+ . then ( function ( ) {
1719
+ return _drag ( [ 30 , 30 ] , [ 50 , 50 ] ) ;
1720
+ } )
1721
+ . then ( function ( ) {
1722
+ var points = _getVisiblePointsData ( gd ) ;
1723
+ expect ( points . length ) . toBe ( 2 ) ;
1724
+ expect ( points [ 0 ] . i ) . toBe ( 0 ) ;
1725
+ expect ( points [ 1 ] . i ) . toBe ( 3 ) ;
1726
+ } )
1727
+ . catch ( failTest )
1728
+ . then ( done ) ;
1729
+ } ) ;
1730
+
1731
+ it ( `select behaves correctly after css transform: ${ transform } ` , function ( done ) {
1732
+
1733
+ function _assertSelected ( expectation ) {
1734
+ var data = gd . _fullData [ 0 ] ;
1735
+ var points = data . selectedpoints ;
1736
+ expect ( typeof ( points ) !== 'undefined' ) . toBeTrue ( ) ;
1737
+ if ( expectation . numPoints )
1738
+ expect ( points . length ) . toBe ( expectation . numPoints ) ;
1739
+ }
1740
+
1741
+ Plotly . plot ( gd , Lib . extendDeep ( { } , mock ) )
1742
+ . then ( function ( ) {
1743
+ transformPlot ( gd , transform ) ;
1744
+ recalculateInverse ( gd ) ;
1745
+ } )
1746
+ . then ( function ( ) {
1747
+ return Plotly . relayout ( gd , 'dragmode' , 'select' ) ;
1748
+ } )
1749
+ . then ( function ( ) { return _drag ( [ 30 , 30 ] , [ 130 , 130 ] ) } )
1750
+ . then ( function ( ) {
1751
+ _assertSelected ( { numPoints : 3 } ) ;
1752
+ } )
1753
+ . catch ( failTest )
1754
+ . then ( done ) ;
1755
+ } ) ;
1692
1756
} ) ;
1693
1757
} ) ;
0 commit comments