mirror of
https://github.com/morrisjs/morris.js.git
synced 2024-11-10 21:36:34 +01: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)
|
@el = $ document.getElementById(options.element)
|
||||||
else
|
else
|
||||||
@el = $ options.element
|
@el = $ options.element
|
||||||
|
#backwards compatibility for units -> postunits
|
||||||
|
if typeof options.units is 'string'
|
||||||
|
options.postunits = options.units
|
||||||
@options = $.extend {}, @defaults, options
|
@options = $.extend {}, @defaults, options
|
||||||
# bail if there's no data
|
# bail if there's no data
|
||||||
if @options.data is undefined or @options.data.length is 0
|
if @options.data is undefined or @options.data.length is 0
|
||||||
@ -59,7 +62,8 @@ class Morris.Line
|
|||||||
smooth: true
|
smooth: true
|
||||||
hideHover: false
|
hideHover: false
|
||||||
parseTime: true
|
parseTime: true
|
||||||
units: ''
|
preunits: ''
|
||||||
|
postunits: ''
|
||||||
dateFormat: (x) -> new Date(x).toString()
|
dateFormat: (x) -> new Date(x).toString()
|
||||||
xLabels: 'auto'
|
xLabels: 'auto'
|
||||||
xLabelFormat: null
|
xLabelFormat: null
|
||||||
@ -143,8 +147,8 @@ class Morris.Line
|
|||||||
if @elementWidth != w or @elementHeight != h
|
if @elementWidth != w or @elementHeight != h
|
||||||
# calculate grid dimensions
|
# calculate grid dimensions
|
||||||
@maxYLabelWidth = Math.max(
|
@maxYLabelWidth = Math.max(
|
||||||
@measureText(@options.ymin + @options.units, @options.gridTextSize).width,
|
@measureText(@options.preunits + @options.ymin + @options.postunits, @options.gridTextSize).width,
|
||||||
@measureText(@options.ymax + @options.units, @options.gridTextSize).width)
|
@measureText(@options.preunits + @options.ymax + @options.postunits, @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
|
||||||
@ -200,7 +204,7 @@ class Morris.Line
|
|||||||
for lineY in [firstY..lastY] by yInterval
|
for lineY in [firstY..lastY] by yInterval
|
||||||
v = Math.floor(lineY)
|
v = Math.floor(lineY)
|
||||||
y = @transY(v)
|
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('font-size', @options.gridTextSize)
|
||||||
.attr('fill', @options.gridTextColor)
|
.attr('fill', @options.gridTextColor)
|
||||||
.attr('text-anchor', 'end')
|
.attr('text-anchor', 'end')
|
||||||
@ -323,7 +327,7 @@ class Morris.Line
|
|||||||
@hoverSet.show()
|
@hoverSet.show()
|
||||||
@xLabel.attr('text', @columnLabels[index])
|
@xLabel.attr('text', @columnLabels[index])
|
||||||
for i in [0..@series.length-1]
|
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
|
# recalculate hover box width
|
||||||
maxLabelWidth = Math.max.apply null, $.map @yLabels, (l) ->
|
maxLabelWidth = Math.max.apply null, $.map @yLabels, (l) ->
|
||||||
l.getBBox().width
|
l.getBBox().width
|
||||||
|
10
morris.js
10
morris.js
@ -19,6 +19,7 @@
|
|||||||
} else {
|
} else {
|
||||||
this.el = $(options.element);
|
this.el = $(options.element);
|
||||||
}
|
}
|
||||||
|
if (typeof options.units === 'string') options.postunits = options.units;
|
||||||
this.options = $.extend({}, this.defaults, options);
|
this.options = $.extend({}, this.defaults, options);
|
||||||
if (this.options.data === void 0 || this.options.data.length === 0) return;
|
if (this.options.data === void 0 || this.options.data.length === 0) return;
|
||||||
this.el.addClass('graph-initialised');
|
this.el.addClass('graph-initialised');
|
||||||
@ -53,7 +54,8 @@
|
|||||||
smooth: true,
|
smooth: true,
|
||||||
hideHover: false,
|
hideHover: false,
|
||||||
parseTime: true,
|
parseTime: true,
|
||||||
units: '',
|
preunits: '',
|
||||||
|
postunits: '',
|
||||||
dateFormat: function(x) {
|
dateFormat: function(x) {
|
||||||
return new Date(x).toString();
|
return new Date(x).toString();
|
||||||
},
|
},
|
||||||
@ -159,7 +161,7 @@
|
|||||||
w = this.el.width();
|
w = this.el.width();
|
||||||
h = this.el.height();
|
h = this.el.height();
|
||||||
if (this.elementWidth !== w || this.elementHeight !== h) {
|
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.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;
|
||||||
@ -229,7 +231,7 @@
|
|||||||
for (lineY = firstY; firstY <= lastY ? lineY <= lastY : lineY >= lastY; lineY += yInterval) {
|
for (lineY = firstY; firstY <= lastY ? lineY <= lastY : lineY >= lastY; lineY += yInterval) {
|
||||||
v = Math.floor(lineY);
|
v = Math.floor(lineY);
|
||||||
y = this.transY(v);
|
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);
|
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;
|
||||||
@ -373,7 +375,7 @@
|
|||||||
this.hoverSet.show();
|
this.hoverSet.show();
|
||||||
this.xLabel.attr('text', this.columnLabels[index]);
|
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--) {
|
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) {
|
maxLabelWidth = Math.max.apply(null, $.map(this.yLabels, function(l) {
|
||||||
return l.getBBox().width;
|
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