non-invasive solution for #138, with mache:spec

This commit is contained in:
Marcin Chwedziak 2012-12-13 22:31:13 +01:00
parent ff9856e8e9
commit 381be72f61
4 changed files with 22 additions and 3 deletions

View File

@ -44,6 +44,7 @@ class Morris.Grid extends Morris.EventEmitter
gridStrokeWidth: 0.5 gridStrokeWidth: 0.5
gridTextColor: '#888' gridTextColor: '#888'
gridTextSize: 12 gridTextSize: 12
yLabelFormat: (label, prefix, suffix) -> "#{prefix}#{Morris.commas(label)}#{suffix}"
numLines: 5 numLines: 5
padding: 25 padding: 25
parseTime: true parseTime: true
@ -254,7 +255,7 @@ class Morris.Grid extends Morris.EventEmitter
# @private # @private
# #
yLabelFormat: (label) -> yLabelFormat: (label) ->
"#{@options.preUnits}#{Morris.commas(label)}#{@options.postUnits}" @options.yLabelFormat.call(@, label, @options.preUnits, @options.postUnits)
# Parse a date into a javascript timestamp # Parse a date into a javascript timestamp

View File

@ -99,6 +99,9 @@
gridStrokeWidth: 0.5, gridStrokeWidth: 0.5,
gridTextColor: '#888', gridTextColor: '#888',
gridTextSize: 12, gridTextSize: 12,
yLabelFormat: function(label, prefix, suffix) {
return "" + prefix + (Morris.commas(label)) + suffix;
},
numLines: 5, numLines: 5,
padding: 25, padding: 25,
parseTime: true, parseTime: true,
@ -356,7 +359,7 @@
}; };
Grid.prototype.yLabelFormat = function(label) { Grid.prototype.yLabelFormat = function(label) {
return "" + this.options.preUnits + (Morris.commas(label)) + this.options.postUnits; return this.options.yLabelFormat.call(this, label, this.options.preUnits, this.options.postUnits);
}; };
return Grid; return Grid;

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"