/
CladeMarker.tsx
53 lines (44 loc) · 1.53 KB
/
CladeMarker.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import React, { SVGProps, useState } from 'react'
import { useTranslation } from 'react-i18next'
import { BASE_MIN_WIDTH_PX } from 'src/constants'
import type { CladeDataGrouped } from 'src/algorithms/types'
import { getSafeId } from 'src/helpers/getSafeId'
import { Tooltip } from 'src/components/Results/Tooltip'
const GENE_MAP_CLADE_MARK_COLOR = '#444444aa' as const
export interface CladeMarkerProps extends SVGProps<SVGRectElement> {
cladeDatum: CladeDataGrouped
pixelsPerBase: number
}
export function CladeMarker({ cladeDatum, pixelsPerBase, ...rest }: CladeMarkerProps) {
const { t } = useTranslation()
const [showTooltip, setShowTooltip] = useState(false)
const { pos, subs } = cladeDatum
const id = getSafeId('clade-marker', { pos })
const fill = GENE_MAP_CLADE_MARK_COLOR
const x = pos * pixelsPerBase
const width = Math.max(BASE_MIN_WIDTH_PX, 1 * pixelsPerBase)
const mutationItems = Object.entries(subs as Record<string, string[]>).map(([nuc, clades]) => {
return <li key={nuc}>{`${nuc}: ${clades.join(', ')}`}</li>
})
return (
<rect
id={id}
fill={fill}
x={x}
y={-10}
width={width}
height="30"
{...rest}
onMouseEnter={() => setShowTooltip(true)}
onMouseLeave={() => setShowTooltip(false)}
>
<Tooltip target={id} isOpen={showTooltip}>
<div>{t('Position: {{position}}', { position: pos })}</div>
<div>{t('Signature mutations:')}</div>
<div>
<ul>{mutationItems}</ul>
</div>
</Tooltip>
</rect>
)
}