Skip to content

Commit

Permalink
Fix #53: Overlapping labels in charts
Browse files Browse the repository at this point in the history
  • Loading branch information
selaux committed Jun 29, 2014
1 parent 029e132 commit f7deb27
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
3 changes: 3 additions & 0 deletions frontend/stylesheets/style.styl
Expand Up @@ -27,6 +27,9 @@ dt
left: 20px
top: 5px
opacity: 1
.x_label
&.bottom
bottom: 0
&:hover strong
opacity: 0

Expand Down
15 changes: 13 additions & 2 deletions lib/views/mixins/renderHistoricalDataGraph.js
Expand Up @@ -2,6 +2,7 @@

var Rickshaw,
_ = require('lodash'),
$ = require(typeof window !== 'undefined' ? 'jquery' : 'cheerio'),
timeHelper = require('../../handlebars/helpers/time');

if (typeof window !== 'undefined') {
Expand Down Expand Up @@ -50,6 +51,8 @@ module.exports = function (attributes, element, graphOptions, hoverOptions) {
},

initializeGraph: function () {
var graphElement = this.$(element)[0];

if (hoverOptions.xFormatter) {
hoverOptions.xFormatter = hoverOptions.xFormatter.bind(this);
}
Expand All @@ -58,7 +61,7 @@ module.exports = function (attributes, element, graphOptions, hoverOptions) {
}

this.graph = new Rickshaw.Graph(_.extend({
element: this.$(element)[0],
element: graphElement,
renderer: 'area',
interpolation: 'linear',
stroke: true,
Expand All @@ -69,7 +72,15 @@ module.exports = function (attributes, element, graphOptions, hoverOptions) {
graph: this.graph,
xFormatter: function (value) {
return timeHelper(value * 1000);
}.bind(this)
}.bind(this),
onRender: function () {
var detailElement = $(this.element);
if (detailElement.find('.item.active').position().top < $(graphElement).height() / 4 ) {
detailElement.find('.x_label').addClass('bottom');
} else {
detailElement.find('.x_label').removeClass('bottom');
}
}
}, hoverOptions));
this.xAxis = new Rickshaw.Graph.Axis.Time({
graph: this.graph,
Expand Down

0 comments on commit f7deb27

Please sign in to comment.