Skip to content

Commit

Permalink
Fix for navigation past end of chromosome
Browse files Browse the repository at this point in the history
  • Loading branch information
cmdcolin committed Feb 20, 2021
1 parent 31ce25f commit 0c0422a
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -102,24 +102,24 @@ export default observer(({ model }: { model: LGV }) => {

const setDisplayedRegion = useCallback(
(newRegionValue: string | undefined) => {
if (newRegionValue) {
const newRegion: Region | undefined = model.displayedRegions.find(
region => newRegionValue === region.refName,
)
// navigate to region or if region not found try navigating to locstring
if (newRegion) {
model.setDisplayedRegions([newRegion])
// we use showAllRegions after setDisplayedRegions to make the entire
// region visible, xref #1703
model.showAllRegions()
} else {
try {
try {
if (newRegionValue) {
const newRegion: Region | undefined = model.displayedRegions.find(
region => newRegionValue === region.refName,
)
// navigate to region or if region not found try navigating to locstring
if (newRegion) {
model.setDisplayedRegions([newRegion])
// we use showAllRegions after setDisplayedRegions to make the entire
// region visible, xref #1703
model.showAllRegions()
} else {
newRegionValue && model.navToLocString(newRegionValue)
} catch (e) {
console.warn(e)
session.notify(`${e}`, 'warning')
}
}
} catch (e) {
console.warn(e)
session.notify(`${e}`, 'warning')
}
},
[model, session],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,18 +113,20 @@ const Polygon = observer(
}) => {
const theme = useTheme()
const classes = useStyles()
const { offsetPx, dynamicBlocks: visibleRegions } = model
const {
offsetPx,
dynamicBlocks: { contentBlocks, totalWidthPxWithoutBorders },
} = model

const polygonColor = theme.palette.tertiary
? theme.palette.tertiary.light
: theme.palette.primary.light

if (!visibleRegions.contentBlocks.length) {
if (!contentBlocks.length) {
return null
}
const firstBlock = visibleRegions.contentBlocks[0]
const lastBlock =
visibleRegions.contentBlocks[visibleRegions.contentBlocks.length - 1]
const firstBlock = contentBlocks[0]
const lastBlock = contentBlocks[contentBlocks.length - 1]
const topLeft = overview.bpToPx({
refName: firstBlock.refName,
coord: firstBlock.reversed ? firstBlock.end : firstBlock.start,
Expand All @@ -139,8 +141,8 @@ const Polygon = observer(
const startPx = Math.max(0, -offsetPx)
const endPx =
startPx +
visibleRegions.totalWidthPxWithoutBorders +
(visibleRegions.contentBlocks.length * model.interRegionPaddingWidth) / 2
totalWidthPxWithoutBorders +
(contentBlocks.length * model.interRegionPaddingWidth) / 2

const points = [
[startPx, HEADER_BAR_HEIGHT],
Expand Down Expand Up @@ -185,6 +187,9 @@ const ScaleBar = observer(
const gridPitch = chooseGridPitch(scale, 120, 15)
const { dynamicBlocks: overviewVisibleRegions } = overview

if (!visibleRegions.contentBlocks.length) {
return null
}
const firstBlock = visibleRegions.contentBlocks[0]
const firstOverviewPx =
overview.bpToPx({
Expand Down
17 changes: 13 additions & 4 deletions plugins/linear-genome-view/src/LinearGenomeView/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -690,11 +690,20 @@ export function stateModelFactory(pluginManager: PluginManager) {
)
if (newDisplayedRegion) {
this.setDisplayedRegions([getSnapshot(newDisplayedRegion)])
} else {
throw new Error(
`Could not find refName ${parsedLocString.refName} in ${assembly.name}`,
)

this.navTo({
...parsedLocString,
start: Math.min(
parsedLocString?.start || 0,
newDisplayedRegion.end,
),
end: Math.min(parsedLocString?.end || 1, newDisplayedRegion.end),
})
return
}
throw new Error(
`Could not find refName ${parsedLocString.refName} in ${assembly.name}`,
)
}
this.navTo(parsedLocString)
},
Expand Down

0 comments on commit 0c0422a

Please sign in to comment.