See this [Observable notebook](https://beta.observablehq.com/@danburzo/color-difference-formulas-with-d3-color-difference) for a demonstration.
npm install d3-color-differenceSee this Observable notebook for a demonstration.
``bash``
$ npm install d3-color-difference
# d3.__differenceEuclideanRGB__(_a_, _b_) <>
Computes the [Euclidean distance][euclidean] between the colors _a_ and _b_ in the [RGB][RGB] color space.
# d3.__differenceEuclideanLab__(_a_, _b_) <>
Computes the [Euclidean distance][euclidean] between the colors _a_ and _b_ in the [Lab][Lab] color space.
# d3.__differenceEuclideanHcl__(_a_, _b_) <>
Computes the [Euclidean distance][euclidean] between the colors _a_ and _b_ in the [HCL][HCL] color space.
# d3.__differenceEuclideanHsl__(_a_, _b_) <>
Computes the [Euclidean distance][euclidean] between the colors _a_ and _b_ in the [HSL][HSL] color space.
# d3.__differenceEuclideanCubehelix__(_a_, _b_) <>
Computes the [Euclidean distance][euclidean] between the colors _a_ and _b_ in the [Cubehelix][Cubehelix] color space.
# d3.__differenceCie76__(_a_, _b_) <>
Computes the [CIE76][CIE76] ΔE\*ab color difference between the colors _a_ and _b_. The computation is done in the [Lab][Lab] color space and it is analogous to differenceEuclideanLab.
# d3.__differenceCie94__(_a_, _b_) <>
Computes the [CIE94][CIE94] ΔE\*94 color difference between the colors _a_ and _b_. The computation is done in the [Lab][Lab] color space, with the default weights _kL = 1_, _K1 = 0.045_, and _K2 = 0.015_.
# d3.__differenceCie94Weighted__(_kL_, _K1_, _K2_) <>
Returns a [CIE94][CIE94] difference function with custom weighting parameters.
# d3.__differenceCiede2000__(_a_, _b_) <>
Computes the [CIEDE2000][CIEDE2000] ΔE\*00 color difference between the colors _a_ and _b_ as implemented by G. Sharma. The computation is done in the [Lab][Lab] color space, with the default weights _kL = kC = kH = 1_.
# d3.__differenceCiede2000Weighted__(_kL_, _kC_, _kH_) <>
Returns a [CIEDE2000][CIEDE2000] difference function with custom weighting parameters.
# d3.__differenceCmc__(_a_, _b_) <>
Computes the [CMC l:c (1984)][CMC] ΔE\*CMC color difference between the colors _a_ and _b_. The computation is done in the [Lab][Lab] color space with the default weights _l = c = 1_.
_Note:_ ΔE\*CMC is not considered a metric since it's not symmetrical, i.e. the distance from _a_ to _b_ is not always equal to the distance from _b_ to _a_.
# d3.__differenceCmcWeighted__(_l_, _c_) <>
Returns a [CMC l:c (1984)][CMC] difference function with custom weighting parameters.
# d3.__differenceDin99o__(_a_, _b_) <>
Computes the [DIN99o][DIN99oDE] ΔE\*99o color difference between the colors _a_ and _b_. The computation is done in the [DIN99o][DIN99o] color space with the default weights _kCH = kE = 1_.
# d3.__differenceDin99oWeighted__(_kCH_, _kE_) <>
Returns a [DIN99o][DIN99oDE] difference function with custom weighting parameters.
# d3.__differenceWithOpacity__(_differenceFunction_, _a_, _b_) <>
The difference functions don't take the colors' alpha channel into account when computing distances. This method allows you to factor the colors' opacities into the distance.
[color-diff]: https://en.wikipedia.org/wiki/Color_difference
[euclidean]: https://en.wikipedia.org/wiki/Color_difference#Euclidean
[CIE76]: https://en.wikipedia.org/wiki/Color_difference#CIE76
[CIE94]: https://en.wikipedia.org/wiki/Color_difference#CIE94
[CIEDE2000]: https://en.wikipedia.org/wiki/Color_difference#CIEDE2000
[CMC]: https://en.wikipedia.org/wiki/Color_difference#CMC_l:c_(1984)
[DIN99o]: https://de.wikipedia.org/wiki/DIN99-Farbraum
[DIN99oDE]: https://de.wikipedia.org/wiki/DIN99-Farbraum#Farbabstandsformel
[RGB]: https://github.com/d3/d3-color#rgb
[HSL]: https://github.com/d3/d3-color#hsl
[Lab]: https://github.com/d3/d3-color#lab
[HCL]: https://github.com/d3/d3-color#hcl
[Cubehelix]: https://github.com/d3/d3-color#cubehelix