Skip to content

Commit a5fd000

Browse files
committed
refactor number format functions
1 parent 3ea8d90 commit a5fd000

File tree

2 files changed

+7
-10
lines changed

2 files changed

+7
-10
lines changed

src/lib/index.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
var d3 = require('@plotly/d3');
44
var utcFormat = require('d3-time-format').utcFormat;
5+
var d3Format = require('d3-format').format;
56
var isNumeric = require('fast-isnumeric');
67

78
var numConstants = require('../constants/numerical');
@@ -11,7 +12,7 @@ var BADNUM = numConstants.BADNUM;
1112

1213
var lib = module.exports = {};
1314

14-
lib.adjustFormat = function(a) {
15+
lib.adjustFormat = function adjustFormat(a) {
1516
if(
1617
!a ||
1718
/^[0123456789].[0123456789]f/.test(a) ||
@@ -28,11 +29,9 @@ lib.adjustFormat = function(a) {
2829
return a;
2930
};
3031

31-
var d3Format = require('d3-format').format;
32-
var numberFormat = function(a) {
32+
lib.numberFormat = function(a) {
3333
return d3Format(lib.adjustFormat(a));
3434
};
35-
lib.numberFormat = numberFormat;
3635

3736
lib.nestedProperty = require('./nested_property');
3837
lib.keyedContainer = require('./keyed_container');
@@ -1141,7 +1140,7 @@ function templateFormatString(string, labels, d3locale) {
11411140
if(format) {
11421141
var fmt;
11431142
if(format[0] === ':') {
1144-
fmt = d3locale ? d3locale.numberFormat : numberFormat;
1143+
fmt = d3locale ? d3locale.numberFormat : lib.numberFormat;
11451144
value = fmt(format.replace(TEMPLATE_STRING_FORMAT_SEPARATOR, ''))(value);
11461145
}
11471146

src/plots/plots.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -704,11 +704,9 @@ function getFormatter(formatObj, separators) {
704704

705705
return {
706706
numberFormat: function(a) {
707-
var b = Lib.adjustFormat(a);
708-
709-
// console.log('"' + a + '" > "' + b + '"');
710-
711-
return formatLocale(formatObj).format(b);
707+
return formatLocale(formatObj).format(
708+
Lib.adjustFormat(a)
709+
);
712710
},
713711
timeFormat: timeFormatLocale(formatObj).utcFormat
714712
};

0 commit comments

Comments
 (0)