Make sure x-axis labels don't overflow.

Fixes #63.
This commit is contained in:
Olly Smith 2012-06-08 22:39:06 +01:00
parent 0015b28ef2
commit acfec20bcf
3 changed files with 6 additions and 4 deletions

View File

@ -237,8 +237,10 @@ class Morris.Line
.attr('font-size', @options.gridTextSize)
.attr('fill', @options.gridTextColor)
labelBox = label.getBBox()
# ensure a minimum of `xLabelMargin` pixels between labels
if prevLabelMargin is null or prevLabelMargin <= labelBox.x
# 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
labelBox.x >= 0 and (labelBox.x + labelBox.width) < @el.width()
prevLabelMargin = labelBox.x + labelBox.width + xLabelMargin
else
label.remove()

View File

@ -271,7 +271,7 @@
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) {
if ((prevLabelMargin === null || prevLabelMargin <= labelBox.x) && labelBox.x >= 0 && (labelBox.x + labelBox.width) < _this.el.width()) {
return prevLabelMargin = labelBox.x + labelBox.width + xLabelMargin;
} else {
return label.remove();

2
morris.min.js vendored

File diff suppressed because one or more lines are too long