Skip to content

Commit

Permalink
method shorthand
Browse files Browse the repository at this point in the history
  • Loading branch information
mbostock committed Mar 28, 2022
1 parent e4bc34e commit 5e9f757
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 22 deletions.
26 changes: 13 additions & 13 deletions src/color.js
Expand Up @@ -168,10 +168,10 @@ var named = {
};

define(Color, color, {
copy: function(channels) {
copy(channels) {
return Object.assign(new this.constructor, this, channels);
},
displayable: function() {
displayable() {
return this.rgb().displayable();
},
hex: color_formatHex, // Deprecated! Use color.formatHex.
Expand Down Expand Up @@ -245,21 +245,21 @@ export function Rgb(r, g, b, opacity) {
}

define(Rgb, rgb, extend(Color, {
brighter: function(k) {
brighter(k) {
k = k == null ? brighter : Math.pow(brighter, k);
return new Rgb(this.r * k, this.g * k, this.b * k, this.opacity);
},
darker: function(k) {
darker(k) {
k = k == null ? darker : Math.pow(darker, k);
return new Rgb(this.r * k, this.g * k, this.b * k, this.opacity);
},
rgb: function() {
rgb() {
return this;
},
clamp: function() {
clamp() {
return new Rgb(clampi(this.r), clampi(this.g), clampi(this.b), clampa(this.opacity));
},
displayable: function() {
displayable() {
return (-0.5 <= this.r && this.r < 255.5)
&& (-0.5 <= this.g && this.g < 255.5)
&& (-0.5 <= this.b && this.b < 255.5)
Expand Down Expand Up @@ -343,15 +343,15 @@ function Hsl(h, s, l, opacity) {
}

define(Hsl, hsl, extend(Color, {
brighter: function(k) {
brighter(k) {
k = k == null ? brighter : Math.pow(brighter, k);
return new Hsl(this.h, this.s, this.l * k, this.opacity);
},
darker: function(k) {
darker(k) {
k = k == null ? darker : Math.pow(darker, k);
return new Hsl(this.h, this.s, this.l * k, this.opacity);
},
rgb: function() {
rgb() {
var h = this.h % 360 + (this.h < 0) * 360,
s = isNaN(h) || isNaN(this.s) ? 0 : this.s,
l = this.l,
Expand All @@ -364,15 +364,15 @@ define(Hsl, hsl, extend(Color, {
this.opacity
);
},
clamp: function() {
clamp() {
return new Hsl(clamph(this.h), clampt(this.s), clampt(this.l), clampa(this.opacity));
},
displayable: function() {
displayable() {
return (0 <= this.s && this.s <= 1 || isNaN(this.s))
&& (0 <= this.l && this.l <= 1)
&& (0 <= this.opacity && this.opacity <= 1);
},
formatHsl: function() {
formatHsl() {
const a = clampa(this.opacity);
return `${a === 1 ? "hsl(" : "hsla("}${clamph(this.h)}, ${clampt(this.s) * 100}%, ${clampt(this.l) * 100}%${a === 1 ? ")" : `, ${a})`}`;
}
Expand Down
6 changes: 3 additions & 3 deletions src/cubehelix.js
Expand Up @@ -37,15 +37,15 @@ export function Cubehelix(h, s, l, opacity) {
}

define(Cubehelix, cubehelix, extend(Color, {
brighter: function(k) {
brighter(k) {
k = k == null ? brighter : Math.pow(brighter, k);
return new Cubehelix(this.h, this.s, this.l * k, this.opacity);
},
darker: function(k) {
darker(k) {
k = k == null ? darker : Math.pow(darker, k);
return new Cubehelix(this.h, this.s, this.l * k, this.opacity);
},
rgb: function() {
rgb() {
var h = isNaN(this.h) ? 0 : (this.h + 120) * radians,
l = +this.l,
a = isNaN(this.s) ? 0 : this.s * l * (1 - l),
Expand Down
12 changes: 6 additions & 6 deletions src/lab.js
Expand Up @@ -43,13 +43,13 @@ export function Lab(l, a, b, opacity) {
}

define(Lab, lab, extend(Color, {
brighter: function(k) {
brighter(k) {
return new Lab(this.l + K * (k == null ? 1 : k), this.a, this.b, this.opacity);
},
darker: function(k) {
darker(k) {
return new Lab(this.l - K * (k == null ? 1 : k), this.a, this.b, this.opacity);
},
rgb: function() {
rgb() {
var y = (this.l + 16) / 116,
x = isNaN(this.a) ? y : y + this.a / 500,
z = isNaN(this.b) ? y : y - this.b / 200;
Expand Down Expand Up @@ -111,13 +111,13 @@ function hcl2lab(o) {
}

define(Hcl, hcl, extend(Color, {
brighter: function(k) {
brighter(k) {
return new Hcl(this.h, this.c, this.l + K * (k == null ? 1 : k), this.opacity);
},
darker: function(k) {
darker(k) {
return new Hcl(this.h, this.c, this.l - K * (k == null ? 1 : k), this.opacity);
},
rgb: function() {
rgb() {
return hcl2lab(this).rgb();
}
}));

0 comments on commit 5e9f757

Please sign in to comment.