@@ -21,13 +21,12 @@ $(function() {
2121 this . selected_element = null ;
2222 this . offset = { x : 0 , y : 0 } ;
2323 this . main_plot = $ ( "#main-plot" ) . main_plot ( "instance" ) ;
24- this . dragging_rect_width = 4 ;
25-
24+ this . dragging_rect_width = 6 ;
2625 //Attach drag event handlers
27- d3 . select ( "# main-plot-div") . on ( "mousemove" , function ( e ) {
26+ document . getElementById ( " main-plot-div") . addEventListener ( "mousemove" , function ( e ) {
2827 self . drag_plot_element ( e ) ;
2928 } ) ;
30- d3 . select ( "# main-plot-div") . on ( "mouseup" , function ( ) {
29+ document . getElementById ( " main-plot-div") . addEventListener ( "mouseup" , function ( ) {
3130 self . end_dragging ( ) ;
3231 } ) ;
3332 this . y_table . append ( "tbody" ) ;
@@ -65,48 +64,54 @@ $(function() {
6564 let marginRight = this . main_plot . width - this . main_plot . margins . right ;
6665 let marginTop = this . main_plot . height - this . main_plot . margins . bottom ;
6766 let marginBottom = this . main_plot . margins . top ;
68- let buffer = 2 ;
6967 var mousePos = this . get_mouse_pos ( e ) ;
7068 if ( this . selected_element . getAttribute ( "class" ) . includes ( "x-reference" ) ) {
71- var currentX = parseFloat ( this . selected_element . getAttribute ( "x1" ) ) ;
72- //Check that line is still on plot, if outside of plot end dragging
73- if ( marginLeft <= currentX && currentX <= marginRight ) {
74- var newX = currentX + ( mousePos . x - this . offset . x ) ;
75- this . move_plot_group ( newX ) ;
76- } else if ( currentX > marginRight ) {
77- this . move_plot_group ( marginRight - buffer ) ;
78- this . end_dragging ( ) ;
79- } else if ( currentX < marginLeft ) {
80- this . move_plot_group ( marginLeft + buffer ) ;
81- this . end_dragging ( ) ;
82- }
8369 //Find the corresponding element in the array and update coordinate
8470 var array = this . _elements . x_lines . find ( x => {
8571 if ( x !== undefined ) {
8672 return x . number === parseInt ( self . selected_element . getAttribute ( "number" ) ) ;
8773 }
8874 } ) ;
89- array . coordinate = parseInt ( this . main_plot . xscale . invert ( currentX ) ) ;
90- } else if ( this . selected_element . getAttribute ( "class" ) . includes ( "y-reference" ) ) {
91- var currentY = parseFloat ( this . selected_element . getAttribute ( "y2" ) ) ;
92- //Check that line is still on plot, if outside of plot end dragging
93- if ( currentY > marginBottom && currentY < marginTop ) {
94- var newY = currentY + ( mousePos . y - this . offset . y ) ;
95- this . move_plot_group ( newY ) ;
96- } else if ( currentY > marginBottom ) {
97- this . move_plot_group ( marginTop - buffer ) ;
75+ var currentX = parseFloat ( this . selected_element . getAttribute ( "x1" ) ) ;
76+ var newX = currentX + ( mousePos . x - this . offset . x ) ;
77+ //Check that line is still on plot, if outside of plot end dragging and put line on margin
78+ if ( marginLeft <= mousePos . x && mousePos . x <= marginRight ) {
79+ this . move_plot_group ( newX ) ;
80+ } else if ( mousePos . x > marginRight ) {
81+ newX = Math . min ( marginRight , mousePos . x ) ;
82+ this . move_plot_group ( newX ) ;
9883 this . end_dragging ( ) ;
99- } else if ( currentY < marginTop ) {
100- this . move_plot_group ( marginBottom + buffer ) ;
84+ } else if ( mousePos . x < marginLeft ) {
85+ newX = Math . max ( marginLeft , mousePos . x ) ;
86+ this . move_plot_group ( newX ) ;
10187 this . end_dragging ( ) ;
10288 }
89+ array . coordinate = parseInt ( this . main_plot . xscale . invert ( newX ) ) ;
90+ } else if ( this . selected_element . getAttribute ( "class" ) . includes ( "y-reference" ) ) {
10391 //Find the corresponding element in the array and update coordinate
10492 var array = this . _elements . y_lines . find ( y => {
10593 if ( y !== undefined ) {
10694 return y . number === parseInt ( self . selected_element . getAttribute ( "number" ) ) ;
10795 }
10896 } ) ;
109- array . coordinate = this . main_plot . yscale . invert ( Math . abs ( currentY ) ) . toFixed ( 2 ) ;
97+ var currentY = parseFloat ( this . selected_element . getAttribute ( "y2" ) ) ;
98+ var newY = currentY + ( mousePos . y - this . offset . y ) ;
99+ console . log ( mousePos . y ) ;
100+ console . log ( marginBottom ) ;
101+ console . log ( marginTop ) ;
102+ //Check that line is still on plot, if outside of plot end dragging and put line on margin
103+ if ( newY >= marginBottom && newY <= marginTop ) {
104+ this . move_plot_group ( newY ) ;
105+ } else if ( newY < marginBottom ) {
106+ newY = Math . max ( marginBottom , newY ) ;
107+ this . move_plot_group ( newY ) ;
108+ this . end_dragging ( ) ;
109+ } else if ( newY > marginTop ) {
110+ newY = Math . min ( newY , marginTop ) ;
111+ this . move_plot_group ( newY ) ;
112+ this . end_dragging ( ) ;
113+ }
114+ array . coordinate = this . main_plot . yscale . invert ( Math . abs ( newY ) ) . toFixed ( 2 ) ;
110115 }
111116 //Update offset, tables, and add numbers to plot
112117 this . offset = this . get_mouse_pos ( e ) ;
0 commit comments