Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

implement one row linear viewer #205

Open
wants to merge 15 commits into
base: develop
Choose a base branch
from
Open
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ export default () => {

#### `viewer (='both')`

The type and orientation of the sequence viewers. One of `"linear" | "circular" | "both" | "both_flip"`. `both` means the circular viewer fills the left side of SeqViz, and the linear viewer fills the right. `both_flip` is the opposite: the linear viewer is on the left, and the circular viewer is on the right.
The type and orientation of the sequence viewers. One of `"linear" | "circular" | "both" | "both_flip" | "linear_one_row"`. `both` means the circular viewer fills the left side of SeqViz, and the linear viewer fills the right. `both_flip` is the opposite: the linear viewer is on the left, and the circular viewer is on the right. `linear_one_row` will render the entire linear sequence in a single row.

#### `name (='')`

Expand Down
7 changes: 4 additions & 3 deletions demo/lib/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const viewerTypeOptions = [
{ key: "circular", text: "Circular", value: "circular" },
{ key: "linear", text: "Linear", value: "linear" },
{ key: "both_flip", text: "Both Flip", value: "both_flip" },
{ key: "linear_one_row", text: "Linear One Row", value: "linear_one_row" },
];

interface AppState {
Expand Down Expand Up @@ -216,18 +217,18 @@ export default class App extends React.Component<any, AppState> {
key={`${this.state.viewer}${this.state.customChildren}`}
annotations={this.state.annotations}
enzymes={this.state.enzymes}
highlights={[{ start: 0, end: 10 }]}
highlights={[{ end: 10, start: 0 }]}
name={this.state.name}
onSelection={selection => this.setState({ selection })}
refs={{ circular: this.circularRef, linear: this.linearRef }}
search={this.state.search}
selection={this.state.selection}
seq={this.state.seq}
showComplement={this.state.showComplement}
showIndex={this.state.showIndex}
translations={this.state.translations}
viewer={this.state.viewer as "linear" | "circular"}
viewer={this.state.viewer as "linear" | "linear_one_row" | "circular"}
zoom={{ linear: this.state.zoom }}
onSelection={selection => this.setState({ selection })}
>
{customChildren}
</SeqViz>
Expand Down
2 changes: 1 addition & 1 deletion src/Circular/Circular.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export interface CircularProps {
center: { x: number; y: number };
compSeq: string;
cutSites: CutSite[];
handleMouseEvent: (e: any) => void;
handleMouseEvent: (e: React.MouseEvent) => void;
highlights: Highlight[];
inputRef: InputRefFunc;
name: string;
Expand Down
2 changes: 1 addition & 1 deletion src/Circular/Labels.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export interface GroupedLabelsWithCoors {
labels: ILabel[];
lineCoor: Coor;
name: string;
overflow: unknown;
overflow: boolean;
textAnchor: "start" | "end";
textCoor: Coor;
}
Expand Down
2 changes: 1 addition & 1 deletion src/EventHandler.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export interface EventsHandlerProps {
bpsPerBlock: number;
children: React.ReactNode;
copyEvent: (e: React.KeyboardEvent<HTMLElement>) => boolean;
handleMouseEvent: (e: any) => void;
handleMouseEvent: (e: React.MouseEvent) => void;
selection: Selection;
seq: string;
setSelection: (selection: Selection) => void;
Expand Down
25 changes: 20 additions & 5 deletions src/Linear/Annotations.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as React from "react";

import { InputRefFunc } from "../SelectionHandler";
import { COLOR_BORDER_MAP, darkerColor } from "../colors";
import { NameRange } from "../elements";
import { Annotation, NameRange } from "../elements";
import { annotation, annotationLabel } from "../style";
import { FindXAndWidthElementType } from "./SeqBlock";

Expand All @@ -27,7 +27,9 @@ const AnnotationRows = (props: {
fullSeq: string;
inputRef: InputRefFunc;
lastBase: number;
oneRow: boolean;
seqBlockRef: unknown;
stackedPositions: Annotation[][];
width: number;
yDiff: number;
}) => (
Expand All @@ -43,9 +45,20 @@ const AnnotationRows = (props: {
height={props.elementHeight}
inputRef={props.inputRef}
lastBase={props.lastBase}
oneRow={props.oneRow}
seqBlockRef={props.seqBlockRef}
width={props.width}
y={props.yDiff + props.elementHeight * i}
y={
props.yDiff +
props.elementHeight *
(props.oneRow
? Math.max(
...anns.map(
ann => props.stackedPositions.findIndex(row => row.some(item => item.id === ann.id)) as number
)
)
: i)
}
/>
))}
</g>
Expand All @@ -66,6 +79,7 @@ const AnnotationRow = (props: {
height: number;
inputRef: InputRefFunc;
lastBase: number;
oneRow: boolean;
seqBlockRef: unknown;
width: number;
y: number;
Expand Down Expand Up @@ -102,8 +116,9 @@ const SingleNamedElement = (props: {
index: number;
inputRef: InputRefFunc;
lastBase: number;
oneRow: boolean;
}) => {
const { element, elements, findXAndWidth, firstBase, index, inputRef, lastBase } = props;
const { element, elements, findXAndWidth, firstBase, index, inputRef, lastBase, oneRow } = props;

const { color, direction, end, name, start } = element;
const forward = direction === 1;
Expand All @@ -130,7 +145,7 @@ const SingleNamedElement = (props: {

let linePath = "";
let bottomRight = `L ${width} ${height}`; // flat right edge
if ((overflowRight && width > 2 * cW) || crossZero) {
if ((overflowRight && width > 2 * cW && !oneRow) || crossZero) {
bottomRight = `
L ${width - cW} ${cH}
L ${width} ${2 * cH}
Expand All @@ -143,7 +158,7 @@ const SingleNamedElement = (props: {
}

let bottomLeft = `L 0 ${height} L 0 0`; // flat left edge
if (overflowLeft && width > 2 * cW) {
if (overflowLeft && width > 2 * cW && !oneRow) {
bottomLeft = `
L 0 ${height}
L ${cW} ${3 * cH}
Expand Down
Loading