forked from egonw/mscpils
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample4.html
More file actions
125 lines (105 loc) · 4.03 KB
/
example4.html
File metadata and controls
125 lines (105 loc) · 4.03 KB
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
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<!--
Copyright (c) 2013 Egon Willighagen <egon.willighagen@maastrichtuniversity.nl>
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
-->
<head>
<title>d3.js example</title>
<!-- ops.js -->
<script src="lib/jquery-1.9.1.min.js"></script>
<script type="text/javascript" src="lib/purl.js"></script>
<script type="text/javascript" src="src/OPS.js"></script>
<script type="text/javascript" src="src/CompoundSearch.js"></script>
<!-- d3.js -->
<script src="lib/d3.v3.min.js" charset="utf-8"></script>
<!-- setup -->
<script type="text/javascript">
var prmstr = window.location.search.substr(1);
var prmarr = prmstr.split ("&");
var params = {};
for ( var i = 0; i < prmarr.length; i++) {
var tmparr = prmarr[i].split("=");
params[tmparr[0]] = tmparr[1];
}
</script>
</head>
<body>
<h3>OpenPHACTS / d3.js mash up</h3>
<p>This example lists the number of activities for paracetamol by unit.</p>
<p><div class="chart"></div></p>
<pre><div class="json1">1</div></pre>
<pre><div class="json2">2</div></pre>
<!-- dynamically create a table with type information -->
<script type="text/javascript">
var sources = new Openphacts.CompoundSearch("https://beta.openphacts.org", params["app_id"], params["app_key"]);
var callback = function(success, status, response){
d3.select(".json2").html(JSON.stringify(response, undefined, 2));
var data = [];
// count the units
unitCounts = {};
list = response.items
max = 0
for (i=0; i<list.length; i++) {
item = list[i]
units = item.standardUnits;
if (!units) units = "none";
// did I encounter this unit before?
if (unitCounts[units]) {
// yes, than increase the count
unitCounts[units] = unitCounts[units] + 1
} else {
// no, first time, so the count = 1
unitCounts[units] = 1;
}
max = Math.max(max, unitCounts[units])
}
// now convert the unit counts to data
for (key in unitCounts) {
data.push({name:key, value:unitCounts[key]})
}
var x = d3.scale.linear()
.domain([0, max])
.range([0, 1000]);
d3.select(".chart")
.selectAll("div")
.data(data)
.enter().append("div")
.style("width", function(d) { return x(d.value) + "px"; })
.style("background-color", "steelblue")
.style("color", "white")
.style("text-align", "right")
.style("text-align", "right")
.style("font", "10px sans-serif")
.style("padding", "3px")
.style("margin", "1px")
.text(function(d) { if (d.value > 5) return d.value + " ( " + d.name + ")"; return d.value; });
};
var callbackCount = function(success, status, response){
d3.select(".json1").html(JSON.stringify(response, undefined, 2));
count = response.primaryTopic.compoundPharmacologyTotalResults
compound = response.primaryTopic._about
sources.compoundPharmacology(compound, 1, count, callback);
};
sources.compoundPharmacologyCount("http://www.conceptwiki.org/concept/a99023df-c3d2-4fa5-82d1-89d3a1d16e0e", callbackCount);
</script>
</body>
</html>