@@ -2,13 +2,13 @@ import { get } from './fetch.js'
2
2
import { CHROMOSOMES } from './track.js'
3
3
import { chromSizes } from './helper.js'
4
4
5
- function redrawEvent ( { region, exclude = [ ] , ...kwargs } ) {
5
+ function redrawEvent ( { region, exclude = [ ] , ...kwargs } ) {
6
6
return new CustomEvent (
7
7
'draw' , { detail : { region : region , exclude : exclude , ...kwargs } }
8
8
)
9
9
}
10
10
11
- function drawEventManager ( { target, throttleTime } ) {
11
+ function drawEventManager ( { target, throttleTime } ) {
12
12
const tracks = [
13
13
...target . querySelectorAll ( '.track-container' ) ,
14
14
target . querySelector ( '#cytogenetic-ideogram' )
@@ -30,7 +30,7 @@ function drawEventManager({ target, throttleTime }) {
30
30
}
31
31
}
32
32
33
- export function setupDrawEventManager ( { target, throttleTime = 20 } ) {
33
+ export function setupDrawEventManager ( { target, throttleTime = 20 } ) {
34
34
const manager = drawEventManager ( { target, throttleTime } )
35
35
target . addEventListener ( 'draw' , ( event ) => {
36
36
manager ( event )
@@ -42,7 +42,7 @@ export function readInputField() {
42
42
return parseRegionDesignation ( field . value )
43
43
}
44
44
45
- function updateInputField ( { chrom, start, end } ) {
45
+ function updateInputField ( { chrom, start, end } ) {
46
46
const field = document . getElementById ( 'region-field' )
47
47
field . value = `${ chrom } :${ start } -${ end } `
48
48
field . placeholder = field . value
@@ -54,7 +54,7 @@ function updateInputField({ chrom, start, end }) {
54
54
// eg 1:12-220 --> 1, 12 220
55
55
// 1: --> 1, null, null
56
56
// 1 --> 1, null, null
57
- export function parseRegionDesignation ( regionString ) {
57
+ export function parseRegionDesignation ( regionString ) {
58
58
if ( regionString . includes ( ':' ) ) {
59
59
const [ chromosome , position ] = regionString . split ( ':' )
60
60
// verify chromosome
@@ -68,7 +68,7 @@ export function parseRegionDesignation(regionString) {
68
68
}
69
69
}
70
70
71
- export async function limitRegionToChromosome ( { chrom, start, end, genomeBuild = '38' } ) {
71
+ export async function limitRegionToChromosome ( { chrom, start, end, genomeBuild = '38' } ) {
72
72
// assert that start/stop are within start and end of chromosome
73
73
const sizes = await chromSizes ( genomeBuild )
74
74
const chromSize = sizes [ chrom ]
@@ -93,7 +93,7 @@ export async function limitRegionToChromosome({ chrom, start, end, genomeBuild =
93
93
return { chrom : chrom , start : Math . round ( updStart ) , end : Math . round ( updEnd ) }
94
94
}
95
95
96
- export async function drawTrack ( {
96
+ export async function drawTrack ( {
97
97
chrom, start, end, genomeBuild = '38' ,
98
98
exclude = [ ] , force = false , ...kwargs
99
99
} ) {
@@ -113,7 +113,7 @@ export async function drawTrack({
113
113
// If query is a regionString draw the relevant region
114
114
// If input is a chromosome display entire chromosome
115
115
// Else query api for genes with that name and draw that region
116
- export function queryRegionOrGene ( query , genomeBuild = 38 ) {
116
+ export function queryRegionOrGene ( query , genomeBuild = 38 ) {
117
117
if ( query . includes ( ':' ) ) {
118
118
drawTrack ( parseRegionDesignation ( query ) )
119
119
} else if ( CHROMOSOMES . includes ( query ) ) {
@@ -133,21 +133,21 @@ export function queryRegionOrGene(query, genomeBuild = 38) {
133
133
}
134
134
135
135
// goto the next chromosome
136
- export function nextChromosome ( ) {
136
+ export function nextChromosome ( ) {
137
137
const position = readInputField ( )
138
138
const chrom = CHROMOSOMES [ CHROMOSOMES . indexOf ( position . chrom ) + 1 ]
139
139
drawTrack ( { chrom : chrom , start : 1 , end : null } )
140
140
}
141
141
142
142
// goto the previous chromosome
143
- export function previousChromosome ( ) {
143
+ export function previousChromosome ( ) {
144
144
const position = readInputField ( )
145
145
const chrom = CHROMOSOMES [ CHROMOSOMES . indexOf ( position . chrom ) - 1 ]
146
146
drawTrack ( { chrom : chrom , start : 1 , end : null } )
147
147
}
148
148
149
149
// Pan whole canvas and tracks to the left
150
- export function panTracks ( direction = 'left' , speed = 0.1 ) {
150
+ export function panTracks ( direction = 'left' , speed = 0.1 ) {
151
151
const pos = readInputField ( )
152
152
const distance = Math . abs ( Math . floor ( speed * ( pos . end - pos . start ) ) )
153
153
if ( direction === 'left' ) {
@@ -166,7 +166,7 @@ export function panTracks(direction = 'left', speed = 0.1) {
166
166
}
167
167
168
168
// Handle zoom in button click
169
- export function zoomIn ( ) {
169
+ export function zoomIn ( ) {
170
170
const pos = readInputField ( )
171
171
const factor = Math . floor ( ( pos . end - pos . start ) * 0.2 )
172
172
pos . start += factor
@@ -175,19 +175,37 @@ export function zoomIn() {
175
175
}
176
176
177
177
// Handle zoom out button click
178
- export function zoomOut ( ) {
178
+ export function zoomOut ( ) {
179
179
const pos = readInputField ( )
180
180
const factor = Math . floor ( ( pos . end - pos . start ) / 3 )
181
181
pos . start = ( pos . start - factor ) < 1 ? 1 : pos . start - factor
182
182
pos . end += factor
183
183
drawTrack ( { chrom : pos . chrom , start : pos . start , end : pos . end , exclude : [ 'cytogenetic-ideogram' ] , drawTitle : false } )
184
184
}
185
185
186
+ // Handle zoom in Y button click
187
+ export function zoomInY ( ) {
188
+ console . log ( 'dispatching zoom in Y' )
189
+ const zoomYEvent = new CustomEvent (
190
+ 'zoomY' , { detail : { direction : 'in' } }
191
+ )
192
+ document . getElementById ( 'interactive-static' ) . dispatchEvent ( zoomYEvent )
193
+ }
194
+
195
+ // Handle zoom out Y button click
196
+ export function zoomOutY ( ) {
197
+ console . log ( 'dispatching zoom out Y' )
198
+ const zoomYEvent = new CustomEvent (
199
+ 'zoomY' , { detail : { direction : 'out' } }
200
+ )
201
+ document . getElementById ( 'interactive-static' ) . dispatchEvent ( zoomYEvent )
202
+ }
203
+
186
204
// Dispatch dispatch an event to draw a given region
187
205
// Redraw events can be limited to certain tracks or include all tracks
188
206
class KeyLogger {
189
207
// Records keypress combinations
190
- constructor ( bufferSize = 10 ) {
208
+ constructor ( bufferSize = 10 ) {
191
209
// Setup variables
192
210
this . bufferSize = bufferSize
193
211
this . lastKeyTime = Date . now ( )
@@ -213,14 +231,14 @@ class KeyLogger {
213
231
} )
214
232
}
215
233
216
- recentKeys ( timeWindow ) {
234
+ recentKeys ( timeWindow ) {
217
235
// get keys pressed within a window of time.
218
236
const currentTime = Date . now ( )
219
237
return this . keyBuffer . filter ( keyEvent =>
220
238
timeWindow > currentTime - keyEvent . time )
221
239
}
222
240
223
- lastKeypressTime ( ) {
241
+ lastKeypressTime ( ) {
224
242
return this . keyBuffer [ this . keyBuffer . length - 1 ] - Date . now ( )
225
243
}
226
244
}
@@ -272,11 +290,19 @@ document.addEventListener('keyevent', event => {
272
290
case '+' :
273
291
zoomIn ( )
274
292
break
293
+ case '?' :
294
+ case 'W' :
295
+ zoomInY ( )
296
+ break
275
297
case 'ArrowDown' :
276
298
case 's' :
277
299
case '-' :
278
300
zoomOut ( )
279
301
break
302
+ case 'S' :
303
+ case '_' :
304
+ zoomOutY ( )
305
+ break
280
306
default :
281
307
}
282
308
}
0 commit comments