Skip to content

Commit

Permalink
Fix prototype initialization.
Browse files Browse the repository at this point in the history
  • Loading branch information
mbostock committed Jul 15, 2015
1 parent eb8b568 commit 3767ff9
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 22 deletions.
8 changes: 0 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down Expand Up @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions src/color.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
},
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/cubehelix.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/hcl.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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));
Expand Down
4 changes: 2 additions & 2 deletions src/hsl.js
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/lab.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/rgb.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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);
Expand Down

0 comments on commit 3767ff9

Please sign in to comment.