UNPKG

d3plus-color

Version:

Color functions that extent the ability of d3-color.

16 lines (15 loc) 600 B
import { getColor } from "./defaults.js"; import { rgb } from "d3-color"; /** @function colorContrast @desc A set of default color values used when assigning colors based on data. @param {String} c A valid CSS color string. @param {Object} [u = defaults] An object containing overrides of the default colors. @returns {String} */ export default function (c) { var u = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; c = rgb(c); var yiq = (c.r * 299 + c.g * 587 + c.b * 114) / 1000; return yiq >= 128 ? getColor("dark", u) : getColor("light", u); }