UNPKG

12.2 kBMarkdownView Raw
1Pvjs
2====================
3
4JavaScript-based biological pathway diagram viewer. Used in [WikiPathways](http://wikipathways.org).
5
6## Beta
7The beta tag given to this version means that it is not advisable to use it in production. There are some known issues
8and it has not been fully cross browser tested.
9
10Having said that, most of the desired functionality does work as intended in most modern browsers.
11
12**Note**: If you need to use the stable version of Pvjs see [this README](https://github.com/wikipathways/pvjs/blob/master/README.md).
13
14## Contents
15* [Installation](#install)
16 * [Using a Module Bundler (Webpack)](#webpack)
17 * [Using the UMD bundle](#umd)
18* [React Usage](#react)
19 * [Basic Example](#react.example)
20 * [Props](#react.props)
21 * [Advanced Example](#react.advanced)
22* [Web Component](#component)
23 * [Example](#component.example)
24 * [Attributes](#component.attributes)
25 * [Properties](#component.properties)
26 * [Events](#component.events)
27 * [Manipulating](#component.manipulation)
28 * [Example](#manipulation.example)
29 * [Methods](#manipulation.methods)
30* [Contributions & Bug Reports](#contributions)
31* [Funding](#funding)
32
33## <a name="install"></a>Installation
34### <a name="webpack"></a>Using a Module Bundler (Webpack)
35We recommend using a module bundler like [Webpack](https://webpack.js.org/) in your project. If you're doing this, just install and import Pvjs. All examples will assume you are using this method and not the UMD bundle.
36
37Note that Pvjs does come with some styles which will be automatically picked up by Webpack.
38
39```
40npm install @wikipathways/pvjs --save
41```
42
43```javascript
44// Somewhere in your project
45import { Pvjs } from '@wikipathways/pvjs';
46```
47
48### <a name="umd"></a>Using the UMD bundle
49Pvjs comes with a UMD bundle that you can include in your HTML page. It's available under `dist/index.js`. Once you've included the bundle, Pvjs is available under the `Pvjs` namespace.
50```
51
52### <a name="umd"></a>Using the UMD bundle
53Pvjs comes with a UMD bundle that you can include in your HTML page. It's available under `dist/index.js`. Once you've included the bundle, Pvjs is available under the `Pvjs` namespace.
54
551. Copy `dist/index.js`, `dist/style.css`, and all of `dist/assets` into your project assets (tip: use a task runner like gulp)
562. Include `index.js` and `style.css` in your project's head tag:
57
58```html
59<script src="assets/pvjs/index.js"></script>
60<link rel="stylesheet" href="assets/pvjs/style.css" />
61```
62
63Alternatively, just use it from the unpkg CDN:
64
65```html
66<script src="https://unpkg.com/@wikipathways/pvjs/dist/index.js"></script>
67<link rel="stylesheet" href="https://unpkg.com/@wikipathways/pvjs/dist/style.css" />
68```
69
70## <a name="react"></a> React Usage
71If you are already using React then you can directly use the React component.
72
73### <a name="react.example"></a> Basic Example
74Use the component as below. Pvjs will fill whatever container it is in, so it is a good idea to place it inside a container with set dimensions.
75
76```javascript
77import React from 'react';
78import ReactDOM from 'react-dom';
79import { Pvjs } from '@wikipathways/pvjs';
80
81ReactDOM.render(
82 <Pvjs
83 wpId="WP4"
84 />,
85 document.getElementById('root')
86);
87```
88
89### <a name="react.props"></a> Props
90* `wpId`: Required. A string for the WikiPathways ID of the desired pathway. E.g. 'WP4'.
91* `version`: Default = 0. A number for the version of the pathway. 0 is latest.
92* `onReady`: Function that is called with the list of entities in the diagram when the diagram has finished loading. You can use this to get the entityIds for other props.
93* `onEntityClick`: Function that is called with the entity whenever a diagram entity has been clicked.
94* `onPanZoomChange`: Function that is called whenever the diagram is panned or zoomed. It is called with an object with the form: `{ x: number, y: number, zoomLevel: number }`. The coordinates in the object are relative to the diagram dimensions.
95* `detailPanelEnabled`: Default = `true`. Indicates whether the annotations pop-up will be shown when an entity is clicked.
96* `panZoomLocked`: Default = `false`. Indicates whether the user can manually pan and zoom the diagram. Note, changes to pannedEntities and zoomedEntities will still have an effect if this is true.
97* `showPanZoomControls`: Default = true. Indicates whether the controls for panning and zooming are shown.
98* `highlightedEntities`: Default = `[]`. Array of objects for highlighted diagram entities. Objects in this array look like `{ entityId: string, color: string }`. Color can be any CSS color. See the [advanced example](#react.advanced).
99* `hiddenEntities`: Default = `[]`. Array of entityIds. See the [advanced example](#react.advanced).
100* `pannedEntities`: Default = `[]`. Array of entityIds. See the [advanced example](#react.advanced).
101* `zoomedEntities`: Default = `[]`. Array of entityIds. See the [advanced example](#react.advanced). Note, that zoomed does not also mean panned. In most cases, an entityId in zoomedEntities should also be in pannedEntities.
102* `zoomLevel`: Default = `1`. Number indicating the level of zoom the diagram should be at. 1 = no zoom in/out.
103* `panCoordinates`: Default: `{x: 0, y: 0}`. Relative coordinates to pan to. `x` is relative to the diagram width and `y` the diagram height. E.g. `{x: 0.5, y: 0.5}` will pan half way across the x and y axis.
104
105*Note that pannedCoordinates and zoomLevel take precedence over pannedEntities and zoomedEntities.*
106
107### <a name="react.advanced"></a> Advanced Example
108
109```javascript
110import React, { Component } from 'react';
111import { Pvjs } from '@wikipathways/pvjs';
112
113class MyPvjsComponent extends Component {
114 constructor(props) {
115 super(props);
116
117 this.state = {
118 highlightedEntities: [],
119 hiddenEntities: [],
120 zoomedEntities: [],
121 pannedEntities: [],
122 }
123 }
124
125 onEntityClick = entity => {
126 // This will highlight an entity red, whenever it is clicked
127 this.setState(state => {
128 return {
129 highlightedEntities: state.highlightedEntities.concat([
130 {
131 entityId: entity.id,
132 color: 'red', // Color can be any CSS color
133 },
134 ]),
135 }
136 });
137 }
138
139 onPvjsReady = entityList => {
140 // Find the entity with TCA cycle as the node text
141 const TCA = entityList.find(singleEntity => singleEntity.textContent === 'TCA Cycle');
142 const BRCA1 = entityList.find(singleEntity => singleEntity.textContent === 'BRCA1');
143
144 this.setState({
145 highlightedEntities: [{entityId: TCA.id, color: 'blue'}],
146 pannedEntities: [TCA.id],
147 zoomedEntities: [TCA.id],
148 hiddenEntities: ['daafb'],
149 });
150 }
151
152 render() {
153 const { highlightedEntities, hiddenEntities, zoomedEntities, pannedEntities } = this.state;
154
155 return (
156 <div style={{width: '100vw', height: '100vh'}}>
157 <Pvjs
158 wpId="WP4"
159 version={0}
160 onReady={this.onPvjsReady}
161 onEntityClick={this.onEntityClick}
162 highlightedEntities={highlightedEntities}
163 hiddenEntities={hiddenEntities}
164 zoomedEntities={zoomedEntities}
165 pannedEntities={pannedEntities}
166 detailPanelEnabled={false}
167 />
168 </div>
169 )
170 }
171}
172```
173
174## <a name="component"></a> Web Component
175The web component allows you to use Pvjs without React. To use it, first make sure that Pvjs is available on the page in which you're using it. The easiest way to do this is to include the UMD bundle in your pages head. If you're using a module bundler, just make sure Pvjs is included in your build process (normally in `index.js`).
176
177### <a name="component.example"></a> Example
178An example is served at [this gist](https://gist.github.com/jacobwindsor/3684220d95210df2dcbdf79b9e5c2ef5).
179
180### <a name="component.attributes"></a> Attributes
181
182* `wp-id`: Required. A string for the WikiPathways ID of the desired pathway. E.g. 'WP4'.
183* `version`: Default = 0. A number for the version of the pathway. 0 is latest.
184* `detail-panel-enabled`: Indicates whether the annotations pop-up will be shown when an entity is clicked.
185* `pan-zoom-locked`: Indicates whether the user can manually pan and zoom the diagram. Note, changes via the [Manipulation API](#component.manipulation) will still take effect.
186* `show-pan-zoom-controls`: Indicates whether the controls for panning and zooming are shown.
187* `ready`: Indicates when the diagram is fully loaded and ready for manipulating. You cannot set this.
188* `highlighted-entities`: Comma separated list of `entityId:color` maps. E.g. `d8bae:red`. You may set this using the [API](#component.manipulation).
189* `panned-entities`: Comma separated list of entity IDs that are panned to. You may set this using the [API](#component.manipulation).
190* `zoomed-entities`: Comma separated list of entity IDs that are zoomed to. You may set this using the [API](#component.manipulation).
191* `hidden-entities`: Comma separated list of entity IDs that are hidden. You may set this using the [API](#component.manipulation).
192
193#### <a name="component.properties"></a> Properties
194These properties are **not** reflected in the DOM attributes.
195
196* `entities`: The list of entity objects in the diagram. This is null until the diagram is ready.
197
198### <a name="component.events"></a> Events
199* `ready`: This is fired when the diagram is ready. `entities` is provided in the detail object for convenience. See [this gist](https://gist.github.com/jacobwindsor/b45fdf2485a2e0c772fe2884c32ee9cc).
200
201### <a name="component.manipulation"></a> Manipulating
202The custom element provides a custom API that allows you to programmatically manipulate the diagram.
203
204#### <a name="manipulation.example"></a> Example
205An example is served at [this gist](https://gist.github.com/jacobwindsor/b45fdf2485a2e0c772fe2884c32ee9cc).
206
207#### <a name="manipulation.methods"></a> Methods
208
209##### zoomOn
210This method accepts a single entity ID or an array of entity IDs. If a single entity is given then the diagram will
211*zoom and pan* to that entity. If an array is given, the diagram will *zoom and pan* to the area defined by all of those
212entities.
213
214```javascript
215zoomOn(entity_id: string | string[])
216```
217
218##### panTo
219Basically the same as zoomOn but without the zooming.
220
221```javascript
222panTo(entity_id: string | string[])
223```
224
225##### highlightOn
226
227### <a name="component.attributes"></a> Attributes
228
229```javascript
230highlightOn(entity_id: string, color: string)
231```
232
233##### highlightOff
234```javascript
235highlightOff(entity_id: string)
236```
237
238##### toggleHighlight
239```javascript
240toggleHighlight(entity_id: string)
241```
242
243##### hide
244```javascript
245hide(entity_id: string)
246```
247
248##### show
249```javascript
250show(entity_id: string)
251```
252
253##### toggleHidden
254```javascript
255toggleHidden(entity_id: string)
256```
257
258##### resetPan
259```javascript
260resetPan()
261
262##### toggleHidden
263```javascript
264toggleHidden(entity_id: string)
265```
266
267##### resetPan
268```javascript
269resetPan()
270```
271
272##### resetZoom
273```javascript
274resetZoom()
275```
276
277##### resetHighlighted
278Un-highlight all highlighted entities.
279Accepts an optional exclude array that will exclude the given entities from being reset.
280```javascript
281resetHighlighted(exclude?: string[])
282```
283
284##### resetHidden
285Show all hidden entities.
286Accepts an optional exclude array that will exclude the given entities from being reset.
287```javascript
288resetHidden(exclude?: string[])
289```
290
291##### reset
292Reset the pan, zoom, hidden, and highlighted entities
293
294```javascript
295reset()
296```
297
298## <a name="contributions"></a> Contributions & Bugs
299We love pull requests! If you want to contribute to Pvjs then please feel free to make a pull request. The GitHub page is available [here](https://github.com/wikipathways/pvjs).
300
301If you find a bug please check the [issue tracker](https://github.com/wikipathways/pvjs/issues) to see if it hasn't already been reported. If not, then please create a new issue. If you can then we would love for you to make a fix for it in a pull request.
302
303## <a name="funding"></a> Funding
304* The National Institute for General Medical Sciences [R01-GM100039](http://www.nigms.nih.gov/)
305* The BioRange program of the Netherlands [Bioinformatics Centre](http://www.nbic.nl/)
306* [University Maastricht](http://www.unimaas.nl/default.asp?taal=en): Broad Research Strategy Program Part 2 (BOS2)