This repository has been archived by the owner on Oct 10, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathScenarioSelector.jsx
116 lines (102 loc) · 4.09 KB
/
ScenarioSelector.jsx
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
import React from 'react'
import GraphWorkspace from './GraphWorkspace'
require('./styles.scss')
export default class ScenarioSelector extends React.Component {
state = {
scenario: "related",
seed: "disease",
graph: undefined,
fetching: false,
msg: "",
error: undefined,
}
renderError = () => {
const {error} = this.state;
return error
? (
<div className="form-group has-danger">
<div className="form-control-feedback">Error: {error}</div>
</div>
)
: null;
};
render() {
return (
<div className="container-fluid demo-root">
<div className="row scenario-selection">
<div className="card col-md-12">
<div className="card-block">
<h4 className="card-title">Scenario Selection</h4>
<form className="form-inline" onSubmit={(e) => {this.onGo(); e.preventDefault();}}>
<div className="form-group">
<label htmlFor="seedText">Seed string</label>
<input id="seedText" className="form-control" type="text" onChange={this.onTextChange} value={this.state.seed}/>
</div>
<div className="form-group">
<label htmlFor="scenario">Scenario</label>
<select id="scenario" className="form-control" onChange={this.onScenarioChange}>
<option value="related">related</option>
<option value="similar">similar</option>
</select>
</div>
<div className="form-group">
<input type="button" onClick={this.onGo} value="Go" className="btn btn-primary"/>
</div>
{this.renderError()}
{/*<div className="text-xs-center">{this.state.msg}</div>*/}
{this.state.fetching ? <progress className="progress" value="50" max="100"></progress> : undefined}
</form>
</div>
</div>
</div>
<GraphWorkspace graph={this.state.graph} />
</div>
);
}
onTextChange = (e) => {
this.setState({seed: e.target.value});
};
onScenarioChange = (e) => {
this.setState({scenario: e.target.value});
};
onGo = () => {
this.setState({msg: 'Fetching data...', fetching: true, error: undefined});
fetch(this.state.scenario + '/' + this.state.seed)
.then(result => {
if (!result.ok) {
throw Error(result.statusText);
}
return result.json();
})
.then(result => {
this.setState({
msg: "Fetching done.",
fetching: false,
graph: this.prepareGraph(result.graph),
error: undefined,
});
})
.catch(e => {
this.setState({msg: "Fetching failed.", fetching: false, graph: undefined, error: e.message});
});
};
prepareGraph = (graph) => {
graph.nodes.push(
{
"id": 0,
"label": this.state.seed,
"type": "entity",
/*"entities": [
{
"frequency": -1,
"id": -1,
"score": -1,
"spread": -1,
"value": this.state.seed
}
],*/
}
);
return graph;
}
}