mirror of
https://github.com/morrisjs/morris.js.git
synced 2024-11-10 21:36:34 +01:00
non-invasive solution for #138, with mache:spec
This commit is contained in:
parent
ff9856e8e9
commit
381be72f61
@ -44,6 +44,7 @@ class Morris.Grid extends Morris.EventEmitter
|
||||
gridStrokeWidth: 0.5
|
||||
gridTextColor: '#888'
|
||||
gridTextSize: 12
|
||||
yLabelFormat: (label, prefix, suffix) -> "#{prefix}#{Morris.commas(label)}#{suffix}"
|
||||
numLines: 5
|
||||
padding: 25
|
||||
parseTime: true
|
||||
@ -254,7 +255,7 @@ class Morris.Grid extends Morris.EventEmitter
|
||||
# @private
|
||||
#
|
||||
yLabelFormat: (label) ->
|
||||
"#{@options.preUnits}#{Morris.commas(label)}#{@options.postUnits}"
|
||||
@options.yLabelFormat.call(@, label, @options.preUnits, @options.postUnits)
|
||||
|
||||
|
||||
# Parse a date into a javascript timestamp
|
||||
|
@ -99,6 +99,9 @@
|
||||
gridStrokeWidth: 0.5,
|
||||
gridTextColor: '#888',
|
||||
gridTextSize: 12,
|
||||
yLabelFormat: function(label, prefix, suffix) {
|
||||
return "" + prefix + (Morris.commas(label)) + suffix;
|
||||
},
|
||||
numLines: 5,
|
||||
padding: 25,
|
||||
parseTime: true,
|
||||
@ -356,7 +359,7 @@
|
||||
};
|
||||
|
||||
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;
|
||||
|
2
morris.min.js
vendored
2
morris.min.js
vendored
File diff suppressed because one or more lines are too long
15
spec/lib/grid/y_label_format_spec.coffee
Normal file
15
spec/lib/grid/y_label_format_spec.coffee
Normal 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"
|
Loading…
Reference in New Issue
Block a user