-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdrugDatabase.php
More file actions
392 lines (349 loc) · 13.2 KB
/
drugDatabase.php
File metadata and controls
392 lines (349 loc) · 13.2 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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Search Engine</title>
<!--Adding the d3 javaascript-->
<script type="text/javascript" src="d3.min.js"></script>
<!--Adding the stylesheet for jquery-->
<link rel="stylesheet" href="http://code.jquery.com/ui/1.11.1/themes/smoothness/jquery-ui.css">
<script src="http://code.jquery.com/jquery-1.10.2.js"></script>
<script src="http://code.jquery.com/ui/1.11.1/jquery-ui.js"></script>
<!--Create MyPage module that allows for access of values outside of the head-->
<script>
var MyPage = (function($)
{
var dL = [];
var init = function()
{
//Get .txt File
function reqListener() {
console.log(this.responseText);
}
var oReq = new XMLHttpRequest(); //New request object
oReq.onload = function(){
dL= JSON.parse(this.responseText); // Assign aT the JSON model - Can be accessed as array
oReq.open("get", "readFile.php", true);
oReq.send();
console.log(dL);
}
$( "#tags" )
//AUTOCOMPLETE FEATURE DISABLED
.autocomplete({
source: dL,
minLength: 4,
disabled: false,
})
};
//MyPage Module will return available tags & initialize those tags
return {
init: init,
availableTags: dL
}
})(jQuery); // Puts correct version of jQuery into MyPage module through function($)
</script>
<!--CSS BIT -->
<style type = "text/css">
/*Modify Rectangles for tooltip - small overlays over data*/
rect {
-moz-transition: all 0.3s;
-o-transition: all 0.3s;
-webkit-transition: all 0.3s;
transition: all 0.3s;
}
/*hover function*/
rect:hover {
fill: orange;
}
#tooltip {
position: absolute;
width: 200px;
height: auto;
padding: 10px;
background-color: white;
-webkit-border-radius: 10px;
-moz-border-radius: 10px;
border-radius: 10px;
-webkit-box-shadow: 4px 4px 10px rgba(0, 0, 0, 0.4);
-moz-box-shadow: 4px 4px 10px rgba(0, 0, 0, 0.4);
box-shadow: 4px 4px 10px rgba(0, 0, 0, 0.4);
pointer-events: none;
}
#tooltip.hidden {
display: none;
}
#tooltip p {
margin: 0;
font-family: sans-serif;
font-size: 16px;
line-height: 20px;
}
body {
background-image:url(gray_jean/gray_jean.png)
}
h1 {
position: relative;
top: 45px;
font-size: 40px;
}
#queryBox {
position: relative;
bottom: 120px;
width: 130px;
background-color: #3c4543;
border-top-left-radius: 5px;
border-top-right-radius: 5px;
border: 2px solid #000000;
font-family: Futura;
}
#scramble {
position: relative;
left: 215px;
top: 36px;
width: 145px;
background-color: #3c4543;
border-top-left-radius: 5px;
border-top-right-radius: 5px;
border: 2px solid #000000;
font-family: Futura;
}
#sort{
position: relative;
top: 8px;
left: 135px;
width: 75px;
background-color: #3c4543;
border-top-left-radius: 5px;
border-top-right-radius: 5px;
border: 2px solid #000000;
font-family: Futura;
}
#glasses{
position: initial;
}
</style>
</head>
<body>
<!--BUTTON - Generates Random Data-->
<div class="buttonex" id="scramble">
<button type="button">Generate Random Data</button>
</div>
<!--BUTTON - Sorts Data-->
<div class="buttonex" id="sort">
<button type="button">Sort Data</button>
</div>
<h1>Drug Query Database</h1>
<div id="tooltip" class="hidden">
<p><strong>Value</strong></p>
<p><span id="value">100</span></p>
</div>
<div id="queryBox">
<input type="text" id="txt_name">
</div>
<div class="glasses" style = "top: 100px;">
<img src="lab_beaker_full.png" style="width:380px;height:150px">
</div>
<!-- JAVASCRIPT -->
<script text="text/javascript">
//Comment below shows access to module from <head></head>
//Initialize the MyPage Module
MyPage.init();
//Get .txt File
function reqListener() {
console.log(this.responseText);
}
var oReq = new XMLHttpRequest(); //New request object
oReq.onload = function(){
MyPage.availableTags = JSON.parse(this.responseText); // Assign aT the JSON model - Can be accessed as array
oReq.open("get", "readFile.php", true);
oReq.send();
//http://stackoverflow.com/questions/23740548/how-to-pass-variables-and-data-from-php-to-javascript
//Creating the Search Box
var queryList = []; // List of terms
$(document).ready(function(){
//get input from search box - finds div id for queryBox and passes user
//query into the input as a value
$('#txt_name').val('query');
var query;
var subStr;
var match;
var query;
var queryLen;
var currentLen;
var repeat;
$("#txt_name").change(function(){
$('svg').empty(); // Emptying svg is necessary to clarify queries
queryList = [];
query = $('#txt_name').val();
queryLen = query.length;
//Search Logic - search for matching substrings
for (i = 0; i < MyPage.availableTags.length; i++){
for(j=0; j + queryLen <= MyPage.availableTags[i][1].length; j++){
subStr = MyPage.availableTags[i][1].substring(j, j+queryLen);
if (query == subStr){
match = MyPage.availableTags[i][1];
repeat = false;
for (k = 0; k<queryList.length; k++) {
if (match == queryList[k][1]) {
repeat = true;
console.log("Match!");
}
}
if (repeat == false) {
queryList.push(MyPage.availableTags[i]);
}
};
};
};
//Make Bars & Drug Labels
makeBars();
makeLabels();
});
});
//Define Variables
var w = 350;
var h = 1000;
var padding = 50;
barHeight = 20;
buffer = 10;
//Defining maxWidth - the limit of the graph
var maxWidth = d3.max(MyPage.availableTags, function(d) {
return d[3]; //# Patients
});
var xScale = d3.scale.linear()
.domain([0, maxWidth])
.range([150, w]);
var yScale = d3.scale.ordinal()
.domain(d3.range(MyPage.availableTags.length))
.rangeRoundBands([padding,h], 0.03);
var svg = d3.select("body")
.append("svg")
.attr({
width: w,
height: h,
});
//Function to make Bars
var makeBars = function() {
svg.selectAll("rect")
.data(queryList)
.enter()
.append("rect")
.attr({
width: function(d) { return (xScale(d[3]))},//# Patients
height: barHeight,
fill: function(d){
return "rgb(10, 150, " + (Math.floor(d[3]/2)) + ")";
},
y: function(d, i) {return (yScale(i))},
x: padding
})
//Adding the mouseOver function - Hover to highlight
.on("mouseover", function(d) {
var xPosition = w + (680 - xScale(d3.select(this).attr("width")));
var yPosition = parseFloat(d3.select(this).attr("y"));// - h/12;
d3.select("#tooltip")
.style("right", xPosition + "px")
.style("top", yPosition + "px")
.select("#value")
.text(d);
d3.select("#tooltip").classed("hidden", false);
})
.on("mouseout", function() {
d3.select("#tooltip").classed("hidden", true);
})
}
//Function to makeLabels
var makeLabels = function() {
svg.selectAll("text")
.data(queryList)
.enter()
.append("text")
.text(function(d) {return d[1]})//Product Name
.attr({
x: 0,
y: function(d,i) {return yScale(i)+buffer},
"font-size": 14,
fill: "blue",
v: function(d) { return (xScale(d[3]))}
})
}
}
//Sorting Feature - By magnitude of associated constant with drug
var sortOrder = false;
var sortBars = function() {
sortOrder = !sortOrder;
//Sort BarGraphs by magnitude
svg.selectAll("rect")
.sort(function(a,b)
{
if (sortOrder) {
return d3.ascending(b[3],a[3]); //Sorting BARS by #Patients
}
else {
return d3.ascending(a[3],b[3]);
}
})
//TRANSITIONS
.transition()
.duration(1000)
.attr("y", function(d, i) {
return yScale(i);
})
//Sort Drug Labels
svg.selectAll("text")
.sort(function(a,b)
{
if (sortOrder) {
return d3.ascending(b[3],a[3]); // Sorting LABELS by #Patients
}
else {
return d3.ascending(a[3],b[3]);
}
})
.transition()
.duration(1000)
.attr("y", function(d, i) {
return (yScale(i)+buffer);
})
};
d3.select("#sort button")
.on("click", function() {
sortBars();
})
d3.select("#scramble button")
.on("click", function() {
dataset = [];
//Create drugs
for (var i=0; i<176826 ; i++){
constant = Math.floor(Math.random()*w);
rel = ["drug" + (i+1), constant];
dataset.push(rel);
}
svg.selectAll("rect")
.data(dataset)
.transition()
.duration(150) // 250 ms is the default
.delay(function(d, i){
return i/dataset.length*1000;
})
.ease("linear")
.attr({
width: function(d) { return (xScale(d[3]))},
height: barHeight,
fill: function(d){
return "rgb(10, 150, " + (Math.floor(d[3]/2)) + ")";
},
y: function(d, i) {return yScale(i)},
x: padding
});
svg.selectAll("text")
.data(dataset)
.attr({
v: function(d) { return (xScale(d[3]))}
})
.text(function(d){
return d[0];
});
});
</script>
</body>