Skip to content

Commit

Permalink
Merge branch 'user-chart-labels' into staging
Browse files Browse the repository at this point in the history
  • Loading branch information
milafrerichs committed Sep 3, 2015
2 parents 8d90609 + fea8bb8 commit 0df09d3
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 2 deletions.
22 changes: 22 additions & 0 deletions public/javascripts/helpers/helper.js
Expand Up @@ -86,5 +86,27 @@ window.helper = {
dataArray.push(transformObject[o]);
}
return dataArray;
},
redrawChartLabels: function(chart) {
var i, data, dataLength, row, pos, date, label, options;
data = chart.data;
options = chart.options;
dataLength = data.length;
pos = chart.elementHeight - options.padding;
for(i=0;i<dataLength;i++) {
row = data[dataLength - 1 - i];
date = row.src.date;
if(date.getHours() % 6 === 0 && date.getMinutes() === 0) {
label = timeFormat.format("%I %p")(date);
if(date.getHours() === 0) {
label = timeFormat.format("%a %I %p")(date);
}
chart.raphael.text(row._x, pos, label)
.attr('font-size', options.gridTextSize)
.attr('font-family', options.gridTextFamily)
.attr('font-weight', options.gridTextWeight)
.attr('fill', options.gridTextColor)
}
}
}
}
4 changes: 2 additions & 2 deletions public/javascripts/traffic.js
Expand Up @@ -54,13 +54,13 @@
stacked: true,
barColors: ["#265C8D", "#B26E00"],
hideHover: 'always',
xLabelMargin: 100,
xLabelFormat: function(data){
return timeFormat.format("%I %p")(data.label);
return "";
},
});
}
traffic.chart.setData(dataArray);
helper.redrawChartLabels(traffic.chart);
}
},
init: function(){
Expand Down
22 changes: 22 additions & 0 deletions tests/helperSpec.js
Expand Up @@ -99,5 +99,27 @@ describe("helper", function() {
expect(subject.arrayFromObject(dataObject)[0]).to.eql({test: 'Test'});
});
});
describe("redrawChartLabels", function() {
beforeEach(function() {
options = { gridTextSize: 0, gridTextFamily: '', gridTextWeight: 0, padding: 0 };
data = [];
raphael = sandbox.stub();
chart = { data: data, options: options, elementHeight: 0, raphael: raphael };
});
context("no data from 6-12", function() {
it("calls raphael never", function() {
subject.redrawChartLabels(chart);
expect(raphael).to.not.have.been.called;
});
});
context("data at 6", function() {
beforeEach(function() {
date = new Date();
date.setHours(6,0,0);
data = [{src: { date: date}, _x: 0}];
chart = { data: data, options: options, elementHeight: 0, raphael: raphael };
});
});
});
});

0 comments on commit 0df09d3

Please sign in to comment.