Adopt d3.map for d3.format.
This commit is contained in:
Родитель
2c5293675e
Коммит
72da0cd88a
|
@ -649,7 +649,7 @@ d3.format = function(specifier) {
|
||||||
// If no precision is specified for r, fallback to general notation.
|
// If no precision is specified for r, fallback to general notation.
|
||||||
if (type == "r" && !precision) type = "g";
|
if (type == "r" && !precision) type = "g";
|
||||||
|
|
||||||
type = d3_format_types[type] || d3_format_typeDefault;
|
type = d3_format_types.get(type) || d3_format_typeDefault;
|
||||||
|
|
||||||
return function(value) {
|
return function(value) {
|
||||||
|
|
||||||
|
@ -694,12 +694,12 @@ d3.format = function(specifier) {
|
||||||
// [[fill]align][sign][#][0][width][,][.precision][type]
|
// [[fill]align][sign][#][0][width][,][.precision][type]
|
||||||
var d3_format_re = /(?:([^{])?([<>=^]))?([+\- ])?(#)?(0)?([0-9]+)?(,)?(\.[0-9]+)?([a-zA-Z%])?/;
|
var d3_format_re = /(?:([^{])?([<>=^]))?([+\- ])?(#)?(0)?([0-9]+)?(,)?(\.[0-9]+)?([a-zA-Z%])?/;
|
||||||
|
|
||||||
var d3_format_types = {
|
var d3_format_types = d3.map({
|
||||||
g: function(x, p) { return x.toPrecision(p); },
|
g: function(x, p) { return x.toPrecision(p); },
|
||||||
e: function(x, p) { return x.toExponential(p); },
|
e: function(x, p) { return x.toExponential(p); },
|
||||||
f: function(x, p) { return x.toFixed(p); },
|
f: function(x, p) { return x.toFixed(p); },
|
||||||
r: function(x, p) { return d3.round(x, p = d3_format_precision(x, p)).toFixed(Math.max(0, Math.min(20, p))); }
|
r: function(x, p) { return d3.round(x, p = d3_format_precision(x, p)).toFixed(Math.max(0, Math.min(20, p))); }
|
||||||
};
|
});
|
||||||
|
|
||||||
function d3_format_precision(x, p) {
|
function d3_format_precision(x, p) {
|
||||||
return p - (x ? 1 + Math.floor(Math.log(x + Math.pow(10, 1 + Math.floor(Math.log(x) / Math.LN10) - p)) / Math.LN10) : 1);
|
return p - (x ? 1 + Math.floor(Math.log(x + Math.pow(10, 1 + Math.floor(Math.log(x) / Math.LN10) - p)) / Math.LN10) : 1);
|
||||||
|
|
Различия файлов скрыты, потому что одна или несколько строк слишком длинны
|
@ -30,7 +30,7 @@ d3.format = function(specifier) {
|
||||||
// If no precision is specified for r, fallback to general notation.
|
// If no precision is specified for r, fallback to general notation.
|
||||||
if (type == "r" && !precision) type = "g";
|
if (type == "r" && !precision) type = "g";
|
||||||
|
|
||||||
type = d3_format_types[type] || d3_format_typeDefault;
|
type = d3_format_types.get(type) || d3_format_typeDefault;
|
||||||
|
|
||||||
return function(value) {
|
return function(value) {
|
||||||
|
|
||||||
|
@ -75,12 +75,12 @@ d3.format = function(specifier) {
|
||||||
// [[fill]align][sign][#][0][width][,][.precision][type]
|
// [[fill]align][sign][#][0][width][,][.precision][type]
|
||||||
var d3_format_re = /(?:([^{])?([<>=^]))?([+\- ])?(#)?(0)?([0-9]+)?(,)?(\.[0-9]+)?([a-zA-Z%])?/;
|
var d3_format_re = /(?:([^{])?([<>=^]))?([+\- ])?(#)?(0)?([0-9]+)?(,)?(\.[0-9]+)?([a-zA-Z%])?/;
|
||||||
|
|
||||||
var d3_format_types = {
|
var d3_format_types = d3.map({
|
||||||
g: function(x, p) { return x.toPrecision(p); },
|
g: function(x, p) { return x.toPrecision(p); },
|
||||||
e: function(x, p) { return x.toExponential(p); },
|
e: function(x, p) { return x.toExponential(p); },
|
||||||
f: function(x, p) { return x.toFixed(p); },
|
f: function(x, p) { return x.toFixed(p); },
|
||||||
r: function(x, p) { return d3.round(x, p = d3_format_precision(x, p)).toFixed(Math.max(0, Math.min(20, p))); }
|
r: function(x, p) { return d3.round(x, p = d3_format_precision(x, p)).toFixed(Math.max(0, Math.min(20, p))); }
|
||||||
};
|
});
|
||||||
|
|
||||||
function d3_format_precision(x, p) {
|
function d3_format_precision(x, p) {
|
||||||
return p - (x ? 1 + Math.floor(Math.log(x + Math.pow(10, 1 + Math.floor(Math.log(x) / Math.LN10) - p)) / Math.LN10) : 1);
|
return p - (x ? 1 + Math.floor(Math.log(x + Math.pow(10, 1 + Math.floor(Math.log(x) / Math.LN10) - p)) / Math.LN10) : 1);
|
||||||
|
|
Загрузка…
Ссылка в новой задаче