Skip to content

Commit

Permalink
Removed Google dependencies and datatable for chart data. JSON is now…
Browse files Browse the repository at this point in the history
… formatted to dygraph native array format.
  • Loading branch information
elcojacobs committed Feb 16, 2014
1 parent df03c83 commit deaef68
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 23 deletions.
1 change: 0 additions & 1 deletion index.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@
<script type="text/javascript" src="js/jquery-1.9.1.js"></script>
<script type="text/javascript" src="js/jquery-ui-1.10.3.custom.min.js"></script>
<script type="text/javascript" src="js/jquery-ui-timepicker-addon.js"></script>
<script type="text/javascript" src="http://www.google.com/jsapi"></script>
<script type="text/javascript" src="js/spin.js"></script>
<script type="text/javascript" src="js/dygraph-combined.js"></script>
<script type="text/javascript">
Expand Down
54 changes: 34 additions & 20 deletions js/beer-chart.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,36 @@ function getState(g, row) {
"use strict";
return (row>= g.numRows()) ? 0 : g.getValue(row, STATE_COLUMN);
}

/**
* Converts json data to Dychart array format
* @param jsonData the data in json format
* @returns {"values": array, "labels": array} The same data, but in Dygraph array format
*/
function toDygraphArray(jsonData) {
"use strict";
var i, j, cols = jsonData.cols, rows = jsonData.rows, dataArray=[], labelsArray = [], row;

for (i = 0; i < cols.length; i++){
labelsArray.push(cols[i].label);
}
for (i = 0; i < rows.length; i++){
row = [];
var date = eval("new " + rows[i].c[0].v); // this is nasty and should be replaced!
row.push(date); // push date
for (j = 1; j < rows[i].c.length; j++) {
if (rows[i].c[j]) {
row.push(rows[i].c[j].v); // push other values
}
else{
row.push(null);
}
}
dataArray.push(row)
}
return {"values": dataArray, "labels": labelsArray};
}

function getTime(g, row) {
"use strict";
if (row>= g.numRows()){
Expand Down Expand Up @@ -279,7 +309,7 @@ function drawBeerChart(beerToDraw, div){
}

$.post("get_beer_data.php", {"beername": beerToDraw}, function(answer) {
var combinedJson = {};
var combinedJson = {};
try{
combinedJson = $.parseJSON(answer);
} catch (e) {
Expand All @@ -296,16 +326,16 @@ function drawBeerChart(beerToDraw, div){

return;
}

var beerData = new google.visualization.DataTable(combinedJson);
var beerData = toDygraphArray(combinedJson);

var tempFormat = function(y) {
return parseFloat(y).toFixed(2) + "\u00B0 " + window.tempFormat;
};

var chart = new Dygraph.GVizChart(document.getElementById(div));
chart.draw(
beerData, {
beerData.values, {
labels: beerData.labels,
colors: chartColors,
axisLabelFontSize:12,
animatedZooms: true,
Expand All @@ -316,22 +346,6 @@ function drawBeerChart(beerToDraw, div){
displayAnnotationsFilter:true,
//showRangeSelector: true,
strokeWidth: 1,

"Beer setting" : {
// strokePattern: [ 5, 5 ],
// strokeWidth: 1
},
"Fridge setting" : {
// strokePattern: [ 5, 5 ],
// strokeWidth: 1
},
"Beer temperature" : {
// strokePattern: [ 5, 5 ],
// strokeWidth: 2
},
"Room temp" : {
// strokeWidth: 1
},
axes: {
y : { valueFormatter: tempFormat }
},
Expand Down
2 changes: 0 additions & 2 deletions js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -377,8 +377,6 @@ function beerNameDialogResult($body, $backButton, result){
$body.append($("<span class='dialog-result-message'>" + result.statusMessage + "</span>"));
}

google.load('visualization', '1', {packages: ['table']});

$(document).ready(function(){
"use strict";
$(".script-status").button({ icons: {primary: "ui-icon-alert" } });
Expand Down

0 comments on commit deaef68

Please # to comment.