Merge branch 'issue-138' of github.com:tiraeth/morris.js

Conflicts:
	lib/morris.grid.coffee
	morris.js
	morris.min.js
This commit is contained in:
Olly Smith 2012-12-20 08:01:56 +00:00
commit ecabc8976b
4 changed files with 22 additions and 3 deletions

View File

@ -66,6 +66,7 @@ class Morris.Grid extends Morris.EventEmitter
gridTextColor: '#888'
gridTextSize: 12
hideHover: false
yLabelFormat: (label, prefix, suffix) -> "#{prefix}#{Morris.commas(label)}#{suffix}"
numLines: 5
padding: 25
parseTime: true
@ -282,7 +283,7 @@ class Morris.Grid extends Morris.EventEmitter
# @private
#
yLabelFormat: (label) ->
"#{@options.preUnits}#{Morris.commas(label)}#{@options.postUnits}"
@options.yLabelFormat(label, @options.preUnits, @options.postUnits)
updateHover: (x, y) ->
hit = @hitTest(x, y)

View File

@ -124,6 +124,9 @@
gridTextColor: '#888',
gridTextSize: 12,
hideHover: false,
yLabelFormat: function(label, prefix, suffix) {
return "" + prefix + (Morris.commas(label)) + suffix;
},
numLines: 5,
padding: 25,
parseTime: true,
@ -394,7 +397,7 @@
};
Grid.prototype.yLabelFormat = function(label) {
return "" + this.options.preUnits + (Morris.commas(label)) + this.options.postUnits;
return this.options.yLabelFormat(label, this.options.preUnits, this.options.postUnits);
};
Grid.prototype.updateHover = function(x, y) {

2
morris.min.js vendored

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,15 @@
describe 'Morris.Grid#yLabelFormat', ->
it 'should use custom formatter for y labels', ->
formatter = (label, prefix, suffix) ->
flabel = parseFloat(label) / 1000
"#{prefix}#{flabel.toFixed(1)}k#{suffix}"
line = Morris.Line
element: 'graph'
data: [{x: 1, y: 1500}, {x: 2, y: 2500}]
xkey: 'x'
ykeys: ['y']
labels: ['dontcare']
preUnits: "$"
yLabelFormat: formatter
line.yLabelFormat(1500).should.equal "$1.5k"