mirror of
https://github.com/morrisjs/morris.js.git
synced 2024-11-10 21:36:34 +01:00
Reduce number of options on yLabelFormatter.
This commit is contained in:
parent
ecabc8976b
commit
0662095c29
@ -66,7 +66,7 @@ class Morris.Grid extends Morris.EventEmitter
|
||||
gridTextColor: '#888'
|
||||
gridTextSize: 12
|
||||
hideHover: false
|
||||
yLabelFormat: (label, prefix, suffix) -> "#{prefix}#{Morris.commas(label)}#{suffix}"
|
||||
yLabelFormat: null
|
||||
numLines: 5
|
||||
padding: 25
|
||||
parseTime: true
|
||||
@ -283,7 +283,10 @@ class Morris.Grid extends Morris.EventEmitter
|
||||
# @private
|
||||
#
|
||||
yLabelFormat: (label) ->
|
||||
@options.yLabelFormat(label, @options.preUnits, @options.postUnits)
|
||||
if typeof @options.yLabelFormat is 'function'
|
||||
@options.yLabelFormat(label)
|
||||
else
|
||||
"#{@options.preUnits}#{Morris.commas(label)}#{@options.postUnits}"
|
||||
|
||||
updateHover: (x, y) ->
|
||||
hit = @hitTest(x, y)
|
||||
|
10
morris.js
10
morris.js
@ -124,9 +124,7 @@
|
||||
gridTextColor: '#888',
|
||||
gridTextSize: 12,
|
||||
hideHover: false,
|
||||
yLabelFormat: function(label, prefix, suffix) {
|
||||
return "" + prefix + (Morris.commas(label)) + suffix;
|
||||
},
|
||||
yLabelFormat: null,
|
||||
numLines: 5,
|
||||
padding: 25,
|
||||
parseTime: true,
|
||||
@ -397,7 +395,11 @@
|
||||
};
|
||||
|
||||
Grid.prototype.yLabelFormat = function(label) {
|
||||
return this.options.yLabelFormat(label, this.options.preUnits, this.options.postUnits);
|
||||
if (typeof this.options.yLabelFormat === 'function') {
|
||||
return this.options.yLabelFormat(label);
|
||||
} else {
|
||||
return "" + this.options.preUnits + (Morris.commas(label)) + this.options.postUnits;
|
||||
}
|
||||
};
|
||||
|
||||
Grid.prototype.updateHover = function(x, y) {
|
||||
|
2
morris.min.js
vendored
2
morris.min.js
vendored
File diff suppressed because one or more lines are too long
@ -1,9 +1,9 @@
|
||||
describe 'Morris.Grid#yLabelFormat', ->
|
||||
|
||||
|
||||
it 'should use custom formatter for y labels', ->
|
||||
formatter = (label, prefix, suffix) ->
|
||||
formatter = (label) ->
|
||||
flabel = parseFloat(label) / 1000
|
||||
"#{prefix}#{flabel.toFixed(1)}k#{suffix}"
|
||||
"#{flabel.toFixed(1)}k"
|
||||
line = Morris.Line
|
||||
element: 'graph'
|
||||
data: [{x: 1, y: 1500}, {x: 2, y: 2500}]
|
||||
@ -12,4 +12,4 @@ describe 'Morris.Grid#yLabelFormat', ->
|
||||
labels: ['dontcare']
|
||||
preUnits: "$"
|
||||
yLabelFormat: formatter
|
||||
line.yLabelFormat(1500).should.equal "$1.5k"
|
||||
line.yLabelFormat(1500).should.equal "1.5k"
|
||||
|
Loading…
Reference in New Issue
Block a user