Changeset 102
- Timestamp:
- 02/03/09 18:48:27 (5 months ago)
- Location:
- trunk/rapidandroid/org.rapidandroid
- Files:
-
- 1 added
- 3 modified
Legend:
- Unmodified
- Added
- Removed
-
trunk/rapidandroid/org.rapidandroid/assets/flot/html/basechart.html
r100 r102 21 21 graphObj.style.height = gheight; 22 22 } 23 function GotGraph(g data) {24 $.plot($("#placeholder"), g data);23 function GotGraph(gData, gOptions) { 24 $.plot($("#placeholder"), gData, gOptions); 25 25 window.graphdata.finishGraph(); 26 26 } -
trunk/rapidandroid/org.rapidandroid/res/layout/tablerow.xml
r90 r102 5 5 <TableRow android:id="@+id/TableRow01" android:layout_width="fill_parent" android:layout_height="wrap_content"> 6 6 <TextView android:id="@+id/TextView01" android:layout_height="wrap_content" android:text="asdfdasfasfaffdffdfdaadsf" android:layout_weight="1" android:layout_gravity="left"></TextView> 7 8 9 10 11 12 13 14 15 7 <TextView android:id="@+id/TextView01" android:layout_width="wrap_content" 8 android:layout_height="wrap_content" android:text="qwerqwrqrqrqr" android:layout_weight="1"></TextView> 9 <TextView android:id="@+id/TextView01" android:layout_width="wrap_content" 10 android:layout_height="wrap_content" android:text="ZXCZXCczCczcCZCC" android:layout_weight="1"></TextView> 11 <TextView android:id="@+id/TextView01" android:layout_width="wrap_content" 12 android:layout_height="wrap_content" android:text="rutyututuytu" android:layout_weight="1"></TextView> 13 <TextView android:id="@+id/TextView01" android:layout_height="wrap_content" android:text="fghjfjfjfhjfj" android:layout_weight="1"></TextView> 14 <TextView android:id="@+id/TextView01" android:layout_width="wrap_content" 15 android:layout_height="wrap_content" android:layout_weight="1" android:text="2345235235243535"></TextView> 16 16 </TableRow> 17 17 </TableLayout> -
trunk/rapidandroid/org.rapidandroid/src/org/rapidandroid/activity/chart/form/FormDataBroker.java
r100 r102 6 6 7 7 import org.json.JSONArray; 8 import org.json.JSONException; 8 9 import org.json.JSONObject; 9 10 import org.rapidandroid.activity.chart.IChartBroker; 11 import org.rapidandroid.activity.chart.JSONGraphData; 10 12 import org.rapidandroid.data.RapidSmsDBConstants; 11 13 import org.rapidandroid.data.SmsDbHelper; … … 76 78 height = height - 50; 77 79 78 JSONArray arr = new JSONArray(); 79 80 JSONArray data = getEmptyData(); 81 JSONObject options = new JSONObject(); 82 JSONGraphData allData = null; 80 83 if (fieldToPlot == null) { 81 84 //we're going to do all messages over timereturn; 82 a rr.put(loadMessageOverTimeHistogram());85 allData = loadMessageOverTimeHistogram(); 83 86 } else if (fieldToPlot.getFieldType().getItemType().equals("word")) { 84 a rr.put(loadHistogramFromField());87 allData = loadHistogramFromField(); 85 88 } else { 86 arr.put(loadNumericLine()); 87 } 88 89 allData = loadNumericLine(); 90 //data.put(loadNumericLine()); 91 } 92 if (allData != null) { 93 data = allData.getData(); 94 options = allData.getOptions(); 95 } 96 System.out.println(data.toString()); 97 System.out.println(options.toString()); 98 89 99 mAppView.loadUrl("javascript:SetGraph(\"" + width + "px\", \"" + height 90 100 + "px\")"); 91 mAppView.loadUrl("javascript:GotGraph(" + arr.toString() + ")"); 92 } 93 94 private JSONObject loadNumericLine() { 101 mAppView.loadUrl("javascript:GotGraph(" + data.toString() + "," + options.toString() + ")"); 102 } 103 104 105 private JSONGraphData loadNumericLine() { 95 106 JSONObject result = new JSONObject(); 96 107 SQLiteDatabase db = rawDB.getReadableDatabase(); … … 124 135 if (barCount == 0) { 125 136 cr.close(); 126 return result;127 137 } else { 128 138 Date[] xVals = new Date[barCount]; … … 144 154 145 155 try { 146 result.put("label", fieldToPlot.getName()); 147 result.put("data", prepareDateData(xVals, yVals)); 148 result.put("label", fieldToPlot.getName()); 149 result.put("lines", getShowTrue()); 150 result.put("points", getShowTrue()); 151 result.put("xaxis", getDateOptions()); 156 // result.put("label", fieldToPlot.getName()); 157 // result.put("data", prepareDateData(xVals, yVals)); 158 // result.put("label", fieldToPlot.getName()); 159 // result.put("lines", getShowTrue()); 160 // result.put("points", getShowTrue()); 161 // result.put("xaxis", getDateOptions()); 162 return new JSONGraphData(prepareDateData(xVals, yVals),loadOptionsForDateGraph(xVals) ); 152 163 } catch (Exception ex) { 153 164 154 165 } 155 cr.close(); 156 return result; 157 } 158 166 finally { 167 if (!cr.isClosed()) { 168 cr.close(); 169 } 170 } 171 172 } 173 // either there was no data or something bad happened 174 return new JSONGraphData(getEmptyData(), new JSONObject()); 175 } 176 177 178 private JSONArray getEmptyData() { 179 JSONArray toReturn = new JSONArray(); 180 JSONArray innerArray = new JSONArray(); 181 innerArray.put(0); 182 innerArray.put(0); 183 toReturn.put(innerArray); 184 return toReturn; 159 185 } 160 186 … … 171 197 172 198 private JSONArray prepareDateData(Date[] xvals, int[] yvals) { 173 JSONArray arr = new JSONArray(); 199 JSONArray outerArray = new JSONArray(); 200 JSONArray innerArray = new JSONArray(); 174 201 int datalen = xvals.length; 175 202 for (int i = 0; i < datalen; i++) { … … 177 204 elem.put(xvals[i].getTime()); 178 205 elem.put(yvals[i]); 179 arr.put(elem);180 } 181 return arr;182 }183 184 private JSONObject loadMessageOverTimeHistogram() {185 JSONObject result = new JSONObject();206 innerArray.put(elem); 207 } 208 outerArray.put(innerArray); 209 return outerArray; 210 } 211 212 private JSONGraphData loadMessageOverTimeHistogram() { 186 213 SQLiteDatabase db = rawDB.getReadableDatabase(); 187 214 Calendar startCal = Calendar.getInstance(); … … 246 273 if (barCount == 0) { 247 274 cr.close(); 248 return result;249 275 } else { 250 276 String[] xVals = new String[barCount]; … … 259 285 260 286 try { 287 //result.put("label", fieldToPlot.getName()); 288 //result.put("data", prepareData(xVals, yVals)); 289 //result.put("bars", getShowTrue()); 290 //result.put("xaxis", getXaxisOptions(xVals)); 291 // todo 292 JSONObject result = new JSONObject(); 293 //return new JSONGraphData(prepareHistogramData(xVals, yVals),loadOptionsForHistogram(xVals) ); 294 261 295 result.put("label", legend); 262 296 result.put("data", prepareData(yVals)); … … 264 298 result.put("points", getShowFalse()); 265 299 result.put("xaxis", getXaxisOptions(xVals)); 300 JSONArray values = new JSONArray(); 301 values.put(result); 302 return new JSONGraphData(values, new JSONObject()); 266 303 267 304 } catch (Exception ex) { 268 305 306 } finally { 307 if (!cr.isClosed()) { 308 cr.close(); 309 } 269 310 } 270 cr.close(); 271 return result; 272 } 273 274 } 275 276 277 private JSONObject loadHistogramFromField() { 278 JSONObject result = new JSONObject(); 311 } 312 // either there was no data or something bad happened 313 return new JSONGraphData(getEmptyData(), new JSONObject()); 314 } 315 316 317 /** 318 * Should return a two element array - the first element is the data, 319 * the second are the options 320 * @return 321 */ 322 private JSONGraphData loadHistogramFromField() { 323 //JSONObject result = new JSONObject(); 279 324 SQLiteDatabase db = rawDB.getReadableDatabase(); 280 325 … … 307 352 int barCount = cr.getCount(); 308 353 309 if (barCount == 0) { 310 return result; 311 } else { 354 if (barCount != 0) { 312 355 String[] xVals = new String[barCount]; 313 356 int[] yVals = new int[barCount]; … … 324 367 325 368 try { 326 result.put("label", fieldToPlot.getName());327 result.put("data", prepareData(yVals));328 result.put("bars", getShowTrue());329 result.put("xaxis", getXaxisOptions(xVals));330 369 //result.put("label", fieldToPlot.getName()); 370 //result.put("data", prepareData(xVals, yVals)); 371 //result.put("bars", getShowTrue()); 372 //result.put("xaxis", getXaxisOptions(xVals)); 373 return new JSONGraphData(prepareHistogramData(xVals, yVals),loadOptionsForHistogram(xVals) ); 331 374 } catch (Exception ex) { 332 375 376 } finally { 377 if (!cr.isClosed()) { 378 cr.close(); 379 } 333 380 } 334 cr.close(); 335 return result; 336 } 337 381 } 382 // either there was no data or something bad happened 383 return new JSONGraphData(getEmptyData(), new JSONObject()); 384 } 385 386 private JSONArray prepareHistogramData(String[] names, int[] counts) throws JSONException { 387 // TODO Auto-generated method stub 388 JSONArray arr = new JSONArray(); 389 int datalen = names.length; 390 for (int i = 0; i < datalen; i++) { 391 392 JSONObject elem = new JSONObject(); 393 // values will just be an array of length 1 with a single value 394 JSONArray values = new JSONArray(); 395 JSONArray value = new JSONArray(); 396 value.put(i); 397 value.put(counts[i]); 398 values.put(value); 399 elem.put("data", values); 400 elem.put("bars", getShowTrue()); 401 elem.put("label", names[i]); 402 arr.put(elem); 403 } 404 return arr; 405 } 406 407 private JSONObject loadOptionsForDateGraph(Date[] vals) throws JSONException { 408 409 JSONObject toReturn = new JSONObject(); 410 //bars: { show: true }, points: { show: false }, xaxis: { mode: "time", timeformat:"%y/%m/%d" } 411 toReturn.put("bars", getShowTrue()); 412 toReturn.put("points", getShowFalse()); 413 toReturn.put("xaxis", getXaxisOptionsForDate()); 414 return toReturn; 415 } 416 417 private JSONObject getXaxisOptionsForDate() throws JSONException { 418 JSONObject toReturn = new JSONObject(); 419 toReturn.put("mode", "time"); 420 toReturn.put("timeformat", "%m/%d/%y"); 421 return toReturn; 422 } 423 424 private JSONObject loadOptionsForHistogram(String[] labels) throws JSONException { 425 426 JSONObject toReturn = new JSONObject(); 427 toReturn.put("xaxis", this.getXaxisOptions(labels)); 428 return toReturn; 338 429 } 339 430