-
Notifications
You must be signed in to change notification settings - Fork 20
/
Anatomogram.js
60 lines (50 loc) · 1.42 KB
/
Anatomogram.js
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
import React from 'react'
import PropTypes from 'prop-types'
import Switcher from './Switcher'
import AnatomogramSvg from './AnatomogramSvg'
import {getDefaultView, supportedSpecies} from './Assets'
class Anatomogram extends React.Component {
constructor(props) {
super(props)
this.state = {
selectedView: getDefaultView(props.species)
}
this._switchAnatomogramView = this._switchAnatomogramView.bind(this)
}
_switchAnatomogramView(anatomogramView) {
this.setState({ selectedView: anatomogramView })
}
static getDerivedStateFromProps(props, state) {
if (props.species !== state.species) {
return {
species: props.species,
selectedView: getDefaultView(props.species)
}
}
return null
}
render() {
return (
supportedSpecies.includes(this.props.species) &&
<div>
<Switcher
atlasUrl={this.props.atlasUrl}
species={this.props.species}
selectedView={this.state.selectedView}
onChangeView={this._switchAnatomogramView} />
<AnatomogramSvg
atlasUrl={this.props.atlasUrl}
{...this.props}
selectedView={this.state.selectedView} />
</div>
)
}
}
Anatomogram.propTypes = {
atlasUrl: PropTypes.string,
species: PropTypes.string.isRequired
}
Anatomogram.defaultProps = {
atlasUrl: `https://www.ebi.ac.uk/gxa/`
}
export default Anatomogram