Browse code

minor revisions 20180219

fractalxaos authored on 02/19/2018 20:08:25
Showing 1 changed files
... ...
@@ -2,6 +2,7 @@
2 2
 <html>
3 3
 <head>
4 4
 <title>DIY Radiation</title>
5
+<meta name="viewport" content="width=device-width, initial-scale=1.0">
5 6
 <style>
6 7
 body {
7 8
     background-image: url("static/chalk.jpg");
... ...
@@ -124,11 +125,11 @@ Mode:
124 125
 <span class="chartNav">
125 126
 <ul class="chartNav">
126 127
 <li class="chartNav">Select charts:</li>
127
-<li class="chartNav"><text class="chartNav" onclick="show_charts(1)">
128
+<li class="chartNav"><text class="chartNav" onclick="setChartPeriod(1)">
128 129
 24 hours</text></li>
129
-<li class="chartNav"><text class="chartNav" onclick="show_charts(2)">
130
+<li class="chartNav"><text class="chartNav" onclick="setChartPeriod(2)">
130 131
 4 weeks</text></li>
131
-<li class="chartNav"><text class="chartNav" onclick="show_charts(3)">
132
+<li class="chartNav"><text class="chartNav" onclick="setChartPeriod(3)">
132 133
 12 months</text></li>
133 134
 </ul>
134 135
 </span>
... ...
@@ -164,7 +165,7 @@ Radiation Dose Chart</a> by Randall Monroe.</li>
164 165
 /* Globals */
165 166
 var radmonDataUrl = "dynamic/radmonOutputData.js";
166 167
 var httpRequest = new XMLHttpRequest();
167
-var graphPeriod;
168
+var graphPeriod = 1;
168 169
 
169 170
 /* Chart elements */
170 171
 var cpmChart_g = document.getElementById("cpmChart");
... ...
@@ -180,45 +181,47 @@ var mode_e = document.getElementById("mode");
180 181
 var status_e = document.getElementById("status");    
181 182
 
182 183
 function main() {
183
-    getRadmonData();
184
-    show_charts(1);
185
-    setInterval(getRadmonData, 5000);
186
-}
187
-
188
-function getRadmonData() {
184
+    /* Register call back function to process http requests */
189 185
     httpRequest.onreadystatechange = function() {
190 186
         if (httpRequest.readyState == 4 && httpRequest.status == 200) {
191 187
             var dataArray = JSON.parse(httpRequest.responseText);
192 188
             displayData(dataArray[0]);
193 189
         }
194 190
     };
191
+
192
+    getRadmonData();
193
+    getRadmonGraphs();
194
+    setInterval(getRadmonData, 5000);
195
+    setInterval(getRadmonGraphs, 300000);
196
+}
197
+
198
+function getRadmonData() {
195 199
     httpRequest.open("POST", radmonDataUrl, true);
196 200
     httpRequest.send();
197 201
 }
198 202
 
199
-function show_charts(n) {
203
+function setChartPeriod(n) {
200 204
     graphPeriod = n;
201 205
     getRadmonGraphs();   
202
-    setInterval(getRadmonGraphs, 300000);
203 206
 }
204 207
 
205 208
 function getRadmonGraphs() {
206 209
     var d = new Date;
210
+    var pfx;
207 211
 
208 212
     switch(graphPeriod) {
209 213
         case 1:
210
-            cpmChart_g.src = "dynamic/24hr_cpm.png?ver=" + d.getTime();
211
-            uSvChart_g.src = "dynamic/24hr_svperhr.png?ver=" + d.getTime();
214
+            pfx = "24hr_";
212 215
             break;
213 216
         case 2:
214
-            cpmChart_g.src = "dynamic/4wk_cpm.png?ver=" + d.getTime();
215
-            uSvChart_g.src = "dynamic/4wk_svperhr.png?ver=" + d.getTime();
217
+            pfx = "4wk_";
216 218
             break;
217 219
        case 3:
218
-            cpmChart_g.src = "dynamic/12m_cpm.png?ver=" + d.getTime();
219
-            uSvChart_g.src = "dynamic/12m_svperhr.png?ver=" + d.getTime();
220
+            pfx = "12m_";
220 221
             break;
221 222
     }
223
+    cpmChart_g.src = "dynamic/" + pfx + "cpm.png?ver=" + d.getTime();
224
+    uSvChart_g.src = "dynamic/" + pfx + "svperhr.png?ver=" + d.getTime();
222 225
 }
223 226
 
224 227
 function displayData(dataItem) {