Skip to content

Commit

Permalink
improve data processing and sorting
Browse files Browse the repository at this point in the history
  • Loading branch information
bretdavidson committed Jul 26, 2013
1 parent 12fcac7 commit 7943fe2
Showing 1 changed file with 18 additions and 22 deletions.
40 changes: 18 additions & 22 deletions analysis/reports/calendar/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,42 +39,38 @@
$("#legend").hide();
console.log("error: ", e);
},
// Sort data according to date
sortData: function (a, b) {
return new Date(a.date).getTime() - new Date(b.date).getTime();
sortData: function (response) {
return _.sortBy(
_.map(response, function (count, date) {
return {
date: date,
count: count
};
}),
function (obj) {
return obj.date;
}
);
},
processData: function (response) {
var dfd = $.Deferred(),
count,
counts = [],
self = this;
var dfd = $.Deferred();

// Does response have enough vlues to draw meaningful graph?
if (Object.keys(response).length < 2) {
dfd.reject('Not enough data.')
}

for (count in response) {
if (response.hasOwnProperty(count)) {
counts.push({
date: count,
count: response[count]
});
}
dfd.reject('Not enough data.');
}

counts.sort(self.sortData);
dfd.resolve(counts);
dfd.resolve(this.sortData(response));

return dfd.promise();
},
drawChart: function (counts) {
var chart;
chart = Calendar();

d3.select('#chart')
.datum(counts)
.call(chart);
d3.select('#chart')
.datum(counts)
.call(chart);
}
};

Expand Down

0 comments on commit 7943fe2

Please sign in to comment.