Skip to content

Commit 9cf4e3f

Browse files
show subset in tooltips
1 parent e192997 commit 9cf4e3f

File tree

2 files changed

+23
-9
lines changed

2 files changed

+23
-9
lines changed

browser/src/ShortTandemRepeatPage/ShortTandemRepeatAlleleSizeDistributionPlot.tsx

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { LegendOrdinal } from '@visx/legend'
1111
import { TooltipAnchor } from '@gnomad/ui'
1212
import { GNOMAD_POPULATION_NAMES } from '@gnomad/dataset-metadata/gnomadPopulations'
1313
import { 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+
149152
const legendLabels = (colorBy: ColorBy, keys: string[]) =>
150-
keys.map((key) => fixedLegendLabels[colorBy]?.[key] || key)
153+
keys.map((key) => legendLabel(colorBy, key))
151154

152155
const colorForValue = (colorBy: ColorBy | '', value: string) =>
153156
colorMap[colorBy]?.[value] || defaultColor
154-
155157
const 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

224228
const 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

browser/src/ShortTandemRepeatPage/ShortTandemRepeatColorBySelect.tsx

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,13 @@ type Props = {
1515
setSelectedScaleType: Dispatch<SetStateAction<ScaleType>>
1616
}
1717

18+
export const colorByLabels: Record<ColorBy, string> = {
19+
quality_description: 'GQ: manual review',
20+
q_score: 'GQ: Q score',
21+
sex: 'Sex',
22+
population: 'Population',
23+
}
24+
1825
const ShortTandemRepeatColorBySelect = ({
1926
id,
2027
selectedColorBy,
@@ -35,10 +42,9 @@ const ShortTandemRepeatColorBySelect = ({
3542
}}
3643
>
3744
<option value="">None</option>
38-
<option value="quality_description">GQ: manual review</option>
39-
<option value="q_score">GQ: Q score</option>
40-
<option value="sex">Sex</option>
41-
<option value="population">Population</option>
45+
{Object.entries(colorByLabels).map(([key, label]) => (
46+
<option value={key}>{label}</option>
47+
))}
4248
</Select>
4349
</Label>
4450
)

0 commit comments

Comments
 (0)