Skip to content

Commit 019583e

Browse files
committed
Merge branch 'color' into 2.11
2 parents b8c58e9 + 428ea4f commit 019583e

12 files changed

Lines changed: 86 additions & 55 deletions

File tree

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ d3.core.js: \
8080
src/core/transform.js \
8181
src/core/interpolate.js \
8282
src/core/uninterpolate.js \
83+
src/core/color.js \
8384
src/core/rgb.js \
8485
src/core/hsl.js \
8586
src/core/hcl.js \

d3.v2.js

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,7 @@
243243
return Math.max(0, Math.min(1, (x - a) * b));
244244
};
245245
}
246+
function d3_Color() {}
246247
function d3_rgb(r, g, b) {
247248
return new d3_Rgb(r, g, b);
248249
}
@@ -3388,14 +3389,18 @@
33883389
}, function(a, b) {
33893390
return (typeof a === "string" || typeof b === "string") && d3.interpolateString(a + "", b + "");
33903391
}, function(a, b) {
3391-
return (typeof b === "string" ? d3_rgb_names.has(b) || /^(#|rgb\(|hsl\()/.test(b) : b instanceof d3_Rgb || b instanceof d3_Hsl) && d3.interpolateRgb(a, b);
3392+
return (typeof b === "string" ? d3_rgb_names.has(b) || /^(#|rgb\(|hsl\()/.test(b) : b instanceof d3_Color) && d3.interpolateRgb(a, b);
33923393
}, function(a, b) {
33933394
return !isNaN(a = +a) && !isNaN(b = +b) && d3.interpolateNumber(a, b);
33943395
} ];
3396+
d3_Color.prototype.toString = function() {
3397+
return this.rgb() + "";
3398+
};
33953399
d3.rgb = function(r, g, b) {
33963400
return arguments.length === 1 ? 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);
33973401
};
3398-
d3_Rgb.prototype.brighter = function(k) {
3402+
var d3_rgbPrototype = d3_Rgb.prototype = new d3_Color;
3403+
d3_rgbPrototype.brighter = function(k) {
33993404
k = Math.pow(.7, arguments.length ? k : 1);
34003405
var r = this.r, g = this.g, b = this.b, i = 30;
34013406
if (!r && !g && !b) return d3_rgb(i, i, i);
@@ -3404,14 +3409,14 @@
34043409
if (b && b < i) b = i;
34053410
return d3_rgb(Math.min(255, Math.floor(r / k)), Math.min(255, Math.floor(g / k)), Math.min(255, Math.floor(b / k)));
34063411
};
3407-
d3_Rgb.prototype.darker = function(k) {
3412+
d3_rgbPrototype.darker = function(k) {
34083413
k = Math.pow(.7, arguments.length ? k : 1);
34093414
return d3_rgb(Math.floor(k * this.r), Math.floor(k * this.g), Math.floor(k * this.b));
34103415
};
3411-
d3_Rgb.prototype.hsl = function() {
3416+
d3_rgbPrototype.hsl = function() {
34123417
return d3_rgb_hsl(this.r, this.g, this.b);
34133418
};
3414-
d3_Rgb.prototype.toString = function() {
3419+
d3_rgbPrototype.toString = function() {
34153420
return "#" + d3_rgb_hex(this.r) + d3_rgb_hex(this.g) + d3_rgb_hex(this.b);
34163421
};
34173422
var d3_rgb_names = d3.map({
@@ -3569,52 +3574,46 @@
35693574
d3.hsl = function(h, s, l) {
35703575
return arguments.length === 1 ? 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);
35713576
};
3572-
d3_Hsl.prototype.brighter = function(k) {
3577+
var d3_hslPrototype = d3_Hsl.prototype = new d3_Color;
3578+
d3_hslPrototype.brighter = function(k) {
35733579
k = Math.pow(.7, arguments.length ? k : 1);
35743580
return d3_hsl(this.h, this.s, this.l / k);
35753581
};
3576-
d3_Hsl.prototype.darker = function(k) {
3582+
d3_hslPrototype.darker = function(k) {
35773583
k = Math.pow(.7, arguments.length ? k : 1);
35783584
return d3_hsl(this.h, this.s, k * this.l);
35793585
};
3580-
d3_Hsl.prototype.rgb = function() {
3586+
d3_hslPrototype.rgb = function() {
35813587
return d3_hsl_rgb(this.h, this.s, this.l);
35823588
};
3583-
d3_Hsl.prototype.toString = function() {
3584-
return this.rgb().toString();
3585-
};
35863589
d3.hcl = function(h, c, l) {
35873590
return arguments.length === 1 ? h instanceof d3_Hcl ? d3_hcl(h.h, h.c, h.l) : h instanceof d3_Lab ? d3_lab_hcl(h.l, h.a, h.b) : d3_lab_hcl((h = d3_rgb_lab((h = d3.rgb(h)).r, h.g, h.b)).l, h.a, h.b) : d3_hcl(+h, +c, +l);
35883591
};
3589-
d3_Hcl.prototype.brighter = function(k) {
3592+
var d3_hclPrototype = d3_Hcl.prototype = new d3_Color;
3593+
d3_hclPrototype.brighter = function(k) {
35903594
return d3_hcl(this.h, this.c, Math.min(100, this.l + d3_lab_K * (arguments.length ? k : 1)));
35913595
};
3592-
d3_Hcl.prototype.darker = function(k) {
3596+
d3_hclPrototype.darker = function(k) {
35933597
return d3_hcl(this.h, this.c, Math.max(0, this.l - d3_lab_K * (arguments.length ? k : 1)));
35943598
};
3595-
d3_Hcl.prototype.rgb = function() {
3599+
d3_hclPrototype.rgb = function() {
35963600
return d3_hcl_lab(this.h, this.c, this.l).rgb();
35973601
};
3598-
d3_Hcl.prototype.toString = function() {
3599-
return this.rgb() + "";
3600-
};
36013602
d3.lab = function(l, a, b) {
36023603
return arguments.length === 1 ? l instanceof d3_Lab ? d3_lab(l.l, l.a, l.b) : l instanceof d3_Hcl ? d3_hcl_lab(l.l, l.c, l.h) : d3_rgb_lab((l = d3.rgb(l)).r, l.g, l.b) : d3_lab(+l, +a, +b);
36033604
};
36043605
var d3_lab_K = 18;
36053606
var d3_lab_X = .95047, d3_lab_Y = 1, d3_lab_Z = 1.08883;
3606-
d3_Lab.prototype.brighter = function(k) {
3607+
var d3_labPrototype = d3_Lab.prototype = new d3_Color;
3608+
d3_labPrototype.brighter = function(k) {
36073609
return d3_lab(Math.min(100, this.l + d3_lab_K * (arguments.length ? k : 1)), this.a, this.b);
36083610
};
3609-
d3_Lab.prototype.darker = function(k) {
3611+
d3_labPrototype.darker = function(k) {
36103612
return d3_lab(Math.max(0, this.l - d3_lab_K * (arguments.length ? k : 1)), this.a, this.b);
36113613
};
3612-
d3_Lab.prototype.rgb = function() {
3614+
d3_labPrototype.rgb = function() {
36133615
return d3_lab_rgb(this.l, this.a, this.b);
36143616
};
3615-
d3_Lab.prototype.toString = function() {
3616-
return this.rgb() + "";
3617-
};
36183617
var d3_select = function(s, n) {
36193618
return n.querySelector(s);
36203619
}, d3_selectAll = function(s, n) {
@@ -4097,7 +4096,7 @@
40974096
d3.tween = function(b, interpolate) {
40984097
function tweenFunction(d, i, a) {
40994098
var v = b.call(this, d, i);
4100-
return v == null ? a != "" && d3_tweenRemove : a != v && interpolate(a, v);
4099+
return v == null ? a != "" && d3_tweenRemove : a != v && interpolate(a, v + "");
41014100
}
41024101
function tweenString(d, i, a) {
41034102
return a != b && interpolate(a, b);

d3.v2.min.js

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/core/color.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
function d3_Color() {}
2+
3+
d3_Color.prototype.toString = function() {
4+
return this.rgb() + "";
5+
};

src/core/hcl.js

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,20 @@ function d3_Hcl(h, c, l) {
1616
this.l = l;
1717
}
1818

19-
d3_Hcl.prototype.brighter = function(k) {
19+
var d3_hclPrototype = d3_Hcl.prototype = new d3_Color;
20+
21+
d3_hclPrototype.brighter = function(k) {
2022
return d3_hcl(this.h, this.c, Math.min(100, this.l + d3_lab_K * (arguments.length ? k : 1)));
2123
};
2224

23-
d3_Hcl.prototype.darker = function(k) {
25+
d3_hclPrototype.darker = function(k) {
2426
return d3_hcl(this.h, this.c, Math.max(0, this.l - d3_lab_K * (arguments.length ? k : 1)));
2527
};
2628

27-
d3_Hcl.prototype.rgb = function() {
29+
d3_hclPrototype.rgb = function() {
2830
return d3_hcl_lab(this.h, this.c, this.l).rgb();
2931
};
3032

31-
d3_Hcl.prototype.toString = function() {
32-
return this.rgb() + "";
33-
};
34-
3533
function d3_hcl_lab(h, c, l) {
3634
return d3_lab(l, Math.cos(h *= Math.PI / 180) * c, Math.sin(h) * c);
3735
}

src/core/hsl.js

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,24 +15,22 @@ function d3_Hsl(h, s, l) {
1515
this.l = l;
1616
}
1717

18-
d3_Hsl.prototype.brighter = function(k) {
18+
var d3_hslPrototype = d3_Hsl.prototype = new d3_Color;
19+
20+
d3_hslPrototype.brighter = function(k) {
1921
k = Math.pow(0.7, arguments.length ? k : 1);
2022
return d3_hsl(this.h, this.s, this.l / k);
2123
};
2224

23-
d3_Hsl.prototype.darker = function(k) {
25+
d3_hslPrototype.darker = function(k) {
2426
k = Math.pow(0.7, arguments.length ? k : 1);
2527
return d3_hsl(this.h, this.s, k * this.l);
2628
};
2729

28-
d3_Hsl.prototype.rgb = function() {
30+
d3_hslPrototype.rgb = function() {
2931
return d3_hsl_rgb(this.h, this.s, this.l);
3032
};
3133

32-
d3_Hsl.prototype.toString = function() {
33-
return this.rgb().toString();
34-
};
35-
3634
function d3_hsl_rgb(h, s, l) {
3735
var m1,
3836
m2;

src/core/interpolate.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,6 @@ d3.interpolators = [
256256
d3.interpolateObject,
257257
function(a, b) { return b instanceof Array && d3.interpolateArray(a, b); },
258258
function(a, b) { return (typeof a === "string" || typeof b === "string") && d3.interpolateString(a + "", b + ""); },
259-
function(a, b) { return (typeof b === "string" ? d3_rgb_names.has(b) || /^(#|rgb\(|hsl\()/.test(b) : b instanceof d3_Rgb || b instanceof d3_Hsl) && d3.interpolateRgb(a, b); },
259+
function(a, b) { return (typeof b === "string" ? d3_rgb_names.has(b) || /^(#|rgb\(|hsl\()/.test(b) : b instanceof d3_Color) && d3.interpolateRgb(a, b); },
260260
function(a, b) { return !isNaN(a = +a) && !isNaN(b = +b) && d3.interpolateNumber(a, b); }
261261
];

src/core/lab.js

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,22 +24,20 @@ var d3_lab_X = 0.950470,
2424
d3_lab_Y = 1,
2525
d3_lab_Z = 1.088830;
2626

27-
d3_Lab.prototype.brighter = function(k) {
27+
var d3_labPrototype = d3_Lab.prototype = new d3_Color;
28+
29+
d3_labPrototype.brighter = function(k) {
2830
return d3_lab(Math.min(100, this.l + d3_lab_K * (arguments.length ? k : 1)), this.a, this.b);
2931
};
3032

31-
d3_Lab.prototype.darker = function(k) {
33+
d3_labPrototype.darker = function(k) {
3234
return d3_lab(Math.max(0, this.l - d3_lab_K * (arguments.length ? k : 1)), this.a, this.b);
3335
};
3436

35-
d3_Lab.prototype.rgb = function() {
37+
d3_labPrototype.rgb = function() {
3638
return d3_lab_rgb(this.l, this.a, this.b);
3739
};
3840

39-
d3_Lab.prototype.toString = function() {
40-
return this.rgb() + "";
41-
};
42-
4341
function d3_lab_rgb(l, a, b) {
4442
var y = (l + 16) / 116,
4543
x = y + a / 500,

src/core/rgb.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ function d3_Rgb(r, g, b) {
1515
this.b = b;
1616
}
1717

18-
d3_Rgb.prototype.brighter = function(k) {
18+
var d3_rgbPrototype = d3_Rgb.prototype = new d3_Color;
19+
20+
d3_rgbPrototype.brighter = function(k) {
1921
k = Math.pow(0.7, arguments.length ? k : 1);
2022
var r = this.r,
2123
g = this.g,
@@ -31,19 +33,19 @@ d3_Rgb.prototype.brighter = function(k) {
3133
Math.min(255, Math.floor(b / k)));
3234
};
3335

34-
d3_Rgb.prototype.darker = function(k) {
36+
d3_rgbPrototype.darker = function(k) {
3537
k = Math.pow(0.7, arguments.length ? k : 1);
3638
return d3_rgb(
3739
Math.floor(k * this.r),
3840
Math.floor(k * this.g),
3941
Math.floor(k * this.b));
4042
};
4143

42-
d3_Rgb.prototype.hsl = function() {
44+
d3_rgbPrototype.hsl = function() {
4345
return d3_rgb_hsl(this.r, this.g, this.b);
4446
};
4547

46-
d3_Rgb.prototype.toString = function() {
48+
d3_rgbPrototype.toString = function() {
4749
return "#" + d3_rgb_hex(this.r) + d3_rgb_hex(this.g) + d3_rgb_hex(this.b);
4850
};
4951

src/core/tween.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ d3.tween = function(b, interpolate) {
44
var v = b.call(this, d, i);
55
return v == null
66
? a != "" && d3_tweenRemove
7-
: a != v && interpolate(a, v);
7+
: a != v && interpolate(a, v + "");
88
}
99

1010
function tweenString(d, i, a) {

0 commit comments

Comments
 (0)