File size: 5,136 Bytes
0936134
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
var React = require('react');
var PredictedGenesPanel = require('../ReactComponents/PredictedGenesPanel');
var PWAPanel = require('./PWAPanel');
var SVGCollection = require('../ReactComponents/SVGCollection');
var color = require('../../js/color.js');
var DownloadPanel = require('../ReactComponents/DownloadPanel');

var AnalysisPanel = React.createClass({

    propTypes: {

        analysisGroup: React.PropTypes.object.isRequired,
        coloring: React.PropTypes.string.isRequired,
        onClose: React.PropTypes.func.isRequired,
        onTermSelect: React.PropTypes.func.isRequired,
        onGeneAdd: React.PropTypes.func.isRequired,
        onGeneRemove: React.PropTypes.func.isRequired,
        addedGenes: React.PropTypes.array.isRequired,

        // selectedTerm: React.PropTypes.object,
        termColoring: React.PropTypes.string,
    },

    getInitialState: function() {
        return {
            activeTab: 0
        }
    },
    
    componentDidMount: function() {
        if (this.refs.pwa.pwaRequest(this.props.analysisGroup)) {
            this.refs.pred.gpRequest(this.props.analysisGroup)
        }
    },

    componentWillReceiveProps: function(newProps) {
        if (newProps.analysisGroup !== this.props.analysisGroup) {
            if (this.refs.pwa.pwaRequest(newProps.analysisGroup)) {
                this.refs.pred.gpRequest(newProps.analysisGroup)
            }
        }
    },

    onTabSelect: function(index) {
        this.setState({
            activeTab: index
        });
    },

    onPWAStart: function() {
        this.setState({
            pwaDownloadable: false
        })
    },

    onPWAFinish: function() {
        this.setState({
            pwaDownloadable: true
        })
    },

    onPredStart: function() {
        this.setState({
            predDownloadable: false
        })
    },

    onPredFinish: function() {
        this.setState({
            predDownloadable: true
        })
    },

    render: function() {

        var d3fd = {getNodeById: function() { return null }};
        var styles = [
            // {position: 'relative', height: '100%', overflow: 'hidden', backgroundColor: color.colors.gnwhite},//, position: 'relative'},
            // {position: 'relative', height: '100%', overflow: 'hidden', backgroundColor: color.colors.gnwhite, display: 'none'}//, position: 'relative'}
            {position: 'relative', backgroundColor: color.colors.gnwhite},
            {position: 'relative', backgroundColor: color.colors.gnwhite, display: 'none'}
        ];
        var classNames = ['button selectedbutton clickable', 'button clickable'];
        if (this.state.activeTab === 1) {
            styles.reverse();
            classNames.reverse()
        }

        return (
                <div className='analysispanel bordered vflex' style={this.props.style}>
                <div className='flex00'>
                <div className={classNames[0]} onClick={this.onTabSelect.bind(null, 0)}>PATHWAYS & PHENOTYPES</div>
                <div className={classNames[1]} onClick={this.onTabSelect.bind(null, 1)}>GENES</div>
                <div style={{float: 'right', display: 'inline-block'}}>
                <div style={{display: 'inline-block'}}>
                {this.state.activeTab === 0 && this.state.pwaDownloadable ? <DownloadButton comp={this.refs.pwa} /> : null}
                {this.state.activeTab === 1 && this.state.predDownloadable ? <DownloadButton comp={this.refs.pred} /> : null}
            </div>
                <div className='clickable xbutton' style={{display: 'inline-block', margin: '0 10px', verticalAlign: 'top'}} onClick={this.props.onClose}>
                <SVGCollection.X size={12} />
                </div>
                </div>
                </div>
                <PWAPanel
            ref='pwa'
            style={styles[0]}
            maxTableHeight={(this.props.style.maxHeight && (this.props.style.maxHeight - 120) + 'px') || '100%'}
            selectedTerm={this.props.selectedTerm}
            group={this.props.analysisGroup}
            termColoring={this.props.termColoring}
            areNodesColoredByTerm={this.props.coloring == 'term'}
            onPWAStart={this.onPWAStart}
            onPWAFinish={this.onPWAFinish}
            onTermClick={this.props.onTermSelect} />
                <PredictedGenesPanel
            ref='pred'
            style={styles[1]}
            group={this.props.analysisGroup}
            onPredStart={this.onPredStart}
            onPredFinish={this.onPredFinish}
            onGeneAdd={this.props.onGeneAdd}
            onGeneRemove={this.props.onGeneRemove}
            addedGenes={this.props.addedGenes}
            d3fd={d3fd}/>
                </div>
        )
    }
});

var DownloadButton = React.createClass({

    propTypes: {
        comp: React.PropTypes.object.isRequired
    },

    render: function() {

        return (
                <div title='Download these results' onClick={this.props.comp.download}>
                <SVGCollection.Download text='TXT' size={24} />
                </div>
        )
    }
});

module.exports = AnalysisPanel;