11import { max } from 'd3-array'
2- import { scaleBand , scaleLinear , scaleLog , scaleOrdinal , scaleThreshold } from 'd3-scale'
2+ import { scaleBand , scaleLinear , scaleLog , scaleOrdinal } from 'd3-scale'
33import React , { useMemo } from 'react'
44import { withSize } from 'react-sizeme'
55import styled from 'styled-components'
66import { AxisBottom , AxisLeft } from '@visx/axis'
7- import { BarStack } from '@visx/shape'
7+ import { BarStack , Bar } from '@visx/shape'
88import { AnyD3Scale } from '@visx/scale'
9- import { LegendOrdinal , LegendThreshold } from '@visx/legend'
9+ import { LegendOrdinal } from '@visx/legend'
1010
1111import { TooltipAnchor } from '@gnomad/ui'
1212import {
@@ -16,9 +16,8 @@ import {
1616 GenotypeQuality ,
1717 QScoreBin ,
1818 ScaleType ,
19- Sex ,
2019} from './ShortTandemRepeatPage'
21- import { GNOMAD_POPULATION_NAMES , PopulationId } from '@gnomad/dataset-metadata/gnomadPopulations'
20+ import { GNOMAD_POPULATION_NAMES } from '@gnomad/dataset-metadata/gnomadPopulations'
2221
2322// The 100% width/height container is necessary the component
2423// to size to fit its container vs staying at its initial size.
@@ -28,11 +27,11 @@ const GraphWrapper = styled.div`
2827 height: 100%; /* stylelint-disable-line unit-whitelist */
2928`
3029
31- const TooltipTrigger = styled . rect `
30+ const BarWithHoverEffect = styled ( Bar ) `
3231 pointer-events: visible;
3332
3433 &:hover {
35- fill: rgba(0, 0, 0, 0.05) ;
34+ fill-opacity: 0.7 ;
3635 }
3736`
3837
@@ -165,6 +164,13 @@ const LegendFromColorBy = ({ colorBy }: { colorBy: ColorBy | '' }) => {
165164 return < LegendOrdinal scale = { scale } direction = "row" />
166165}
167166
167+ const tooltipContent = ( data : Bin , key : ColorByValue | '' ) : string => {
168+ const repeatText = data . label === '1' ? '1 repeat' : data . label . toString ( ) + ' repeats'
169+ const alleles = data [ key ] || 0
170+ const alleleText = alleles === 1 ? '1 allele' : alleles . toString ( ) + ' alleles'
171+ return `${ repeatText } : ${ alleleText } `
172+ }
173+
168174const ShortTandemRepeatAlleleSizeDistributionPlot = withSize ( ) (
169175 ( {
170176 maxRepeats,
@@ -347,7 +353,27 @@ const ShortTandemRepeatAlleleSizeDistributionPlot = withSize()(
347353 x = { ( bin ) => bin . index }
348354 y0 = { ( point ) => point [ 0 ] || 0 }
349355 y1 = { ( point ) => point [ 1 ] || 0 }
350- /> { ' ' }
356+ >
357+ { ( stacks ) =>
358+ stacks . map ( ( stack ) =>
359+ stack . bars . map ( ( bar ) => {
360+ const tooltip = tooltipContent ( bar . bar . data , bar . key as ColorByValue | '' )
361+ return (
362+ < React . Fragment key = { 'bar-stack-' + bar . x + '-' + bar . y } >
363+ < TooltipAnchor
364+ // @ts -expect-error
365+ tooltip = { tooltip }
366+ >
367+ < g >
368+ < BarWithHoverEffect { ...bar } stroke = "black" fill = { bar . color } />
369+ </ g >
370+ </ TooltipAnchor >
371+ </ React . Fragment >
372+ )
373+ } )
374+ )
375+ }
376+ </ BarStack >
351377 </ g >
352378
353379 < g transform = { `translate(${ margin . left } , 0)` } >
0 commit comments