Переглянути джерело

Adjust y axis for unit selection. Fixes #7

Neal Wilson 11 роки тому
джерело
коміт
b617890439
1 змінених файлів з 24 додано та 4 видалено
  1. 24
    4
      config/Reports/chart.xml

+ 24
- 4
config/Reports/chart.xml Переглянути файл

205
                         avgchange[i] = sum / parseInt(avgField.text);
205
                         avgchange[i] = sum / parseInt(avgField.text);
206
                     }
206
                     }
207
                 }
207
                 }
208
+				// Calculate the domain of the primary y axis.
208
                 var maxy1 = 0;
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
                 while(maxy1 < Math.max(curpounds[days - 1], prevpounds[days - 1]))
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
                 var pos = 0;
225
                 var pos = 0;
214
                 while(pos <= maxy1)
226
                 while(pos <= maxy1)
215
                 {
227
                 {
220
                     output.writeAttribute("y2", (450/maxy1)*pos);
232
                     output.writeAttribute("y2", (450/maxy1)*pos);
221
                     output.writeAttribute("style", "stroke:rgb(0,0,0);stroke-width:1;");
233
                     output.writeAttribute("style", "stroke:rgb(0,0,0);stroke-width:1;");
222
                     output.writeEndElement();
234
                     output.writeEndElement();
223
-                    pos += 100;
235
+					pos += increment;
224
                 }
236
                 }
225
                 var n = Math.min.apply(Math, change);
237
                 var n = Math.min.apply(Math, change);
226
                 var m = Math.max.apply(Math, change);
238
                 var m = Math.max.apply(Math, change);
323
                     output.writeAttribute("x", "0");
335
                     output.writeAttribute("x", "0");
324
                     output.writeAttribute("y", -((450/maxy1)*i)+5);
336
                     output.writeAttribute("y", -((450/maxy1)*i)+5);
325
                     output.writeAttribute("font-size", "12");
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
                     output.writeEndElement();
347
                     output.writeEndElement();
328
-                    i += 100;
348
+                    i += increment;
329
                 }
349
                 }
330
                 i = miny2;
350
                 i = miny2;
331
                 while(i <= maxy2)
351
                 while(i <= maxy2)

Завантаження…
Відмінити
Зберегти