mirror of
https://github.com/morrisjs/morris.js.git
synced 2024-09-21 02:31:32 +02:00
Added 'preunits' options and renamed 'units' to 'postunits'. 'units' option will be fill 'postunits' automatically to preserve backwards compatibility.
This commit is contained in:
parent
5e4191060c
commit
0079d307f3
@ -14,6 +14,9 @@ class Morris.Line
|
||||
@el = $ document.getElementById(options.element)
|
||||
else
|
||||
@el = $ options.element
|
||||
#backwards compatibility for units -> postunits
|
||||
if typeof options.units is 'string'
|
||||
options.postunits = options.units
|
||||
@options = $.extend {}, @defaults, options
|
||||
# bail if there's no data
|
||||
if @options.data is undefined or @options.data.length is 0
|
||||
@ -59,7 +62,8 @@ class Morris.Line
|
||||
smooth: true
|
||||
hideHover: false
|
||||
parseTime: true
|
||||
units: ''
|
||||
preunits: ''
|
||||
postunits: ''
|
||||
dateFormat: (x) -> new Date(x).toString()
|
||||
xLabels: 'auto'
|
||||
xLabelFormat: null
|
||||
@ -143,8 +147,8 @@ class Morris.Line
|
||||
if @elementWidth != w or @elementHeight != h
|
||||
# calculate grid dimensions
|
||||
@maxYLabelWidth = Math.max(
|
||||
@measureText(@options.ymin + @options.units, @options.gridTextSize).width,
|
||||
@measureText(@options.ymax + @options.units, @options.gridTextSize).width)
|
||||
@measureText(@options.preunits + @options.ymin + @options.postunits, @options.gridTextSize).width,
|
||||
@measureText(@options.preunits + @options.ymax + @options.postunits, @options.gridTextSize).width)
|
||||
@left = @maxYLabelWidth + @options.marginLeft
|
||||
@width = @el.width() - @left - @options.marginRight
|
||||
@height = @el.height() - @options.marginTop - @options.marginBottom
|
||||
@ -200,7 +204,7 @@ class Morris.Line
|
||||
for lineY in [firstY..lastY] by yInterval
|
||||
v = Math.floor(lineY)
|
||||
y = @transY(v)
|
||||
@r.text(@left - @options.marginLeft/2, y, Morris.commas(v) + @options.units)
|
||||
@r.text(@left - @options.marginLeft/2, y, @options.preunits + Morris.commas(v) + @options.postunits)
|
||||
.attr('font-size', @options.gridTextSize)
|
||||
.attr('fill', @options.gridTextColor)
|
||||
.attr('text-anchor', 'end')
|
||||
@ -323,7 +327,7 @@ class Morris.Line
|
||||
@hoverSet.show()
|
||||
@xLabel.attr('text', @columnLabels[index])
|
||||
for i in [0..@series.length-1]
|
||||
@yLabels[i].attr('text', "#{@seriesLabels[i]}: #{Morris.commas(@series[i][index])}#{@options.units}")
|
||||
@yLabels[i].attr('text', "#{@seriesLabels[i]}: #{@options.preunits}#{Morris.commas(@series[i][index])}#{@options.postunits}")
|
||||
# recalculate hover box width
|
||||
maxLabelWidth = Math.max.apply null, $.map @yLabels, (l) ->
|
||||
l.getBBox().width
|
||||
|
10
morris.js
10
morris.js
@ -19,6 +19,7 @@
|
||||
} else {
|
||||
this.el = $(options.element);
|
||||
}
|
||||
if (typeof options.units === 'string') options.postunits = options.units;
|
||||
this.options = $.extend({}, this.defaults, options);
|
||||
if (this.options.data === void 0 || this.options.data.length === 0) return;
|
||||
this.el.addClass('graph-initialised');
|
||||
@ -53,7 +54,8 @@
|
||||
smooth: true,
|
||||
hideHover: false,
|
||||
parseTime: true,
|
||||
units: '',
|
||||
preunits: '',
|
||||
postunits: '',
|
||||
dateFormat: function(x) {
|
||||
return new Date(x).toString();
|
||||
},
|
||||
@ -159,7 +161,7 @@
|
||||
w = this.el.width();
|
||||
h = this.el.height();
|
||||
if (this.elementWidth !== w || this.elementHeight !== h) {
|
||||
this.maxYLabelWidth = Math.max(this.measureText(this.options.ymin + this.options.units, this.options.gridTextSize).width, this.measureText(this.options.ymax + this.options.units, this.options.gridTextSize).width);
|
||||
this.maxYLabelWidth = Math.max(this.measureText(this.options.preunits + this.options.ymin + this.options.postunits, this.options.gridTextSize).width, this.measureText(this.options.preunits + this.options.ymax + this.options.postunits, this.options.gridTextSize).width);
|
||||
this.left = this.maxYLabelWidth + this.options.marginLeft;
|
||||
this.width = this.el.width() - this.left - this.options.marginRight;
|
||||
this.height = this.el.height() - this.options.marginTop - this.options.marginBottom;
|
||||
@ -229,7 +231,7 @@
|
||||
for (lineY = firstY; firstY <= lastY ? lineY <= lastY : lineY >= lastY; lineY += yInterval) {
|
||||
v = Math.floor(lineY);
|
||||
y = this.transY(v);
|
||||
this.r.text(this.left - this.options.marginLeft / 2, y, Morris.commas(v) + this.options.units).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.options.preunits + Morris.commas(v) + this.options.postunits).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);
|
||||
}
|
||||
ypos = this.options.marginTop + this.height + this.options.marginBottom / 2;
|
||||
@ -373,7 +375,7 @@
|
||||
this.hoverSet.show();
|
||||
this.xLabel.attr('text', this.columnLabels[index]);
|
||||
for (i = 0, _ref = this.series.length - 1; 0 <= _ref ? i <= _ref : i >= _ref; 0 <= _ref ? i++ : i--) {
|
||||
this.yLabels[i].attr('text', "" + this.seriesLabels[i] + ": " + (Morris.commas(this.series[i][index])) + this.options.units);
|
||||
this.yLabels[i].attr('text', "" + this.seriesLabels[i] + ": " + this.options.preunits + (Morris.commas(this.series[i][index])) + this.options.postunits);
|
||||
}
|
||||
maxLabelWidth = Math.max.apply(null, $.map(this.yLabels, function(l) {
|
||||
return l.getBBox().width;
|
||||
|
2
morris.min.js
vendored
2
morris.min.js
vendored
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue
Block a user