@@ -4,15 +4,24 @@ $(function() {
44 // Default axis limits
55 xmin : - 500 ,
66 xmax : 500 ,
7+ ymin : - 1 ,
78 ymax : 1 ,
89
10+ // Flag to indicate whether axes are locked
11+ locked : false ,
12+
13+ // Flag to indicate whether the strands are combined
14+ combined : false ,
15+
916 _elements : {
1017 xmin_text : null ,
1118 xmax_text : null ,
19+ ymin_text : null ,
1220 ymax_text : null
1321 } ,
1422
1523 _create : function ( ) {
24+ // Create container for axis controls
1625 let container = d3 . select ( this . element . context ) ,
1726 xaxis = container . append ( "div" )
1827 . attr ( "class" , "row" )
@@ -23,6 +32,7 @@ $(function() {
2332 . append ( "div" )
2433 . attr ( "class" , "col" ) ;
2534
35+ // Create x axis controls
2636 xaxis . append ( "label" )
2737 . attr ( "for" , "xmin-text" )
2838 . text ( "x axis limits:" ) ;
@@ -32,56 +42,101 @@ $(function() {
3242 . attr ( "type" , "text" )
3343 . attr ( "value" , this . xmin )
3444 . style ( "width" , "50px" )
35- . on ( "change" , function ( ) { $ ( "#axes-input" ) . axes_input ( "change_axis_limits" , this . value , null , null ) } ) ;
45+ . on ( "change" , function ( ) { $ ( "#axes-input" ) . axes_input ( "change_axis_limits" , this . value , null , null , null ) } ) ;
3646
3747 this . _elements . xmax_text = xaxis . append ( "input" )
3848 . attr ( "id" , "xmax-text" )
3949 . attr ( "type" , "text" )
4050 . attr ( "value" , this . xmax )
4151 . style ( "width" , "50px" )
4252 . style ( "margin-left" , "5px" )
43- . on ( "change" , function ( ) { $ ( "#axes-input" ) . axes_input ( "change_axis_limits" , null , this . value , null ) } ) ;
53+ . on ( "change" , function ( ) { $ ( "#axes-input" ) . axes_input ( "change_axis_limits" , null , this . value , null , null ) } ) ;
4454
55+ // Create y axis controls
4556 yaxis . append ( "label" )
46- . attr ( "for" , "ymax-text" )
47- . text ( "y axis max:" ) ;
57+ . attr ( "for" , "ymin-text" )
58+ . text ( "y axis limits:" ) ;
59+
60+ this . _elements . ymin_text = yaxis . append ( "input" )
61+ . attr ( "id" , "ymin-text" )
62+ . attr ( "type" , "text" )
63+ . attr ( "value" , this . ymin )
64+ . style ( "width" , "50px" )
65+ . on ( "change" , function ( ) { $ ( "#axes-input" ) . axes_input ( "change_axis_limits" , null , null , this . value , null ) } ) ;
4866
4967 this . _elements . ymax_text = yaxis . append ( "input" )
5068 . attr ( "id" , "ymax-text" )
5169 . attr ( "type" , "text" )
5270 . attr ( "value" , this . ymax )
53- . style ( "width" , "40px" )
54- . on ( "change" , function ( ) { $ ( "#axes-input" ) . axes_input ( "change_axis_limits" , null , null , this . value ) } )
71+ . style ( "width" , "50px" )
72+ . style ( "margin-left" , "5px" )
73+ . on ( "change" , function ( ) { $ ( "#axes-input" ) . axes_input ( "change_axis_limits" , null , null , null , this . value ) } )
5574 } ,
5675
57- change_axis_limits : function ( xmin , xmax , ymax , change_plot = true ) {
76+ change_axis_limits : function ( xmin , xmax , ymin , ymax , change_plot = true ) {
77+ // Change x axis limits
5878 if ( xmin !== null ) {
5979 this . xmin = xmin ;
6080 } ;
6181 if ( xmax !== null ) {
6282 this . xmax = xmax ;
6383 } ;
64- if ( ymax !== null ) {
65- this . ymax = ymax ;
84+ // Change y axis limits
85+ if ( this . combined && change_plot ) {
86+ // If the strands are combined, the y axis limits are scaled relative to the difference
87+ if ( ymax !== null ) {
88+ let factor = ymax / ( this . ymax - this . ymin ) ;
89+ this . ymin = ( this . ymin * factor ) . toPrecision ( 2 ) ;
90+ this . ymax = ( this . ymax * factor ) . toPrecision ( 2 )
91+ }
92+ } else {
93+ if ( ymin !== null ) {
94+ this . ymin = ymin ;
95+ } ;
96+ if ( ymax !== null ) {
97+ this . ymax = ymax ;
98+ }
6699 } ;
67100
101+ // Change the text boxes
68102 this . _elements . xmin_text . node ( ) . value = this . xmin ;
69103 this . _elements . xmax_text . node ( ) . value = this . xmax ;
70- this . _elements . ymax_text . node ( ) . value = this . ymax ;
104+ // If the strands are combined, the y axis limit text boxes show 0 for the lower limit and the difference for the upper limit
105+ this . _elements . ymin_text . node ( ) . value = this . combined ? 0 : this . ymin ;
106+ this . _elements . ymax_text . node ( ) . value = this . combined ? this . ymax - this . ymin : this . ymax ;
71107
108+ // Change the plot, if requested
72109 if ( change_plot ) {
73- $ ( "#main-plot" ) . main_plot ( "scale_axes" , this . xmin , this . xmax , this . ymax ) ;
110+ $ ( "#main-plot" ) . main_plot ( "scale_axes" , this . xmin , this . xmax , this . ymin , this . ymax ) ;
74111 $ ( "#settings-table" ) . settings_table ( "plot_all_composites" )
75112 }
76113 } ,
77114
115+ toggle_combined : function ( combined ) {
116+ this . combined = combined ;
117+ // If the strands are combined, the y axis limit text boxes show 0 for the lower limit and the difference for the upper limit
118+ this . _elements . ymin_text . node ( ) . value = combined ? 0 : this . ymin ;
119+ this . _elements . ymax_text . node ( ) . value = combined ? this . ymax - this . ymin : this . ymax ;
120+
121+ // Disable the y axis lower limit text box if the strands are combined
122+ this . _elements . ymin_text
123+ . property ( "disabled" , combined || this . locked )
124+ . style ( "background-color" , combined || this . locked ? "#DDDDDD" : "white" )
125+ } ,
126+
78127 toggle_locked : function ( locked ) {
128+ this . locked = locked ;
129+
130+ // Disable the text boxes if the axes are locked
79131 this . _elements . xmin_text
80132 . property ( "disabled" , locked )
81133 . style ( "background-color" , locked ? "#DDDDDD" : "white" ) ;
82134 this . _elements . xmax_text
83135 . property ( "disabled" , locked )
84136 . style ( "background-color" , locked ? "#DDDDDD" : "white" ) ;
137+ this . _elements . ymin_text
138+ . property ( "disabled" , locked || this . combined )
139+ . style ( "background-color" , locked || this . combined ? "#DDDDDD" : "white" ) ;
85140 this . _elements . ymax_text
86141 . property ( "disabled" , locked )
87142 . style ( "background-color" , locked ? "#DDDDDD" : "white" )
0 commit comments