-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds URL query param for highlight on LGV (#4234)
--------- Co-authored-by: Colin <colin.diesh@gmail.com>
- Loading branch information
1 parent
9f43937
commit 8f8da20
Showing
9 changed files
with
254 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
136 changes: 136 additions & 0 deletions
136
plugins/linear-genome-view/src/LinearGenomeView/components/Highlight.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
import React, { useRef, useState } from 'react' | ||
import { observer } from 'mobx-react' | ||
import { makeStyles } from 'tss-react/mui' | ||
import { colord } from '@jbrowse/core/util/colord' | ||
import { | ||
ParsedLocString, | ||
Region, | ||
SessionWithWidgets, | ||
getSession, | ||
} from '@jbrowse/core/util' | ||
import { Menu } from '@jbrowse/core/ui' | ||
import { IconButton, Tooltip, useTheme } from '@mui/material' | ||
|
||
// icons | ||
import LinkIcon from '@mui/icons-material/Link' | ||
import CloseIcon from '@mui/icons-material/Close' | ||
import BookmarkIcon from '@mui/icons-material/Bookmark' | ||
|
||
// locals | ||
import { LinearGenomeViewModel } from '../model' | ||
|
||
type LGV = LinearGenomeViewModel | ||
|
||
const useStyles = makeStyles()(theme => ({ | ||
highlight: { | ||
height: '100%', | ||
position: 'absolute', | ||
background: `${colord(theme.palette.quaternary?.main ?? 'goldenrod') | ||
.alpha(0.35) | ||
.toRgbString()}`, | ||
borderLeft: `1px solid ${theme.palette.quaternary?.main ?? 'goldenrod'}`, | ||
borderRight: `1px solid ${theme.palette.quaternary?.main ?? 'goldenrod'}`, | ||
}, | ||
})) | ||
|
||
const Highlight = observer(function Highlight({ model }: { model: LGV }) { | ||
const { classes } = useStyles() | ||
const [open, setOpen] = useState(false) | ||
const anchorEl = useRef(null) | ||
const color = useTheme().palette.quaternary?.main ?? 'goldenrod' | ||
|
||
const session = getSession(model) as SessionWithWidgets | ||
|
||
const dismissHighlight = () => { | ||
model.setHighlight(undefined) | ||
} | ||
|
||
const menuItems = [ | ||
{ | ||
label: 'Dismiss highlight', | ||
icon: CloseIcon, | ||
onClick: () => dismissHighlight(), | ||
}, | ||
{ | ||
label: 'Bookmark highlighted region', | ||
icon: BookmarkIcon, | ||
onClick: () => { | ||
let bookmarkWidget = session.widgets.get('GridBookmark') | ||
if (!bookmarkWidget) { | ||
bookmarkWidget = session.addWidget( | ||
'GridBookmarkWidget', | ||
'GridBookmark', | ||
) | ||
} | ||
// @ts-ignore | ||
bookmarkWidget.addBookmark(model.highlight as Region) | ||
dismissHighlight() | ||
}, | ||
}, | ||
] | ||
|
||
function handleClose() { | ||
setOpen(false) | ||
} | ||
|
||
if (!model.highlight) { | ||
return | ||
} | ||
|
||
// coords | ||
const mapCoords = (r: Required<ParsedLocString>) => { | ||
const s = model.bpToPx({ | ||
refName: r.refName, | ||
coord: r.start, | ||
}) | ||
const e = model.bpToPx({ | ||
refName: r.refName, | ||
coord: r.end, | ||
}) | ||
return s && e | ||
? { | ||
width: Math.max(Math.abs(e.offsetPx - s.offsetPx), 3), | ||
left: Math.min(s.offsetPx, e.offsetPx) - model.offsetPx, | ||
} | ||
: undefined | ||
} | ||
|
||
const h = mapCoords(model.highlight as Required<ParsedLocString>) | ||
|
||
return ( | ||
<> | ||
{h ? ( | ||
<div | ||
className={classes.highlight} | ||
style={{ | ||
left: h.left, | ||
width: h.width, | ||
}} | ||
> | ||
<Tooltip title={'Highlighted from URL parameter'} arrow> | ||
<IconButton ref={anchorEl} onClick={() => setOpen(true)}> | ||
<LinkIcon | ||
fontSize="small" | ||
sx={{ | ||
color: `${colord(color).darken(0.2).toRgbString()}`, | ||
}} | ||
/> | ||
</IconButton> | ||
</Tooltip> | ||
<Menu | ||
anchorEl={anchorEl.current} | ||
onMenuItemClick={(_event, callback) => { | ||
callback(session) | ||
handleClose() | ||
}} | ||
open={open} | ||
onClose={handleClose} | ||
menuItems={menuItems} | ||
/> | ||
</div> | ||
) : null} | ||
</> | ||
) | ||
}) | ||
|
||
export default Highlight |
72 changes: 72 additions & 0 deletions
72
plugins/linear-genome-view/src/LinearGenomeView/components/OverviewHighlight.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import React from 'react' | ||
import { observer } from 'mobx-react' | ||
import { makeStyles } from 'tss-react/mui' | ||
import { colord } from '@jbrowse/core/util/colord' | ||
import { ParsedLocString } from '@jbrowse/core/util' | ||
import { Base1DViewModel } from '@jbrowse/core/util/Base1DViewModel' | ||
|
||
// locals | ||
import { LinearGenomeViewModel } from '../model' | ||
|
||
type LGV = LinearGenomeViewModel | ||
|
||
const useStyles = makeStyles()(theme => ({ | ||
highlight: { | ||
height: '100%', | ||
position: 'absolute', | ||
background: `${colord(theme.palette.quaternary?.main ?? 'goldenrod') | ||
.alpha(0.35) | ||
.toRgbString()}`, | ||
borderLeft: `1px solid ${theme.palette.quaternary?.main ?? 'goldenrod'}`, | ||
borderRight: `1px solid ${theme.palette.quaternary?.main ?? 'goldenrod'}`, | ||
}, | ||
})) | ||
|
||
const OverviewHighlight = observer(function OverviewHighlight({ | ||
model, | ||
overview, | ||
}: { | ||
model: LGV | ||
overview: Base1DViewModel | ||
}) { | ||
const { classes } = useStyles() | ||
const { cytobandOffset } = model | ||
|
||
// coords | ||
const mapCoords = (r: Required<ParsedLocString>) => { | ||
const s = overview.bpToPx({ | ||
...r, | ||
coord: r.reversed ? r.end : r.start, | ||
}) | ||
|
||
const e = overview.bpToPx({ | ||
...r, | ||
coord: r.reversed ? r.start : r.end, | ||
}) | ||
|
||
return s !== undefined && e != undefined | ||
? { | ||
width: Math.abs(e - s), | ||
left: s + cytobandOffset, | ||
} | ||
: undefined | ||
} | ||
|
||
const h = mapCoords(model.highlight as Required<ParsedLocString>) | ||
|
||
return ( | ||
<> | ||
{h ? ( | ||
<div | ||
className={classes.highlight} | ||
style={{ | ||
width: h.width, | ||
left: h.left, | ||
}} | ||
/> | ||
) : null} | ||
</> | ||
) | ||
}) | ||
|
||
export default OverviewHighlight |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters