@@ -11,6 +11,7 @@ import { LegendOrdinal } from '@visx/legend'
11
11
import { TooltipAnchor } from '@gnomad/ui'
12
12
import { GNOMAD_POPULATION_NAMES } from '@gnomad/dataset-metadata/gnomadPopulations'
13
13
import { PopulationId } from '@gnomad/dataset-metadata/gnomadPopulations'
14
+ import { colorByLabels } from './ShortTandemRepeatColorBySelect'
14
15
15
16
// The 100% width/height container is necessary the component
16
17
// to size to fit its container vs staying at its initial size.
@@ -146,12 +147,13 @@ const fixedLegendLabels: Partial<Record<ColorBy, Record<string, string>>> = {
146
147
population : GNOMAD_POPULATION_NAMES ,
147
148
}
148
149
150
+ const legendLabel = ( colorBy : ColorBy , key : string ) => fixedLegendLabels [ colorBy ] ?. [ key ] || key
151
+
149
152
const legendLabels = ( colorBy : ColorBy , keys : string [ ] ) =>
150
- keys . map ( ( key ) => fixedLegendLabels [ colorBy ] ?. [ key ] || key )
153
+ keys . map ( ( key ) => legendLabel ( colorBy , key ) )
151
154
152
155
const colorForValue = ( colorBy : ColorBy | '' , value : string ) =>
153
156
colorMap [ colorBy ] ?. [ value ] || defaultColor
154
-
155
157
const tickFormat = ( n : number ) => {
156
158
if ( n >= 1e9 ) {
157
159
return `${ ( n / 1e9 ) . toPrecision ( 3 ) } B`
@@ -214,11 +216,13 @@ const LegendFromColorBy = ({ colorBy }: { colorBy: ColorBy | '' }) => {
214
216
)
215
217
}
216
218
217
- const tooltipContent = ( data : Bin , key : ColorByValue | '' ) : string => {
219
+ const tooltipContent = ( data : Bin , colorBy : ColorBy | '' , key : ColorByValue | '' ) : string => {
218
220
const repeatText = data . label === '1' ? '1 repeat' : data . label . toString ( ) + ' repeats'
219
221
const alleles = data [ key ] || 0
220
222
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 } `
222
226
}
223
227
224
228
const ShortTandemRepeatAlleleSizeDistributionPlot = withSize ( ) (
@@ -411,7 +415,11 @@ const ShortTandemRepeatAlleleSizeDistributionPlot = withSize()(
411
415
{ ( stacks ) =>
412
416
stacks . map ( ( stack ) =>
413
417
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
+ )
415
423
return (
416
424
< React . Fragment key = { 'bar-stack-' + bar . x + '-' + bar . y } >
417
425
< TooltipAnchor
0 commit comments