@@ -6,6 +6,8 @@ $(function() {
66 xmax : 500 ,
77 ymin : - 1 ,
88 ymax : 1 ,
9+ xrange : 1000 ,
10+ yrange : 2 ,
911
1012 // Flag to indicate whether axes are locked
1113 locked : false ,
@@ -55,7 +57,9 @@ $(function() {
5557 . style ( "margin-left" , "5px" )
5658 . on ( "change" , function ( ) { $ ( "#axes-input" ) . axes_input ( "change_axis_limits" , null , this . value , null , null ) } ) ;
5759
58- //Appends the "+" svg/button for the xaxis
60+ let self = this ;
61+
62+ // Appends the "+" svg/button for the xaxis
5963 let x_plus = xaxis . append ( "div" )
6064 . attr ( "title" , "x_plus" )
6165 . style ( "margin-left" , "5px" )
@@ -69,10 +73,7 @@ $(function() {
6973 . attr ( "version" , "1.1" )
7074 . attr ( "xmlns" , "http://www.w3.org/2000/svg" )
7175 . on ( "click" , function ( ) {
72- let value_change = 50 ;
73- let xmin = parseInt ( $ ( "#axes-input" ) . axes_input ( "get_axis_values" , 1 , value_change ) ) ;
74- let xmax = parseInt ( $ ( "#axes-input" ) . axes_input ( "get_axis_values" , 0 , value_change ) ) ;
75- $ ( "#axes-input" ) . axes_input ( "change_axis_limits" , xmin - value_change , xmax + value_change , null , null )
76+ $ ( "#axes-input" ) . axes_input ( "change_axis_limits" , parseInt ( self . xmin - self . xrange / 20 ) , parseInt ( self . xmax + self . xrange / 20 ) , null , null , true , false )
7677 } )
7778
7879 x_plus . append ( "path" )
@@ -82,7 +83,7 @@ $(function() {
8283 . attr ( "stroke-width" , 2 )
8384 . node ( ) ;
8485
85- //Appends the "-" svg/button for the xaxis
86+ // Appends the "-" svg/button for the xaxis
8687 let x_minus = xaxis . append ( "div" )
8788 . attr ( "title" , "x_minus" )
8889 . style ( "margin-left" , "5px" )
@@ -96,10 +97,7 @@ $(function() {
9697 . attr ( "version" , "1.1" )
9798 . attr ( "xmlns" , "http://www.w3.org/2000/svg" )
9899 . on ( "click" , function ( ) {
99- let value_change = 50 ;
100- let xmin = parseInt ( $ ( "#axes-input" ) . axes_input ( "get_axis_values" , 1 , value_change ) ) ;
101- let xmax = parseInt ( $ ( "#axes-input" ) . axes_input ( "get_axis_values" , 0 , value_change ) ) ;
102- $ ( "#axes-input" ) . axes_input ( "change_axis_limits" , xmin + value_change , xmax - value_change , null , null )
100+ $ ( "#axes-input" ) . axes_input ( "change_axis_limits" , parseInt ( self . xmin + self . xrange / 20 ) , parseInt ( self . xmax - self . xrange / 20 ) , null , null , true , false )
103101 } )
104102
105103 x_minus . append ( "path" )
@@ -108,7 +106,6 @@ $(function() {
108106 . attr ( "stroke" , "orange" )
109107 . attr ( "stroke-width" , 2 )
110108 . node ( ) ;
111-
112109
113110 // Create y axis controls
114111 yaxis . append ( "label" )
@@ -145,10 +142,8 @@ $(function() {
145142 . attr ( "version" , "1.1" )
146143 . attr ( "xmlns" , "http://www.w3.org/2000/svg" )
147144 . on ( "click" , function ( ) {
148- let value_change = .1 ;
149- let ymin = parseFloat ( $ ( "#axes-input" ) . axes_input ( "get_axis_values" , 3 , value_change ) ) ;
150- let ymax = parseFloat ( $ ( "#axes-input" ) . axes_input ( "get_axis_values" , 2 , value_change ) ) ;
151- $ ( "#axes-input" ) . axes_input ( "change_axis_limits" , null , null , ymin - value_change , ymax + value_change ) ;
145+ $ ( "#axes-input" ) . axes_input ( "change_axis_limits" , null , null , ( self . ymin - self . yrange / 20 ) * ( 1 - self . combined ) ,
146+ ( self . ymax + self . yrange / 20 ) * ( self . combined + 1 ) , true , false ) ;
152147 } )
153148
154149 y_plus . append ( "path" )
@@ -172,10 +167,8 @@ $(function() {
172167 . attr ( "version" , "1.1" )
173168 . attr ( "xmlns" , "http://www.w3.org/2000/svg" )
174169 . on ( "click" , function ( ) {
175- let value_change = .1 ;
176- let ymin = parseFloat ( $ ( "#axes-input" ) . axes_input ( "get_axis_values" , 3 , value_change ) ) ;
177- let ymax = parseFloat ( $ ( "#axes-input" ) . axes_input ( "get_axis_values" , 2 , value_change ) ) ;
178- $ ( "#axes-input" ) . axes_input ( "change_axis_limits" , null , null , parseFloat ( ymin + value_change ) , parseFloat ( ymax - value_change ) ) ;
170+ $ ( "#axes-input" ) . axes_input ( "change_axis_limits" , null , null , ( self . ymin + self . yrange / 20 ) * ( 1 - self . combined ) ,
171+ ( self . ymax - self . yrange / 20 ) * ( self . combined + 1 ) , true , false ) ;
179172 } )
180173
181174 y_minus . append ( "path" )
@@ -186,28 +179,36 @@ $(function() {
186179 . node ( ) ;
187180 } ,
188181
189- change_axis_limits : function ( xmin , xmax , ymin , ymax , change_plot = true ) {
182+ change_axis_limits : function ( xmin , xmax , ymin , ymax , change_plot = true , change_range = true ) {
190183 // Change x axis limits
191184 if ( xmin !== null ) {
192- this . xmin = xmin ;
185+ this . xmin = parseInt ( xmin ) ;
193186 } ;
194187 if ( xmax !== null ) {
195- this . xmax = xmax ;
188+ this . xmax = parseInt ( xmax ) ;
196189 } ;
197190 // Change y axis limits
198191 if ( this . combined && change_plot ) {
199192 // If the strands are combined, the y axis limits are scaled relative to the difference
200193 if ( ymax !== null ) {
201194 let factor = ymax / ( this . ymax - this . ymin ) ;
202- this . ymin = ( this . ymin * factor ) . toPrecision ( 2 ) ;
203- this . ymax = ( this . ymax * factor ) . toPrecision ( 2 )
195+ this . ymin = parseFloat ( ( this . ymin * factor ) . toPrecision ( 2 ) ) ;
196+ this . ymax = parseFloat ( ( this . ymax * factor ) . toPrecision ( 2 ) )
204197 }
205198 } else {
206199 if ( ymin !== null ) {
207- this . ymin = ymin ;
200+ this . ymin = parseFloat ( ymin ) ;
208201 } ;
209202 if ( ymax !== null ) {
210- this . ymax = ymax ;
203+ this . ymax = parseFloat ( ymax ) ;
204+ }
205+ } ;
206+ if ( change_range ) {
207+ if ( xmin !== null || xmax !== null ) {
208+ this . xrange = this . xmax - this . xmin
209+ } ;
210+ if ( ymin !== null || ymax !== null ) {
211+ this . yrange = this . ymax - this . ymin
211212 }
212213 } ;
213214
@@ -225,25 +226,6 @@ $(function() {
225226 }
226227 } ,
227228
228- //Returns the current value an axis given an integer and a value the axis is being changed by (so the function calling it can default to zero)
229- get_axis_values : function ( axis , change_val ) {
230- if ( parseInt ( axis ) == 0 ) {
231- return ( this . xmax > change_val ) ? this . xmax : change_val ;
232- }
233- else if ( parseInt ( axis ) == 1 ) {
234- return ( this . xmin < - change_val ) ? this . xmin : - change_val ;
235- }
236- else if ( parseInt ( axis ) == 2 ) {
237- return ( this . ymax > change_val ) ? this . ymax : change_val ;
238- }
239- else if ( parseInt ( axis ) == 3 ) {
240- return ( this . ymin < - change_val ) ? this . ymin : - change_val ;
241- }
242- else {
243- return null ;
244- }
245- } ,
246-
247229 toggle_combined : function ( combined ) {
248230 this . combined = combined ;
249231 // If the strands are combined, the y axis limit text boxes show 0 for the lower limit and the difference for the upper limit
0 commit comments