-
Notifications
You must be signed in to change notification settings - Fork 272
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
show mutation count and number of samples in tooltip
- Loading branch information
Bryan Lai
committed
Dec 6, 2022
1 parent
d3e1f9e
commit 8cf256a
Showing
2 changed files
with
42 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { action, makeObservable, observable } from 'mobx'; | ||
import { observer } from 'mobx-react'; | ||
import { Mutation } from 'cbioportal-ts-api-client'; | ||
import * as React from 'react'; | ||
import { | ||
formatPercentValue, | ||
numberOfLeadingDecimalZeros, | ||
} from 'cbioportal-utils'; | ||
import { AxisScale } from 'react-mutation-mapper'; | ||
import { countUniqueMutations } from 'shared/lib/MutationUtils'; | ||
|
||
interface ILollipopTooltipCountInfoProps { | ||
count: number; | ||
mutations?: Mutation[]; | ||
axisMode?: AxisScale; | ||
} | ||
|
||
export const LollipopTooltipCountInfo: React.FC<ILollipopTooltipCountInfoProps> = ({ | ||
count, | ||
mutations, | ||
axisMode, | ||
}: ILollipopTooltipCountInfoProps) => { | ||
const decimalZeros = numberOfLeadingDecimalZeros(count); | ||
const fractionDigits = decimalZeros < 0 ? 1 : decimalZeros + 2; | ||
|
||
return mutations && | ||
mutations.length > 0 && | ||
axisMode === AxisScale.PERCENT ? ( | ||
<strong> | ||
{formatPercentValue(count, fractionDigits)}% mutation rate ( | ||
{countUniqueMutations(mutations)} of{' '} | ||
{Math.round((countUniqueMutations(mutations) / count) * 100)}{' '} | ||
samples) | ||
</strong> | ||
) : ( | ||
<strong> | ||
{count} mutation{`${count !== 1 ? 's' : ''}`} | ||
</strong> | ||
); | ||
}; |