Skip to content

Commit

Permalink
Make minimum block width smaller, and make the pxToBp account for pad…
Browse files Browse the repository at this point in the history
…ding blocks
  • Loading branch information
cmdcolin committed Dec 21, 2020
1 parent 57f34d9 commit 535800b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
2 changes: 1 addition & 1 deletion packages/core/util/Base1DViewModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ const Base1DView = types
return 2
},
get minimumBlockWidth() {
return 20
return 3
},
/**
* calculates the Px at which coord is found.
Expand Down
19 changes: 15 additions & 4 deletions plugins/linear-genome-view/src/LinearGenomeView/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ export function stateModelFactory(pluginManager: PluginManager) {
})
.volatile(() => ({
volatileWidth: undefined as number | undefined,
minimumBlockWidth: 20,
minimumBlockWidth: 3,
draggingTrackId: undefined as undefined | string,
error: undefined as undefined | Error,

Expand Down Expand Up @@ -310,6 +310,10 @@ export function stateModelFactory(pluginManager: PluginManager) {
let bpSoFar = 0
const bp = (self.offsetPx + px) * self.bpPerPx
const n = self.displayedRegions.length
const nNotEllided = self.displayedRegions.filter(r => {
return (r.end - r.start) / self.bpPerPx > self.minimumBlockWidth
}).length

if (bp < 0) {
const region = self.displayedRegions[0]
const offset = bp
Expand All @@ -323,7 +327,9 @@ export function stateModelFactory(pluginManager: PluginManager) {
index: 0,
}
}
if (bp >= this.totalBp) {
const interRegionPaddingBp = this.interRegionPaddingWidth * self.bpPerPx

if (bp >= this.totalBp + (nNotEllided + 1) * interRegionPaddingBp) {
const region = self.displayedRegions[n - 1]
const len = region.end - region.start
const offset = bp - this.totalBp + len
Expand All @@ -339,7 +345,12 @@ export function stateModelFactory(pluginManager: PluginManager) {
}
for (let index = 0; index < self.displayedRegions.length; index += 1) {
const region = self.displayedRegions[index]
const len = region.end - region.start
let len = region.end - region.start
const extra =
len / self.bpPerPx > self.minimumBlockWidth
? interRegionPaddingBp
: 0
len += extra
if (len + bpSoFar > bp && bpSoFar <= bp) {
const offset = bp - bpSoFar
return {
Expand All @@ -354,7 +365,7 @@ export function stateModelFactory(pluginManager: PluginManager) {
}
bpSoFar += len
}
throw new Error('pxToBp failed to map to a region')
return { refName: '', coord: '' }
},
getTrack(id: string) {
return self.tracks.find(t => t.configuration.trackId === id)
Expand Down

0 comments on commit 535800b

Please sign in to comment.