-
Notifications
You must be signed in to change notification settings - Fork 0
/
msPage_DXbyAge.php
219 lines (189 loc) · 7.2 KB
/
msPage_DXbyAge.php
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
<!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">
<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: blue;
}
#tooltip {
position: absolute;
width: 40px;
height: 20px;
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: 30px;
line-height: 20px;
}
body {
background-image:url(gray_jean/gray_jean.png)
}
h1 {
position: relative;
left: 1%;
top: 2%;
font-size: 50px;
}
.axis path,
.axis line {
fill: none;
stroke: black;
shape-rendering: crispEdges;
}
.axis text {
font-family: sans-serif;
font-size: 11px;
}
</style>
</head>
<body>
<h1>Age of Patients at Diagnosis of MS</h1>
<div id="tooltip" class="hidden">
<p><strong></strong></p>
<p><span id="value">20</span></p>
</div>
<script type="text/javascript">
var pL = [
<?php
$patientList = array();
ini_set('auto_detect_line_endings',TRUE);
$handle = fopen('msReportData_DXbyAge.txt','r') or die("Unable to open file!");
if($handle){
while ( ($data = fgetcsv($handle, 1000) ) !== FALSE ) {
$x = explode(chr(9), $data[0]);
$Age = $x[0];
$NumPatients = $x[1];
$patient = array(
$Age,
$NumPatients
);
array_push($patientList, $patient);
}
} else {
echo "Error reading File";
}
fclose($handle);
echo json_encode($patientList);
?>
];
//console.log(pL);
//Define Variables
var buffer = 50;
var barWidth = 25;
var barBuffer = 5
var w = (barWidth+barBuffer)*pL[0].length; // Width to include every entry
var h = 550;
//Defining maxHeight - vertical limit of the graph
var maxHeight = d3.max(pL[0], function(d) {
return parseInt(d[1]); // Number of patients
});
var maxWidth = d3.max(pL[0], function(d) {
return parseInt(d[0]);
});
var yScale = d3.scale.linear()
.domain([0, maxHeight])
.range([0, h]);
var yAxisScale = d3.scale.linear()
.domain([0, maxHeight])
.range([h, 0]);
var xScale = d3.scale.linear()
.domain([0, maxWidth])
.range([buffer, w]);
var svg = d3.select("body")
.append("svg")
.attr({
width: w,
height: h,
});
//Function to make Bars
var makeBars = function() {
svg.selectAll("rect")
.data(pL[0])
.enter()
.append("rect")
.attr({
width: barWidth,
height: function(d) {
return (yScale(parseInt(d[1])))
},
fill: function(d){
return "rgb(10, 150, 100)";
},
y: function(d){return h-(yScale(parseInt(d[1])))},
x: function(d,j) {return xScale(j)}
/*{
console.log(d[0][0]);
return (xScale(parseInt(d[0][0])))
}
*/
})
//Adding the mouseOver function - Hover to highlight
.on("mouseover", function(d) {
var xPosition = parseFloat(d3.select(this).attr("x"));
var yPosition = parseFloat(d3.select(this).attr("y"));
console.log("xPosition: " + xPosition + "; yPosition: " + yPosition);
d3.select("#tooltip")
.style("left", xPosition + "px")
.style("top", yPosition+70 + "px")
.select("#value")
.text(d[1]); //function(d) {return d[0]}),
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(pL[0])
.enter()
.append("text")
.text(function(d) {return d[0]})
.attr({
x: function(d,j) {return xScale(j) + barBuffer},
y: h-barBuffer,//function(d,j) {return h-(yScale(parseInt(d[1])))},
"font-size": 20,
fill: "white"
})
}
makeBars();
makeLabels();
//Interesting Note - this needs to go after making the bars/labels or else the labels will not appear
var yAxis = d3.svg.axis()
.scale(yAxisScale)
.orient("left")
.ticks(13);
svg.append("g")
.attr("class", "axis")
.attr("transform", "translate(" + (buffer-10) + ",0)")
.call(yAxis);
</script>
</body>