Copy constructors for d3.rgb and d3.hsl.

Previously, these would work by coercing the input color to a string and then
parsing it. This is slow, but more importantly, this is a lossy process for HSL
colors due to the conversion to hexadecimal RGB format. This commit detects
instances of d3_Rgb and d3_Hsl on input and copies them efficiently.
This commit is contained in:
Mike Bostock 2011-10-07 12:10:10 -07:00
Родитель cc0ae766b7
Коммит 0b852dd892
4 изменённых файлов: 10 добавлений и 6 удалений

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

@ -867,7 +867,8 @@ function d3_uninterpolateClamp(a, b) {
}
d3.rgb = function(r, g, b) {
return arguments.length === 1
? d3_rgb_parse("" + r, d3_rgb, d3_hsl_rgb)
? (r instanceof d3_Rgb ? d3_rgb(r.r, r.g, r.b)
: d3_rgb_parse("" + r, d3_rgb, d3_hsl_rgb))
: d3_rgb(~~r, ~~g, ~~b);
};
@ -1151,7 +1152,8 @@ for (var d3_rgb_name in d3_rgb_names) {
}
d3.hsl = function(h, s, l) {
return arguments.length === 1
? d3_rgb_parse("" + h, d3_rgb_hsl, d3_hsl)
? (h instanceof d3_Hsl ? d3_hsl(h.h, h.s, h.l)
: d3_rgb_parse("" + h, d3_rgb_hsl, d3_hsl))
: d3_hsl(+h, +s, +l);
};

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

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

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

@ -1,6 +1,7 @@
d3.hsl = function(h, s, l) {
return arguments.length === 1
? d3_rgb_parse("" + h, d3_rgb_hsl, d3_hsl)
? (h instanceof d3_Hsl ? d3_hsl(h.h, h.s, h.l)
: d3_rgb_parse("" + h, d3_rgb_hsl, d3_hsl))
: d3_hsl(+h, +s, +l);
};

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

@ -1,6 +1,7 @@
d3.rgb = function(r, g, b) {
return arguments.length === 1
? d3_rgb_parse("" + r, d3_rgb, d3_hsl_rgb)
? (r instanceof d3_Rgb ? d3_rgb(r.r, r.g, r.b)
: d3_rgb_parse("" + r, d3_rgb, d3_hsl_rgb))
: d3_rgb(~~r, ~~g, ~~b);
};