-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.tsx
114 lines (107 loc) · 3.27 KB
/
App.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
import React, { useState, useEffect } from 'react'
import '@fontsource/roboto'
import {
createViewState,
JBrowseLinearGenomeView,
} from '@jbrowse/react-linear-genome-view'
import makeWorkerInstance from '@jbrowse/react-linear-genome-view/esm/makeWorkerInstance'
import assembly from './assembly'
import tracks from './tracks'
import defaultSession from './defaultSession'
type ViewModel = ReturnType<typeof createViewState>
function View() {
const [viewState, setViewState] = useState<ViewModel>()
const [patches, setPatches] = useState('')
const [stateSnapshot, setStateSnapshot] = useState('')
useEffect(() => {
const state = createViewState({
assembly,
tracks,
onChange: (patch: any) => {
setPatches(previous => previous + JSON.stringify(patch) + '\n')
},
defaultSession,
configuration: {
rpc: {
defaultDriver: 'WebWorkerRpcDriver',
},
},
makeWorkerInstance,
})
setViewState(state)
}, [])
if (!viewState) {
return null
}
return (
<>
<h1>
JBrowse 2 React Linear Genome View Demo (with create-react-app v5)
</h1>
<JBrowseLinearGenomeView viewState={viewState} />
<h3>Code</h3>
<p>
The code for this app is available at{' '}
<a
href="https://github.com/GMOD/jbrowse-react-linear-genome-view-cra5-demo"
target="_blank"
rel="noreferrer"
>
https://github.com/GMOD/jbrowse-react-linear-genome-view-cra5-demo
</a>
.
</p>
<h3>Control the view</h3>
<div>
<p>
This is an example of controlling the view from other elements on the
page. Clicking on a button will navigate the view to the location of
that gene.
</p>
<button
onClick={() => {
viewState.session.view.navToLocString('10:94762681..94855547')
}}
>
CYP2C19
</button>
<button
onClick={() => {
viewState.session.view.navToLocString('13:32315086..32400266')
}}
>
BRCA2
</button>
</div>
<h3>See the state</h3>
<div>
<p>
The button below will show you the current session, which includes
things like what region the view is showing and which tracks are open.
This session JSON object can be used in the{' '}
<code>defaultSession</code> of <code>createViewState</code>.
</p>
<button
onClick={() => {
setStateSnapshot(JSON.stringify(viewState.session, undefined, 2))
}}
>
Show session
</button>
</div>
<textarea value={stateSnapshot} readOnly rows={20} cols={80} />
<h3>React to the view</h3>
<p>
Using <code>onChange</code> in <code>createViewState</code>, you can
observe what is happening in the view and react to it. The changes in
the state of the view are emitted as{' '}
<a href="http://jsonpatch.com/" target="_blank" rel="noreferrer">
JSON patches
</a>
. The patches for the component on this page are shown below.
</p>
<textarea value={patches} readOnly rows={5} cols={80} wrap="off" />
</>
)
}
export default View