Skip to content

Commit

Permalink
100% is 255, not 254.99999999999997.
Browse files Browse the repository at this point in the history
  • Loading branch information
mbostock committed Oct 18, 2015
1 parent a01276b commit 710e5a7
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "d3-color",
"version": "0.2.5",
"version": "0.2.6",
"description": "Color spaces! RGB, HSL, Cubehelix, Lab and HCL (Lch).",
"keywords": [
"d3",
Expand Down
4 changes: 2 additions & 2 deletions src/color.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ export default function color(format) {
return (m = reHex3.exec(format)) ? (m = parseInt(m[1], 16), rgb((m >> 8 & 0xf) | (m >> 4 & 0x0f0), (m >> 4 & 0xf) | (m & 0xf0), ((m & 0xf) << 4) | (m & 0xf))) // #f00
: (m = reHex6.exec(format)) ? rgbn(parseInt(m[1], 16)) // #ff0000
: (m = reRgbInteger.exec(format)) ? rgb(m[1], m[2], m[3]) // rgb(255,0,0)
: (m = reRgbPercent.exec(format)) ? rgb(m[1] * 2.55, m[2] * 2.55, m[3] * 2.55) // rgb(100%,0%,0%)
: (m = reHslPercent.exec(format)) ? hsl(m[1], m[2] * .01, m[3] * .01) // hsl(120,50%,50%)
: (m = reRgbPercent.exec(format)) ? rgb(m[1] * 255 / 100, m[2] * 255 / 100, m[3] * 255 / 100) // rgb(100%,0%,0%)
: (m = reHslPercent.exec(format)) ? hsl(m[1], m[2] / 100, m[3] / 100) // hsl(120,50%,50%)
: named.hasOwnProperty(format) ? rgbn(named[format])
: null;
};
Expand Down
1 change: 1 addition & 0 deletions test/color-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ tape("color(format) parses RGB integer format (e.g., \"rgb(12,34,56)\")", functi

tape("color(format) parses RGB percentage format (e.g., \"rgb(12%,34%,56%)\")", function(test) {
test.rgbEqual(color.color("rgb(12%,34%,56%)"), 31, 87, 143);
test.rgbStrictEqual(color.color("rgb(100%,100%,100%)"), 255, 255, 255);
test.end();
});

Expand Down

0 comments on commit 710e5a7

Please sign in to comment.