Changeset 112
- Timestamp:
- 02/05/09 11:40:59 (16 months ago)
- Location:
- trunk/rapidandroid/org.rapidandroid/src/org/rapidandroid/activity
- Files:
-
- 3 modified
Legend:
- Unmodified
- Added
- Removed
-
trunk/rapidandroid/org.rapidandroid/src/org/rapidandroid/activity/Dashboard.java
r110 r112 506 506 return; 507 507 } 508 mListviewCursor.moveToLast(); 509 int msg_id = mListviewCursor.getInt(Message.COL_PARSED_MESSAGE_ID); 510 Message m = MessageTranslator.GetMessage(this, msg_id); 511 512 i.putExtra(ChartData.CallParams.START_DATE, m.getTimestamp().getTime()); 508 Date startDate; 509 if (mListviewCursor.getCount() > 0) { 510 mListviewCursor.moveToLast(); 511 int msg_id = mListviewCursor.getInt(Message.COL_PARSED_MESSAGE_ID); 512 Message m = MessageTranslator.GetMessage(this, msg_id); 513 startDate = m.getTimestamp(); 514 }else { 515 Calendar startCal = Calendar.getInstance(); 516 startCal.add(Calendar.DATE, -7); 517 startDate = startCal.getTime(); 518 519 } 520 i.putExtra(ChartData.CallParams.START_DATE, startDate); 513 521 i.putExtra(ChartData.CallParams.CHART_FORM, mChosenForm.getFormId()); 514 522 } else if (mShowAllMessages) { … … 522 530 e.printStackTrace(); 523 531 Calendar cal = Calendar.getInstance(); 524 cal. set(Calendar.DATE, -7);532 cal.add(Calendar.DATE, -7); 525 533 i.putExtra(ChartData.CallParams.START_DATE, cal.getTimeInMillis()); 526 534 } -
trunk/rapidandroid/org.rapidandroid/src/org/rapidandroid/activity/chart/ChartBroker.java
r109 r112 229 229 } 230 230 231 protected Date getNextValue(DateDisplayTypes displayType, Date date) { 232 Calendar cal = Calendar.getInstance(); 233 cal.setTime(date); 234 switch (displayType) { 235 case Hourly: 236 cal.add(Calendar.HOUR, 1); 237 break; 238 case Daily: 239 cal.add(Calendar.DATE, 1); 240 break; 241 case Weekly: 242 cal.add(Calendar.WEEK_OF_YEAR, 1); 243 break; 244 case Monthly: 245 cal.add(Calendar.MONTH, 1); 246 break; 247 case Yearly: 248 cal.add(Calendar.YEAR, 1); 249 break; 250 default: 251 throw new IllegalArgumentException("Bad display type: " + displayType); 252 } 253 return cal.getTime(); 254 } 255 256 protected boolean isBefore(DateDisplayTypes displayType, Date date1, Date date2) { 257 Calendar cal1 = Calendar.getInstance(); 258 cal1.setTime(date1); 259 Calendar cal2 = Calendar.getInstance(); 260 cal2.setTime(date2); 261 if (cal2.before(cal1)) { 262 return false; 263 } 264 // i really feel like there should be a cleaner way to do this but it escapes me 265 if (cal1.get(Calendar.YEAR) < cal2.get(Calendar.YEAR)) { 266 return true; 267 } else if (cal1.get(Calendar.YEAR) > cal2.get(Calendar.YEAR) || displayType == DateDisplayTypes.Yearly ) { 268 return false; 269 } 270 // we know the years are the same and we're comparing less than years 271 if (cal1.get(Calendar.MONTH) < cal2.get(Calendar.MONTH)) { 272 return true; 273 } else if (cal1.get(Calendar.MONTH) > cal2.get(Calendar.MONTH) || displayType == DateDisplayTypes.Monthly) { 274 return false; 275 } 276 // we know months and years are the same and we're comparing less than months 277 if (cal1.get(Calendar.WEEK_OF_YEAR) < cal2.get(Calendar.WEEK_OF_YEAR)) { 278 return true; 279 } else if (cal1.get(Calendar.WEEK_OF_YEAR) > cal2.get(Calendar.WEEK_OF_YEAR) || displayType == DateDisplayTypes.Weekly) { 280 return false; 281 } 282 // we know months, years, and weeks are the same and we're comparing less than weeks 283 if (cal1.get(Calendar.DATE) < cal2.get(Calendar.DATE)) { 284 return true; 285 } else if (cal1.get(Calendar.DATE) > cal2.get(Calendar.DATE) || displayType == DateDisplayTypes.Daily) { 286 return false; 287 } 288 // we know months, years,weeks, and days are the same and we're comparing less than days 289 if (cal1.get(Calendar.HOUR) < cal2.get(Calendar.HOUR)) { 290 return true; 291 } 292 // anything else is not before 293 return false; 294 } 295 296 231 297 protected Date getDate(DateDisplayTypes displayType, String string) { 232 298 // TODO Auto-generated method stub -
trunk/rapidandroid/org.rapidandroid/src/org/rapidandroid/activity/chart/form/FormDataBroker.java
r109 r112 130 130 // result.put("points", getShowTrue()); 131 131 // result.put("xaxis", getDateOptions()); 132 return new JSONGraphData(prepareDateData(xVals, yVals),loadOptionsForDateGraph(xVals ) );132 return new JSONGraphData(prepareDateData(xVals, yVals),loadOptionsForDateGraph(xVals, false) ); 133 133 } catch (Exception ex) { 134 134 … … 166 166 } 167 167 168 private JSONArray prepareDateHistogramData(DateDisplayTypes displayType, Date[] xvals, int[] yvals, String legend) throws JSONException { 169 JSONArray outerArray = new JSONArray(); 170 JSONArray innerArray = new JSONArray(); 171 int datalen = xvals.length; 172 Date prevVal = null; 173 for (int i = 0; i < datalen; i++) { 174 Date thisVal = xvals[i]; 175 if (prevVal != null) { 176 // add logic to fill in zeros 177 Date nextInSeries = getNextValue(displayType, prevVal); 178 while (isBefore(displayType, nextInSeries, thisVal)) 179 { 180 JSONArray elem = new JSONArray(); 181 elem.put(nextInSeries.getTime()); 182 elem.put(0); 183 innerArray.put(elem); 184 nextInSeries = getNextValue(displayType, nextInSeries); 185 } 186 } 187 JSONArray elem = new JSONArray(); 188 elem.put(xvals[i].getTime()); 189 elem.put(yvals[i]); 190 innerArray.put(elem); 191 prevVal = thisVal; 192 } 193 JSONObject finalObj = new JSONObject(); 194 finalObj.put("data", innerArray); 195 finalObj.put("label", legend); 196 outerArray.put(finalObj); 197 return outerArray; 198 } 199 168 200 private JSONArray prepareDateData(Date[] xvals, int[] yvals) { 169 201 JSONArray outerArray = new JSONArray(); … … 237 269 //result.put("xaxis", getXaxisOptions(xVals)); 238 270 // todo 239 return new JSONGraphData(prepareDate Data(xVals, yVals),loadOptionsForDateGraph(xVals) );271 return new JSONGraphData(prepareDateHistogramData(displayType, xVals, yVals, legend),loadOptionsForDateGraph(xVals, true) ); 240 272 241 273 } catch (Exception ex) { … … 350 382 return arr; 351 383 } 352 353 private JSONObject loadOptionsForDateGraph(Date[] vals ) throws JSONException {384 385 private JSONObject loadOptionsForDateGraph(Date[] vals, boolean displayLegend) throws JSONException { 354 386 355 387 JSONObject toReturn = new JSONObject(); 356 388 //bars: { show: true }, points: { show: false }, xaxis: { mode: "time", timeformat:"%y/%m/%d" } 357 toReturn.put("bars", getShowTrue()); 389 toReturn.put("bars", getShowFalse()); 390 toReturn.put("lines", getShowTrue()); 358 391 toReturn.put("points", getShowFalse()); 359 392 toReturn.put("xaxis", getXaxisOptionsForDate()); 393 if (displayLegend) { 394 toReturn.put("legend", getShowTrue()); 395 } 360 396 return toReturn; 361 397 }