@@ -3,6 +3,7 @@ var Lib = require('@src/lib');
33var Drawing = require ( '@src/components/drawing' ) ;
44var DBLCLICKDELAY = require ( '@src/plots/cartesian/constants' ) . DBLCLICKDELAY ;
55
6+ var d3 = require ( 'd3' ) ;
67var createGraphDiv = require ( '../assets/create_graph_div' ) ;
78var destroyGraphDiv = require ( '../assets/destroy_graph_div' ) ;
89var mouseEvent = require ( '../assets/mouse_event' ) ;
@@ -809,3 +810,48 @@ describe('Test click interactions:', function() {
809810 } ) ;
810811 } ) ;
811812} ) ;
813+
814+ describe ( 'dragbox' , function ( ) {
815+
816+ afterEach ( destroyGraphDiv ) ;
817+
818+ it ( 'should scale subplot and inverse scale scatter points' , function ( done ) {
819+ var mock = Lib . extendDeep ( { } , require ( '@mocks/bar_line.json' ) ) ;
820+
821+ function assertScale ( node , x , y ) {
822+ var scale = Drawing . getScale ( node ) ;
823+ expect ( scale . x ) . toBeCloseTo ( x , 1 ) ;
824+ expect ( scale . y ) . toBeCloseTo ( y , 1 ) ;
825+ }
826+
827+ Plotly . plot ( createGraphDiv ( ) , mock ) . then ( function ( ) {
828+ var node = d3 . select ( 'rect.nedrag' ) . node ( ) ;
829+ var pos = getRectCenter ( node ) ;
830+
831+ assertScale ( d3 . select ( '.plot' ) . node ( ) , 1 , 1 ) ;
832+
833+ d3 . selectAll ( '.point' ) . each ( function ( ) {
834+ assertScale ( this , 1 , 1 ) ;
835+ } ) ;
836+
837+ mouseEvent ( 'mousemove' , pos [ 0 ] , pos [ 1 ] ) ;
838+ mouseEvent ( 'mousedown' , pos [ 0 ] , pos [ 1 ] ) ;
839+ mouseEvent ( 'mousemove' , pos [ 0 ] + 50 , pos [ 1 ] ) ;
840+
841+ setTimeout ( function ( ) {
842+ assertScale ( d3 . select ( '.plot' ) . node ( ) , 1.14 , 1 ) ;
843+
844+ d3 . select ( '.scatterlayer' ) . selectAll ( '.point' ) . each ( function ( ) {
845+ assertScale ( this , 0.87 , 1 ) ;
846+ } ) ;
847+ d3 . select ( '.barlayer' ) . selectAll ( '.point' ) . each ( function ( ) {
848+ assertScale ( this , 1 , 1 ) ;
849+ } ) ;
850+
851+ mouseEvent ( 'mouseup' , pos [ 0 ] + 50 , pos [ 1 ] ) ;
852+ done ( ) ;
853+ } , DBLCLICKDELAY / 4 ) ;
854+ } ) ;
855+ } ) ;
856+
857+ } ) ;
0 commit comments