Commit 04fe8f8e authored by Mike Bostock's avatar Mike Bostock
Browse files

Refactor color tests using smash.

parent fe0d6f3e
require("../env");
var vows = require("vows"),
load = require("../load"),
assert = require("../env-assert");
var suite = vows.describe("d3.hcl");
suite.addBatch({
"hcl": {
topic: function() {
return d3.hcl;
},
"converts string channel values to numbers": function(hcl) {
assertHclEqual(hcl("50", "-4", "32"), 50, -4, 32);
topic: load("color/hcl"),
"converts string channel values to numbers": function(d3) {
assertHclEqual(d3.hcl("50", "-4", "32"), 50, -4, 32);
},
"converts null channel values to zero": function(hcl) {
assertHclEqual(hcl(null, null, null), 0, 0, 0);
"converts null channel values to zero": function(d3) {
assertHclEqual(d3.hcl(null, null, null), 0, 0, 0);
},
"exposes h, c and l properties": function(hcl) {
var color = hcl(50, -4, 32);
"exposes h, c and l properties": function(d3) {
var color = d3.hcl(50, -4, 32);
assert.equal(color.h, 50);
assert.equal(color.c, -4);
assert.equal(color.l, 32);
},
"changing h, c or l affects the string format": function(hcl) {
var color = hcl(50, -4, 32);
"changing h, c or l affects the string format": function(d3) {
var color = d3.hcl(50, -4, 32);
assert.equal(color + "", "#444d50");
color.h++;
assert.equal(color + "", "#444d50");
......@@ -32,50 +29,50 @@ suite.addBatch({
color.l++;
assert.equal(color + "", "#494f51");
},
"parses hexadecimal shorthand format (e.g., \"#abc\")": function(hcl) {
assertHclEqual(hcl("#abc"), -102.28223831811077, 10.774886733325554, 75.10497524893663);
"parses hexadecimal shorthand format (e.g., \"#abc\")": function(d3) {
assertHclEqual(d3.hcl("#abc"), -102.28223831811077, 10.774886733325554, 75.10497524893663);
},
"parses hexadecimal format (e.g., \"#abcdef\")": function(hcl) {
assertHclEqual(hcl("#abcdef"), -100.15785184209284, 20.768234621934273, 81.04386565274363);
"parses hexadecimal format (e.g., \"#abcdef\")": function(d3) {
assertHclEqual(d3.hcl("#abcdef"), -100.15785184209284, 20.768234621934273, 81.04386565274363);
},
"parses HSL format (e.g., \"hsl(210, 64%, 13%)\")": function(hcl) {
assertHclEqual(hcl("hsl(210, 64.7058%, 13.33333%)"), -89.58282792342067, 16.833655998102003, 12.65624852526134);
"parses HSL format (e.g., \"hsl(210, 64%, 13%)\")": function(d3) {
assertHclEqual(d3.hcl("hsl(210, 64.7058%, 13.33333%)"), -89.58282792342067, 16.833655998102003, 12.65624852526134);
},
"parses color names (e.g., \"moccasin\")": function(hcl) {
assertHclEqual(hcl("moccasin"), 84.71288921124494, 26.472460854104156, 91.72317744746022);
"parses color names (e.g., \"moccasin\")": function(d3) {
assertHclEqual(d3.hcl("moccasin"), 84.71288921124494, 26.472460854104156, 91.72317744746022);
},
"parses and converts RGB format (e.g., \"rgb(102, 102, 0)\")": function(hcl) {
assertHclEqual(hcl("rgb(102, 102, 0)"), 102.85124420310271, 49.44871600399321, 41.73251953866431);
"parses and converts RGB format (e.g., \"rgb(102, 102, 0)\")": function(d3) {
assertHclEqual(d3.hcl("rgb(102, 102, 0)"), 102.85124420310271, 49.44871600399321, 41.73251953866431);
},
"can convert from RGB": function(hcl) {
assertHclEqual(hcl(d3.rgb(12, 34, 56)), -89.58282792342067, 16.833655998102003, 12.65624852526134);
"can convert from RGB": function(d3) {
assertHclEqual(d3.hcl(d3.rgb(12, 34, 56)), -89.58282792342067, 16.833655998102003, 12.65624852526134);
},
"can convert from HSL": function(hcl) {
assertHclEqual(hcl(d3.hcl(20, .8, .3)), 20, 0.8, 0.3);
"can convert from HSL": function(d3) {
assertHclEqual(d3.hcl(d3.hcl(20, .8, .3)), 20, 0.8, 0.3);
},
"can convert to RGB": function(hcl) {
assert.rgbEqual(hcl("steelblue").rgb(), 70, 130, 180);
"can convert to RGB": function(d3) {
assert.rgbEqual(d3.hcl("steelblue").rgb(), 70, 130, 180);
},
"can derive a brighter color": function(hcl) {
assertHclEqual(hcl("steelblue").brighter(), -97.21873224090723, 32.44906314974561, 70.46551718768575);
assertHclEqual(hcl("steelblue").brighter(.5), -97.21873224090723, 32.44906314974561, 61.46551718768575);
"can derive a brighter color": function(d3) {
assertHclEqual(d3.hcl("steelblue").brighter(), -97.21873224090723, 32.44906314974561, 70.46551718768575);
assertHclEqual(d3.hcl("steelblue").brighter(.5), -97.21873224090723, 32.44906314974561, 61.46551718768575);
},
"can derive a darker color": function(hcl) {
assertHclEqual(hcl("lightsteelblue").darker(), -94.8160116310511, 15.26488988314746, 60.45157936968134);
assertHclEqual(hcl("lightsteelblue").darker(.5), -94.8160116310511, 15.26488988314746, 69.45157936968134);
"can derive a darker color": function(d3) {
assertHclEqual(d3.hcl("lightsteelblue").darker(), -94.8160116310511, 15.26488988314746, 60.45157936968134);
assertHclEqual(d3.hcl("lightsteelblue").darker(.5), -94.8160116310511, 15.26488988314746, 69.45157936968134);
},
"string coercion returns RGB format": function(hcl) {
assert.strictEqual(hcl("hsl(60, 100%, 20%)") + "", "#666600");
assert.strictEqual(hcl(d3.hcl(60, -4, 32)) + "", "#454c51");
"string coercion returns RGB format": function(d3) {
assert.strictEqual(d3.hcl("hsl(60, 100%, 20%)") + "", "#666600");
assert.strictEqual(d3.hcl(d3.hcl(60, -4, 32)) + "", "#454c51");
},
"roundtrip to HSL is idempotent": function(hcl) {
assert.hslEqual(d3.hsl(hcl("steelblue")), d3.hsl("steelblue"));
"roundtrip to HSL is idempotent": function(d3) {
assert.hslEqual(d3.hsl(d3.hcl("steelblue")), d3.hsl("steelblue"));
},
"roundtrip to RGB is idempotent": function(hcl) {
assert.hslEqual(d3.rgb(hcl("steelblue")), d3.rgb("steelblue"));
"roundtrip to RGB is idempotent": function(d3) {
assert.hslEqual(d3.rgb(d3.hcl("steelblue")), d3.rgb("steelblue"));
},
"roundtrip to Lab is idempotent": function(hcl) {
assert.hslEqual(d3.lab(hcl("steelblue")), d3.lab("steelblue"));
"roundtrip to Lab is idempotent": function(d3) {
assert.hslEqual(d3.lab(d3.hcl("steelblue")), d3.lab("steelblue"));
}
}
});
......
require("../env");
var vows = require("vows"),
load = require("../load"),
assert = require("../env-assert");
var suite = vows.describe("d3.hsl");
suite.addBatch({
"hsl": {
topic: function() {
return d3.hsl;
},
"does not clamp channel values": function(hsl) {
assert.hslEqual(hsl(-100, -1, -2), -100, -1, -2);
assert.hslEqual(hsl(400, 2, 3), 400, 2, 3);
topic: load("color/hsl"),
"does not clamp channel values": function(d3) {
assert.hslEqual(d3.hsl(-100, -1, -2), -100, -1, -2);
assert.hslEqual(d3.hsl(400, 2, 3), 400, 2, 3);
},
"converts string channel values to numbers": function(hsl) {
assert.hslEqual(hsl("180", ".5", ".6"), 180, .5, .6);
"converts string channel values to numbers": function(d3) {
assert.hslEqual(d3.hsl("180", ".5", ".6"), 180, .5, .6);
},
"converts null channel values to zero": function(hsl) {
assert.hslEqual(hsl(null, null, null), 0, 0, 0);
"converts null channel values to zero": function(d3) {
assert.hslEqual(d3.hsl(null, null, null), 0, 0, 0);
},
"exposes h, s and l properties": function(hsl) {
var color = hsl("hsl(180, 50%, 60%)");
"exposes h, s and l properties": function(d3) {
var color = d3.hsl("hsl(180, 50%, 60%)");
assert.equal(color.h, 180);
assert.equal(color.s, .5);
assert.equal(color.l, .6);
},
"changing h, s or l affects the string format": function(hsl) {
var color = hsl("hsl(180, 50%, 60%)");
"changing h, s or l affects the string format": function(d3) {
var color = d3.hsl("hsl(180, 50%, 60%)");
color.h++;
color.s += .1;
color.l += .1;
assert.equal(color + "", "#85dfe0");
},
"parses hexadecimal shorthand format (e.g., \"#abc\")": function(hsl) {
assert.hslEqual(hsl("#abc"), 210, .25, .733333);
"parses hexadecimal shorthand format (e.g., \"#abc\")": function(d3) {
assert.hslEqual(d3.hsl("#abc"), 210, .25, .733333);
},
"parses hexadecimal format (e.g., \"#abcdef\")": function(hsl) {
assert.hslEqual(hsl("#abcdef"), 210, .68, .803922);
"parses hexadecimal format (e.g., \"#abcdef\")": function(d3) {
assert.hslEqual(d3.hsl("#abcdef"), 210, .68, .803922);
},
"parses HSL format (e.g., \"hsl(210, 64%, 13%)\")": function(hsl) {
assert.hslEqual(hsl("hsl(210, 64.7058%, 13.33333%)"), 210, .647058, .133333);
"parses HSL format (e.g., \"hsl(210, 64%, 13%)\")": function(d3) {
assert.hslEqual(d3.hsl("hsl(210, 64.7058%, 13.33333%)"), 210, .647058, .133333);
},
"parses color names (e.g., \"moccasin\")": function(hsl) {
assert.hslEqual(hsl("moccasin"), 38.108108, 1, .854902);
assert.hslEqual(hsl("aliceblue"), 208, 1, .970588);
assert.hslEqual(hsl("yellow"), 60, 1, .5);
"parses color names (e.g., \"moccasin\")": function(d3) {
assert.hslEqual(d3.hsl("moccasin"), 38.108108, 1, .854902);
assert.hslEqual(d3.hsl("aliceblue"), 208, 1, .970588);
assert.hslEqual(d3.hsl("yellow"), 60, 1, .5);
},
"parses and converts RGB format (e.g., \"rgb(102, 102, 0)\")": function(hsl) {
assert.hslEqual(hsl("rgb(102, 102, 0)"), 60, 1, .2);
"parses and converts RGB format (e.g., \"rgb(102, 102, 0)\")": function(d3) {
assert.hslEqual(d3.hsl("rgb(102, 102, 0)"), 60, 1, .2);
},
"can convert from RGB": function(hsl) {
assert.hslEqual(hsl(d3.rgb(12, 34, 56)), 210, .647058, .133333);
"can convert from RGB": function(d3) {
assert.hslEqual(d3.hsl(d3.rgb(12, 34, 56)), 210, .647058, .133333);
},
"can convert from HSL": function(hsl) {
assert.hslEqual(hsl(d3.hsl(20, .8, .3)), 20, .8, .3);
"can convert from HSL": function(d3) {
assert.hslEqual(d3.hsl(d3.hsl(20, .8, .3)), 20, .8, .3);
},
"can convert to RGB": function(hsl) {
assert.rgbEqual(hsl("steelblue").rgb(), 70, 130, 180);
"can convert to RGB": function(d3) {
assert.rgbEqual(d3.hsl("steelblue").rgb(), 70, 130, 180);
},
"can derive a brighter color": function(hsl) {
assert.hslEqual(hsl("steelblue").brighter(), 207.272727, .44, .7002801);
assert.hslEqual(hsl("steelblue").brighter(.5), 207.272727, .44, .5858964);
assert.hslEqual(hsl("steelblue").brighter(1), 207.272727, .44, .7002801);
assert.hslEqual(hsl("steelblue").brighter(2), 207.272727, .44, 1.0004002);
"can derive a brighter color": function(d3) {
assert.hslEqual(d3.hsl("steelblue").brighter(), 207.272727, .44, .7002801);
assert.hslEqual(d3.hsl("steelblue").brighter(.5), 207.272727, .44, .5858964);
assert.hslEqual(d3.hsl("steelblue").brighter(1), 207.272727, .44, .7002801);
assert.hslEqual(d3.hsl("steelblue").brighter(2), 207.272727, .44, 1.0004002);
},
"can derive a darker color": function(hsl) {
assert.hslEqual(hsl("lightsteelblue").darker(), 213.913043, .4107143, .5462745);
assert.hslEqual(hsl("lightsteelblue").darker(.5), 213.913043, .4107143, .6529229);
assert.hslEqual(hsl("lightsteelblue").darker(1), 213.913043, .4107143, .5462745);
assert.hslEqual(hsl("lightsteelblue").darker(2), 213.913043, .4107143, .38239216);
"can derive a darker color": function(d3) {
assert.hslEqual(d3.hsl("lightsteelblue").darker(), 213.913043, .4107143, .5462745);
assert.hslEqual(d3.hsl("lightsteelblue").darker(.5), 213.913043, .4107143, .6529229);
assert.hslEqual(d3.hsl("lightsteelblue").darker(1), 213.913043, .4107143, .5462745);
assert.hslEqual(d3.hsl("lightsteelblue").darker(2), 213.913043, .4107143, .38239216);
},
"string coercion returns RGB format": function(hsl) {
assert.strictEqual(hsl("hsl(60, 100%, 20%)") + "", "#666600");
assert.strictEqual(hsl(d3.hsl(60, 1, .2)) + "", "#666600");
"string coercion returns RGB format": function(d3) {
assert.strictEqual(d3.hsl("hsl(60, 100%, 20%)") + "", "#666600");
assert.strictEqual(d3.hsl(d3.hsl(60, 1, .2)) + "", "#666600");
}
}
});
......
require("../env");
var vows = require("vows"),
load = require("../load"),
assert = require("../env-assert");
var suite = vows.describe("d3.lab");
suite.addBatch({
"lab": {
topic: function() {
return d3.lab;
},
"converts string channel values to numbers": function(lab) {
assertLabEqual(lab("50", "-4", "-32"), 50, -4, -32);
topic: load("color/lab"),
"converts string channel values to numbers": function(d3) {
assertLabEqual(d3.lab("50", "-4", "-32"), 50, -4, -32);
},
"converts null channel values to zero": function(lab) {
assertLabEqual(lab(null, null, null), 0, 0, 0);
"converts null channel values to zero": function(d3) {
assertLabEqual(d3.lab(null, null, null), 0, 0, 0);
},
"exposes l, a and b properties": function(lab) {
var color = lab(50, -4, -32);
"exposes l, a and b properties": function(d3) {
var color = d3.lab(50, -4, -32);
assert.equal(color.l, 50);
assert.equal(color.a, -4);
assert.equal(color.b, -32);
},
"changing l, a or b affects the string format": function(lab) {
var color = lab(50, -4, -32);
"changing l, a or b affects the string format": function(d3) {
var color = d3.lab(50, -4, -32);
assert.equal(color + "", "#3f7cad");
color.l++;
assert.equal(color + "", "#427eb0");
......@@ -32,50 +29,50 @@ suite.addBatch({
color.b++;
assert.equal(color + "", "#487eae");
},
"parses hexadecimal shorthand format (e.g., \"#abc\")": function(lab) {
assertLabEqual(lab("#abc"), 75.10497524893663, -2.292114632248876, -10.528266458853786);
"parses hexadecimal shorthand format (e.g., \"#abc\")": function(d3) {
assertLabEqual(d3.lab("#abc"), 75.10497524893663, -2.292114632248876, -10.528266458853786);
},
"parses hexadecimal format (e.g., \"#abcdef\")": function(lab) {
assertLabEqual(lab("#abcdef"), 81.04386565274363, -3.6627002800885267, -20.442705201854984);
"parses hexadecimal format (e.g., \"#abcdef\")": function(d3) {
assertLabEqual(d3.lab("#abcdef"), 81.04386565274363, -3.6627002800885267, -20.442705201854984);
},
"parses HSL format (e.g., \"hsl(210, 64%, 13%)\")": function(lab) {
assertLabEqual(lab("hsl(210, 64.7058%, 13.33333%)"), 12.65624852526134, 0.12256520883417721, -16.833209795877284);
"parses HSL format (e.g., \"hsl(210, 64%, 13%)\")": function(d3) {
assertLabEqual(d3.lab("hsl(210, 64.7058%, 13.33333%)"), 12.65624852526134, 0.12256520883417721, -16.833209795877284);
},
"parses color names (e.g., \"moccasin\")": function(lab) {
assertLabEqual(lab("moccasin"), 91.72317744746022, 2.4393469358685027, 26.359832514614844);
"parses color names (e.g., \"moccasin\")": function(d3) {
assertLabEqual(d3.lab("moccasin"), 91.72317744746022, 2.4393469358685027, 26.359832514614844);
},
"parses and converts RGB format (e.g., \"rgb(102, 102, 0)\")": function(lab) {
assertLabEqual(lab("rgb(102, 102, 0)"), 41.73251953866431, -10.998411255098816, 48.21006600604577);
"parses and converts RGB format (e.g., \"rgb(102, 102, 0)\")": function(d3) {
assertLabEqual(d3.lab("rgb(102, 102, 0)"), 41.73251953866431, -10.998411255098816, 48.21006600604577);
},
"can convert from RGB": function(lab) {
assertLabEqual(lab(d3.rgb(12, 34, 56)), 12.65624852526134, 0.12256520883417721, -16.833209795877284);
"can convert from RGB": function(d3) {
assertLabEqual(d3.lab(d3.rgb(12, 34, 56)), 12.65624852526134, 0.12256520883417721, -16.833209795877284);
},
"can convert from HSL": function(lab) {
assertLabEqual(lab(d3.lab(20, .8, .3)), 20, 0.8, 0.3);
"can convert from HSL": function(d3) {
assertLabEqual(d3.lab(d3.lab(20, .8, .3)), 20, 0.8, 0.3);
},
"can convert to RGB": function(lab) {
assert.rgbEqual(lab("steelblue").rgb(), 70, 130, 180);
"can convert to RGB": function(d3) {
assert.rgbEqual(d3.lab("steelblue").rgb(), 70, 130, 180);
},
"can derive a brighter color": function(lab) {
assertLabEqual(lab("steelblue").brighter(), 70.46551718768575, -4.0774710123572255, -32.19186122981343);
assertLabEqual(lab("steelblue").brighter(.5), 61.46551718768575, -4.0774710123572255, -32.19186122981343);
"can derive a brighter color": function(d3) {
assertLabEqual(d3.lab("steelblue").brighter(), 70.46551718768575, -4.0774710123572255, -32.19186122981343);
assertLabEqual(d3.lab("steelblue").brighter(.5), 61.46551718768575, -4.0774710123572255, -32.19186122981343);
},
"can derive a darker color": function(lab) {
assertLabEqual(lab("lightsteelblue").darker(), 60.45157936968134, -1.2815839134120433, -15.210996213841522);
assertLabEqual(lab("lightsteelblue").darker(.5), 69.45157936968134, -1.2815839134120433, -15.210996213841522);
"can derive a darker color": function(d3) {
assertLabEqual(d3.lab("lightsteelblue").darker(), 60.45157936968134, -1.2815839134120433, -15.210996213841522);
assertLabEqual(d3.lab("lightsteelblue").darker(.5), 69.45157936968134, -1.2815839134120433, -15.210996213841522);
},
"string coercion returns RGB format": function(lab) {
assert.strictEqual(lab("hsl(60, 100%, 20%)") + "", "#666600");
assert.strictEqual(lab(d3.lab(60, -4, -32)) + "", "#5d95c8");
"string coercion returns RGB format": function(d3) {
assert.strictEqual(d3.lab("hsl(60, 100%, 20%)") + "", "#666600");
assert.strictEqual(d3.lab(d3.lab(60, -4, -32)) + "", "#5d95c8");
},
"roundtrip to HSL is idempotent": function(lab) {
assert.hslEqual(d3.hsl(lab("steelblue")), d3.hsl("steelblue"));
"roundtrip to HSL is idempotent": function(d3) {
assert.hslEqual(d3.hsl(d3.lab("steelblue")), d3.hsl("steelblue"));
},
"roundtrip to RGB is idempotent": function(lab) {
assert.hslEqual(d3.rgb(lab("steelblue")), d3.rgb("steelblue"));
"roundtrip to RGB is idempotent": function(d3) {
assert.hslEqual(d3.rgb(d3.lab("steelblue")), d3.rgb("steelblue"));
},
"roundtrip to HCL is idempotent": function(lab) {
assert.hslEqual(d3.hcl(lab("steelblue")), d3.hcl("steelblue"));
"roundtrip to HCL is idempotent": function(d3) {
assert.hslEqual(d3.hcl(d3.lab("steelblue")), d3.hcl("steelblue"));
}
}
});
......
require("../env");
var vows = require("vows"),
load = require("../load"),
assert = require("../env-assert");
var suite = vows.describe("d3.rgb");
suite.addBatch({
"rgb": {
topic: function() {
return d3.rgb;
},
"floors channel values": function(rgb) {
assert.rgbEqual(rgb(1.2, 2.6, 42.9), 1, 2, 42);
topic: load("color/rgb"),
"floors channel values": function(d3) {
assert.rgbEqual(d3.rgb(1.2, 2.6, 42.9), 1, 2, 42);
},
"defaults to black for invalid inputs": function(rgb) {
assert.rgbEqual(rgb("invalid"), 0, 0, 0);
assert.rgbEqual(rgb("hasOwnProperty"), 0, 0, 0);
assert.rgbEqual(rgb("__proto__"), 0, 0, 0);
"defaults to black for invalid inputs": function(d3) {
assert.rgbEqual(d3.rgb("invalid"), 0, 0, 0);
assert.rgbEqual(d3.rgb("hasOwnProperty"), 0, 0, 0);
assert.rgbEqual(d3.rgb("__proto__"), 0, 0, 0);
},
"does not clamp channel values": function(rgb) {
assert.rgbEqual(rgb(-10, -20, -30), -10, -20, -30);
assert.rgbEqual(rgb(300, 400, 500), 300, 400, 500);
"does not clamp channel values": function(d3) {
assert.rgbEqual(d3.rgb(-10, -20, -30), -10, -20, -30);
assert.rgbEqual(d3.rgb(300, 400, 500), 300, 400, 500);
},
"converts string channel values to numbers": function(rgb) {
assert.rgbEqual(rgb("12", "34", "56"), 12, 34, 56);
"converts string channel values to numbers": function(d3) {
assert.rgbEqual(d3.rgb("12", "34", "56"), 12, 34, 56);
},
"converts null channel values to zero": function(rgb) {
assert.rgbEqual(rgb(null, null, null), 0, 0, 0);
"converts null channel values to zero": function(d3) {
assert.rgbEqual(d3.rgb(null, null, null), 0, 0, 0);
},
"exposes r, g and b properties": function(rgb) {
var color = rgb("#abc");
"exposes r, g and b properties": function(d3) {
var color = d3.rgb("#abc");
assert.equal(color.r, 170);
assert.equal(color.g, 187);
assert.equal(color.b, 204);
},
"changing r, g or b affects the string format": function(rgb) {
var color = rgb("#abc");
"changing r, g or b affects the string format": function(d3) {
var color = d3.rgb("#abc");
color.r++;
color.g++;
color.b++;
assert.equal(color + "", "#abbccd");
},
"parses hexadecimal shorthand format (e.g., \"#abc\")": function(rgb) {
assert.rgbEqual(rgb("#abc"), 170, 187, 204);
"parses hexadecimal shorthand format (e.g., \"#abc\")": function(d3) {
assert.rgbEqual(d3.rgb("#abc"), 170, 187, 204);
},
"parses hexadecimal format (e.g., \"#abcdef\")": function(rgb) {
assert.rgbEqual(rgb("#abcdef"), 171, 205, 239);
"parses hexadecimal format (e.g., \"#abcdef\")": function(d3) {
assert.rgbEqual(d3.rgb("#abcdef"), 171, 205, 239);
},
"parses RGB format (e.g., \"rgb(12, 34, 56)\")": function(rgb) {
assert.rgbEqual(rgb("rgb(12, 34, 56)"), 12, 34, 56);
"parses RGB format (e.g., \"rgb(12, 34, 56)\")": function(d3) {
assert.rgbEqual(d3.rgb("rgb(12, 34, 56)"), 12, 34, 56);
},
"parses color names (e.g., \"moccasin\")": function(rgb) {
assert.rgbEqual(rgb("moccasin"), 255, 228, 181);
assert.rgbEqual(rgb("aliceblue"), 240, 248, 255);
assert.rgbEqual(rgb("yellow"), 255, 255, 0);
"parses color names (e.g., \"moccasin\")": function(d3) {
assert.rgbEqual(d3.rgb("moccasin"), 255, 228, 181);
assert.rgbEqual(d3.rgb("aliceblue"), 240, 248, 255);
assert.rgbEqual(d3.rgb("yellow"), 255, 255, 0);
},
"parses and converts HSL format (e.g., \"hsl(60, 100%, 20%)\")": function(rgb) {
assert.rgbEqual(rgb("hsl(60, 100%, 20%)"), 102, 102, 0);
"parses and converts HSL format (e.g., \"hsl(60, 100%, 20%)\")": function(d3) {
assert.rgbEqual(d3.rgb("hsl(60, 100%, 20%)"), 102, 102, 0);
},
"can convert from RGB": function(rgb) {
assert.rgbEqual(rgb(d3.rgb(12, 34, 56)), 12, 34, 56);
"can convert from RGB": function(d3) {
assert.rgbEqual(d3.rgb(d3.rgb(12, 34, 56)), 12, 34, 56);
},
"can convert from HSL": function(rgb) {
assert.rgbEqual(rgb(d3.hsl(0, 1, .5)), 255, 0, 0);
"can convert from HSL": function(d3) {
assert.rgbEqual(d3.rgb(d3.hsl(0, 1, .5)), 255, 0, 0);
},
"can convert to HSL": function(rgb) {
assert.hslEqual(rgb("red").hsl(), 0, 1, .5);
"can convert to HSL": function(d3) {
assert.hslEqual(d3.rgb("red").hsl(), 0, 1, .5);
},
"can derive a brighter color": function(rgb) {
assert.rgbEqual(rgb("brown").brighter(), 235, 60, 60);
assert.rgbEqual(rgb("brown").brighter(.5), 197, 50, 50);
assert.rgbEqual(rgb("brown").brighter(1), 235, 60, 60);
assert.rgbEqual(rgb("brown").brighter(2), 255, 85, 85);
"can derive a brighter color": function(d3) {
assert.rgbEqual(d3.rgb("brown").brighter(), 235, 60, 60);
assert.rgbEqual(d3.rgb("brown").brighter(.5), 197, 50, 50);
assert.rgbEqual(d3.rgb("brown").brighter(1), 235, 60, 60);
assert.rgbEqual(d3.rgb("brown").brighter(2), 255, 85, 85);
},
"can derive a darker color": function(rgb) {
assert.rgbEqual(rgb("coral").darker(), 178, 88, 56);
assert.rgbEqual(rgb("coral").darker(.5), 213, 106, 66);
assert.rgbEqual(rgb("coral").darker(1), 178, 88, 56);
assert.rgbEqual(rgb("coral").darker(2), 124, 62, 39);
"can derive a darker color": function(d3) {
assert.rgbEqual(d3.rgb("coral").darker(), 178, 88, 56);
assert.rgbEqual(d3.rgb("coral").darker(.5), 213, 106, 66);
assert.rgbEqual(d3.rgb("coral").darker(1), 178, 88, 56);
assert.rgbEqual(d3.rgb("coral").darker(2), 124, 62, 39);
},
"string coercion returns hexadecimal format": function(rgb) {
assert.strictEqual(rgb("#abcdef") + "", "#abcdef");
assert.strictEqual(rgb("moccasin") + "", "#ffe4b5");
assert.strictEqual(rgb("hsl(60, 100%, 20%)") + "", "#666600");
assert.strictEqual(rgb("rgb(12, 34, 56)") + "", "#0c2238");
assert.strictEqual(rgb(d3.rgb(12, 34, 56)) + "", "#0c2238");
assert.strictEqual(rgb(d3.hsl(60, 1, .2)) + "", "#666600");
"string coercion returns hexadecimal format": function(d3) {
assert.strictEqual(d3.rgb("#abcdef") + "", "#abcdef");
assert.strictEqual(d3.rgb("moccasin") + "", "#ffe4b5");
assert.strictEqual(d3.rgb("hsl(60, 100%, 20%)") + "", "#666600");
assert.strictEqual(d3.rgb("rgb(12, 34, 56)") + "", "#0c2238");
assert.strictEqual(d3.rgb(d3.rgb(12, 34, 56)) + "", "#0c2238");
assert.strictEqual(d3.rgb(d3.hsl(60, 1, .2)) + "", "#666600");
}
}
});
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment