Label x-axis from right to left.

This commit is contained in:
Olly Smith 2012-10-28 20:30:48 +00:00
parent df63f19358
commit a03926897b
3 changed files with 31 additions and 26 deletions

View File

@ -116,9 +116,9 @@ class Morris.Line extends Morris.Grid
labelBox = label.getBBox()
# ensure a minimum of `xLabelMargin` pixels between labels, and ensure
# labels don't overflow the container
if (prevLabelMargin is null or prevLabelMargin <= labelBox.x) and
if (prevLabelMargin is null or prevLabelMargin >= labelBox.x + labelBox.width) and
labelBox.x >= 0 and (labelBox.x + labelBox.width) < @el.width()
prevLabelMargin = labelBox.x + labelBox.width + xLabelMargin
prevLabelMargin = labelBox.x - xLabelMargin
else
label.remove()
if @options.parseTime
@ -126,13 +126,14 @@ class Morris.Line extends Morris.Grid
# where there's only one value in the series, we can't make a
# sensible guess for an x labelling scheme, so just use the original
# column label
drawLabel(@data[0].label, @data[0].x)
labels = [[@data[0].label, @data[0].x]]
else
for l in Morris.labelSeries(@xmin, @xmax, @width, @options.xLabels, @options.xLabelFormat)
drawLabel(l[0], l[1])
labels = Morris.labelSeries(@xmin, @xmax, @width, @options.xLabels, @options.xLabelFormat)
else
for row in @data
drawLabel(row.label, row.x)
labels = ([row.label, row.x] for row in @data)
labels.reverse()
for l in labels
drawLabel(l[0], l[1])
# draw the data series
#

View File

@ -510,7 +510,7 @@
};
Line.prototype.drawXAxis = function() {
var drawLabel, l, prevLabelMargin, row, xLabelMargin, ypos, _i, _j, _len, _len1, _ref, _ref1, _results, _results1,
var drawLabel, l, labels, prevLabelMargin, row, xLabelMargin, ypos, _i, _len, _results,
_this = this;
ypos = this.bottom + this.options.gridTextSize * 1.25;
xLabelMargin = 50;
@ -519,33 +519,37 @@
var label, labelBox;
label = _this.r.text(_this.transX(xpos), ypos, labelText).attr('font-size', _this.options.gridTextSize).attr('fill', _this.options.gridTextColor);
labelBox = label.getBBox();
if ((prevLabelMargin === null || prevLabelMargin <= labelBox.x) && labelBox.x >= 0 && (labelBox.x + labelBox.width) < _this.el.width()) {
return prevLabelMargin = labelBox.x + labelBox.width + xLabelMargin;
if ((prevLabelMargin === null || prevLabelMargin >= labelBox.x + labelBox.width) && labelBox.x >= 0 && (labelBox.x + labelBox.width) < _this.el.width()) {
return prevLabelMargin = labelBox.x - xLabelMargin;
} else {
return label.remove();
}
};
if (this.options.parseTime) {
if (this.data.length === 1 && this.options.xLabels === 'auto') {
return drawLabel(this.data[0].label, this.data[0].x);
labels = [[this.data[0].label, this.data[0].x]];
} else {
_ref = Morris.labelSeries(this.xmin, this.xmax, this.width, this.options.xLabels, this.options.xLabelFormat);
_results = [];
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
l = _ref[_i];
_results.push(drawLabel(l[0], l[1]));
}
return _results;
labels = Morris.labelSeries(this.xmin, this.xmax, this.width, this.options.xLabels, this.options.xLabelFormat);
}
} else {
_ref1 = this.data;
_results1 = [];
for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {
row = _ref1[_j];
_results1.push(drawLabel(row.label, row.x));
}
return _results1;
labels = (function() {
var _i, _len, _ref, _results;
_ref = this.data;
_results = [];
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
row = _ref[_i];
_results.push([row.label, row.x]);
}
return _results;
}).call(this);
}
labels.reverse();
_results = [];
for (_i = 0, _len = labels.length; _i < _len; _i++) {
l = labels[_i];
_results.push(drawLabel(l[0], l[1]));
}
return _results;
};
Line.prototype.drawSeries = function() {

2
morris.min.js vendored

File diff suppressed because one or more lines are too long