Morris.Line: separate generation of y-axis labels and hover text

This commit is contained in:
Brian Sanders 2012-09-28 15:10:48 -04:00
parent bd9f9d5580
commit 2903d086c6
3 changed files with 14 additions and 6 deletions

View File

@ -178,8 +178,8 @@ class Morris.Line
@dirty = false @dirty = false
# calculate grid dimensions # calculate grid dimensions
@maxYLabelWidth = Math.max( @maxYLabelWidth = Math.max(
@measureText(@yLabelFormat(@ymin), @options.gridTextSize).width, @measureText(@yAxisFormat(@ymin), @options.gridTextSize).width,
@measureText(@yLabelFormat(@ymax), @options.gridTextSize).width) @measureText(@yAxisFormat(@ymax), @options.gridTextSize).width)
@left = @maxYLabelWidth + @options.marginLeft @left = @maxYLabelWidth + @options.marginLeft
@width = @el.width() - @left - @options.marginRight @width = @el.width() - @left - @options.marginRight
@height = @el.height() - @options.marginTop - @options.marginBottom @height = @el.height() - @options.marginTop - @options.marginBottom
@ -236,7 +236,7 @@ class Morris.Line
for lineY in [firstY..lastY] by @yInterval for lineY in [firstY..lastY] by @yInterval
v = parseFloat(lineY.toFixed(@precision)) v = parseFloat(lineY.toFixed(@precision))
y = @transY(v) y = @transY(v)
@r.text(@left - @options.marginLeft/2, y, @yLabelFormat(v)) @r.text(@left - @options.marginLeft/2, y, @yAxisFormat(v))
.attr('font-size', @options.gridTextSize) .attr('font-size', @options.gridTextSize)
.attr('fill', @options.gridTextColor) .attr('fill', @options.gridTextColor)
.attr('text-anchor', 'end') .attr('text-anchor', 'end')
@ -419,6 +419,10 @@ class Morris.Line
tt.remove() tt.remove()
return ret return ret
# @private
yAxisFormat: (label) ->
@yLabelFormat(label)
# @private # @private
yLabelFormat: (label) -> yLabelFormat: (label) ->
"#{@options.preUnits}#{Morris.commas(label)}#{@options.postUnits}" "#{@options.preUnits}#{Morris.commas(label)}#{@options.postUnits}"

View File

@ -496,7 +496,7 @@
this.elementWidth = w; this.elementWidth = w;
this.elementHeight = h; this.elementHeight = h;
this.dirty = false; this.dirty = false;
this.maxYLabelWidth = Math.max(this.measureText(this.yLabelFormat(this.ymin), this.options.gridTextSize).width, this.measureText(this.yLabelFormat(this.ymax), this.options.gridTextSize).width); this.maxYLabelWidth = Math.max(this.measureText(this.yAxisFormat(this.ymin), this.options.gridTextSize).width, this.measureText(this.yAxisFormat(this.ymax), this.options.gridTextSize).width);
this.left = this.maxYLabelWidth + this.options.marginLeft; this.left = this.maxYLabelWidth + this.options.marginLeft;
this.width = this.el.width() - this.left - this.options.marginRight; this.width = this.el.width() - this.left - this.options.marginRight;
this.height = this.el.height() - this.options.marginTop - this.options.marginBottom; this.height = this.el.height() - this.options.marginTop - this.options.marginBottom;
@ -564,7 +564,7 @@
for (lineY = _i = firstY, _ref = this.yInterval; firstY <= lastY ? _i <= lastY : _i >= lastY; lineY = _i += _ref) { for (lineY = _i = firstY, _ref = this.yInterval; firstY <= lastY ? _i <= lastY : _i >= lastY; lineY = _i += _ref) {
v = parseFloat(lineY.toFixed(this.precision)); v = parseFloat(lineY.toFixed(this.precision));
y = this.transY(v); y = this.transY(v);
this.r.text(this.left - this.options.marginLeft / 2, y, this.yLabelFormat(v)).attr('font-size', this.options.gridTextSize).attr('fill', this.options.gridTextColor).attr('text-anchor', 'end'); this.r.text(this.left - this.options.marginLeft / 2, y, this.yAxisFormat(v)).attr('font-size', this.options.gridTextSize).attr('fill', this.options.gridTextColor).attr('text-anchor', 'end');
this.r.path("M" + this.left + "," + y + "H" + (this.left + this.width)).attr('stroke', this.options.gridLineColor).attr('stroke-width', this.options.gridStrokeWidth); this.r.path("M" + this.left + "," + y + "H" + (this.left + this.width)).attr('stroke', this.options.gridLineColor).attr('stroke-width', this.options.gridStrokeWidth);
} }
ypos = this.options.marginTop + this.height + this.options.marginBottom / 2; ypos = this.options.marginTop + this.height + this.options.marginBottom / 2;
@ -783,6 +783,10 @@
return ret; return ret;
}; };
Line.prototype.yAxisFormat = function(label) {
return this.yLabelFormat(label);
};
Line.prototype.yLabelFormat = function(label) { Line.prototype.yLabelFormat = function(label) {
return "" + this.options.preUnits + (Morris.commas(label)) + this.options.postUnits; return "" + this.options.preUnits + (Morris.commas(label)) + this.options.postUnits;
}; };

2
morris.min.js vendored

File diff suppressed because one or more lines are too long