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

View File

@ -271,7 +271,7 @@
var label, labelBox; var label, labelBox;
label = _this.r.text(_this.transX(xpos), ypos, labelText).attr('font-size', _this.options.gridTextSize).attr('fill', _this.options.gridTextColor); label = _this.r.text(_this.transX(xpos), ypos, labelText).attr('font-size', _this.options.gridTextSize).attr('fill', _this.options.gridTextColor);
labelBox = label.getBBox(); 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; return prevLabelMargin = labelBox.x + labelBox.width + xLabelMargin;
} else { } else {
return label.remove(); return label.remove();

2
morris.min.js vendored

File diff suppressed because one or more lines are too long