adding numeral.js as a dependency

This commit is contained in:
Shelby Sturgis 2015-01-13 10:18:17 -05:00
parent 20b4c8df34
commit 2bc1caf725
4 changed files with 7 additions and 10 deletions

View file

@ -49,7 +49,8 @@
"requirejs": "~2.1.10",
"requirejs-text": "~2.0.10",
"lodash-deep": "spenceralger/lodash-deep#compat",
"marked": "~0.3.2"
"marked": "~0.3.2",
"numeral": "~1.5.3"
},
"devDependencies": {}
}

View file

@ -2,6 +2,7 @@ define(function (require) {
return function YAxisFactory(d3, Private) {
var _ = require('lodash');
var $ = require('jquery');
var numeral = require('numeral');
var ErrorHandler = Private(require('components/vislib/lib/_error_handler'));
@ -58,11 +59,7 @@ define(function (require) {
* @returns {*}
*/
YAxis.prototype.formatAxisLabel = function (d) {
var formatNumber = d3.format('s');
var str = formatNumber(d);
var replaceG = str.replace(/G/i, 'B');
return (d >= 1e9 && d < 1e12) ? replaceG : str;
return numeral(d).format('0.[0]a');
};
/**

View file

@ -34,7 +34,8 @@ require.config({
'ng-clip': 'bower_components/ng-clip/src/ngClip',
text: 'bower_components/requirejs-text/text',
zeroclipboard: 'bower_components/zeroclipboard/dist/ZeroClipboard',
marked: 'bower_components/marked/lib/marked'
marked: 'bower_components/marked/lib/marked',
numeral: 'bower_components/numeral/numeral'
},
shim: {
angular: {

View file

@ -198,16 +198,14 @@ define(function (require) {
describe('formatAxisLabel method', function () {
var num = 1e9;
var re = /B/i;
var val;
var str;
beforeEach(function () {
val = yAxis.formatAxisLabel(num);
});
it('should return a string with suffix B', function () {
expect(val).to.be('1B');
expect(val).to.be('1b');
});
});