Skip to content

Commit

Permalink
Prefix exported symbols with “scale”.
Browse files Browse the repository at this point in the history
  • Loading branch information
mbostock committed Jan 7, 2016
1 parent a830459 commit 2cc073c
Show file tree
Hide file tree
Showing 20 changed files with 692 additions and 624 deletions.
94 changes: 47 additions & 47 deletions README.md

Large diffs are not rendered by default.

99 changes: 80 additions & 19 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,80 @@
export {default as band, point} from "./src/band";
export {default as identity} from "./src/identity";
export {default as linear} from "./src/linear";
export {default as log} from "./src/log";
export {default as ordinal, implicit} from "./src/ordinal";
export {default as pow, sqrt} from "./src/pow";
export {default as quantile} from "./src/quantile";
export {default as quantize} from "./src/quantize";
export {default as threshold} from "./src/threshold";
export {default as time} from "./src/time";
export {default as utcTime} from "./src/utcTime";

export {default as category10} from "./src/category10";
export {default as category20b} from "./src/category20b";
export {default as category20c} from "./src/category20c";
export {default as category20} from "./src/category20";
export {default as cubehelix} from "./src/cubehelix";
export {default as rainbow, warm, cool} from "./src/rainbow";
export {default as viridis, magma, inferno, plasma} from "./src/viridis";
export {
default as scaleBand,
point as scalePoint
} from "./src/band";

export {
default as scaleIdentity
} from "./src/identity";

export {
default as scaleLinear
} from "./src/linear";

export {
default as scaleLog
} from "./src/log";

export {
default as scaleOrdinal,
implicit as scaleImplicit
} from "./src/ordinal";

export {
default as scalePow,
sqrt as scaleSqrt
} from "./src/pow";

export {
default as scaleQuantile
} from "./src/quantile";

export {
default as scaleQuantize
} from "./src/quantize";

export {
default as scaleThreshold
} from "./src/threshold";

export {
default as scaleTime
} from "./src/time";

export {
default as scaleUtc
} from "./src/utcTime";

export {
default as scaleCategory10
} from "./src/category10";

export {
default as scaleCategory20b
} from "./src/category20b";

export {
default as scaleCategory20c
} from "./src/category20c";

export {
default as scaleCategory20
} from "./src/category20";

export {
default as scaleCubehelix
} from "./src/cubehelix";

export {
default as scaleRainbow,
warm as scaleWarm,
cool as scaleCool
} from "./src/rainbow";

export {
default as scaleViridis,
magma as scaleMagma,
inferno as scaleInferno,
plasma as scalePlasma
} from "./src/viridis";

50 changes: 25 additions & 25 deletions test/band-test.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
var tape = require("tape"),
scale = require("../");

tape("band() has the expected defaults", function(test) {
var s = scale.band();
tape("scaleBand() has the expected defaults", function(test) {
var s = scale.scaleBand();
test.deepEqual(s.domain(), []);
test.deepEqual(s.range(), [0, 1]);
test.equal(s.bandwidth(), 1);
Expand All @@ -15,7 +15,7 @@ tape("band() has the expected defaults", function(test) {
});

tape("band(value) computes discrete bands in a continuous range", function(test) {
var s = scale.band().range([0, 960]);
var s = scale.scaleBand().range([0, 960]);
test.equal(s("foo"), undefined);
s.domain(["foo", "bar"]);
test.equal(s("foo"), 0);
Expand All @@ -30,23 +30,23 @@ tape("band(value) computes discrete bands in a continuous range", function(test)
});

tape("band(value) returns undefined for values outside the domain", function(test) {
var s = scale.band().domain(["a", "b", "c"]);
var s = scale.scaleBand().domain(["a", "b", "c"]);
test.equal(s("d"), undefined);
test.equal(s("e"), undefined);
test.equal(s("f"), undefined);
test.end();
});

tape("band(value) does not implicitly add values to the domain", function(test) {
var s = scale.band().domain(["a", "b", "c"]);
var s = scale.scaleBand().domain(["a", "b", "c"]);
s("d");
s("e");
test.deepEqual(s.domain(), ["a", "b", "c"]);
test.end();
});

tape("band.step() returns the distance between the starts of adjacent bands", function(test) {
var s = scale.band().range([0, 960]);
var s = scale.scaleBand().range([0, 960]);
test.equal(s.domain(["foo"]).step(), 960);
test.equal(s.domain(["foo", "bar"]).step(), 480);
test.equal(s.domain(["foo", "bar", "baz"]).step(), 320);
Expand All @@ -57,7 +57,7 @@ tape("band.step() returns the distance between the starts of adjacent bands", fu
});

tape("band.bandwidth() returns the width of the band", function(test) {
var s = scale.band().range([0, 960]);
var s = scale.scaleBand().range([0, 960]);
test.equal(s.domain([]).bandwidth(), 960);
test.equal(s.domain(["foo"]).bandwidth(), 960);
test.equal(s.domain(["foo", "bar"]).bandwidth(), 480);
Expand All @@ -70,7 +70,7 @@ tape("band.bandwidth() returns the width of the band", function(test) {
});

tape("band.domain([]) computes reasonable band and step values", function(test) {
var s = scale.band().domain([]).range([0, 960]);
var s = scale.scaleBand().domain([]).range([0, 960]);
test.equal(s.step(), 960);
test.equal(s.bandwidth(), 960);
s.padding(0.5);
Expand All @@ -83,7 +83,7 @@ tape("band.domain([]) computes reasonable band and step values", function(test)
});

tape("band.domain([value]) computes a reasonable singleton band, even with padding", function(test) {
var s = scale.band().domain(["foo"]).range([0, 960]);
var s = scale.scaleBand().domain(["foo"]).range([0, 960]);
test.equal(s("foo"), 0);
test.equal(s.step(), 960);
test.equal(s.bandwidth(), 960);
Expand All @@ -99,7 +99,7 @@ tape("band.domain([value]) computes a reasonable singleton band, even with paddi
});

tape("band.domain(values) recomputes the bands", function(test) {
var s = scale.band().domain(["a", "b", "c"]).rangeRound([0, 100]);
var s = scale.scaleBand().domain(["a", "b", "c"]).rangeRound([0, 100]);
test.deepEqual(s.domain().map(s), [1, 34, 67]);
test.equal(s.bandwidth(), 33);
s.domain(["a", "b", "c", "d"]);
Expand All @@ -110,14 +110,14 @@ tape("band.domain(values) recomputes the bands", function(test) {

tape("band.domain(values) makes a copy of the specified domain values", function(test) {
var domain = ["red", "green"],
s = scale.band().domain(domain);
s = scale.scaleBand().domain(domain);
domain.push("blue");
test.deepEqual(s.domain(), ["red", "green"]);
test.end();
});

tape("band.domain() returns a copy of the domain", function(test) {
var s = scale.band().domain(["red", "green"]),
var s = scale.scaleBand().domain(["red", "green"]),
domain = s.domain();
test.deepEqual(domain, ["red", "green"]);
domain.push("blue");
Expand All @@ -126,7 +126,7 @@ tape("band.domain() returns a copy of the domain", function(test) {
});

tape("band.range(values) can be descending", function(test) {
var s = scale.band().domain(["a", "b", "c"]).range([120, 0]);
var s = scale.scaleBand().domain(["a", "b", "c"]).range([120, 0]);
test.deepEqual(s.domain().map(s), [80, 40, 0]);
test.equal(s.bandwidth(), 40);
s.padding(0.2);
Expand All @@ -137,14 +137,14 @@ tape("band.range(values) can be descending", function(test) {

tape("band.range(values) makes a copy of the specified range values", function(test) {
var range = [1, 2],
s = scale.band().range(range);
s = scale.scaleBand().range(range);
range.push("blue");
test.deepEqual(s.range(), [1, 2]);
test.end();
});

tape("band.range() returns a copy of the range", function(test) {
var s = scale.band().range([1, 2]),
var s = scale.scaleBand().range([1, 2]),
range = s.range();
test.deepEqual(range, [1, 2]);
range.push("blue");
Expand All @@ -153,13 +153,13 @@ tape("band.range() returns a copy of the range", function(test) {
});

tape("band.range(values) coerces values[0] and values[1] to numbers", function(test) {
var s = scale.band().range({0: "1.0", 1: "2.0", length: 2});
var s = scale.scaleBand().range({0: "1.0", 1: "2.0", length: 2});
test.deepEqual(s.range(), [1, 2]);
test.end();
});

tape("band.paddingInner(p) specifies the inner padding p", function(test) {
var s = scale.band().domain(["a", "b", "c"]).range([120, 0]).paddingInner(0.1).round(true);
var s = scale.scaleBand().domain(["a", "b", "c"]).range([120, 0]).paddingInner(0.1).round(true);
test.deepEqual(s.domain().map(s), [83, 42, 1]);
test.equal(s.bandwidth(), 37);
s.paddingInner(0.2);
Expand All @@ -169,7 +169,7 @@ tape("band.paddingInner(p) specifies the inner padding p", function(test) {
});

tape("band.paddingInner(p) coerces p to a number in [0, 1]", function(test) {
var s = scale.band();
var s = scale.scaleBand();
test.equal(s.paddingInner("1.0").paddingInner(), 1);
test.equal(s.paddingInner("-1.0").paddingInner(), 0);
test.equal(s.paddingInner("2.0").paddingInner(), 1);
Expand All @@ -178,7 +178,7 @@ tape("band.paddingInner(p) coerces p to a number in [0, 1]", function(test) {
});

tape("band.paddingOuter(p) specifies the outer padding p", function(test) {
var s = scale.band().domain(["a", "b", "c"]).range([120, 0]).paddingInner(0.2).paddingOuter(0.1);
var s = scale.scaleBand().domain(["a", "b", "c"]).range([120, 0]).paddingInner(0.2).paddingOuter(0.1);
test.deepEqual(s.domain().map(s), [84, 44, 4]);
test.equal(s.bandwidth(), 32);
s.paddingOuter(1);
Expand All @@ -188,7 +188,7 @@ tape("band.paddingOuter(p) specifies the outer padding p", function(test) {
});

tape("band.paddingOuter(p) coerces p to a number in [0, 1]", function(test) {
var s = scale.band();
var s = scale.scaleBand();
test.equal(s.paddingOuter("1.0").paddingOuter(), 1);
test.equal(s.paddingOuter("-1.0").paddingOuter(), 0);
test.equal(s.paddingOuter("2.0").paddingOuter(), 1);
Expand All @@ -197,14 +197,14 @@ tape("band.paddingOuter(p) coerces p to a number in [0, 1]", function(test) {
});

tape("band.rangeRound(values) is an alias for band.range(values).round(true)", function(test) {
var s = scale.band().domain(["a", "b", "c"]).rangeRound([0, 100]);
var s = scale.scaleBand().domain(["a", "b", "c"]).rangeRound([0, 100]);
test.deepEqual(s.range(), [0, 100]);
test.equal(s.round(), true);
test.end();
});

tape("band.round(true) computes discrete rounded bands in a continuous range", function(test) {
var s = scale.band().domain(["a", "b", "c"]).range([0, 100]).round(true);
var s = scale.scaleBand().domain(["a", "b", "c"]).range([0, 100]).round(true);
test.deepEqual(s.domain().map(s), [1, 34, 67]);
test.equal(s.bandwidth(), 33);
s.padding(0.2);
Expand All @@ -214,7 +214,7 @@ tape("band.round(true) computes discrete rounded bands in a continuous range", f
});

tape("band.copy() copies all fields", function(test) {
var s1 = scale.band().domain(["red", "green"]).range([1, 2]).round(true).paddingInner(0.1).paddingOuter(0.2),
var s1 = scale.scaleBand().domain(["red", "green"]).range([1, 2]).round(true).paddingInner(0.1).paddingOuter(0.2),
s2 = s1.copy();
test.deepEqual(s2.domain(), s1.domain());
test.deepEqual(s2.range(), s1.range());
Expand All @@ -225,7 +225,7 @@ tape("band.copy() copies all fields", function(test) {
});

tape("band.copy() isolates changes to the domain", function(test) {
var s1 = scale.band().domain(["foo", "bar"]).range([0, 2]),
var s1 = scale.scaleBand().domain(["foo", "bar"]).range([0, 2]),
s2 = s1.copy();
s1.domain(["red", "blue"]);
test.deepEqual(s2.domain(), ["foo", "bar"]);
Expand All @@ -239,7 +239,7 @@ tape("band.copy() isolates changes to the domain", function(test) {
});

tape("band.copy() isolates changes to the range", function(test) {
var s1 = scale.band().domain(["foo", "bar"]).range([0, 2]),
var s1 = scale.scaleBand().domain(["foo", "bar"]).range([0, 2]),
s2 = s1.copy();
s1.range([3, 5]);
test.deepEqual(s2.range(), [0, 2]);
Expand Down
10 changes: 5 additions & 5 deletions test/category10-test.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
var tape = require("tape"),
scale = require("../");

tape("category10() is an ordinal scale", function(test) {
var s = scale.category10();
tape("scaleCategory10() is an ordinal scale", function(test) {
var s = scale.scaleCategory10();
test.deepEqual(s.domain(), []);
test.deepEqual(s.range(), ["#1f77b4", "#ff7f0e", "#2ca02c", "#d62728", "#9467bd", "#8c564b", "#e377c2", "#7f7f7f", "#bcbd22", "#17becf"]);
test.equal(s(0), "#1f77b4");
Expand All @@ -16,9 +16,9 @@ tape("category10() is an ordinal scale", function(test) {
test.end();
});

tape("category10() returns an isolated instance", function(test) {
var s1 = scale.category10(),
s2 = scale.category10();
tape("scaleCategory10() returns an isolated instance", function(test) {
var s1 = scale.scaleCategory10(),
s2 = scale.scaleCategory10();
test.equal(s1(1), "#1f77b4");
test.equal(s2(2), "#1f77b4");
test.equal(s2(1), "#ff7f0e");
Expand Down
10 changes: 5 additions & 5 deletions test/category20-test.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
var tape = require("tape"),
scale = require("../");

tape("category20() is an ordinal scale", function(test) {
var s = scale.category20();
tape("scaleCategory20() is an ordinal scale", function(test) {
var s = scale.scaleCategory20();
test.deepEqual(s.domain(), []);
test.deepEqual(s.range(), ["#1f77b4", "#aec7e8", "#ff7f0e", "#ffbb78", "#2ca02c", "#98df8a", "#d62728", "#ff9896", "#9467bd", "#c5b0d5", "#8c564b", "#c49c94", "#e377c2", "#f7b6d2", "#7f7f7f", "#c7c7c7", "#bcbd22", "#dbdb8d", "#17becf", "#9edae5"]);
test.equal(s(0), "#1f77b4");
Expand All @@ -16,9 +16,9 @@ tape("category20() is an ordinal scale", function(test) {
test.end();
});

tape("category20() returns an isolated instance", function(test) {
var s1 = scale.category20(),
s2 = scale.category20();
tape("scaleCategory20() returns an isolated instance", function(test) {
var s1 = scale.scaleCategory20(),
s2 = scale.scaleCategory20();
test.equal(s1(1), "#1f77b4");
test.equal(s2(2), "#1f77b4");
test.equal(s2(1), "#aec7e8");
Expand Down
10 changes: 5 additions & 5 deletions test/category20b-test.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
var tape = require("tape"),
scale = require("../");

tape("category20b() is an ordinal scale", function(test) {
var s = scale.category20b();
tape("scaleCategory20b() is an ordinal scale", function(test) {
var s = scale.scaleCategory20b();
test.deepEqual(s.domain(), []);
test.deepEqual(s.range(), ["#393b79", "#5254a3", "#6b6ecf", "#9c9ede", "#637939", "#8ca252", "#b5cf6b", "#cedb9c", "#8c6d31", "#bd9e39", "#e7ba52", "#e7cb94", "#843c39", "#ad494a", "#d6616b", "#e7969c", "#7b4173", "#a55194", "#ce6dbd", "#de9ed6"]);
test.equal(s(0), "#393b79");
Expand All @@ -16,9 +16,9 @@ tape("category20b() is an ordinal scale", function(test) {
test.end();
});

tape("category20b() returns an isolated instance", function(test) {
var s1 = scale.category20b(),
s2 = scale.category20b();
tape("scaleCategory20b() returns an isolated instance", function(test) {
var s1 = scale.scaleCategory20b(),
s2 = scale.scaleCategory20b();
test.equal(s1(1), "#393b79");
test.equal(s2(2), "#393b79");
test.equal(s2(1), "#5254a3");
Expand Down

0 comments on commit 2cc073c

Please sign in to comment.