@@ -11,6 +11,7 @@ import { LegendOrdinal } from '@visx/legend'
1111import { TooltipAnchor } from '@gnomad/ui'
1212import { GNOMAD_POPULATION_NAMES } from '@gnomad/dataset-metadata/gnomadPopulations'
1313import { PopulationId } from '@gnomad/dataset-metadata/gnomadPopulations'
14+ import { colorByLabels } from './ShortTandemRepeatColorBySelect'
1415
1516// The 100% width/height container is necessary the component
1617// to size to fit its container vs staying at its initial size.
@@ -146,12 +147,13 @@ const fixedLegendLabels: Partial<Record<ColorBy, Record<string, string>>> = {
146147 population : GNOMAD_POPULATION_NAMES ,
147148}
148149
150+ const legendLabel = ( colorBy : ColorBy , key : string ) => fixedLegendLabels [ colorBy ] ?. [ key ] || key
151+
149152const legendLabels = ( colorBy : ColorBy , keys : string [ ] ) =>
150- keys . map ( ( key ) => fixedLegendLabels [ colorBy ] ?. [ key ] || key )
153+ keys . map ( ( key ) => legendLabel ( colorBy , key ) )
151154
152155const colorForValue = ( colorBy : ColorBy | '' , value : string ) =>
153156 colorMap [ colorBy ] ?. [ value ] || defaultColor
154-
155157const tickFormat = ( n : number ) => {
156158 if ( n >= 1e9 ) {
157159 return `${ ( n / 1e9 ) . toPrecision ( 3 ) } B`
@@ -214,11 +216,13 @@ const LegendFromColorBy = ({ colorBy }: { colorBy: ColorBy | '' }) => {
214216 )
215217}
216218
217- const tooltipContent = ( data : Bin , key : ColorByValue | '' ) : string => {
219+ const tooltipContent = ( data : Bin , colorBy : ColorBy | '' , key : ColorByValue | '' ) : string => {
218220 const repeatText = data . label === '1' ? '1 repeat' : data . label . toString ( ) + ' repeats'
219221 const alleles = data [ key ] || 0
220222 const alleleText = alleles === 1 ? '1 allele' : alleles . toString ( ) + ' alleles'
221- return `${ repeatText } : ${ alleleText } `
223+ const colorByText =
224+ colorBy === '' ? '' : `, ${ colorByLabels [ colorBy ] } is ${ legendLabel ( colorBy , key ) } `
225+ return `${ repeatText } ${ colorByText } : ${ alleleText } `
222226}
223227
224228const ShortTandemRepeatAlleleSizeDistributionPlot = withSize ( ) (
@@ -411,7 +415,11 @@ const ShortTandemRepeatAlleleSizeDistributionPlot = withSize()(
411415 { ( stacks ) =>
412416 stacks . map ( ( stack ) =>
413417 stack . bars . map ( ( bar ) => {
414- const tooltip = tooltipContent ( bar . bar . data , bar . key as ColorByValue | '' )
418+ const tooltip = tooltipContent (
419+ bar . bar . data ,
420+ colorBy ,
421+ bar . key as ColorByValue | ''
422+ )
415423 return (
416424 < React . Fragment key = { 'bar-stack-' + bar . x + '-' + bar . y } >
417425 < TooltipAnchor
0 commit comments