Browse Source

Adjust y axis for unit selection. Fixes #7

Neal Wilson 11 years ago
parent
commit
b617890439
1 changed files with 24 additions and 4 deletions
  1. 24
    4
      config/Reports/chart.xml

+ 24
- 4
config/Reports/chart.xml View File

@@ -205,11 +205,23 @@
205 205
                         avgchange[i] = sum / parseInt(avgField.text);
206 206
                     }
207 207
                 }
208
+				// Calculate the domain of the primary y axis.
208 209
                 var maxy1 = 0;
210
+				var increment = 100; // Starting increment is 100 Lb.
211
+				if(unitBox.currentIndex == 0) {
212
+					increment = 110; // Starting increment is 50 Kg if Kg is requested.
213
+				}
209 214
                 while(maxy1 < Math.max(curpounds[days - 1], prevpounds[days - 1]))
210 215
                 {
211
-                    maxy1 += 100;
216
+					maxy1 += increment;
212 217
                 }
218
+				// Calculate the number of grid lines and loosen spacing if there are too many.
219
+				var divisions = maxy1 / increment;
220
+				while(divisions > 10) {
221
+					increment *= 2;
222
+					divisions = maxy1 / increment;
223
+				}
224
+				// Draw y axis grid lines.
213 225
                 var pos = 0;
214 226
                 while(pos <= maxy1)
215 227
                 {
@@ -220,7 +232,7 @@
220 232
                     output.writeAttribute("y2", (450/maxy1)*pos);
221 233
                     output.writeAttribute("style", "stroke:rgb(0,0,0);stroke-width:1;");
222 234
                     output.writeEndElement();
223
-                    pos += 100;
235
+					pos += increment;
224 236
                 }
225 237
                 var n = Math.min.apply(Math, change);
226 238
                 var m = Math.max.apply(Math, change);
@@ -323,9 +335,17 @@
323 335
                     output.writeAttribute("x", "0");
324 336
                     output.writeAttribute("y", -((450/maxy1)*i)+5);
325 337
                     output.writeAttribute("font-size", "12");
326
-                    output.writeCharacters(i);
338
+					switch(unitBox.currentIndex) {
339
+						case 0:
340
+							output.writeCharacters((i / 2.2).toFixed(0));
341
+							break;
342
+						case 1:
343
+						default:
344
+							output.writeCharacters(i);
345
+							break;
346
+					}
327 347
                     output.writeEndElement();
328
-                    i += 100;
348
+                    i += increment;
329 349
                 }
330 350
                 i = miny2;
331 351
                 while(i <= maxy2)

Loading…
Cancel
Save