Skip to content

Commit ba7fe63

Browse files
committed
Added docs, removed outer div container, adjusted selection to accept a single sequence region, added warning when using selection and coverage.
1 parent 4856065 commit ba7fe63

File tree

4 files changed

+98
-9
lines changed

4 files changed

+98
-9
lines changed

README.md

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,80 @@
44
[![npm package][npm-badge]][npm]
55
[![Coveralls][coveralls-badge]][coveralls]
66

7+
##Description
78

89
A [React](https://facebook.github.io/react/) wrapper around the [BioJS](https://biojs.net/) [sequence-viewer](https://github.com/calipho-sib/sequence-viewer)
910
component.
1011

12+
## Installation
13+
14+
```
15+
npm install --save react-sequence-viewer
16+
```
17+
18+
## Usage
19+
20+
The following code renders a sequence-viewer component in the HTML
21+
element with an ID of 'sequence-viewer1'.
22+
23+
**ES6**
24+
25+
```jsx
26+
import React from 'react';
27+
import {render} from 'react-dom';
28+
import ReactSequenceViewer from 'react-sequence-viewer';
29+
30+
const mySeq = 'CAGTCGATCGTAGCTAGCTAGCTGATCGATGC';
31+
32+
render(React.createClass({
33+
render() {
34+
return (
35+
<ReactSequenceViewer sequence={mySeq} />
36+
);
37+
}
38+
}),document.getElementsById('#sequence-viewer1'));
39+
```
40+
41+
```jsx
42+
import React from 'react';
43+
import {render} from 'react-dom';
44+
import ReactSequenceViewer from 'react-sequence-viewer';
45+
46+
const mySeq = 'CAGTCGATCGTAGCTAGCTAGCTGATCGATGC';
47+
const options = {
48+
showLineNumbers: true,
49+
toolbar: false,
50+
search: false,
51+
title: "my sequence",
52+
badge: true,
53+
};
54+
55+
render(React.createClass({
56+
render() {
57+
return (
58+
<ReactSequenceViewer sequence={mySeq} {...options} />
59+
);
60+
}
61+
}),document.getElementsById('#sequence-viewer1'));
62+
```
63+
64+
## Properties / Options
65+
66+
Please see the [Sequence Viewer documentation](https://cdn.rawgit.com/calipho-sib/sequence-viewer/master/examples/index.html)
67+
for more details on the options below.
68+
69+
70+
| Name | Description | Default Value | Type | Required | Comment |
71+
|:-----|:------------|---------------|------|----------|:--------|
72+
| id | The ID to use for the Sequence Viewer container element | A random unique ID | String | No | |
73+
| className | HTML class name to apply to the Sequence Viewer div container | | String | No | |
74+
| sequence | The sequence to render. | | String | Yes | |
75+
| selection | A region to highlight | | Array | No | Not compatible with `coverage` |
76+
| coverage | Advanced sequence hightlighting | | Array[Objects] | No | Not compatible with `selection` |
77+
| legend | Adds a legend to the sequence | | | Array[Objects] | No | |
78+
| onMouseSelection | Event handler for sequence selection with the mouse | | function | No | |
79+
| onSubpartSelected | Event handler for sequence selected via the search box | | function | No | |
80+
1181
[build-badge]: https://img.shields.io/travis/user/repo/master.png?style=flat-square
1282
[build]: https://travis-ci.org/FlyBase/react-sequence-viewer
1383

demo/src/index.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,11 @@ const subPart = (e) => {
1818
console.log("Subpart");
1919
console.log(e.detail);
2020
}
21+
22+
const selection = [0,30,'red']
23+
2124
//Coverage list
2225
const exampleSequenceCoverage = [
23-
{start: 0, end: 25, color: "black", underscore: false, bgcolor: "#ffd891"},
2426
{start: 25, end: 47, color: "#ff0000", underscore: false, tooltip: "this is a tooltip"},
2527
{start: 47, end: 54, color: "#ff0000", underscore: true},
2628
{start: 54, end: 55, color: "#ff0000", underscore: false},
@@ -41,7 +43,7 @@ let Demo = React.createClass({
4143
render() {
4244
return <div>
4345
<h1>react-sequence-viewer Demo</h1>
44-
<Component onSubpartSelected={subPart} onMouseSelection={mouseClick} legend={exampleLegend} coverage={exampleSequenceCoverage} id="blah" sequence={seq} showLineNumbers={true} toolbar={true} search={true} badge={false} title="" />
46+
<Component onSubpartSelected={subPart} onMouseSelection={mouseClick} legend={exampleLegend} coverage={exampleSequenceCoverage} sequence={seq} showLineNumbers={true} toolbar={true} search={true} badge={false} title="" />
4547
</div>
4648
}
4749
})

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-sequence-viewer",
3-
"version": "0.1.0",
3+
"version": "0.1.1",
44
"description": "A React wrapper around the BioJS sequence-viewer component",
55
"main": "lib/index.js",
66
"jsnext:main": "es/index.js",
@@ -23,6 +23,7 @@
2323
"bootstrap": "^3.3.7",
2424
"handlebars": "3.0.2",
2525
"jquery": "^3.1.0",
26+
"node-uuid": "^1.4.7",
2627
"sequence-viewer": "^0.2.18"
2728
},
2829
"peerDependencies": {

src/index.js

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import React, {PropTypes, Component} from 'react';
2+
import { v4 } from 'node-uuid';
23

34
import Bootstrap from 'bootstrap/dist/css/bootstrap.min.css';
45
// See nwb.config.js for some webpack magic that allows this to work.
@@ -9,6 +10,9 @@ export default class ReactSequenceViewer extends Component {
910
super(props);
1011
this.handleChange = this.handleChange.bind(this);
1112

13+
if (props.selection && props.selection.length > 0 && props.coverage && props.coverage.length > 0) {
14+
console.warn("The selection and coverage options are not compatible with each other.");
15+
}
1216
// Initialize the sequence-viewer object.
1317
this._seqObj = new Sequence(this.props.sequence);
1418
this._div = null;
@@ -21,13 +25,17 @@ export default class ReactSequenceViewer extends Component {
2125
// callRender({toolbar: false})
2226
// would override the existing toolbar setting.
2327
callRender(newProps = {}) {
28+
const { selection, ...props} = this.props;
29+
2430
// Read in div from private variable.
2531
const div = this._div;
32+
2633
//Render div if it is not null.
27-
if (div != null) {
28-
this._seqObj.render('#' + div.id,{...this.props,...newProps});
34+
if (div !== null) {
35+
this._seqObj.render('#' + div.id,{...props,...newProps});
2936
this._seqObj.coverage(this.props.coverage);
3037
this._seqObj.addLegend(this.props.legend);
38+
if (selection.length > 0) this._seqObj.selection(...selection);
3139
}
3240
}
3341

@@ -67,16 +75,22 @@ export default class ReactSequenceViewer extends Component {
6775
// in the DOM. The componentDidMount function above will then get called
6876
// and render the widget.
6977
return (
70-
<div className={className}>
71-
<div id={this.props.id} ref={(div) => this._div = div}></div>
72-
</div>
78+
<div className={className} id={this.props.id} ref={(div) => this._div = div}></div>
7379
);
7480
}
7581
}
7682

7783
ReactSequenceViewer.propTypes = {
78-
id: PropTypes.string.isRequired,
84+
id: PropTypes.string,
7985
sequence: PropTypes.string.isRequired,
86+
className: PropTypes.string,
87+
selection: PropTypes.arrayOf((arr, key, compName, location, propFullName) => {
88+
if (arr.length !== 3) {
89+
return new Error(
90+
'Invalid prop `selection` supplied to `' + compName + '`. Validation failed.'
91+
);
92+
}
93+
}),
8094
coverage: PropTypes.arrayOf(
8195
PropTypes.shape({
8296
start: PropTypes.number.isRequired,
@@ -99,8 +113,10 @@ ReactSequenceViewer.propTypes = {
99113
};
100114

101115
ReactSequenceViewer.defaultProps = {
116+
id: v4(),
102117
coverage: [],
103118
legend: [],
119+
selection: [],
104120
seqLenClass: "CPLChoice",
105121
onMouseSelection: (elem) => {},
106122
onSubpartSelected: (elem) => {},

0 commit comments

Comments
 (0)