|
243 | 243 | return Math.max(0, Math.min(1, (x - a) * b)); |
244 | 244 | }; |
245 | 245 | } |
| 246 | + function d3_Color() {} |
246 | 247 | function d3_rgb(r, g, b) { |
247 | 248 | return new d3_Rgb(r, g, b); |
248 | 249 | } |
|
3388 | 3389 | }, function(a, b) { |
3389 | 3390 | return (typeof a === "string" || typeof b === "string") && d3.interpolateString(a + "", b + ""); |
3390 | 3391 | }, 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); |
3392 | 3393 | }, function(a, b) { |
3393 | 3394 | return !isNaN(a = +a) && !isNaN(b = +b) && d3.interpolateNumber(a, b); |
3394 | 3395 | } ]; |
| 3396 | + d3_Color.prototype.toString = function() { |
| 3397 | + return this.rgb() + ""; |
| 3398 | + }; |
3395 | 3399 | d3.rgb = function(r, g, b) { |
3396 | 3400 | 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); |
3397 | 3401 | }; |
3398 | | - d3_Rgb.prototype.brighter = function(k) { |
| 3402 | + var d3_rgbPrototype = d3_Rgb.prototype = new d3_Color; |
| 3403 | + d3_rgbPrototype.brighter = function(k) { |
3399 | 3404 | k = Math.pow(.7, arguments.length ? k : 1); |
3400 | 3405 | var r = this.r, g = this.g, b = this.b, i = 30; |
3401 | 3406 | if (!r && !g && !b) return d3_rgb(i, i, i); |
|
3404 | 3409 | if (b && b < i) b = i; |
3405 | 3410 | return d3_rgb(Math.min(255, Math.floor(r / k)), Math.min(255, Math.floor(g / k)), Math.min(255, Math.floor(b / k))); |
3406 | 3411 | }; |
3407 | | - d3_Rgb.prototype.darker = function(k) { |
| 3412 | + d3_rgbPrototype.darker = function(k) { |
3408 | 3413 | k = Math.pow(.7, arguments.length ? k : 1); |
3409 | 3414 | return d3_rgb(Math.floor(k * this.r), Math.floor(k * this.g), Math.floor(k * this.b)); |
3410 | 3415 | }; |
3411 | | - d3_Rgb.prototype.hsl = function() { |
| 3416 | + d3_rgbPrototype.hsl = function() { |
3412 | 3417 | return d3_rgb_hsl(this.r, this.g, this.b); |
3413 | 3418 | }; |
3414 | | - d3_Rgb.prototype.toString = function() { |
| 3419 | + d3_rgbPrototype.toString = function() { |
3415 | 3420 | return "#" + d3_rgb_hex(this.r) + d3_rgb_hex(this.g) + d3_rgb_hex(this.b); |
3416 | 3421 | }; |
3417 | 3422 | var d3_rgb_names = d3.map({ |
|
3569 | 3574 | d3.hsl = function(h, s, l) { |
3570 | 3575 | 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); |
3571 | 3576 | }; |
3572 | | - d3_Hsl.prototype.brighter = function(k) { |
| 3577 | + var d3_hslPrototype = d3_Hsl.prototype = new d3_Color; |
| 3578 | + d3_hslPrototype.brighter = function(k) { |
3573 | 3579 | k = Math.pow(.7, arguments.length ? k : 1); |
3574 | 3580 | return d3_hsl(this.h, this.s, this.l / k); |
3575 | 3581 | }; |
3576 | | - d3_Hsl.prototype.darker = function(k) { |
| 3582 | + d3_hslPrototype.darker = function(k) { |
3577 | 3583 | k = Math.pow(.7, arguments.length ? k : 1); |
3578 | 3584 | return d3_hsl(this.h, this.s, k * this.l); |
3579 | 3585 | }; |
3580 | | - d3_Hsl.prototype.rgb = function() { |
| 3586 | + d3_hslPrototype.rgb = function() { |
3581 | 3587 | return d3_hsl_rgb(this.h, this.s, this.l); |
3582 | 3588 | }; |
3583 | | - d3_Hsl.prototype.toString = function() { |
3584 | | - return this.rgb().toString(); |
3585 | | - }; |
3586 | 3589 | d3.hcl = function(h, c, l) { |
3587 | 3590 | 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); |
3588 | 3591 | }; |
3589 | | - d3_Hcl.prototype.brighter = function(k) { |
| 3592 | + var d3_hclPrototype = d3_Hcl.prototype = new d3_Color; |
| 3593 | + d3_hclPrototype.brighter = function(k) { |
3590 | 3594 | return d3_hcl(this.h, this.c, Math.min(100, this.l + d3_lab_K * (arguments.length ? k : 1))); |
3591 | 3595 | }; |
3592 | | - d3_Hcl.prototype.darker = function(k) { |
| 3596 | + d3_hclPrototype.darker = function(k) { |
3593 | 3597 | return d3_hcl(this.h, this.c, Math.max(0, this.l - d3_lab_K * (arguments.length ? k : 1))); |
3594 | 3598 | }; |
3595 | | - d3_Hcl.prototype.rgb = function() { |
| 3599 | + d3_hclPrototype.rgb = function() { |
3596 | 3600 | return d3_hcl_lab(this.h, this.c, this.l).rgb(); |
3597 | 3601 | }; |
3598 | | - d3_Hcl.prototype.toString = function() { |
3599 | | - return this.rgb() + ""; |
3600 | | - }; |
3601 | 3602 | d3.lab = function(l, a, b) { |
3602 | 3603 | 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); |
3603 | 3604 | }; |
3604 | 3605 | var d3_lab_K = 18; |
3605 | 3606 | 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) { |
3607 | 3609 | return d3_lab(Math.min(100, this.l + d3_lab_K * (arguments.length ? k : 1)), this.a, this.b); |
3608 | 3610 | }; |
3609 | | - d3_Lab.prototype.darker = function(k) { |
| 3611 | + d3_labPrototype.darker = function(k) { |
3610 | 3612 | return d3_lab(Math.max(0, this.l - d3_lab_K * (arguments.length ? k : 1)), this.a, this.b); |
3611 | 3613 | }; |
3612 | | - d3_Lab.prototype.rgb = function() { |
| 3614 | + d3_labPrototype.rgb = function() { |
3613 | 3615 | return d3_lab_rgb(this.l, this.a, this.b); |
3614 | 3616 | }; |
3615 | | - d3_Lab.prototype.toString = function() { |
3616 | | - return this.rgb() + ""; |
3617 | | - }; |
3618 | 3617 | var d3_select = function(s, n) { |
3619 | 3618 | return n.querySelector(s); |
3620 | 3619 | }, d3_selectAll = function(s, n) { |
|
4097 | 4096 | d3.tween = function(b, interpolate) { |
4098 | 4097 | function tweenFunction(d, i, a) { |
4099 | 4098 | 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 + ""); |
4101 | 4100 | } |
4102 | 4101 | function tweenString(d, i, a) { |
4103 | 4102 | return a != b && interpolate(a, b); |
|
0 commit comments