From 693572be4c654b9e38eeb94ab6cbdb65a609e3cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philippe=20Rivi=C3=A8re?= Date: Tue, 2 Jun 2020 16:17:14 +0200 Subject: [PATCH 1/5] deliberate ES6 syntax (rationale: don't let people install @2 in a build system that will not alert them that we have moved to ES6, only to cause trouble with a later release.) --- src/lab.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lab.js b/src/lab.js index b27196e..02545c4 100644 --- a/src/lab.js +++ b/src/lab.js @@ -3,7 +3,7 @@ import {Color, rgbConvert, Rgb} from "./color.js"; import {deg2rad, rad2deg} from "./math.js"; // https://observablehq.com/@mbostock/lab-and-rgb -var K = 18, +const K = 18, Xn = 0.96422, Yn = 1, Zn = 0.82521, From c1b93f1bcb27945403aceac36bc64648d8a2b8a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philippe=20Rivi=C3=A8re?= Date: Tue, 2 Jun 2020 16:21:34 +0200 Subject: [PATCH 2/5] normalize "degrees" and "radians" for deg2rad conversions --- src/cubehelix.js | 6 +++--- src/lab.js | 6 +++--- src/math.js | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/cubehelix.js b/src/cubehelix.js index bc31659..83536dd 100644 --- a/src/cubehelix.js +++ b/src/cubehelix.js @@ -1,6 +1,6 @@ import define, {extend} from "./define.js"; import {Color, rgbConvert, Rgb, darker, brighter} from "./color.js"; -import {deg2rad, rad2deg} from "./math.js"; +import {degrees, radians} from "./math.js"; var A = -0.14861, B = +1.78277, @@ -21,7 +21,7 @@ function cubehelixConvert(o) { bl = b - l, k = (E * (g - l) - C * bl) / D, s = Math.sqrt(k * k + bl * bl) / (E * l * (1 - l)), // NaN if l=0 or l=1 - h = s ? Math.atan2(k, bl) * rad2deg - 120 : NaN; + h = s ? Math.atan2(k, bl) * degrees - 120 : NaN; return new Cubehelix(h < 0 ? h + 360 : h, s, l, o.opacity); } @@ -46,7 +46,7 @@ define(Cubehelix, cubehelix, extend(Color, { return new Cubehelix(this.h, this.s, this.l * k, this.opacity); }, rgb: function() { - var h = isNaN(this.h) ? 0 : (this.h + 120) * deg2rad, + var h = isNaN(this.h) ? 0 : (this.h + 120) * radians, l = +this.l, a = isNaN(this.s) ? 0 : this.s * l * (1 - l), cosh = Math.cos(h), diff --git a/src/lab.js b/src/lab.js index 02545c4..645e1a5 100644 --- a/src/lab.js +++ b/src/lab.js @@ -1,6 +1,6 @@ import define, {extend} from "./define.js"; import {Color, rgbConvert, Rgb} from "./color.js"; -import {deg2rad, rad2deg} from "./math.js"; +import {degrees, radians} from "./math.js"; // https://observablehq.com/@mbostock/lab-and-rgb const K = 18, @@ -85,7 +85,7 @@ function hclConvert(o) { if (o instanceof Hcl) return new Hcl(o.h, o.c, o.l, o.opacity); if (!(o instanceof Lab)) o = labConvert(o); if (o.a === 0 && o.b === 0) return new Hcl(NaN, 0 < o.l && o.l < 100 ? 0 : NaN, o.l, o.opacity); - var h = Math.atan2(o.b, o.a) * rad2deg; + var h = Math.atan2(o.b, o.a) * degrees; return new Hcl(h < 0 ? h + 360 : h, Math.sqrt(o.a * o.a + o.b * o.b), o.l, o.opacity); } @@ -106,7 +106,7 @@ export function Hcl(h, c, l, opacity) { function hcl2lab(o) { if (isNaN(o.h)) return new Lab(o.l, 0, 0, o.opacity); - var h = o.h * deg2rad; + var h = o.h * radians; return new Lab(o.l, Math.cos(h) * o.c, Math.sin(h) * o.c, o.opacity); } diff --git a/src/math.js b/src/math.js index e94b840..66b172e 100644 --- a/src/math.js +++ b/src/math.js @@ -1,2 +1,2 @@ -export var deg2rad = Math.PI / 180; -export var rad2deg = 180 / Math.PI; +export const radians = Math.PI / 180; +export const degrees = 180 / Math.PI; From d86e36ba1631b78c5bea2bb091d8fd3db8418b2e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philippe=20Rivi=C3=A8re?= Date: Tue, 2 Jun 2020 16:45:29 +0200 Subject: [PATCH 3/5] link to https://d3js.org/d3-color.v2.min.js --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index f6d79b2..386d4dc 100644 --- a/README.md +++ b/README.md @@ -47,10 +47,10 @@ For additional color spaces, see: ## Installing -If you use NPM, `npm install d3-color`. Otherwise, download the [latest release](https://github.com/d3/d3-color/releases/latest). You can also load directly from [d3js.org](https://d3js.org), either as a [standalone library](https://d3js.org/d3-color.v1.min.js) or as part of [D3](https://github.com/d3/d3). AMD, CommonJS, and vanilla environments are supported. In vanilla, a `d3` global is exported: +If you use NPM, `npm install d3-color`. Otherwise, download the [latest release](https://github.com/d3/d3-color/releases/latest). You can also load directly from [d3js.org](https://d3js.org), either as a [standalone library](https://d3js.org/d3-color.v2.min.js) or as part of [D3](https://github.com/d3/d3). AMD, CommonJS, and vanilla environments are supported. In vanilla, a `d3` global is exported: ```html - +