-
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.
Add bookmark highlight to overview scale bar (#4266)
- Loading branch information
1 parent
72d6402
commit c7dc049
Showing
7 changed files
with
156 additions
and
12 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
111 changes: 111 additions & 0 deletions
111
plugins/grid-bookmark/src/GridBookmarkWidget/components/Highlight/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,111 @@ | ||
import React, { useEffect, useRef } from 'react' | ||
import { observer } from 'mobx-react' | ||
import { makeStyles } from 'tss-react/mui' | ||
import { SessionWithWidgets, getSession, notEmpty } from '@jbrowse/core/util' | ||
import { Base1DViewModel } from '@jbrowse/core/util/Base1DViewModel' | ||
import { Tooltip } from '@mui/material' | ||
|
||
// locals | ||
import { GridBookmarkModel } from '../../model' | ||
import { IExtendedLGV } from '../../model' | ||
|
||
type LGV = IExtendedLGV | ||
|
||
const useStyles = makeStyles()({ | ||
highlight: { | ||
height: '100%', | ||
position: 'absolute', | ||
}, | ||
}) | ||
|
||
const OverviewHighlight = observer(function OverviewHighlight({ | ||
model, | ||
overview, | ||
}: { | ||
model: LGV | ||
overview: Base1DViewModel | ||
}) { | ||
const { classes } = useStyles() | ||
const { cytobandOffset } = model | ||
const session = getSession(model) as SessionWithWidgets | ||
|
||
const { showBookmarkHighlights, showBookmarkLabels } = model | ||
const assemblyNames = new Set(session.assemblyNames) | ||
|
||
const bookmarkWidget = session.widgets.get( | ||
'GridBookmark', | ||
) as GridBookmarkModel | ||
|
||
const bookmarks = useRef(bookmarkWidget?.bookmarks ?? []) | ||
|
||
useEffect(() => { | ||
if (!bookmarkWidget) { | ||
const newBookmarkWidget = session.addWidget( | ||
'GridBookmarkWidget', | ||
'GridBookmark', | ||
) as GridBookmarkModel | ||
bookmarks.current = newBookmarkWidget.bookmarks | ||
} | ||
}, [session, bookmarkWidget]) | ||
|
||
return ( | ||
<> | ||
{showBookmarkHighlights && bookmarks.current | ||
? bookmarks.current | ||
.filter(value => assemblyNames.has(value.assemblyName)) | ||
.map(r => { | ||
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, | ||
highlight: r.highlight, | ||
label: r.label, | ||
} | ||
: undefined | ||
}) | ||
.filter(notEmpty) | ||
.map(({ left, width, highlight, label }, idx) => ( | ||
<> | ||
{showBookmarkLabels ? ( | ||
<Tooltip title={label} arrow> | ||
<div | ||
key={`${left}_${width}_${idx}`} | ||
className={classes.highlight} | ||
style={{ | ||
left, | ||
width, | ||
background: highlight, | ||
borderLeft: `1px solid ${highlight}`, | ||
borderRight: `1px solid ${highlight}`, | ||
}} | ||
/> | ||
</Tooltip> | ||
) : ( | ||
<div | ||
key={`${left}_${width}_${idx}`} | ||
className={classes.highlight} | ||
style={{ | ||
left, | ||
width, | ||
background: highlight, | ||
borderLeft: `1px solid ${highlight}`, | ||
borderRight: `1px solid ${highlight}`, | ||
}} | ||
/> | ||
)} | ||
</> | ||
)) | ||
: 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