Skip to content

Commit 1e5a2f1

Browse files
committed
Generalize "paintAxis" function to work with tracks without dataRange
1 parent f6f64d5 commit 1e5a2f1

File tree

5 files changed

+40
-140
lines changed

5 files changed

+40
-140
lines changed

dev/shoebox/shoebox.html

Lines changed: 0 additions & 106 deletions
This file was deleted.

js/feature/featureParser.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,9 @@ class FeatureParser {
127127
const tokens = line.split(this.delimiter || "\t")
128128
try {
129129
const tmpHeader = Object.assign({columnNames}, header)
130-
if (this.decode(tokens, tmpHeader)) {
130+
let firstFeature
131+
if (firstFeature = this.decode(tokens, tmpHeader)) {
132+
header.firstFeature = firstFeature
131133
break
132134
} else {
133135
if (tokens.length > 1) {

js/shoebox/decodeShoebox.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export default function decodeShoebox(tokens, header, maxColumnCount = Number.MA
66

77
const chr = tokens[0]
88
const start = parseInt(tokens[1])
9-
const end = tokens.length > 2 ? parseInt(tokens[2]) : start + 1
9+
const end = parseInt(tokens[2])
1010
if (isNaN(start) || isNaN(end)) {
1111
return new DecodeError(`Unparsable bed record.`)
1212
}

js/shoebox/shoeboxTrack.js

Lines changed: 21 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import FeatureSource from "../feature/featureSource.js"
33
import TrackBase from "../trackBase.js"
44
import IGVGraphics from "../igv-canvas.js"
55
import ShoeboxColorScale from "./shoeboxColorScale.js"
6+
import paintAxis from "../util/paintAxis.js"
67

78
/**
89
* Configurable properties
@@ -33,12 +34,6 @@ class ShoeboxTrack extends TrackBase {
3334

3435
this.type = "shoebox"
3536

36-
// Hardcoded -- todo, perhaps, get from track line
37-
this.sampleKeys = []
38-
for (let i = 1; i <= this.rowCount; i++) {
39-
this.sampleKeys.push(i)
40-
}
41-
4237
if (config.max) {
4338
this.dataRange = {
4439
min: config.min || 0,
@@ -49,9 +44,12 @@ class ShoeboxTrack extends TrackBase {
4944
const configCopy = Object.assign({}, this.config)
5045
configCopy.format = 'shoebox' // bit of a hack
5146
this.featureSource = FeatureSource(configCopy, this.browser.genome)
47+
48+
this.paintAxis = paintAxis
5249
}
5350

5451
async postInit() {
52+
5553
if (typeof this.featureSource.getHeader === "function") {
5654
this.header = await this.featureSource.getHeader()
5755
if (this.disposed) return // This track was removed during async load
@@ -62,6 +60,8 @@ class ShoeboxTrack extends TrackBase {
6260
this.header.scale = Number.parseFloat(this.header.scale)
6361
}
6462
this.setTrackProperties(this.header)
63+
64+
this.rowCount = this.header.firstFeature ? this.header.firstFeature.values.length : 100
6565
}
6666

6767
// Must do the following after setting track properties as they can be overriden via a track line
@@ -76,10 +76,6 @@ class ShoeboxTrack extends TrackBase {
7676

7777
}
7878

79-
get rowCount() {
80-
return 100 // TODO Hardcoded, get from data
81-
}
82-
8379
get color() {
8480
return this._color || "rgb(0,0,255)"
8581
}
@@ -91,6 +87,14 @@ class ShoeboxTrack extends TrackBase {
9187
}
9288
}
9389

90+
get axisMin() {
91+
return 1
92+
}
93+
94+
get axisMax() {
95+
return this.rowCount
96+
}
97+
9498
menuItemList() {
9599

96100
const menuItems = []
@@ -99,6 +103,7 @@ class ShoeboxTrack extends TrackBase {
99103
let object = $('<div>')
100104
object.text('Set row height')
101105

106+
const browser = this.browser
102107
function dialogHandler(e) {
103108

104109
const callback = () => {
@@ -107,6 +112,8 @@ class ShoeboxTrack extends TrackBase {
107112

108113
if (undefined !== number) {
109114

115+
browser.sampleNameViewportWidth = undefined // TODO, a better way to trigger this
116+
110117
const tracks = []
111118
if (this.trackView.track.selected) {
112119
tracks.push(...(this.trackView.browser.getSelectedTrackViews().map(({track}) => track)))
@@ -116,7 +123,7 @@ class ShoeboxTrack extends TrackBase {
116123

117124
for (const track of tracks) {
118125
track.rowHeight = number
119-
if(track.rowHeight * track.rowCount < track.height) {
126+
if (track.rowHeight * track.rowCount < track.height) {
120127
track.trackView.setTrackHeight(track.rowHeight * track.rowCount, true)
121128
}
122129
track.trackView.checkContentHeight()
@@ -165,23 +172,12 @@ class ShoeboxTrack extends TrackBase {
165172
this.trackView.repaintViews()
166173
}
167174

168-
hasSamples() {
169-
return true // by definition
170-
}
171-
172-
getSamples() {
173-
return {
174-
names: this.sampleKeys,
175-
height: this.rowHeight,
176-
yOffset: 0
177-
}
178-
}
179-
180175
async getFeatures(chr, start, end, bpPerPixel) {
181176
const visibilityWindow = this.visibilityWindow
182-
return this.featureSource.getFeatures({chr, start, end, bpPerPixel, visibilityWindow})
183-
}
177+
const features = await this.featureSource.getFeatures({chr, start, end, bpPerPixel, visibilityWindow})
184178

179+
return features
180+
}
185181

186182
draw({context, pixelTop, pixelWidth, pixelHeight, features, bpPerPixel, bpStart}) {
187183

@@ -254,7 +250,6 @@ class ShoeboxTrack extends TrackBase {
254250
const rect = feature.pixelRect
255251
return rect && y >= rect.y && y <= (rect.y + rect.h)
256252
})
257-
258253
}
259254

260255
hoverText(clickState) {

js/util/paintAxis.js

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,28 @@ const shim = .01
44
const diagnosticColor = "rgb(251,128,114)"
55
const colorStripWidth = 4
66
const axesXOffset = colorStripWidth + 1
7+
78
function paintAxis(ctx, width, height, colorOrUndefined) {
89

9-
if (undefined === this.dataRange || undefined === this.dataRange.max || undefined === this.dataRange.min) {
10+
let axisMin = this.axisMin //|| this.dataRange ? this.dataRange.min : 0
11+
let axisMax = this.axisMax //|| this.dataRange ? this.dataRange.max : undefined
12+
if (undefined === axisMax && this.dataRange) {
13+
axisMin = this.dataRange.min || 0
14+
axisMax = this.dataRange.max
15+
}
16+
if (undefined === axisMax) {
1017
return
1118
}
1219

13-
IGVGraphics.fillRect(ctx, 0, 0, width, height, { fillStyle: 'white' })
20+
IGVGraphics.fillRect(ctx, 0, 0, width, height, {fillStyle: 'white'})
1421
if (colorOrUndefined) {
15-
IGVGraphics.fillRect(ctx, width - colorStripWidth - 2, 0, colorStripWidth, height, { fillStyle: colorOrUndefined })
22+
IGVGraphics.fillRect(ctx, width - colorStripWidth - 2, 0, colorStripWidth, height, {fillStyle: colorOrUndefined})
1623
}
1724

1825
const flipAxis = (undefined === this.flipAxis) ? false : this.flipAxis
1926

2027
const xTickStart = 0.95 * width - 8 - axesXOffset
21-
const xTickEnd = 0.95 * width - axesXOffset
28+
const xTickEnd = 0.95 * width - axesXOffset
2229

2330
const properties =
2431
{
@@ -30,13 +37,13 @@ function paintAxis(ctx, width, height, colorOrUndefined) {
3037

3138
// tick
3239
IGVGraphics.strokeLine(ctx, xTickStart, shim * height, xTickEnd, shim * height, properties)
33-
IGVGraphics.fillText(ctx, prettyPrint(flipAxis ? this.dataRange.min : this.dataRange.max), xTickStart + 4, shim * height + 12, properties)
40+
IGVGraphics.fillText(ctx, prettyPrint(flipAxis ? axisMin : axisMax), xTickStart + 4, shim * height + 12, properties)
3441

3542
const y = (1.0 - shim) * height
3643

3744
// tick
3845
IGVGraphics.strokeLine(ctx, xTickStart, y, xTickEnd, y, properties)
39-
IGVGraphics.fillText(ctx, prettyPrint(flipAxis ? this.dataRange.max : this.dataRange.min), xTickStart + 4, y - 4, properties)
46+
IGVGraphics.fillText(ctx, prettyPrint(flipAxis ? axisMax : axisMin), xTickStart + 4, y - 4, properties)
4047

4148
// vertical axis
4249
IGVGraphics.strokeLine(ctx, xTickEnd, shim * height, xTickEnd, y, properties)
@@ -45,6 +52,8 @@ function paintAxis(ctx, width, height, colorOrUndefined) {
4552

4653
if (number === 0) {
4754
return "0"
55+
} else if (Number.isInteger()) {
56+
return number
4857
} else if (Math.abs(number) >= 10) {
4958
return number.toFixed()
5059
} else if (Math.abs(number) >= 1) {

0 commit comments

Comments
 (0)