From 3767ff95cbe59625cf6f3997449b5987919ad852 Mon Sep 17 00:00:00 2001 From: Mike Bostock Date: Wed, 15 Jul 2015 12:51:06 -0700 Subject: [PATCH] Fix prototype initialization. --- index.js | 8 -------- package.json | 4 ++-- src/color.js | 4 ++-- src/cubehelix.js | 4 ++-- src/hcl.js | 4 ++-- src/hsl.js | 4 ++-- src/lab.js | 4 ++-- src/rgb.js | 4 ++-- 8 files changed, 14 insertions(+), 22 deletions(-) diff --git a/index.js b/index.js index 44df3da..9c95efc 100644 --- a/index.js +++ b/index.js @@ -16,14 +16,6 @@ import interpolateCubehelixGammaLong from "./src/interpolateCubehelixGammaLong"; export var interpolateCubehelix = interpolateCubehelixGamma(1); export var interpolateCubehelixLong = interpolateCubehelixGammaLong(1); -// Done lazily to avoid circular dependency between Color, Rgb and Hsl. -color.prototype = Color.prototype; -rgb.prototype = Rgb.prototype; -hsl.prototype = Hsl.prototype; -lab.prototype = Lab.prototype; -hcl.prototype = Hcl.prototype; -cubehelix.prototype = Cubehelix.prototype; - export { color, rgb, diff --git a/package.json b/package.json index 9b286b7..29d3bdf 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "d3-color", - "version": "0.2.3", + "version": "0.2.4", "description": "Color spaces! RGB, HSL, Cubehelix, Lab and HCL (Lch).", "keywords": [ "d3", @@ -30,7 +30,7 @@ "prepublish": "npm run test && uglifyjs build/color.js -c -m -o build/color.min.js && rm -f build/color.zip && zip -j build/color.zip -- LICENSE README.md build/color.js build/color.min.js" }, "devDependencies": { - "d3-bundler": "~0.2.5", + "d3-bundler": "~0.2.8", "faucet": "0.0", "tape": "4", "uglify-js": "2" diff --git a/src/color.js b/src/color.js index dac5add..bfbdc9f 100644 --- a/src/color.js +++ b/src/color.js @@ -9,7 +9,7 @@ var reHex3 = /^#([0-9a-f]{3})$/, reRgbPercent = /^rgb\(\s*([-+]?\d+(?:\.\d+)?)%\s*,\s*([-+]?\d+(?:\.\d+)?)%\s*,\s*([-+]?\d+(?:\.\d+)?)%\s*\)$/, reHslPercent = /^hsl\(\s*([-+]?\d+(?:\.\d+)?)\s*,\s*([-+]?\d+(?:\.\d+)?)%\s*,\s*([-+]?\d+(?:\.\d+)?)%\s*\)$/; -Color.prototype = { +color.prototype = Color.prototype = { displayable: function() { return this.rgb().displayable(); }, @@ -18,7 +18,7 @@ Color.prototype = { } }; -export default function(format) { +export default function color(format) { var m; format = (format + "").trim().toLowerCase(); return (m = reHex3.exec(format)) ? (m = parseInt(m[1], 16), rgb((m >> 8 & 0xf) | (m >> 4 & 0x0f0), (m >> 4 & 0xf) | (m & 0xf0), ((m & 0xf) << 4) | (m & 0xf))) // #f00 diff --git a/src/cubehelix.js b/src/cubehelix.js index 68582b2..e2b2992 100644 --- a/src/cubehelix.js +++ b/src/cubehelix.js @@ -11,7 +11,7 @@ var A = -0.14861, EB = E * B, BC_DA = B * C - D * A; -export default function(h, s, l) { +export default function cubehelix(h, s, l) { if (arguments.length === 1) { if (h instanceof Cubehelix) { l = h.l; @@ -36,7 +36,7 @@ export function Cubehelix(h, s, l) { this.l = +l; }; -var prototype = Cubehelix.prototype = new Color; +var prototype = cubehelix.prototype = Cubehelix.prototype = new Color; prototype.brighter = function(k) { k = k == null ? brighter : Math.pow(brighter, k); diff --git a/src/hcl.js b/src/hcl.js index ff795c3..1095dd3 100644 --- a/src/hcl.js +++ b/src/hcl.js @@ -4,7 +4,7 @@ import {default as lab, Lab, Kn} from "./lab"; export var deg2rad = Math.PI / 180; export var rad2deg = 180 / Math.PI; -export default function(h, c, l) { +export default function hcl(h, c, l) { if (arguments.length === 1) { if (h instanceof Hcl) { l = h.l; @@ -27,7 +27,7 @@ export function Hcl(h, c, l) { this.l = +l; }; -var prototype = Hcl.prototype = new Color; +var prototype = hcl.prototype = Hcl.prototype = new Color; prototype.brighter = function(k) { return new Hcl(this.h, this.c, this.l + Kn * (k == null ? 1 : k)); diff --git a/src/hsl.js b/src/hsl.js index 2435e20..ad80c7b 100644 --- a/src/hsl.js +++ b/src/hsl.js @@ -1,7 +1,7 @@ import {default as color, Color} from "./color"; import {default as rgb, Rgb, darker, brighter} from "./rgb"; -export default function(h, s, l) { +export default function hsl(h, s, l) { if (arguments.length === 1) { if (h instanceof Hsl) { l = h.l; @@ -43,7 +43,7 @@ export function Hsl(h, s, l) { this.l = +l; }; -var prototype = Hsl.prototype = new Color; +var prototype = hsl.prototype = Hsl.prototype = new Color; prototype.brighter = function(k) { k = k == null ? brighter : Math.pow(brighter, k); diff --git a/src/lab.js b/src/lab.js index ef7a714..0596057 100644 --- a/src/lab.js +++ b/src/lab.js @@ -12,7 +12,7 @@ var Xn = 0.950470, // D65 standard referent t2 = 3 * t1 * t1, t3 = t1 * t1 * t1; -export default function(l, a, b) { +export default function lab(l, a, b) { if (arguments.length === 1) { if (l instanceof Lab) { b = l.b; @@ -45,7 +45,7 @@ export function Lab(l, a, b) { this.b = +b; }; -var prototype = Lab.prototype = new Color; +var prototype = lab.prototype = Lab.prototype = new Color; prototype.brighter = function(k) { return new Lab(this.l + Kn * (k == null ? 1 : k), this.a, this.b); diff --git a/src/rgb.js b/src/rgb.js index edaf199..4659ed4 100644 --- a/src/rgb.js +++ b/src/rgb.js @@ -3,7 +3,7 @@ import {default as color, Color} from "./color"; export var darker = .7; export var brighter = 1 / darker; -export default function(r, g, b) { +export default function rgb(r, g, b) { if (arguments.length === 1) { if (!(r instanceof Color)) r = color(r); if (r) { @@ -24,7 +24,7 @@ export function Rgb(r, g, b) { this.b = +b; }; -var prototype = Rgb.prototype = new Color; +var prototype = rgb.prototype = Rgb.prototype = new Color; prototype.brighter = function(k) { k = k == null ? brighter : Math.pow(brighter, k);