Skip to content

Commit

Permalink
Added ExternalSelection interface
Browse files Browse the repository at this point in the history
  • Loading branch information
guzmanvig committed Feb 14, 2024
1 parent b7ea117 commit 3649075
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 22 deletions.
19 changes: 3 additions & 16 deletions src/SeqViewerContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import SelectionHandler, { InputRefFunc } from "./SelectionHandler";
import CentralIndexContext from "./centralIndexContext";
import { Annotation, CutSite, Highlight, NameRange, Primer, Range, SeqType } from "./elements";
import { isEqual } from "./isEqual";
import SelectionContext, { Selection, defaultSelection } from "./selectionContext";
import SelectionContext, { ExternalSelection, Selection, defaultSelection } from "./selectionContext";

/**
* This is the width in pixels of a character that's 12px
Expand Down Expand Up @@ -46,11 +46,7 @@ interface SeqViewerContainerProps {
rotateOnScroll: boolean;
search: NameRange[];
selectAllEvent: (event: React.KeyboardEvent<HTMLElement>) => boolean;
selection?: {
clockwise?: boolean;
end: number;
start: number;
};
selection?: ExternalSelection;
seq: string;
seqType: SeqType;
showComplement: boolean;
Expand Down Expand Up @@ -142,16 +138,7 @@ class SeqViewerContainer extends React.Component<SeqViewerContainerProps, SeqVie
/**
* Returns the selection that was either a prop (optional) or the selection maintained in state.
*/
getSelection = (
state: Selection,
prop?:
| {
clockwise?: boolean;
end: number;
start: number;
}
| Selection
): Selection => {
getSelection = (state: Selection, prop?: ExternalSelection): Selection => {
if (prop) {
return { ...prop, clockwise: typeof prop.clockwise === "undefined" || !!prop.clockwise, type: "" };
}
Expand Down
8 changes: 2 additions & 6 deletions src/SeqViz.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
} from "./elements";
import { isEqual } from "./isEqual";
import search from "./search";
import { Selection } from "./selectionContext";
import { ExternalSelection, Selection } from "./selectionContext";
import { complement, directionality, guessType, randomID } from "./sequence";

/** `SeqViz` props. See the README for more details. One of `seq`, `file` or `accession` is required. */
Expand Down Expand Up @@ -121,11 +121,7 @@ export interface SeqVizProps {
* Externally managed selection.
*
* If passed, SeqViz uses this prop as the selection range, rather than the internally managed selection */
selection?: {
clockwise?: boolean;
end: number;
start: number;
};
selection?: ExternalSelection;

/** a sequence to render. Can be DNA, RNA, or an amino acid sequence. Setting accession or file overrides this */
seq?: string;
Expand Down
6 changes: 6 additions & 0 deletions src/selectionContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ export interface Selection {
viewer?: "LINEAR" | "CIRCULAR";
}

export interface ExternalSelection {
clockwise?: boolean;
end: number;
start: number;
}

/** Initial/default selection */
export const defaultSelection: Selection = {
clockwise: true,
Expand Down

0 comments on commit 3649075

Please sign in to comment.