forked from wdingx/pan-genome-visualization
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: show position indices in msa viewer
- Loading branch information
1 parent
818915b
commit 497fc85
Showing
2 changed files
with
64 additions
and
2 deletions.
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,62 @@ | ||
/* eslint-disable react/no-array-index-key */ | ||
import React, { ComponentProps, ForwardedRef, forwardRef, useMemo } from 'react' | ||
import Konva from 'konva' | ||
import { Group, Rect, Text } from 'react-konva' | ||
import { MSA_CHAR_HEIGHT, MSA_CHAR_WIDTH, MsaCharacter } from 'src/components/Msa/MsaCharacter' | ||
import type { SequenceType } from 'src/hooks/useDataIndexQuery' | ||
|
||
const MSA_POS_FONT_SIZE = 8 | ||
|
||
export interface MsaRefSequenceProps extends ComponentProps<typeof Group> { | ||
seq: string | ||
seqType: SequenceType | ||
} | ||
|
||
export const MsaRefSequence = forwardRef(function MsaRefSequenceWithRef( | ||
{ seq, seqType, ...restProps }: MsaRefSequenceProps, | ||
ref: ForwardedRef<Konva.Group>, | ||
) { | ||
const chars = useMemo( | ||
() => | ||
seq.split('').map((c, pos) => ( | ||
<Group key={pos} x={MSA_CHAR_WIDTH * pos}> | ||
{(pos + 1) % 2 === 0 && <MsaPosition pos={pos + 1} />} | ||
<MsaCharacter y={MSA_CHAR_HEIGHT} character={c} seqType={seqType} /> | ||
</Group> | ||
)), | ||
[seq, seqType], | ||
) | ||
return ( | ||
<Group ref={ref} {...restProps}> | ||
{chars} | ||
</Group> | ||
) | ||
}) | ||
|
||
export interface MsaPositionProps extends ComponentProps<typeof Group> { | ||
pos: number | ||
} | ||
|
||
function MsaPosition({ pos, ...restProps }: MsaPositionProps) { | ||
const text = useMemo(() => { | ||
return ( | ||
<Text | ||
width={MSA_CHAR_WIDTH} | ||
height={MSA_CHAR_HEIGHT} | ||
fill="#222a" | ||
text={pos.toString()} | ||
fontSize={MSA_POS_FONT_SIZE} | ||
fontFamily="monospace" | ||
align="center" | ||
verticalAlign="middle" | ||
/> | ||
) | ||
}, [pos]) | ||
|
||
return ( | ||
<Group {...restProps}> | ||
<Rect x={-MSA_CHAR_WIDTH} width={MSA_CHAR_WIDTH * 2} height={MSA_CHAR_HEIGHT} fill="#aaa" /> | ||
{text} | ||
</Group> | ||
) | ||
} |
497fc85
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
pangenome – ./
pangenome-neherlab.vercel.app
pangenome-git-react-app-neherlab.vercel.app