diff --git a/index.html b/index.html
index ff7ea09..f15e322 100644
--- a/index.html
+++ b/index.html
@@ -179,225 +179,229 @@
@@ -491,7 +495,7 @@
Create A Bar Chart With D3 JavaScript
var pie = d3.layout.pie()
.sort(null)
.value(function(d) {
- return d.value;
+ return d.size;
});
var arc = d3.svg.arc()
@@ -625,7 +629,7 @@ Create A Bar Chart With D3 JavaScript
.append("text")
.attr("dy", ".35em")
.text(function(d) {
- return (d.data.label+": "+d.value);
+ return (d.data.label+": "+d.size);
});
function midAngle(d){
@@ -655,7 +659,7 @@ Create A Bar Chart With D3 JavaScript
};
})
.text(function(d) {
- return (d.data.label+": "+d.value);
+ return (d.data.label+": "+d.size);
});
@@ -879,8 +883,63 @@ Create A Bar Chart With D3 JavaScript
function createBarChart(data) {
console.log('received bar query response');
- console.log('Creating a bar graph with: ' + JSON.stringify(data));//data contains the message contents
- //call function to create chart
+ console.log(data);
+ var childData = []
+ data.forEach(function (d){
+ if(d.avg_hotttnesss.value != null){
+ var obj = {name: d.key, size: (d.avg_hotttnesss.value) * 100}
+ childData.push(obj);
+ }
+ });
+ console.log('child data: ');
+ console.log(childData)
+
+ var currentDecade = 1920
+ var sum = 0;
+ var count = 1;
+ var totalSum = 0;
+
+ var parentData = [];
+ var tempChild = [];
+ var maxAvg = -1;
+
+ childData.forEach(function(d){
+ if(d.name != 0){
+ if(d.name > (currentDecade + 9)){
+ if(count > 1){
+ var obj = {name: currentDecade, size: (sum / count), children: tempChild};
+ totalSum += (sum / count);
+ parentData.push(obj)
+ if((sum / count) > maxAvg){
+ maxAvg = sum / count;
+ }
+ sum = 0;
+ count = 1;
+ tempChild = [];
+ }
+ currentDecade = Math.floor(d.name / 10) * 10;
+ }
+ tempChild.push(d);
+ sum += d.size;
+ count ++;
+ }
+
+
+ });
+ var obj = {name: currentDecade, size: sum}
+ totalSum += sum;
+ parentData.push(obj)
+
+ // this is an object array
+ console.log('parentdata')
+ console.log(parentData)
+ console.log(currentDecade)
+
+ var finalData = {name: "barChart", size: (totalSum / parentData.length), children: parentData}
+
+ barGraph(finalData, maxAvg);
+
+
}
diff --git a/server.js b/server.js
index 490dac8..ff8d6f5 100644
--- a/server.js
+++ b/server.js
@@ -70,9 +70,6 @@ var server = http.createServer(function (req, res){
case '/index.html':
sendFile(res, 'index.html')
break
- case '/index2.html':
- sendFile(res, 'index2.html')
- break
case '/README.md':
sendFile(res, 'README.md', 'text/md')
break
@@ -101,7 +98,6 @@ function sendFile(res, filename, contentType){
// SAMPLE FUNCTIONS START HERE:
-
// NOTE: all min/max years are inclusive (for exclusive do gte-->gt and lte-->lt)
// for most of these, also consider doing when the year is 0 (that's default/no year)
function sampleScatterPlotByYears(min_year, max_year){
@@ -110,7 +106,7 @@ function sampleScatterPlotByYears(min_year, max_year){
type: 'song',
body: {
_source: [
- "song_hotttnesss", // categories here
+ "song_hotttnesss", // categories here, it's artist_hottnesss and song_hotttnesss
"artist_familiarity"
// consider including artist name + song name so we can mouse over things maybe
],
@@ -131,7 +127,7 @@ function sampleScatterPlotByYears(min_year, max_year){
})
}
-function barGraphByDecades(){
+function barGraphByYears(){
client.search({
index: 'million_songs',
type: 'song',
@@ -148,7 +144,7 @@ function barGraphByDecades(){
by_year: {
histogram: {
field: "year",
- interval: 10, // 10 years
+ interval: 1, // 10 years
min_doc_count: 1 // don't return results unless there's at least 1 thing there
},
aggs: {
@@ -163,7 +159,7 @@ function barGraphByDecades(){
}
}).then(function (resp){
console.log(resp)
- barYearQueryEmitter(resp);
+ barYearQueryEmitter(resp.aggregations.by_year.buckets);
}, function (err){
console.trace(err.message);
});
@@ -221,7 +217,7 @@ function topTitleWords(min_year, max_year){
function barYearQuery() {
console.log('recieved a bar year request');
- barGraphByDecades();
+ barGraphByYears();
}
function barYearQueryEmitter(result) {