Merge branch 'locale' of git://github.com/jasondavies/d3 into 3.0

This commit is contained in:
Mike Bostock 2012-10-29 09:23:18 -07:00
Родитель 9b1fefca81 9daa61fb70
Коммит 6d7b74241a
11 изменённых файлов: 100 добавлений и 70 удалений

Просмотреть файл

@ -28,6 +28,7 @@ all: \
src/end.js
d3.core.js: \
src/core/format-$(LOCALE).js \
src/compat/date.js \
src/compat/style.js \
src/core/core.js \
@ -252,5 +253,15 @@ package.json: src/package.js
node src/package.js > $@
@chmod a-w $@
src/core/format-$(LOCALE).js: src/locale.js src/core/format-locale.js
LC_NUMERIC=$(LOCALE) locale -ck LC_NUMERIC | node src/locale.js src/core/format-locale.js > $@
src/time/format-$(LOCALE).js: src/locale.js src/time/format-locale.js
LC_TIME=$(LOCALE) locale -ck LC_TIME | node src/locale.js src/time/format-locale.js > $@
.INTERMEDIATE: \
src/core/format-$(LOCALE).js \
src/time/format-$(LOCALE).js
clean:
rm -f d3*.js package.json component.json

27
d3.js поставляемый
Просмотреть файл

@ -97,11 +97,6 @@
function d3_format_typeDefault(x) {
return x + "";
}
function d3_format_group(value) {
var i = value.lastIndexOf("."), f = i >= 0 ? value.substring(i) : (i = value.length, ""), t = [];
while (i > 0) t.push(value.substring(i -= 3, i + 3));
return t.reverse().join(",") + f;
}
function d3_formatPrefix(d, i) {
var k = Math.pow(10, Math.abs(8 - i) * 3);
return {
@ -2747,9 +2742,6 @@
function d3_time_utc() {
this._ = new Date(arguments.length > 1 ? Date.UTC.apply(this, arguments) : arguments[0]);
}
function d3_time_formatAbbreviate(name) {
return name.substring(0, 3);
}
function d3_time_parse(date, template, string, j) {
var c, p, i = 0, n = template.length, m = string.length;
while (i < n) {
@ -2985,6 +2977,7 @@
var y = d.getUTCFullYear(), d0 = d3_time_scaleUTCSetYear(y), d1 = d3_time_scaleUTCSetYear(y + 1);
return y + (d - d0) / (d1 - d0);
}
var d3_format_decimalPoint = ".", d3_format_thousandsSeparator = ",", d3_format_grouping = [ 3, 3 ];
if (!Date.now) Date.now = function() {
return +(new Date);
};
@ -3473,7 +3466,7 @@
var length = value.length;
if (length < width) value = (new Array(width - length + 1)).join(fill) + value;
}
return value + suffix;
return value.replace(".", d3_format_decimalPoint) + suffix;
};
};
var d3_format_re = /(?:([^{])?([<>=^]))?([+\- ])?(#)?(0)?([0-9]+)?(,)?(\.[0-9]+)?([a-zA-Z%])?/;
@ -3491,6 +3484,18 @@
return d3.round(x, p = d3_format_precision(x, p)).toFixed(Math.max(0, Math.min(20, p)));
}
});
var d3_format_group = d3_identity;
if (d3_format_grouping) {
var d3_format_groupingLength = d3_format_grouping.length;
d3_format_group = function(value) {
var i = value.lastIndexOf("."), f = i >= 0 ? "." + value.substring(i + 1) : (i = value.length, ""), t = [], j = 0, g = d3_format_grouping[0];
while (i > 0 && g > 0) {
t.push(value.substring(i -= g, i + g));
g = d3_format_grouping[j = (j + 1) % d3_format_groupingLength];
}
return t.reverse().join(d3_format_thousandsSeparator || "") + f;
};
}
var d3_formatPrefixes = [ "y", "z", "a", "f", "p", "n", "μ", "m", "", "k", "M", "G", "T", "P", "E", "Z", "Y" ].map(d3_formatPrefix);
d3.formatPrefix = function(value, precision) {
var i = 0;
@ -7219,8 +7224,8 @@
}
};
var d3_time_prototype = Date.prototype;
var d3_time_formatDateTime = "%a %b %e %H:%M:%S %Y", d3_time_formatDate = "%m/%d/%y", d3_time_formatTime = "%H:%M:%S";
var d3_time_days = d3_time_daySymbols, d3_time_dayAbbreviations = d3_time_days.map(d3_time_formatAbbreviate), d3_time_months = [ "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" ], d3_time_monthAbbreviations = d3_time_months.map(d3_time_formatAbbreviate);
var d3_time_formatDateTime = "%a %b %e %X %Y", d3_time_formatDate = "%m/%d/%Y", d3_time_formatTime = "%H:%M:%S";
var d3_time_days = [ "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" ], d3_time_dayAbbreviations = [ "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" ], d3_time_months = [ "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" ], d3_time_monthAbbreviations = [ "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" ];
d3.time.format = function(template) {
function format(date) {
var string = [], i = -1, j = 0, c, f;

8
d3.min.js поставляемый

Различия файлов скрыты, потому что одна или несколько строк слишком длинны

Просмотреть файл

@ -0,0 +1,3 @@
var d3_format_decimalPoint = {decimal_point},
d3_format_thousandsSeparator = {thousands_sep},
d3_format_grouping = {grouping};

Просмотреть файл

@ -68,7 +68,7 @@ d3.format = function(specifier) {
if (length < width) value = new Array(width - length + 1).join(fill) + value;
}
return value + suffix;
return value.replace(".", d3_format_decimalPoint) + suffix;
};
};
@ -91,10 +91,19 @@ function d3_format_typeDefault(x) {
}
// Apply comma grouping for thousands.
function d3_format_group(value) {
var d3_format_group = d3_identity;
if (d3_format_grouping) {
var d3_format_groupingLength = d3_format_grouping.length;
d3_format_group = function(value) {
var i = value.lastIndexOf("."),
f = i >= 0 ? value.substring(i) : (i = value.length, ""),
t = [];
while (i > 0) t.push(value.substring(i -= 3, i + 3));
return t.reverse().join(",") + f;
f = i >= 0 ? "." + value.substring(i + 1) : (i = value.length, ""),
t = [],
j = 0,
g = d3_format_grouping[0];
while (i > 0 && g > 0) {
t.push(value.substring(i -= g, i + g));
g = d3_format_grouping[j = (j + 1) % d3_format_groupingLength];
}
return t.reverse().join(d3_format_thousandsSeparator || "") + f;
};
}

30
src/locale.js Normal file
Просмотреть файл

@ -0,0 +1,30 @@
var fs = require("fs"),
puts = require("util").puts,
formats = {},
kvRe = /=/,
valueRe = /("[^"]+")/g,
data = [];
process.stdin.resume();
process.stdin.setEncoding("utf8");
process.stdin.on("data", function(chunk) { data.push(chunk); });
process.stdin.on("end", write);
function write() {
data.join("\n").split(/\n/g).forEach(function(line) {
var i = line.match(kvRe);
if (i && (i = i.index)) {
var value = line.substring(i + 1).split(valueRe);
formats[line.substring(0, i)] = value.length > 3
? value.map(function(d, i) { return d === "" ? i ? "]" : "[" : d === ";" ? ", " : d; }).join("")
: value[1];
}
});
puts(fs.readFileSync(process.argv[2], "utf8").replace(/\{([^\}]+)\}/g, function(d, k) {
d = formats[k];
return k === "grouping"
? d === "\"127\"" ? null : d.replace(/^"/, "[").replace(/"$/, "]").replace(/;/, ", ")
: d == null ? null : d;
}));
}

Просмотреть файл

@ -1,14 +0,0 @@
// The date and time format (%c), date format (%x) and time format (%X).
var d3_time_formatDateTime = "%a %b %e %H:%M:%S %Y",
d3_time_formatDate = "%m/%d/%y",
d3_time_formatTime = "%H:%M:%S";
// The weekday and month names.
var d3_time_days = d3_time_daySymbols,
d3_time_dayAbbreviations = d3_time_days.map(d3_time_formatAbbreviate),
d3_time_months = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"],
d3_time_monthAbbreviations = d3_time_months.map(d3_time_formatAbbreviate);
function d3_time_formatAbbreviate(name) {
return name.substring(0, 3);
}

Просмотреть файл

@ -1,14 +0,0 @@
// The date and time format (%c), date format (%x) and time format (%X).
var d3_time_formatDateTime = "%a %e %b %H:%M:%S %Y",
d3_time_formatDate = "%d.%m.%y",
d3_time_formatTime = "%H:%M:%S";
// The weekday and month names.
var d3_time_days = ["dimanche", "lundi", "mardi", "mercredi", "jeudi", "vendredi", "samedi"],
d3_time_dayAbbreviations = d3_time_days.map(d3_time_formatAbbreviate),
d3_time_months = ["janvier", "février", "mars", "avril", "mai", "juin", "juillet", "août", "septembre", "octobre", "novembre", "décembre"],
d3_time_monthAbbreviations = d3_time_months.map(d3_time_formatAbbreviate);
function d3_time_formatAbbreviate(name) {
return name.substring(0, 3);
}

10
src/time/format-locale.js Normal file
Просмотреть файл

@ -0,0 +1,10 @@
// The date and time format (%c), date format (%x) and time format (%X).
var d3_time_formatDateTime = {d_t_fmt},
d3_time_formatDate = {d_fmt},
d3_time_formatTime = {t_fmt};
// The weekday and month names.
var d3_time_days = {day},
d3_time_dayAbbreviations = {abday},
d3_time_months = {mon},
d3_time_monthAbbreviations = {abmon};

Просмотреть файл

@ -1,10 +0,0 @@
// The date and time format (%c), date format (%x) and time format (%X).
var d3_time_formatDateTime = "%a %e %b %H:%M:%S %Y",
d3_time_formatDate = "%d.%m.%y",
d3_time_formatTime = "%H:%M:%S";
// The weekday and month names.
var d3_time_days = ["воскресенье", "понедельник", "вторник", "среда", "четверг", "пятница", "суббота"],
d3_time_dayAbbreviations = ["Вс", "Пн", "Вт", "Ср", "Чт", "Пт", "Сб"],
d3_time_months = ["январь", "февраль", "март", "апрель", "май", "июнь", "июль", "август", "сентябрь", "октябрь", "ноябрь", "декабрь"],
d3_time_monthAbbreviations = ["янв", "фев", "мар", "апр", "май", "июн", "июл", "авг", "сен", "окт", "ноя", "дек"];

Просмотреть файл

@ -119,8 +119,8 @@ suite.addBatch({
},
"formats locale date": function(format) {
var f = format("%x");
assert.equal(f(local(1990, 0, 1)), "01/01/90");
assert.equal(f(local(2010, 5, 1)), "06/01/10");
assert.equal(f(local(1990, 0, 1)), "01/01/1990");
assert.equal(f(local(2010, 5, 1)), "06/01/2010");
},
"formats locale time": function(format) {
var f = format("%X");
@ -257,8 +257,8 @@ suite.addBatch({
},
"formats locale date": function(format) {
var f = format("%x");
assert.equal(f(utc(1990, 0, 1)), "01/01/90");
assert.equal(f(utc(2010, 5, 1)), "06/01/10");
assert.equal(f(utc(1990, 0, 1)), "01/01/1990");
assert.equal(f(utc(2010, 5, 1)), "06/01/2010");
},
"formats locale time": function(format) {
var f = format("%X");
@ -323,9 +323,9 @@ suite.addBatch({
},
"parses locale date": function(format) {
var p = format("%x").parse;
assert.deepEqual(p("01/01/90"), local(1990, 0, 1));
assert.deepEqual(p("02/03/91"), local(1991, 1, 3));
assert.isNull(p("03/10/2010"));
assert.deepEqual(p("01/01/1990"), local(1990, 0, 1));
assert.deepEqual(p("02/03/1991"), local(1991, 1, 3));
assert.deepEqual(p("03/10/2010"), local(2010, 2, 10));
},
"parses abbreviated month, date and year": function(format) {
var p = format("%b %d, %Y").parse;
@ -404,9 +404,9 @@ suite.addBatch({
},
"parses locale date": function(format) {
var p = format("%x").parse;
assert.deepEqual(p("01/01/90"), utc(1990, 0, 1));
assert.deepEqual(p("02/03/91"), utc(1991, 1, 3));
assert.isNull(p("03/10/2010"));
assert.deepEqual(p("01/01/1990"), utc(1990, 0, 1));
assert.deepEqual(p("02/03/1991"), utc(1991, 1, 3));
assert.deepEqual(p("03/10/2010"), utc(2010, 2, 10));
},
"parses abbreviated month, date and year": function(format) {
var p = format("%b %d, %Y").parse;