Skip to content

Commit

Permalink
Crosshair component
Browse files Browse the repository at this point in the history
  • Loading branch information
cmdcolin committed Jan 24, 2025
1 parent 14c613c commit 766f2f1
Show file tree
Hide file tree
Showing 5 changed files with 134 additions and 79 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import { SanitizedHTML } from '@jbrowse/core/ui'
import BaseTooltip from '@jbrowse/core/ui/BaseTooltip'
import { getContainingView } from '@jbrowse/core/util'
import { observer } from 'mobx-react'
import { makeStyles } from 'tss-react/mui'

import type { MultiLinearVariantDisplayModel } from '../model'
import type { LinearGenomeViewModel } from '@jbrowse/plugin-linear-genome-view'

const useStyles = makeStyles()({
cursor: {
pointerEvents: 'none',
zIndex: 1000,
position: 'relative',
},
})

const Crosshair = observer(function ({
mouseX,
mouseY,
model,
}: {
mouseX: number
mouseY: number
model: MultiLinearVariantDisplayModel
}) {
const { classes } = useStyles()
const { height, scrollTop, rowHeight, sources } = model
const { width } = getContainingView(model) as LinearGenomeViewModel
const source = sources?.[Math.floor(mouseY / rowHeight)]
const y = mouseY - scrollTop
return source ? (
<div style={{ position: 'relative' }}>
<svg
className={classes.cursor}
width={width}
height={height}
style={{
position: 'absolute',
top: scrollTop,
}}
>
<line x1={0} x2={width} y1={y} y2={y} stroke="black" />
<line x1={mouseX} x2={mouseX} y1={0} y2={height} stroke="black" />
</svg>
<BaseTooltip>
{source.color ? (
<div
style={{
width: 10,
height: 10,
backgroundColor: source.color,
}}
/>
) : null}
<SanitizedHTML
html={Object.entries(source)
.filter(([key]) => key !== 'color')
.map(([key, value]) => `${key}:${value}`)
.join('<br/>')}
/>
</BaseTooltip>
</div>
) : null
})

export default Crosshair
Original file line number Diff line number Diff line change
@@ -1,33 +1,20 @@
import { useRef, useState } from 'react'

import { SanitizedHTML } from '@jbrowse/core/ui'
import BaseTooltip from '@jbrowse/core/ui/BaseTooltip'
import { getContainingView } from '@jbrowse/core/util'
import { BaseLinearDisplayComponent } from '@jbrowse/plugin-linear-genome-view'
import { observer } from 'mobx-react'
import { makeStyles } from 'tss-react/mui'

import Crosshair from './Crosshair'
import LegendBar from '../../shared/LegendBar'

import type { MultiLinearVariantDisplayModel } from '../model'
import type { LinearGenomeViewModel } from '@jbrowse/plugin-linear-genome-view'

const useStyles = makeStyles()({
cursor: {
pointerEvents: 'none',
},
})

const MultiLinearVariantDisplayComponent = observer(function (props: {
model: MultiLinearVariantDisplayModel
}) {
const { model } = props
const { classes } = useStyles()
const { height, sources, rowHeight, scrollTop } = model
const ref = useRef<HTMLDivElement>(null)
const [mouseY, setMouseY] = useState<number>()
const [mouseX, setMouseX] = useState<number>()
const { width } = getContainingView(model) as LinearGenomeViewModel

return (
<div
Expand All @@ -46,34 +33,9 @@ const MultiLinearVariantDisplayComponent = observer(function (props: {
>
<BaseLinearDisplayComponent {...props} />
<LegendBar model={model} />
{mouseY && sources ? (
<div style={{ position: 'relative' }}>
<svg
className={classes.cursor}
width={width}
height={height}
style={{ position: 'absolute', top: scrollTop }}
>
<line
x1={0}
x2={width}
y1={mouseY - scrollTop}
y2={mouseY - scrollTop}
stroke="black"
/>
<line x1={mouseX} x2={mouseX} y1={0} y2={height} stroke="black" />
</svg>
<BaseTooltip>
<SanitizedHTML
html={Object.entries(
sources[Math.floor(mouseY / rowHeight)] || {},
)
.filter(([key]) => key !== 'color')
.map(([key, value]) => `${key}:${value}`)
.join('<br/>')}
/>
</BaseTooltip>
</div>

{mouseX && mouseY ? (
<Crosshair mouseX={mouseX} mouseY={mouseY} model={model} />
) : null}
</div>
)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import { SanitizedHTML } from '@jbrowse/core/ui'
import BaseTooltip from '@jbrowse/core/ui/BaseTooltip'
import { getContainingView } from '@jbrowse/core/util'
import { observer } from 'mobx-react'
import { makeStyles } from 'tss-react/mui'

import type { MultiLinearVariantMatrixDisplayModel } from '../model'
import type { LinearGenomeViewModel } from '@jbrowse/plugin-linear-genome-view'

const useStyles = makeStyles()({
cursor: {
pointerEvents: 'none',
zIndex: 1000,
position: 'relative',
},
})

const Crosshair = observer(function ({
mouseX,
mouseY,
model,
}: {
mouseX: number
mouseY: number
model: MultiLinearVariantMatrixDisplayModel
}) {
const { classes } = useStyles()
const { lineZoneHeight, height, rowHeight, sources } = model
const { width } = getContainingView(model) as LinearGenomeViewModel
const source = sources?.[Math.floor((mouseY - lineZoneHeight) / rowHeight)]
return source ? (
<>
<svg className={classes.cursor} width={width} height={height}>
<line x1={0} x2={width} y1={mouseY} y2={mouseY} stroke="black" />
<line x1={mouseX} x2={mouseX} y1={0} y2={height} stroke="black" />
</svg>
<BaseTooltip>
{source.color ? (
<div
style={{
width: 10,
height: 10,
backgroundColor: source.color,
}}
/>
) : null}
<SanitizedHTML
html={Object.entries(source)
.filter(([key]) => key !== 'color')
.map(([key, value]) => `${key}:${value}`)
.join('<br/>')}
/>
</BaseTooltip>
</>
) : null
})

export default Crosshair
Original file line number Diff line number Diff line change
@@ -1,36 +1,22 @@
import { useRef, useState } from 'react'

import { SanitizedHTML } from '@jbrowse/core/ui'
import BaseTooltip from '@jbrowse/core/ui/BaseTooltip'
import { getContainingView } from '@jbrowse/core/util'
import { BaseLinearDisplayComponent } from '@jbrowse/plugin-linear-genome-view'
import { observer } from 'mobx-react'
import { makeStyles } from 'tss-react/mui'

import Crosshair from './Crosshair'
import LinesConnectingMatrixToGenomicPosition from './LinesConnectingMatrixToGenomicPosition'
import LegendBar from '../../shared/LegendBar'

import type { MultiLinearVariantMatrixDisplayModel } from '../model'
import type { LinearGenomeViewModel } from '@jbrowse/plugin-linear-genome-view'

const useStyles = makeStyles()({
cursor: {
pointerEvents: 'none',
zIndex: 1000,
position: 'relative',
},
})

const MultiLinearVariantMatrixDisplayComponent = observer(function (props: {
model: MultiLinearVariantMatrixDisplayModel
}) {
const { classes } = useStyles()
const { model } = props
const { height, sources, rowHeight } = model
const { lineZoneHeight } = model
const ref = useRef<HTMLDivElement>(null)
const [mouseY, setMouseY] = useState<number>()
const [mouseX, setMouseX] = useState<number>()
const { width } = getContainingView(model) as LinearGenomeViewModel

return (
<div
Expand All @@ -49,34 +35,16 @@ const MultiLinearVariantMatrixDisplayComponent = observer(function (props: {
>
<div style={{ position: 'relative' }}>
<LinesConnectingMatrixToGenomicPosition model={model} />
<div style={{ position: 'absolute', top: 20 }}>
<div style={{ position: 'absolute', top: lineZoneHeight }}>
<LegendBar model={model} />
<BaseLinearDisplayComponent {...props} />
</div>
</div>

{mouseY &&
mouseY > 20 &&
sources?.[Math.floor((mouseY - 20) / rowHeight)] ? (
<>
<svg className={classes.cursor} width={width} height={height}>
<line x1={0} x2={width} y1={mouseY} y2={mouseY} stroke="black" />
<line x1={mouseX} x2={mouseX} y1={0} y2={height} stroke="black" />
</svg>
<BaseTooltip>
<SanitizedHTML
html={Object.entries(
sources[Math.floor((mouseY - 20) / rowHeight)] || {},
)
.filter(([key]) => key !== 'color')
.map(([key, value]) => `${key}:${value}`)
.join('<br/>')}
/>
</BaseTooltip>
</>
{mouseX && mouseY && mouseY > lineZoneHeight ? (
<Crosshair mouseX={mouseX} mouseY={mouseY} model={model} />
) : null}
</div>
)
})

export default MultiLinearVariantMatrixDisplayComponent
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 766f2f1

Please sign in to comment.