Skip to content

Instantly share code, notes, and snippets.

@lukehorvat
Last active June 21, 2016 04:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lukehorvat/dd5a40b85b95ac61377c985beb63685c to your computer and use it in GitHub Desktop.
Save lukehorvat/dd5a40b85b95ac61377c985beb63685c to your computer and use it in GitHub Desktop.
Get a color within a defined color range, based on a percentage number.
import { scaleLinear } from "d3-scale";
const getColor = scaleLinear().domain([0, 100]).range(["#ccc", "#419fcf"]);
getColor(0); // 0% = #ccc
getColor(80); // 80% = #5da8ce
getColor(100); // 100% = #419fcf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment