How to use the chroma-js.distance function in chroma-js

To help you get started, we’ve selected a few chroma-js examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Automattic / wp-calypso / bin / audit-svg-colors.js View on Github external
function findClosestColor( value, targetValues ) {
	let closestValue = value;
	let closestDistance = Infinity;
	let targetValue;

	for ( targetValue of targetValues ) {
		const distance = chroma.distance( value, targetValue );

		// This bit shortens existing variations of white to `#fff`
		if ( distance === 0 ) {
			closestValue = targetValue;
			closestDistance = distance;
			break;
		}

		// Unless white is explicitely used, let’s not convert darker colors to it
		if ( targetValue === '#fff' ) {
			continue;
		}

		if ( distance < closestDistance ) {
			closestValue = targetValue;
			closestDistance = distance;
github Automattic / color-studio / info / material-elevation.js View on Github external
forIn(PALETTE, (colorValue, colorName) => {
    if (colorValue === color) {
      closestColorName = colorName
      closestColorValue = colorValue
      return false
    }

    const colorDistance = chroma.distance(color, colorValue)
    if (!isNumber(closestColorDistance) || closestColorDistance > colorDistance) {
      closestColorDistance = colorDistance
      closestColorName = colorName
      closestColorValue = colorValue
    }
  })
github BlueBrain / Brayns / js / apps / viewer / src / common / components / transfer-function / transfer-function.spec.tsx View on Github external
function compareColor(a: string, b: string) {
    const a0 = chroma(a);
    const b0 = chroma(b);
    const d: number = distance(a0, b0) as any;
    return d === 0;
}
github colorjs / color-namer / index.js View on Github external
.map (function(name) {
        name.distance = chroma.distance(color, chroma(name.hex))
        return name
      })
      .sort (function(a, b) {