@@ -13,6 +13,7 @@ var destroyGraphDiv = require('../assets/destroy_graph_div');
1313var failTest = require ( '../assets/fail_test' ) ;
1414var supplyAllDefaults = require ( '../assets/supply_defaults' ) ;
1515var mockLists = require ( '../assets/mock_lists' ) ;
16+ var mouseEvent = require ( '../assets/mouse_event' ) ;
1617var drag = require ( '../assets/drag' ) ;
1718
1819var MAPBOX_ACCESS_TOKEN = require ( '@build/credentials.json' ) . MAPBOX_ACCESS_TOKEN ;
@@ -1806,3 +1807,67 @@ describe('Plotly.react and uirevision attributes', function() {
18061807 _run ( fig , editComponents , checkInitial , checkEdited ) . then ( done ) ;
18071808 } ) ;
18081809} ) ;
1810+
1811+ describe ( 'Test Plotly.react + interactions under uirevision:' , function ( ) {
1812+ var gd ;
1813+
1814+ beforeEach ( function ( ) {
1815+ gd = createGraphDiv ( ) ;
1816+ } ) ;
1817+
1818+ afterEach ( function ( ) {
1819+ Plotly . purge ( gd ) ;
1820+ destroyGraphDiv ( ) ;
1821+ } ) ;
1822+
1823+ it ( '@gl gl3d subplots preserve camera changes on interactions' , function ( done ) {
1824+ function _react ( ) {
1825+ return Plotly . react ( gd , [ {
1826+ type : 'surface' ,
1827+ z : [ [ 1 , 2 , 3 ] , [ 3 , 1 , 2 ] , [ 2 , 3 , 1 ] ]
1828+ } ] , {
1829+ width : 500 ,
1830+ height : 500 ,
1831+ uirevision : true
1832+ } ) ;
1833+ }
1834+
1835+ // mocking panning/scrolling is brittle,
1836+ // this here is enough to to trigger the relayoutCallback
1837+ function _mouseup ( ) {
1838+ var target = gd . querySelector ( '.svg-container .gl-container #scene canvas' ) ;
1839+ return new Promise ( function ( resolve ) {
1840+ mouseEvent ( 'mouseup' , 200 , 200 , { element : target } ) ;
1841+ setTimeout ( resolve , 0 ) ;
1842+ } ) ;
1843+ }
1844+
1845+ // should be same before & after 2nd react()
1846+ function _assertGUI ( msg ) {
1847+ var preGUI = gd . _fullLayout . _preGUI ;
1848+ expect ( preGUI [ 'scene.camera' ] ) . toBe ( null , msg ) ;
1849+ }
1850+
1851+ _react ( )
1852+ . then ( function ( ) {
1853+ expect ( gd . layout . scene ) . toEqual ( jasmine . objectContaining ( {
1854+ aspectratio : { x : 1 , y : 1 , z : 1 } ,
1855+ aspectmode : 'auto'
1856+ } ) ) ;
1857+ expect ( gd . layout . scene . camera ) . toBe ( undefined ) ;
1858+
1859+ var fullEye = gd . _fullLayout . scene . camera . eye ;
1860+ expect ( fullEye . x ) . toBe ( 1.25 ) ;
1861+ expect ( fullEye . y ) . toBe ( 1.25 ) ;
1862+ expect ( fullEye . z ) . toBe ( 1.25 ) ;
1863+
1864+ expect ( gd . _fullLayout . _preGUI ) . toEqual ( { } ) ;
1865+ } )
1866+ . then ( function ( ) { return _mouseup ( ) ; } )
1867+ . then ( function ( ) { _assertGUI ( 'before' ) ; } )
1868+ . then ( _react )
1869+ . then ( function ( ) { _assertGUI ( 'after' ) ; } )
1870+ . catch ( failTest )
1871+ . then ( done ) ;
1872+ } ) ;
1873+ } ) ;
0 commit comments