UNPKG

@jbrowse/plugin-linear-genome-view

Version:

JBrowse 2 linear genome view

142 lines (141 loc) 7.28 kB
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime"; import { useMemo } from 'react'; import { getEnv, getSession } from '@jbrowse/core/util'; import Base1DView from '@jbrowse/core/util/Base1DViewModel'; import { Typography, alpha, useTheme } from '@mui/material'; import { observer } from 'mobx-react'; import { makeStyles } from 'tss-react/mui'; import Cytobands from './Cytobands'; import OverviewHighlight from './OverviewHighlight'; import OverviewRubberband from './OverviewRubberband'; import OverviewScalebarPolygon from './OverviewScalebarPolygon'; import OverviewScalebarTickLabels from './OverviewScalebarTickLabels'; import { getCytobands } from './util'; import { HEADER_BAR_HEIGHT, HEADER_OVERVIEW_HEIGHT } from '../consts'; const wholeSeqSpacer = 2; const useStyles = makeStyles()(theme => ({ scalebar: { height: HEADER_OVERVIEW_HEIGHT, }, scalebarBorder: { border: '1px solid', }, scalebarContig: { backgroundColor: theme.palette.background.default, position: 'absolute', top: 0, height: HEADER_OVERVIEW_HEIGHT, overflow: 'hidden', }, scalebarContigForward: { backgroundImage: `url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 15 9'%3E%3Cpath d='M-.1 0L6 4.5L-.1 9' fill='none' stroke='${theme.palette.divider}'/%3E%3C/svg%3E")`, backgroundRepeat: 'repeat', }, scalebarContigReverse: { backgroundImage: `url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 15 9'%3E%3Cpath d='M6 0L0 4.5L6 9' fill='none' stroke='${theme.palette.divider}'/%3E%3C/svg%3E")`, backgroundRepeat: 'repeat', }, scalebarRefName: { position: 'absolute', fontWeight: 'bold', pointerEvents: 'none', zIndex: 100, }, scalebarVisibleRegion: { position: 'absolute', height: HEADER_OVERVIEW_HEIGHT, pointerEvents: 'none', zIndex: 100, border: '1px solid', }, overview: { height: HEADER_BAR_HEIGHT, position: 'relative', }, overviewSvg: { pointerEvents: 'none', width: '100%', position: 'absolute', }, })); const OverviewBox = observer(function ({ scale, model, block, overview, }) { const { classes, cx } = useStyles(); const theme = useTheme(); const { cytobandOffset, showCytobands } = model; const { reversed, refName, assemblyName } = block; const { assemblyManager } = getSession(model); const assembly = assemblyManager.get(assemblyName); const refNameColor = assembly === null || assembly === void 0 ? void 0 : assembly.getRefNameColor(refName); const canDisplayCytobands = showCytobands && getCytobands(assembly, block.refName).length; return (_jsxs("div", { children: [_jsx(Typography, { style: { left: block.offsetPx + 3, color: canDisplayCytobands ? theme.palette.text.primary : refNameColor, }, className: classes.scalebarRefName, children: refName }), _jsx("div", { className: cx(classes.scalebarContig, canDisplayCytobands ? undefined : reversed ? classes.scalebarContigReverse : classes.scalebarContigForward, !canDisplayCytobands ? classes.scalebarBorder : undefined), style: { left: block.offsetPx + cytobandOffset, width: block.widthPx, borderColor: refNameColor, }, children: canDisplayCytobands ? (_jsx("svg", { style: { width: '100%' }, children: _jsx(Cytobands, { overview: overview, assembly: assembly, block: block }) })) : (_jsx(OverviewScalebarTickLabels, { model: model, overview: overview, scale: scale, block: block })) })] })); }); const Scalebar = observer(function ({ model, scale, overview, }) { const { classes } = useStyles(); const theme = useTheme(); const { dynamicBlocks, showCytobands, cytobandOffset } = model; const { pluginManager } = getEnv(model); const visibleRegions = dynamicBlocks.contentBlocks; const overviewVisibleRegions = overview.dynamicBlocks; const scalebarColor = theme.palette.tertiary.light; if (!visibleRegions.length) { return null; } const first = visibleRegions.at(0); const last = visibleRegions.at(-1); const firstOverviewPx = overview.bpToPx({ ...first, coord: first.reversed ? first.end : first.start, }) || 0; const lastOverviewPx = overview.bpToPx({ ...last, coord: last.reversed ? last.start : last.end, }) || 0; const color = showCytobands ? '#f00' : scalebarColor; const transparency = showCytobands ? 0.1 : 0.3; const additional = pluginManager.evaluateExtensionPoint('LinearGenomeView-OverviewScalebarComponent', undefined, { model, overview }); return (_jsxs("div", { className: classes.scalebar, children: [_jsx("div", { className: classes.scalebarVisibleRegion, style: { width: lastOverviewPx - firstOverviewPx, left: firstOverviewPx + cytobandOffset, background: alpha(color, transparency), borderColor: color, } }), overviewVisibleRegions.map((block, idx) => { return !(block.type === 'ContentBlock') ? (_jsx("div", { className: classes.scalebarContig, style: { width: block.widthPx, left: block.offsetPx, backgroundColor: '#999', backgroundImage: 'repeating-linear-gradient(90deg, transparent, transparent 1px, rgba(255,255,255,.5) 1px, rgba(255,255,255,.5) 3px)', } }, `${JSON.stringify(block)}-${idx}`)) : (_jsx(OverviewBox, { scale: scale, block: block, model: model, overview: overview }, `${JSON.stringify(block)}-${idx}`)); }), _jsx(OverviewHighlight, { model: model, overview: overview }), additional] })); }); const OverviewScalebar = observer(function ({ model, children, }) { const { classes } = useStyles(); const { minimumBlockWidth, totalBp, width, cytobandOffset, displayedRegions, } = model; const modWidth = width - cytobandOffset; const str = JSON.stringify(displayedRegions); const overview = useMemo(() => { const overview = Base1DView.create({ displayedRegions: JSON.parse(str), interRegionPaddingWidth: 0, minimumBlockWidth, }); overview.setVolatileWidth(modWidth); overview.showAllRegions(); return overview; }, [str, minimumBlockWidth, modWidth]); const scale = totalBp / (modWidth - (displayedRegions.length - 1) * wholeSeqSpacer); return (_jsxs("div", { children: [_jsx(OverviewRubberband, { model: model, overview: overview, ControlComponent: _jsx(Scalebar, { model: model, overview: overview, scale: scale }) }), _jsxs("div", { className: classes.overview, children: [_jsx("svg", { height: HEADER_BAR_HEIGHT, className: classes.overviewSvg, children: _jsx(OverviewScalebarPolygon, { model: model, overview: overview }) }), children] })] })); }); export default OverviewScalebar;