Skip to content

Commit 3359dc8

Browse files
committed
Merge branch 'develop' into one_row_viewer
2 parents 9008211 + 9ea7759 commit 3359dc8

File tree

8 files changed

+543
-119
lines changed

8 files changed

+543
-119
lines changed

README.md

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ export default () => (
8282

8383
#### Non-React
8484

85-
More details are in the [Viewer without React](#viewer-without-react) section.
85+
More details are in the [Viewer without React](#without-react) section.
8686

8787
```html
8888
<script>
@@ -292,6 +292,42 @@ Whether to show the complement sequence.
292292

293293
By default, the circular viewer rotates when scrolling over the viewer. That can be disabled with rotateOnScroll: false.
294294

295+
#### `Custom Rendering`
296+
297+
This makes use of the `children` and `refs` props to allow custom rendering of the sequence viewers. For example, to render the linear viewer above the circular viewer:
298+
299+
```jsx
300+
import { useRef } from "react";
301+
import { SeqViz, Linear, Circular } from "seqviz";
302+
303+
export default () => {
304+
const linearRef = useRef();
305+
const circularRef = useRef();
306+
307+
return (
308+
<SeqViz
309+
name="J23100"
310+
seq="TTGACGGCTAGCTCAGTCCTAGGTACAGTGCTAGC"
311+
refs={{circular: circularRef, linear: linearRef}}
312+
>
313+
{({ circularProps, linearProps, ...props }) => (
314+
<div
315+
style={{ display: "flex", flexDirection: "column", width: "100%" }}
316+
>
317+
<div ref={linearRef} style={{ height: "25%", width: "100%" }}>
318+
<Linear {...linearProps} {...props} />
319+
</div>
320+
<div ref={circularRef} style={{ height: "75%", width: "100%" }}>
321+
<Circular {...circularProps} {...props} />
322+
</div>
323+
</div>
324+
)}
325+
</SeqViz>
326+
);
327+
};
328+
329+
```
330+
295331
### Without React
296332

297333
For usability in non-React apps, we provide a thin wrapper around the React component. The viewer's constructor accepts two arguments:

demo/lib/App.tsx

Lines changed: 71 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ import {
1414
} from "semantic-ui-react";
1515
import seqparse from "seqparse";
1616

17+
import Circular from "../../src/Circular/Circular";
18+
import Linear from "../../src/Linear/Linear";
1719
import SeqViz from "../../src/SeqViz";
1820
import { AnnotationProp } from "../../src/elements";
1921
import Header from "./Header";
@@ -29,6 +31,7 @@ const viewerTypeOptions = [
2931

3032
interface AppState {
3133
annotations: AnnotationProp[];
34+
customChildren: boolean;
3235
enzymes: any[];
3336
name: string;
3437
primers: boolean;
@@ -48,6 +51,7 @@ interface AppState {
4851
export default class App extends React.Component<any, AppState> {
4952
state: AppState = {
5053
annotations: [],
54+
customChildren: true,
5155
enzymes: ["PstI", "EcoRI", "XbaI", "SpeI"],
5256
name: "",
5357
primers: true,
@@ -67,6 +71,8 @@ export default class App extends React.Component<any, AppState> {
6771
viewer: "",
6872
zoom: 50,
6973
};
74+
linearRef: React.RefObject<HTMLDivElement> = React.createRef();
75+
circularRef: React.RefObject<HTMLDivElement> = React.createRef();
7076

7177
componentDidMount = async () => {
7278
const seq = await seqparse(file);
@@ -98,6 +104,59 @@ export default class App extends React.Component<any, AppState> {
98104
};
99105

100106
render() {
107+
108+
let customChildren = null;
109+
if (this.state.customChildren) {
110+
customChildren = ({ circularProps, linearProps, ...props }) => {
111+
if (this.state.viewer === "linear") {
112+
return (
113+
<div ref={this.linearRef} style={{ height: "100%", width: "100%" }}>
114+
<Linear {...linearProps} {...props} />
115+
</div>
116+
);
117+
} else if (this.state.viewer === "circular") {
118+
return (
119+
<div ref={this.circularRef} style={{ height: "100%", width: "100%" }}>
120+
<Circular {...circularProps} {...props} />
121+
</div>
122+
);
123+
} else if (this.state.viewer === "both") {
124+
return (
125+
<div style={{ display: "flex", flexDirection: "row", height: "100%", width: "100%" }}>
126+
<div ref={this.circularRef} style={{ height: "100%", width: "70%" }}>
127+
<Circular {...circularProps} {...props} />
128+
</div>
129+
<div ref={this.linearRef} style={{ height: "100%", width: "30%" }}>
130+
<Linear {...linearProps} {...props} />
131+
</div>
132+
</div>
133+
);
134+
} else if (this.state.viewer === "both_flip") {
135+
return (
136+
<div style={{ display: "flex", flexDirection: "row", height: "100%", width: "100%" }}>
137+
<div ref={this.linearRef} style={{ height: "100%", width: "30%" }}>
138+
<Linear {...linearProps} {...props} />
139+
</div>
140+
<div ref={this.circularRef} style={{ height: "100%", width: "70%" }}>
141+
<Circular {...circularProps} {...props} />
142+
</div>
143+
</div>
144+
);
145+
} else {
146+
return (
147+
<div style={{ display: "flex", flexDirection: "column", width: "100%" }}>
148+
<div ref={this.linearRef} style={{ height: "25%", width: "100%" }}>
149+
<Linear {...linearProps} {...props} />
150+
</div>
151+
<div ref={this.circularRef} style={{ height: "75%", width: "100%" }}>
152+
<Circular {...circularProps} {...props} />
153+
</div>
154+
</div>
155+
);
156+
}
157+
}
158+
}
159+
101160
return (
102161
<div style={{ height: "100vh" }}>
103162
<Sidebar.Pushable className="sidebar-container">
@@ -134,6 +193,13 @@ export default class App extends React.Component<any, AppState> {
134193
<Menu.Item as="a" className="options-checkbox">
135194
<CheckboxInput label="Show index" name="index" set={showIndex => this.setState({ showIndex })} />
136195
</Menu.Item>
196+
<Menu.Item as="a" className="options-checkbox">
197+
<CheckboxInput
198+
label="Custom Children"
199+
name="customChildren"
200+
set={customChildren => this.setState({ customChildren })}
201+
/>
202+
</Menu.Item>
137203
<Menu.Item as="a">
138204
<EnzymeInput enzymes={this.state.enzymes} toggleEnzyme={this.toggleEnzyme} />
139205
</Menu.Item>
@@ -151,9 +217,11 @@ export default class App extends React.Component<any, AppState> {
151217
{this.state.seq && (
152218
<SeqViz
153219
// accession="MN623123"
220+
key={`${this.state.viewer}${this.state.customChildren}`}
154221
annotations={this.state.annotations}
155222
enzymes={this.state.enzymes}
156223
name={this.state.name}
224+
refs={{circular: this.circularRef, linear: this.linearRef}}
157225
search={this.state.search}
158226
selection={this.state.selection}
159227
seq={this.state.seq}
@@ -163,7 +231,9 @@ export default class App extends React.Component<any, AppState> {
163231
viewer={this.state.viewer as "linear" | "circular"}
164232
zoom={{ linear: this.state.zoom }}
165233
onSelection={selection => this.setState({ selection })}
166-
/>
234+
>
235+
{customChildren}
236+
</SeqViz>
167237
)}
168238
</div>
169239
</div>

0 commit comments

Comments
 (0)