@@ -8,12 +8,10 @@ $(function() {
88 this . start_coord = 0 ;
99 this . nucleosome_length = 146 ;
1010 this . plot_svg_height = 18 ;
11- this . main_plot_scale = $ ( "#main-plot" ) . main_plot ( "get_xscale" ) ;
12- this . plot_dimensions = $ ( "#main-plot" ) . main_plot ( "get_dimensions" ) ;
11+ this . main_plot = $ ( "#main-plot" ) . main_plot ( "instance" ) ;
1312 this . plot_points = null ;
1413 this . projection_coords = [ ] ;
1514 this . mark_coords = [ ] ;
16- this . bp_to_px = ( this . plot_dimensions [ 1 ] - this . plot_dimensions [ 2 ] - this . plot_dimensions [ 4 ] ) / ( this . main_plot_scale . domain ( ) [ 1 ] - this . main_plot_scale . domain ( ) [ 0 ] ) ;
1715
1816 this . attach_event_handlers ( ) ;
1917
@@ -99,8 +97,8 @@ $(function() {
9997 this . selected_element . setAttribute ( "x" , newX + "px" ) ;
10098 if ( this . selected_element . getAttribute ( "class" ) . includes ( "nucleosome-svg" ) ) {
10199 //Update start text if selected element is nucleosome
102- this . start_coord = parseInt ( ( newX - this . main_plot_scale ( 0 ) ) * ( 1 / this . bp_to_px ) ) ;
103- this . start_text . property ( "value" , this . start_coord ) ;
100+ this . start_coord = this . main_plot . xscale . invert ( newX ) ;
101+ this . start_text . property ( "value" , this . start_coord . toFixed ( 0 ) ) ;
104102 } else if ( this . selected_element . getAttribute ( "class" ) . includes ( "plotted-coord" ) ) {
105103 //Otherwise use generic method
106104 this . update_text_box ( ) ;
@@ -137,7 +135,7 @@ $(function() {
137135 }
138136 } else if ( this . selected_element . getAttribute ( "class" ) . includes ( "plotted-coord" ) ) {
139137 let plottedCoords = d3 . select ( "#coord-svg-layer" ) . selectAll ( ".plotted-coord" ) ;
140- this . projection_coords = plottedCoords . nodes ( ) . map ( ( element ) => parseInt ( parseInt ( parseFloat ( element . getAttribute ( "x" ) ) - this . main_plot_scale ( 0 ) ) * ( 1 / this . bp_to_px ) ) ) ;
138+ this . projection_coords = plottedCoords . nodes ( ) . map ( ( element ) => this . main_plot . xscale . invert ( parseInt ( element . getAttribute ( "x" ) ) ) . toFixed ( 0 ) ) ;
141139 this . projection_text . property ( "value" , this . projection_coords . join ( "," ) ) ;
142140 }
143141 }
@@ -154,23 +152,18 @@ $(function() {
154152 let new_nucleosome = d3 . select ( nucleosome_svg . cloneNode ( true ) ) ;
155153 //Calculate dimensions
156154 this . start_coord = d3 . select ( "#nucleosome-start-text" ) . property ( "value" ) ;
157- let new_width = this . nucleosome_length * this . bp_to_px ;
158- let starting_pos = this . main_plot_scale ( 0 ) + this . start_coord * this . bp_to_px ;
155+ let new_width = this . nucleosome_length * ( this . main_plot . xscale ( 1 ) - this . main_plot . xscale ( 0 ) ) ;
156+ let starting_pos = this . main_plot . xscale ( this . start_coord ) ;
159157 new_nucleosome . attr ( "height" , self . plot_svg_height + "px" )
160158 . attr ( "width" , new_width + "px" )
161159 . attr ( "x" , starting_pos + "px" )
162160 . attr ( "id" , "nucleosome-svg-plot" )
161+ . attr ( "y" , this . main_plot . yscale ( 0 ) - self . plot_svg_height / 2 )
163162 . selectAll ( ".mark-coord" )
164163 . attr ( "width" , "2px" )
165164 . attr ( "stroke-width" , "1px" )
166165 new_nucleosome . selectAll ( ".projection-coord" )
167166 . remove ( ) ;
168- //Place on x-axis if plot is combined
169- if ( $ ( "#main-plot" ) . main_plot ( "get_combined" ) ) {
170- new_nucleosome . attr ( "y" , self . plot_dimensions [ 0 ] - self . plot_dimensions [ 3 ] - self . plot_svg_height / 2 - 2 + "px" ) ;
171- } else {
172- new_nucleosome . attr ( "y" , ( self . plot_dimensions [ 0 ] - self . plot_svg_height ) / 2 - 2 + "px" ) ;
173- }
174167 //Add dragging listeners
175168 new_nucleosome . on ( "mousedown" , function ( e ) {
176169 self . start_dragging ( e , d3 . select ( "#nucleosome-svg-plot" ) . node ( ) ) ;
@@ -203,18 +196,13 @@ $(function() {
203196 . attr ( "width" , "2px" )
204197 . attr ( "stroke-width" , "1px" )
205198 . attr ( "stroke" , "black" )
206- . attr ( "x" , self . main_plot_scale ( 0 ) + coord * self . bp_to_px + "px" )
207- . attr ( "y" , ( self . plot_dimensions [ 0 ] - self . plot_svg_height ) / 2 - 2 + "px" ) // 2px subtracted to account for outline
199+ . attr ( "x" , self . main_plot . xscale ( coord ) )
200+ . attr ( "y" , self . main_plot . yscale ( 0 ) - self . plot_svg_height / 2 ) // 2px subtracted to account for outline
208201 . attr ( "height" , self . plot_svg_height + "px" )
209202 . style ( "fill" , "rgb(255, 252, 97)" )
210203 . on ( "mousedown" , function ( e ) {
211204 self . start_dragging ( e , d3 . select ( this ) . node ( ) ) ;
212205 } )
213- if ( $ ( "#main-plot" ) . main_plot ( "get_combined" ) ) {
214- coordElement . attr ( "y" , self . plot_dimensions [ 0 ] - self . plot_dimensions [ 3 ] - self . plot_svg_height / 2 - 2 + "px" ) ;
215- } else {
216- coordElement . attr ( "y" , ( self . plot_dimensions [ 0 ] - self . plot_svg_height ) / 2 - 2 + "px" ) ;
217- }
218206 i += 1 ;
219207 }
220208 }
@@ -225,12 +213,11 @@ $(function() {
225213 //Remove old pointers and add new ones to plot based on widget arrays
226214 let self = this ;
227215 d3 . select ( "#coord-svg-layer" ) . selectAll ( ".pointer" ) . remove ( ) ;
228- let y_axis = self . main_plot_scale ( 0 ) ;
229216 if ( this . plot_points ) {
230217 let i = 0 ;
231218 for ( var coord of this . projection_coords ) {
232219 if ( coord != "" && ! isNaN ( coord ) ) {
233- let x = y_axis + coord * self . bp_to_px ;
220+ let x = this . main_plot . xscale ( parseInt ( coord ) ) ;
234221 let y = this . plot_points . get ( parseInt ( x ) ) ;
235222 d3 . select ( "#coord-svg-layer" ) . append ( "circle" )
236223 . attr ( "id" , "projection-" + i )
@@ -242,8 +229,8 @@ $(function() {
242229 }
243230 i = 0 ;
244231 for ( var coord of this . mark_coords ) {
245- if ( coord != "" ) {
246- let x = y_axis + ( ( parseInt ( coord ) + parseInt ( self . start_coord ) ) * self . bp_to_px ) ;
232+ if ( coord != "" && ! isNaN ( coord ) ) {
233+ let x = this . main_plot . xscale ( parseInt ( coord ) ) ;
247234 let y = this . plot_points . get ( parseInt ( x ) ) ;
248235 d3 . select ( "#coord-svg-layer" ) . append ( "circle" )
249236 . attr ( "id" , "mark-" + i )
@@ -319,10 +306,7 @@ $(function() {
319306 } ,
320307
321308 update_plot_stats ( ) {
322- //Update plot dimensions and points on the composite plot
323- this . main_plot_scale = $ ( "#main-plot" ) . main_plot ( "get_xscale" ) ;
324- this . plot_dimensions = $ ( "#main-plot" ) . main_plot ( "get_dimensions" ) ;
325- this . bp_to_px = ( this . plot_dimensions [ 1 ] - this . plot_dimensions [ 2 ] - this . plot_dimensions [ 4 ] ) / ( this . main_plot_scale . domain ( ) [ 1 ] - this . main_plot_scale . domain ( ) [ 0 ] ) ;
309+ //Points on the composite plot
326310 this . get_plot_points ( ) ;
327311 } ,
328312
0 commit comments