Skip to content

Commit 634e41e

Browse files
committed
Add axis for sb track
1 parent 9fd9152 commit 634e41e

File tree

2 files changed

+50
-11
lines changed

2 files changed

+50
-11
lines changed

js/shoebox/shoeboxTrack.js

Lines changed: 48 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ class ShoeboxTrack extends TrackBase {
2121
max: 3,
2222
scale: 1.0,
2323
visibilityWindow: 10000,
24-
supportHiDPI: false
24+
supportHiDPI: false,
25+
rowStepSize: 1 // Stepsize for each row in bp for footprint radius
2526
}
2627

2728
constructor(config, browser) {
@@ -45,9 +46,10 @@ class ShoeboxTrack extends TrackBase {
4546
configCopy.format = 'shoebox' // bit of a hack
4647
this.featureSource = FeatureSource(configCopy, this.browser.genome)
4748

48-
this.paintAxis = paintAxis
49+
// this.paintAxis = paintAxis
4950
}
5051

52+
5153
async postInit() {
5254

5355
if (typeof this.featureSource.getHeader === "function") {
@@ -87,13 +89,6 @@ class ShoeboxTrack extends TrackBase {
8789
}
8890
}
8991

90-
get axisMin() {
91-
return 1
92-
}
93-
94-
get axisMax() {
95-
return this.rowCount
96-
}
9792

9893
menuItemList() {
9994

@@ -104,6 +99,7 @@ class ShoeboxTrack extends TrackBase {
10499
object.text('Set row height')
105100

106101
const browser = this.browser
102+
107103
function dialogHandler(e) {
108104

109105
const callback = () => {
@@ -230,6 +226,32 @@ class ShoeboxTrack extends TrackBase {
230226

231227
}
232228

229+
paintAxis(ctx, pixelWidth, pixelHeight) {
230+
231+
//IGVGraphics.fillRect(ctx, 0, 0, pixelWidth, pixelHeight, {'fillStyle': "rgb(255, 255, 255)"})
232+
var font = {
233+
'font': 'normal 10px Arial',
234+
'textAlign': 'right',
235+
'strokeStyle': "black"
236+
}
237+
238+
const max = 2 * (this.rowCount + 1) //2x for size in diameter, rather than radius
239+
const min = 0
240+
const yScale = (max - min) / pixelHeight
241+
242+
const n = 50
243+
for (let p = n; p <= max; p += n) {
244+
const yp = Math.max(10, pixelHeight - Math.round((p - min) / yScale))
245+
IGVGraphics.strokeLine(ctx, 35, yp , 40, yp , font)
246+
if(p > min ) {
247+
IGVGraphics.fillText(ctx, prettyPrint(p), 30, yp + 4, font) // Offset numbers down by 2 pixels;
248+
}
249+
}
250+
font['textAlign'] = 'center'
251+
font['font'] = 'normal 10px Arial'
252+
IGVGraphics.fillText(ctx, "Footprint size (bp)", 10, pixelHeight / 2, font, {rotate: {angle: -90}})
253+
}
254+
233255
/**
234256
* Optional method to compute pixel height to accomodate the list of features.
235257
*
@@ -301,4 +323,21 @@ class ShoeboxTrack extends TrackBase {
301323
}
302324

303325

326+
function prettyPrint(number) {
327+
328+
if (Number.isInteger(number)) {
329+
return number
330+
} else if (number % 1 === 0) { // Number can be represented exactly as an integer
331+
return number
332+
} else if (Math.abs(number) >= 10) {
333+
return number.toFixed()
334+
} else if (Math.abs(number) >= 1) {
335+
return number.toFixed(1)
336+
} else if (Math.abs(number) >= 0.1) {
337+
return number.toFixed(2)
338+
} else {
339+
return number.toExponential(1)
340+
}
341+
}
342+
304343
export default ShoeboxTrack

js/util/paintAxis.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ function paintAxis(ctx, width, height, colorOrUndefined) {
5050

5151
function prettyPrint(number) {
5252

53-
if (number === 0) {
54-
return "0"
53+
if (Number.isInteger(number)) {
54+
return number
5555
} else if (number % 1 === 0) { // Number can be represented exactly as an integer
5656
return number
5757
} else if (Math.abs(number) >= 10) {

0 commit comments

Comments
 (0)