diff --git a/README.md b/README.md index 20ae5fe..66e8575 100644 --- a/README.md +++ b/README.md @@ -233,6 +233,12 @@ Given a number *t* in the range [0,1], returns the corresponding color from the Sequential, multi-hue color schemes are available as continuous interpolators (often used with [d3.scaleSequential](https://github.com/d3/d3-scale/blob/master/README.md#sequential-scales)) and as discrete schemes (often used with [d3.scaleOrdinal](https://github.com/d3/d3-scale/blob/master/README.md#ordinal-scales)). Each discrete scheme, such as [d3.schemeBuGn](#schemeBuGn), is represented as an array of arrays of hexadecimal color strings. The *k*th element of this array contains the color scheme of size *k*; for example, `d3.schemeBuGn[9]` contains an array of nine strings representing the nine colors of the blue-green sequential color scheme. Sequential, multi-hue color schemes support a size *k* ranging from 3 to 9. +# d3.interpolateStdGammaII(t) [<>](https://github.com/d3/d3-scale-chromatic/blob/master/src/sequential-multi/stdGammaII.js "Source") + +StdGammaII + +Given a number *t* in the range [0,1], returns the corresponding color from the “STD GAMMA-II” color scheme initially implemented in [IDL](https://www.l3harrisgeospatial.com/docs/loadingdefaultcolortables.html). + # d3.interpolateTurbo(t) [<>](https://github.com/d3/d3-scale-chromatic/blob/master/src/sequential-multi/turbo.js "Source") turbo diff --git a/img/StdGammaII.png b/img/StdGammaII.png new file mode 100644 index 0000000..bea9b2f Binary files /dev/null and b/img/StdGammaII.png differ diff --git a/package.json b/package.json index 47206a2..f6f928c 100644 --- a/package.json +++ b/package.json @@ -37,7 +37,8 @@ }, "dependencies": { "d3-color": "1 - 2", - "d3-interpolate": "1 - 2" + "d3-interpolate": "1 - 2", + "d3-scale": "3" }, "devDependencies": { "eslint": "6", diff --git a/src/index.js b/src/index.js index 3170296..086ab63 100644 --- a/src/index.js +++ b/src/index.js @@ -39,5 +39,6 @@ export {default as interpolateCividis} from "./sequential-multi/cividis.js"; export {default as interpolateCubehelixDefault} from "./sequential-multi/cubehelix.js"; export {default as interpolateRainbow, warm as interpolateWarm, cool as interpolateCool} from "./sequential-multi/rainbow.js"; export {default as interpolateSinebow} from "./sequential-multi/sinebow.js"; +export {default as interpolateStdGammaII} from "./sequential-multi/stdGammaII.js"; export {default as interpolateTurbo} from "./sequential-multi/turbo.js"; export {default as interpolateViridis, magma as interpolateMagma, inferno as interpolateInferno, plasma as interpolatePlasma} from "./sequential-multi/viridis.js"; diff --git a/src/sequential-multi/stdGammaII.js b/src/sequential-multi/stdGammaII.js new file mode 100644 index 0000000..46fbc2c --- /dev/null +++ b/src/sequential-multi/stdGammaII.js @@ -0,0 +1,16 @@ + +import {rgb} from "d3-color"; +import {scaleLinear} from "d3-scale"; + +// Reimplementation of the IDL "STD Gamma II" color scale, based on bioRad's implementation (https://github.com/adokter/bioRad/blob/e0ede427eb34007dc9985302d40cbdab158e0636/R/color_scale.R#L65-L85) +// and the explanations at: https://github.com/inbo/crow/issues/38 +export default function(t) { + t = 255 - (t * 255); // Constants below are taken from bioRad and have a 0-255 range + + return rgb( + scaleLinear().domain([0, 62, 81, 93, 145, 176, 191, 208, 255]).range([255, 255, 163, 255, 255, 81, 81, 0, 0])(t), + scaleLinear().domain([0, 64, 79, 110, 142, 255]).range([255, 255, 163, 163, 0, 0])(t), + scaleLinear().domain([0, 79, 96, 110, 127, 159, 206, 255]).range([255, 0, 0, 82, 0, 0, 255, 0])(t), + 1 + ) + } \ No newline at end of file diff --git a/test/index-test.js b/test/index-test.js index 015aeee..6bd2960 100644 --- a/test/index-test.js +++ b/test/index-test.js @@ -34,6 +34,7 @@ tape("exports the expected schemes", function(test) { "interpolateReds", "interpolateSinebow", "interpolateSpectral", + "interpolateStdGammaII", "interpolateTurbo", "interpolateViridis", "interpolateWarm", diff --git a/yarn.lock b/yarn.lock index c8ba9f1..1569d26 100644 --- a/yarn.lock +++ b/yarn.lock @@ -169,18 +169,55 @@ cross-spawn@^6.0.5: shebang-command "^1.2.0" which "^1.2.9" +d3-array@2, d3-array@^2.3.0: + version "2.12.1" + resolved "https://registry.yarnpkg.com/d3-array/-/d3-array-2.12.1.tgz#e20b41aafcdffdf5d50928004ececf815a465e81" + integrity sha512-B0ErZK/66mHtEsR1TkPEEkwdy+WDesimkM5gpZr5Dsg54BiTA5RXtYW5qTLIAcekaS9xfZrzBLF/OAkB3Qn1YQ== + dependencies: + internmap "^1.0.0" + "d3-color@1 - 2": version "2.0.0" resolved "https://registry.yarnpkg.com/d3-color/-/d3-color-2.0.0.tgz#8d625cab42ed9b8f601a1760a389f7ea9189d62e" integrity sha512-SPXi0TSKPD4g9tw0NMZFnR95XVgUZiBH+uUTqQuDu1OsE2zomHU7ho0FISciaPvosimixwHFl3WHLGabv6dDgQ== -"d3-interpolate@1 - 2": +"d3-format@1 - 2": + version "2.0.0" + resolved "https://registry.yarnpkg.com/d3-format/-/d3-format-2.0.0.tgz#a10bcc0f986c372b729ba447382413aabf5b0767" + integrity sha512-Ab3S6XuE/Q+flY96HXT0jOXcM4EAClYFnRGY5zsjRGNy6qCYrQsMffs7cV5Q9xejb35zxW5hf/guKw34kvIKsA== + +"d3-interpolate@1 - 2", "d3-interpolate@1.2.0 - 2": version "2.0.1" resolved "https://registry.yarnpkg.com/d3-interpolate/-/d3-interpolate-2.0.1.tgz#98be499cfb8a3b94d4ff616900501a64abc91163" integrity sha512-c5UhwwTs/yybcmTpAVqwSFl6vrQ8JZJoT5F7xNFK9pymv5C0Ymcc9/LIJHtYIggg/yS9YHw8i8O8tgb9pupjeQ== dependencies: d3-color "1 - 2" +d3-scale@3: + version "3.3.0" + resolved "https://registry.yarnpkg.com/d3-scale/-/d3-scale-3.3.0.tgz#28c600b29f47e5b9cd2df9749c206727966203f3" + integrity sha512-1JGp44NQCt5d1g+Yy+GeOnZP7xHo0ii8zsQp6PGzd+C1/dl0KGsp9A7Mxwp+1D1o4unbTTxVdU/ZOIEBoeZPbQ== + dependencies: + d3-array "^2.3.0" + d3-format "1 - 2" + d3-interpolate "1.2.0 - 2" + d3-time "^2.1.1" + d3-time-format "2 - 3" + +"d3-time-format@2 - 3": + version "3.0.0" + resolved "https://registry.yarnpkg.com/d3-time-format/-/d3-time-format-3.0.0.tgz#df8056c83659e01f20ac5da5fdeae7c08d5f1bb6" + integrity sha512-UXJh6EKsHBTjopVqZBhFysQcoXSv/5yLONZvkQ5Kk3qbwiUYkdX17Xa1PT6U1ZWXGGfB1ey5L8dKMlFq2DO0Ag== + dependencies: + d3-time "1 - 2" + +"d3-time@1 - 2", d3-time@^2.1.1: + version "2.1.1" + resolved "https://registry.yarnpkg.com/d3-time/-/d3-time-2.1.1.tgz#e9d8a8a88691f4548e68ca085e5ff956724a6682" + integrity sha512-/eIQe/eR4kCQwq7yxi7z4c6qEXf2IYGcjoWB5OOQy4Tq9Uv39/947qlDcN2TLkiTzQWzvnsuYPB9TrWaNfipKQ== + dependencies: + d3-array "2" + debug@^4.0.1: version "4.1.1" resolved "https://registry.yarnpkg.com/debug/-/debug-4.1.1.tgz#3b72260255109c6b589cee050f1d516139664791" @@ -526,6 +563,11 @@ inquirer@^6.4.1: strip-ansi "^5.1.0" through "^2.3.6" +internmap@^1.0.0: + version "1.0.1" + resolved "https://registry.yarnpkg.com/internmap/-/internmap-1.0.1.tgz#0017cc8a3b99605f0302f2b198d272e015e5df95" + integrity sha512-lDB5YccMydFBtasVtxnZ3MRBHuaoE8GKsppq+EchKL2U4nK/DmEpPHNH8MZe5HkMtpSiTSOZwfN0tzYjO/lJEw== + is-callable@^1.1.3, is-callable@^1.1.4: version "1.1.4" resolved "https://registry.yarnpkg.com/is-callable/-/is-callable-1.1.4.tgz#1e1adf219e1eeb684d691f9d6a05ff0d30a24d75"