@@ -1623,8 +1623,17 @@ describe('Polar plots with css transforms', function() {
16231623 }
16241624
16251625 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 } ) ;
16281637 }
16291638
16301639 function _hover ( pos ) {
@@ -1643,6 +1652,15 @@ describe('Polar plots with css transforms', function() {
16431652 } ) ;
16441653 }
16451654
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+
16461664 var rVals = [ 100 , 50 , 50 , 100 ] ;
16471665 var thetaVals = [ 135 , 135 , 315 , 315 ] ;
16481666 var plotSize = [ 400 , 400 ] ;
@@ -1666,7 +1684,7 @@ describe('Polar plots with css transforms', function() {
16661684 var transforms = [ 'scale(0.5)' ] ;
16671685
16681686 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 ) {
16701688 var hoverEvents = { } ;
16711689
16721690 Plotly . plot ( gd , Lib . extendDeep ( { } , mock ) )
@@ -1689,5 +1707,51 @@ describe('Polar plots with css transforms', function() {
16891707 . catch ( failTest )
16901708 . then ( done ) ;
16911709 } ) ;
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+ } ) ;
16921756 } ) ;
16931757} ) ;
0 commit comments