From 5dd14d0735e5c57e7775795080f5ddebbd751156 Mon Sep 17 00:00:00 2001 From: Mike Bostock Date: Wed, 18 Nov 2015 20:51:51 -0800 Subject: [PATCH 01/15] Symbolic definition of symbol types. Related #23. --- index.js | 5 +++++ src/symbol.js | 27 +++++++++------------------ src/symbol/circle.js | 10 ++++++---- src/symbol/cross.js | 32 +++++++++++++++++--------------- src/symbol/diamond.js | 18 ++++++++++-------- src/symbol/square.js | 10 ++++++---- src/symbol/triangle.js | 32 ++++++++++++++++++-------------- test/symbol-test.js | 28 +++++++++++----------------- test/symbolTypes-test.js | 12 ++++++------ 9 files changed, 88 insertions(+), 86 deletions(-) diff --git a/index.js b/index.js index 0b1d71d..c7a5859 100644 --- a/index.js +++ b/index.js @@ -1,3 +1,8 @@ export {default as area} from "./src/area"; export {default as line} from "./src/line"; export {default as symbol, symbolTypes} from "./src/symbol"; +export {default as circle} from "./src/symbol/circle"; +export {default as cross} from "./src/symbol/cross"; +export {default as diamond} from "./src/symbol/diamond"; +export {default as square} from "./src/symbol/square"; +export {triangleDown, triangleUp} from "./src/symbol/triangle"; diff --git a/src/symbol.js b/src/symbol.js index f5eee68..db0f5aa 100644 --- a/src/symbol.js +++ b/src/symbol.js @@ -11,16 +11,16 @@ function constantSixtyFour() { } function constantCircle() { - return "circle"; + return circle; } export var symbolTypes = [ - "circle", - "cross", - "diamond", - "square", - "triangle-down", - "triangle-up" + circle, + cross, + diamond, + square, + triangleDown, + triangleUp ]; export default function() { @@ -31,21 +31,12 @@ export default function() { function symbol(d, i) { var buffer; if (!context) context = buffer = path(); - var t; - switch (type(d, i) + "") { - case "cross": t = cross; break; - case "diamond": t = diamond; break; - case "square": t = square; break; - case "triangle-down": t = triangleDown; break; - case "triangle-up": t = triangleUp; break; - default: t = circle; break; - } - t(context, +size(d, i)); + type(d, i).draw(context, +size(d, i)); if (buffer) return context = null, buffer + "" || null; } symbol.type = function(_) { - return arguments.length ? (type = typeof _ === "function" ? _ : constant(_ + ""), symbol) : type; + return arguments.length ? (type = typeof _ === "function" ? _ : constant(_), symbol) : type; }; symbol.size = function(_) { diff --git a/src/symbol/circle.js b/src/symbol/circle.js index 0c32775..c9168fa 100644 --- a/src/symbol/circle.js +++ b/src/symbol/circle.js @@ -1,5 +1,7 @@ -export default function(context, size) { - var r = Math.sqrt(size / Math.PI); - context.moveTo(r, 0); - context.arc(0, 0, r, 0, 2 * Math.PI); +export default { + draw: function(context, size) { + var r = Math.sqrt(size / Math.PI); + context.moveTo(r, 0); + context.arc(0, 0, r, 0, 2 * Math.PI); + } }; diff --git a/src/symbol/cross.js b/src/symbol/cross.js index b1b1e2f..a282f80 100644 --- a/src/symbol/cross.js +++ b/src/symbol/cross.js @@ -1,16 +1,18 @@ -export default function(context, size) { - var r = Math.sqrt(size / 5) / 2; - context.moveTo(-3 * r, -r); - context.lineTo(-r, -r); - context.lineTo(-r, -3 * r); - context.lineTo(r, -3 * r); - context.lineTo(r, -r); - context.lineTo(3 * r, -r); - context.lineTo(3 * r, r); - context.lineTo(r, r); - context.lineTo(r, 3 * r); - context.lineTo(-r, 3 * r); - context.lineTo(-r, r); - context.lineTo(-3 * r, r); - context.closePath(); +export default { + draw: function(context, size) { + var r = Math.sqrt(size / 5) / 2; + context.moveTo(-3 * r, -r); + context.lineTo(-r, -r); + context.lineTo(-r, -3 * r); + context.lineTo(r, -3 * r); + context.lineTo(r, -r); + context.lineTo(3 * r, -r); + context.lineTo(3 * r, r); + context.lineTo(r, r); + context.lineTo(r, 3 * r); + context.lineTo(-r, 3 * r); + context.lineTo(-r, r); + context.lineTo(-3 * r, r); + context.closePath(); + } }; diff --git a/src/symbol/diamond.js b/src/symbol/diamond.js index 43abfa3..9f4ff1a 100644 --- a/src/symbol/diamond.js +++ b/src/symbol/diamond.js @@ -1,12 +1,14 @@ var tan30 = Math.sqrt(1 / 3), tan30_2 = tan30 * 2; -export default function(context, size) { - var y = Math.sqrt(size / tan30_2), - x = y * tan30; - context.moveTo(0, -y); - context.lineTo(x, 0); - context.lineTo(0, y); - context.lineTo(-x, 0); - context.closePath(); +export default { + draw: function(context, size) { + var y = Math.sqrt(size / tan30_2), + x = y * tan30; + context.moveTo(0, -y); + context.lineTo(x, 0); + context.lineTo(0, y); + context.lineTo(-x, 0); + context.closePath(); + } }; diff --git a/src/symbol/square.js b/src/symbol/square.js index 9e7dbf0..10beccd 100644 --- a/src/symbol/square.js +++ b/src/symbol/square.js @@ -1,5 +1,7 @@ -export default function(context, size) { - var w = Math.sqrt(size), - x = -w / 2; - context.rect(x, x, w, w); +export default { + draw: function(context, size) { + var w = Math.sqrt(size), + x = -w / 2; + context.rect(x, x, w, w); + } }; diff --git a/src/symbol/triangle.js b/src/symbol/triangle.js index 155f33f..30f946c 100644 --- a/src/symbol/triangle.js +++ b/src/symbol/triangle.js @@ -1,19 +1,23 @@ var sqrt3 = Math.sqrt(3); -export function triangleDown(context, size) { - var x = Math.sqrt(size / sqrt3), - y = x * sqrt3 / 2; - context.moveTo(0, y); - context.lineTo(x, -y); - context.lineTo(-x, -y); - context.closePath(); +export var triangleDown = { + draw: function(context, size) { + var x = Math.sqrt(size / sqrt3), + y = x * sqrt3 / 2; + context.moveTo(0, y); + context.lineTo(x, -y); + context.lineTo(-x, -y); + context.closePath(); + } }; -export function triangleUp(context, size) { - var x = Math.sqrt(size / sqrt3), - y = x * sqrt3 / 2; - context.moveTo(0, -y); - context.lineTo(x, y); - context.lineTo(-x, y); - context.closePath(); +export var triangleUp = { + draw: function(context, size) { + var x = Math.sqrt(size / sqrt3), + y = x * sqrt3 / 2; + context.moveTo(0, -y); + context.lineTo(x, y); + context.lineTo(-x, y); + context.closePath(); + } }; diff --git a/test/symbol-test.js b/test/symbol-test.js index 45dffa9..bdc5368 100644 --- a/test/symbol-test.js +++ b/test/symbol-test.js @@ -3,7 +3,7 @@ var tape = require("tape"), tape("symbol() returns a default symbol shape", function(test) { var s = shape.symbol(); - test.equal(s.type()(), "circle"); + test.equal(s.type()(), shape.circle); test.equal(s.size()(), 64); test.equal(s.context(), null); test.equal(s(), "M4.51351666838205,0A4.51351666838205,4.51351666838205,0,1,1,-4.51351666838205,0A4.51351666838205,4.51351666838205,0,1,1,4.51351666838205,0"); @@ -31,44 +31,38 @@ tape("symbol.size(size) observes the specified size constant", function(test) { test.end(); }); -tape("symbol.type(\"cross\") generates the expected path", function(test) { - var s = shape.symbol().type("cross").size(function(d) { return d; }); +tape("symbol.type(cross) generates the expected path", function(test) { + var s = shape.symbol().type(shape.cross).size(function(d) { return d; }); test.equal(s(0), "M0,0L0,0L0,0L0,0L0,0L0,0L0,0L0,0L0,0L0,0L0,0L0,0Z"); test.equal(s(20), "M-3,-1L-1,-1L-1,-3L1,-3L1,-1L3,-1L3,1L1,1L1,3L-1,3L-1,1L-3,1Z"); test.end(); }); -tape("symbol.type(\"diamond\") generates the expected path", function(test) { - var s = shape.symbol().type("diamond").size(function(d) { return d; }); +tape("symbol.type(diamond) generates the expected path", function(test) { + var s = shape.symbol().type(shape.diamond).size(function(d) { return d; }); test.equal(s(0), "M0,0L0,0L0,0L0,0Z"); test.equal(s(10), "M0,-2.942830956382712L1.6990442448471226,0L0,2.942830956382712L-1.6990442448471226,0Z"); test.end(); }); -tape("symbol.type(\"square\") generates the expected path", function(test) { - var s = shape.symbol().type("square").size(function(d) { return d; }); +tape("symbol.type(square) generates the expected path", function(test) { + var s = shape.symbol().type(shape.square).size(function(d) { return d; }); test.equal(s(0), "M0,0h0v0h0Z"); test.equal(s(4), "M-1,-1h2v2h-2Z"); test.equal(s(16), "M-2,-2h4v4h-4Z"); test.end(); }); -tape("symbol.type(\"triangle-up\") generates the expected path", function(test) { - var s = shape.symbol().type("triangle-down").size(function(d) { return d; }); +tape("symbol.type(triangleUp) generates the expected path", function(test) { + var s = shape.symbol().type(shape.triangleDown).size(function(d) { return d; }); test.equal(s(0), "M0,0L0,0L0,0Z"); test.equal(s(10), "M0,2.0808957251439084L2.4028114141347543,-2.0808957251439084L-2.4028114141347543,-2.0808957251439084Z"); test.end(); }); -tape("symbol.type(\"triangle-down\") generates the expected path", function(test) { - var s = shape.symbol().type("triangle-up").size(function(d) { return d; }); +tape("symbol.type(triangleDown) generates the expected path", function(test) { + var s = shape.symbol().type(shape.triangleUp).size(function(d) { return d; }); test.equal(s(0), "M0,0L0,0L0,0Z"); test.equal(s(10), "M0,-2.0808957251439084L2.4028114141347543,2.0808957251439084L-2.4028114141347543,2.0808957251439084Z"); test.end(); }); - -tape("symbol.type(invalid) defaults to circle", function(test) { - var s = shape.symbol().type("__proto__"); - test.equal(s(), "M4.51351666838205,0A4.51351666838205,4.51351666838205,0,1,1,-4.51351666838205,0A4.51351666838205,4.51351666838205,0,1,1,4.51351666838205,0"); - test.end(); -}); diff --git a/test/symbolTypes-test.js b/test/symbolTypes-test.js index c322369..f3786dd 100644 --- a/test/symbolTypes-test.js +++ b/test/symbolTypes-test.js @@ -3,12 +3,12 @@ var tape = require("tape"), tape("symbolTypes is the array of symbol types", function(test) { test.deepEqual(shape.symbolTypes, [ - "circle", - "cross", - "diamond", - "square", - "triangle-down", - "triangle-up" + shape.circle, + shape.cross, + shape.diamond, + shape.square, + shape.triangleDown, + shape.triangleUp ]); test.end(); }); From 84e82f1cbf60345bb2ff78195f10acb2c7b610ce Mon Sep 17 00:00:00 2001 From: Mike Bostock Date: Wed, 18 Nov 2015 20:54:46 -0800 Subject: [PATCH 02/15] Inline constants. --- src/symbol.js | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/src/symbol.js b/src/symbol.js index db0f5aa..cf228d4 100644 --- a/src/symbol.js +++ b/src/symbol.js @@ -6,14 +6,6 @@ import square from "./symbol/square"; import {triangleDown, triangleUp} from "./symbol/triangle"; import constant from "./constant"; -function constantSixtyFour() { - return 64; -} - -function constantCircle() { - return circle; -} - export var symbolTypes = [ circle, cross, @@ -24,8 +16,8 @@ export var symbolTypes = [ ]; export default function() { - var type = constantCircle, - size = constantSixtyFour, + var type = constant(circle), + size = constant(64), context = null; function symbol(d, i) { From b0f1f5b8762207e6b839f7587da815ca49f8c81c Mon Sep 17 00:00:00 2001 From: Mike Bostock Date: Wed, 18 Nov 2015 20:56:00 -0800 Subject: [PATCH 03/15] Inline constants. --- src/area.js | 6 +++--- src/constant.js | 8 -------- src/line.js | 4 ++-- 3 files changed, 5 insertions(+), 13 deletions(-) diff --git a/src/area.js b/src/area.js index 83b7713..68f2af1 100644 --- a/src/area.js +++ b/src/area.js @@ -5,7 +5,7 @@ import cardinal from "./interpolate/cardinal"; import cardinalOpen from "./interpolate/cardinal-open"; import catmullRom from "./interpolate/catmull-rom"; import catmullRomOpen from "./interpolate/catmull-rom-open"; -import constant, {constantTrue, constantZero} from "./constant"; +import constant from "./constant"; import linear from "./interpolate/linear"; import natural from "./interpolate/natural"; import step from "./interpolate/step"; @@ -16,9 +16,9 @@ import {x as pointX, y as pointY} from "./point"; export default function() { var x0 = pointX, x1 = null, - y0 = constantZero, + y0 = constant(0), y1 = pointY, - defined = constantTrue, + defined = constant(true), context = null, interpolate = linear, interpolator = null; diff --git a/src/constant.js b/src/constant.js index ef00a83..df6c780 100644 --- a/src/constant.js +++ b/src/constant.js @@ -3,11 +3,3 @@ export default function(x) { return x; }; }; - -export function constantTrue() { - return true; -}; - -export function constantZero() { - return 0; -}; diff --git a/src/line.js b/src/line.js index 45dcc5d..f817ddd 100644 --- a/src/line.js +++ b/src/line.js @@ -9,7 +9,7 @@ import cardinalOpen from "./interpolate/cardinal-open"; import catmullRom from "./interpolate/catmull-rom"; import catmullRomClosed from "./interpolate/catmull-rom-closed"; import catmullRomOpen from "./interpolate/catmull-rom-open"; -import constant, {constantTrue} from "./constant"; +import constant from "./constant"; import linear from "./interpolate/linear"; import linearClosed from "./interpolate/linear-closed"; import natural from "./interpolate/natural"; @@ -21,7 +21,7 @@ import {x as pointX, y as pointY} from "./point"; export default function() { var x = pointX, y = pointY, - defined = constantTrue, + defined = constant(true), context = null, interpolate = linear, interpolator = null; From 722db72a419f74f893a7b49ff11208bd467912b2 Mon Sep 17 00:00:00 2001 From: Mike Bostock Date: Wed, 18 Nov 2015 21:13:57 -0800 Subject: [PATCH 04/15] Symbolic line and area interpolation. --- README.md | 68 +++++++++++++++++++ index.js | 17 +++++ src/area.js | 28 +------- src/interpolate/cardinal.js | 2 + src/line.js | 40 +---------- test/area-test.js | 45 +++++++------ test/line-test.js | 131 +++++++++++++++--------------------- 7 files changed, 166 insertions(+), 165 deletions(-) diff --git a/README.md b/README.md index 48159f9..88287de 100644 --- a/README.md +++ b/README.md @@ -92,6 +92,70 @@ If you use NPM, `npm install d3-shape`. Otherwise, download the [latest release] … +# basis + +… + +# basisClosed + +… + +# basisOpen + +… + +# bundle(beta) + +… + +# cardinal(tension) + +… + +# cardinalClosed(tension) + +… + +# cardinalOpen(tension) + +… + +# catmullRom(alpha) + +… + +# catmullRomClosed(alpha) + +… + +# catmullRomOpen(alpha) + +… + +# linear + +… + +# linearClosed + +… + +# natural + +… + +# step + +… + +# stepAfter + +… + +# stepBefore + +… + # interpolate(context) … @@ -100,10 +164,14 @@ If you use NPM, `npm install d3-shape`. Otherwise, download the [latest release] … +Note: not implemented by closed interpolators, such as linearClosed. + # interpolator.areaEnd() … +Note: not implemented by closed interpolators, such as linearClosed. + # interpolator.lineStart() … diff --git a/index.js b/index.js index c7a5859..5a007db 100644 --- a/index.js +++ b/index.js @@ -1,5 +1,22 @@ export {default as area} from "./src/area"; export {default as line} from "./src/line"; +export {default as basisClosed} from "./src/interpolate/basis-closed"; +export {default as basisOpen} from "./src/interpolate/basis-open"; +export {default as basis} from "./src/interpolate/basis"; +export {default as bundle} from "./src/interpolate/bundle"; +export {default as cardinalClosed} from "./src/interpolate/cardinal-closed"; +export {default as cardinalOpen} from "./src/interpolate/cardinal-open"; +export {default as cardinal} from "./src/interpolate/cardinal"; +export {default as catmullRomClosed} from "./src/interpolate/catmull-rom-closed"; +export {default as catmullRomOpen} from "./src/interpolate/catmull-rom-open"; +export {default as catmullRom} from "./src/interpolate/catmull-rom"; +export {default as linearClosed} from "./src/interpolate/linear-closed"; +export {default as linear} from "./src/interpolate/linear"; +export {default as natural} from "./src/interpolate/natural"; +export {default as stepAfter} from "./src/interpolate/step-after"; +export {default as stepBefore} from "./src/interpolate/step-before"; +export {default as step} from "./src/interpolate/step"; + export {default as symbol, symbolTypes} from "./src/symbol"; export {default as circle} from "./src/symbol/circle"; export {default as cross} from "./src/symbol/cross"; diff --git a/src/area.js b/src/area.js index 68f2af1..63e31ae 100644 --- a/src/area.js +++ b/src/area.js @@ -1,16 +1,6 @@ import {path} from "d3-path"; -import basis from "./interpolate/basis"; -import basisOpen from "./interpolate/basis-open"; -import cardinal from "./interpolate/cardinal"; -import cardinalOpen from "./interpolate/cardinal-open"; -import catmullRom from "./interpolate/catmull-rom"; -import catmullRomOpen from "./interpolate/catmull-rom-open"; import constant from "./constant"; import linear from "./interpolate/linear"; -import natural from "./interpolate/natural"; -import step from "./interpolate/step"; -import stepAfter from "./interpolate/step-after"; -import stepBefore from "./interpolate/step-before"; import {x as pointX, y as pointY} from "./point"; export default function() { @@ -90,23 +80,7 @@ export default function() { }; area.interpolate = function(_, a) { - if (!arguments.length) return interpolate; - if (typeof _ === "function") interpolate = _; - else switch (_ + "") { - case "step": interpolate = step; break; - case "step-before": interpolate = stepBefore; break; - case "step-after": interpolate = stepAfter; break; - case "basis": interpolate = basis; break; - case "basis-open": interpolate = basisOpen; break; - case "cardinal": interpolate = cardinal(a); break; - case "cardinal-open": interpolate = cardinalOpen(a); break; - case "catmull-rom": interpolate = catmullRom(a); break; - case "catmull-rom-open": interpolate = catmullRomOpen(a); break; - case "natural": interpolate = natural; break; - default: interpolate = linear; break; - } - if (context != null) interpolator = interpolate(context); - return area; + return arguments.length ? (interpolate = _, context != null && (interpolator = _(context)), area) : interpolate; }; area.context = function(_) { diff --git a/src/interpolate/cardinal.js b/src/interpolate/cardinal.js index b51e215..996f84e 100644 --- a/src/interpolate/cardinal.js +++ b/src/interpolate/cardinal.js @@ -9,6 +9,8 @@ export function point(that, x, y) { ); }; + +// TODO cardinal(context) returns new Cardinal(context, 0)? function cardinal(tension) { var k = (tension == null ? 1 : 1 - tension) / 6; return function(context) { diff --git a/src/line.js b/src/line.js index f817ddd..6f9915d 100644 --- a/src/line.js +++ b/src/line.js @@ -1,21 +1,6 @@ import {path} from "d3-path"; -import basis from "./interpolate/basis"; -import basisClosed from "./interpolate/basis-closed"; -import basisOpen from "./interpolate/basis-open"; -import bundle from "./interpolate/bundle"; -import cardinal from "./interpolate/cardinal"; -import cardinalClosed from "./interpolate/cardinal-closed"; -import cardinalOpen from "./interpolate/cardinal-open"; -import catmullRom from "./interpolate/catmull-rom"; -import catmullRomClosed from "./interpolate/catmull-rom-closed"; -import catmullRomOpen from "./interpolate/catmull-rom-open"; import constant from "./constant"; import linear from "./interpolate/linear"; -import linearClosed from "./interpolate/linear-closed"; -import natural from "./interpolate/natural"; -import step from "./interpolate/step"; -import stepAfter from "./interpolate/step-after"; -import stepBefore from "./interpolate/step-before"; import {x as pointX, y as pointY} from "./point"; export default function() { @@ -58,29 +43,8 @@ export default function() { return arguments.length ? (defined = typeof _ === "function" ? _ : constant(!!_), line) : defined; }; - line.interpolate = function(_, a) { - if (!arguments.length) return interpolate; - if (typeof _ === "function") interpolate = _; - else switch (_ + "") { - case "linear-closed": interpolate = linearClosed; break; - case "step": interpolate = step; break; - case "step-before": interpolate = stepBefore; break; - case "step-after": interpolate = stepAfter; break; - case "basis": interpolate = basis; break; - case "basis-open": interpolate = basisOpen; break; - case "basis-closed": interpolate = basisClosed; break; - case "bundle": interpolate = bundle(a); break; - case "cardinal": interpolate = cardinal(a); break; - case "cardinal-open": interpolate = cardinalOpen(a); break; - case "cardinal-closed": interpolate = cardinalClosed(a); break; - case "catmull-rom": interpolate = catmullRom(a); break; - case "catmull-rom-open": interpolate = catmullRomOpen(a); break; - case "catmull-rom-closed": interpolate = catmullRomClosed(a); break; - case "natural": interpolate = natural; break; - default: interpolate = linear; break; - } - if (context != null) interpolator = interpolate(context); - return line; + line.interpolate = function(_) { + return arguments.length ? (interpolate = _, context != null && (interpolator = _(context)), line) : interpolate; }; line.context = function(_) { diff --git a/test/area-test.js b/test/area-test.js index 8c6b40c..d2ae2cc 100644 --- a/test/area-test.js +++ b/test/area-test.js @@ -8,6 +8,7 @@ tape("area() returns a default area shape", function(test) { test.equal(a.y0()([42, 34]), 0); test.equal(a.y1()([42, 34]), 34); test.equal(a.defined()([42, 34]), true); + test.equal(a.interpolate(), shape.linear); test.equal(a.context(), null); test.equal(a([[0, 1], [2, 3], [4, 5]]), "M0,1L2,3L4,5L4,0L2,0L0,0Z"); test.end(); @@ -52,8 +53,8 @@ tape("area.y(y)(data) observes the specified constant", function(test) { test.end(); }); -tape("area.interpolate(\"linear\")(data) generates the expected path", function(test) { - var a = shape.area().interpolate("linear"); +tape("area.interpolate(linear)(data) generates the expected path", function(test) { + var a = shape.area().interpolate(shape.linear); test.equal(a([]), null); test.equal(a([[0, 1]]), "M0,1L0,0Z"); test.equal(a([[0, 1], [2, 3]]), "M0,1L2,3L2,0L0,0Z"); @@ -61,8 +62,8 @@ tape("area.interpolate(\"linear\")(data) generates the expected path", function( test.end(); }); -tape("area.interpolate(\"basis\")(data) generates the expected path", function(test) { - var a = shape.area().interpolate("basis"); +tape("area.interpolate(basis)(data) generates the expected path", function(test) { + var a = shape.area().interpolate(shape.basis); test.equal(a([]), null); test.equal(a([[0, 1]]), "M0,1L0,0Z"); test.equal(a([[0, 1], [1, 3]]), "M0,1L1,3L1,0L0,0Z"); @@ -70,8 +71,8 @@ tape("area.interpolate(\"basis\")(data) generates the expected path", function(t test.end(); }); -tape("area.interpolate(\"basis-open\")(data) generates the expected path", function(test) { - var a = shape.area().interpolate("basis-open"); +tape("area.interpolate(basisOpen)(data) generates the expected path", function(test) { + var a = shape.area().interpolate(shape.basisOpen); test.equal(a([]), null); test.equal(a([[0, 1]]), null); test.equal(a([[0, 1], [1, 3]]), null); @@ -81,8 +82,8 @@ tape("area.interpolate(\"basis-open\")(data) generates the expected path", funct test.end(); }); -tape("area.interpolate(\"cardinal\")(data) generates the expected path", function(test) { - var a = shape.area().interpolate("cardinal"); +tape("area.interpolate(cardinal)(data) generates the expected path", function(test) { + var a = shape.area().interpolate(shape.cardinal()); // TODO no empty invocation? test.equal(a([]), null); test.equal(a([[0, 1]]), "M0,1L0,0Z"); test.equal(a([[0, 1], [1, 3]]), "M0,1L1,3L1,0L0,0Z"); @@ -91,8 +92,8 @@ tape("area.interpolate(\"cardinal\")(data) generates the expected path", functio test.end(); }); -tape("area.interpolate(\"cardinal-open\")(data) generates the expected path", function(test) { - var a = shape.area().interpolate("cardinal-open"); +tape("area.interpolate(cardinalOpen)(data) generates the expected path", function(test) { + var a = shape.area().interpolate(shape.cardinalOpen()); // TODO no empty invocation? test.equal(a([]), null); test.equal(a([[0, 1]]), null); test.equal(a([[0, 1], [1, 3]]), null); @@ -101,8 +102,8 @@ tape("area.interpolate(\"cardinal-open\")(data) generates the expected path", fu test.end(); }); -tape("area.interpolate(\"catmull-rom\", 0.5)(data) generates the expected path", function(test) { - var a = shape.area().interpolate("catmull-rom", 0.5); +tape("area.interpolate(catmullRom, 0.5)(data) generates the expected path", function(test) { + var a = shape.area().interpolate(shape.catmullRom(0.5)); test.equal(a([]), null); test.equal(a([[0, 1]]), "M0,1L0,0Z"); test.equal(a([[0, 1], [1, 3]]), "M0,1L1,3L1,0L0,0Z"); @@ -111,8 +112,8 @@ tape("area.interpolate(\"catmull-rom\", 0.5)(data) generates the expected path", test.end(); }); -tape("area.interpolate(\"catmull-rom-open\", 0.5)(data) generates the expected path", function(test) { - var a = shape.area().interpolate("catmull-rom-open", 0.5); +tape("area.interpolate(catmullRomOpen, 0.5)(data) generates the expected path", function(test) { + var a = shape.area().interpolate(shape.catmullRomOpen(0.5)); test.equal(a([]), null); test.equal(a([[0, 1]]), null); test.equal(a([[0, 1], [1, 3]]), null); @@ -121,8 +122,8 @@ tape("area.interpolate(\"catmull-rom-open\", 0.5)(data) generates the expected p test.end(); }); -tape("area.interpolate(\"step\")(data) generates the expected path", function(test) { - var a = shape.area().interpolate("step"); +tape("area.interpolate(step)(data) generates the expected path", function(test) { + var a = shape.area().interpolate(shape.step); test.equal(a([]), null); test.equal(a([[0, 1]]), "M0,1L0,0Z"); test.equal(a([[0, 1], [2, 3]]), "M0,1L1,1L1,3L2,3L2,0L1,0L1,0L0,0Z"); @@ -130,8 +131,8 @@ tape("area.interpolate(\"step\")(data) generates the expected path", function(te test.end(); }); -tape("area.interpolate(\"step-before\")(data) generates the expected path", function(test) { - var a = shape.area().interpolate("step-before"); +tape("area.interpolate(stepBefore)(data) generates the expected path", function(test) { + var a = shape.area().interpolate(shape.stepBefore); test.equal(a([]), null); test.equal(a([[0, 1]]), "M0,1L0,0Z"); test.equal(a([[0, 1], [2, 3]]), "M0,1L0,3L2,3L2,0L2,0L0,0Z"); @@ -139,8 +140,8 @@ tape("area.interpolate(\"step-before\")(data) generates the expected path", func test.end(); }); -tape("area.interpolate(\"step-after\")(data) generates the expected path", function(test) { - var a = shape.area().interpolate("step-after"); +tape("area.interpolate(stepAfter)(data) generates the expected path", function(test) { + var a = shape.area().interpolate(shape.stepAfter); test.equal(a([]), null); test.equal(a([[0, 1]]), "M0,1L0,0Z"); test.equal(a([[0, 1], [2, 3]]), "M0,1L2,1L2,3L2,0L0,0L0,0Z"); @@ -148,8 +149,8 @@ tape("area.interpolate(\"step-after\")(data) generates the expected path", funct test.end(); }); -tape("area.interpolate(\"natural\")(data) generates the expected path", function(test) { - var a = shape.area().interpolate("natural"); +tape("area.interpolate(natural)(data) generates the expected path", function(test) { + var a = shape.area().interpolate(shape.natural); test.equal(a([]), null); test.equal(a([[0, 1]]), "M0,1L0,0Z"); test.equal(a([[0, 1], [1, 3]]), "M0,1L1,3L1,0L0,0Z"); diff --git a/test/line-test.js b/test/line-test.js index d9f0ac1..07f8b3b 100644 --- a/test/line-test.js +++ b/test/line-test.js @@ -6,6 +6,7 @@ tape("line() returns a default line shape", function(test) { test.equal(l.x()([42, 34]), 42); test.equal(l.y()([42, 34]), 34); test.equal(l.defined()([42, 34]), true); + test.equal(l.interpolate(), shape.linear); test.equal(l.context(), null); test.equal(l([[0, 1], [2, 3], [4, 5]]), "M0,1L2,3L4,5"); test.end(); @@ -35,15 +36,15 @@ tape("line.y(y)(data) observes the specified constant", function(test) { test.end(); }); -tape("line.interpolate(name) sets the interpolation method", function(test) { - var l = shape.line().interpolate("linear-closed"); +tape("line.interpolate(interpolate) sets the interpolation method", function(test) { + var l = shape.line().interpolate(shape.linearClosed); test.equal(l([]), null); test.equal(l([[0, 1], [2, 3]]), "M0,1L2,3Z"); test.end(); }); -tape("line.interpolate(\"cardinal\", tension) sets the cardinal interpolation tension", function(test) { - var l = shape.line().interpolate("cardinal", 0.1); +tape("line.interpolate(cardinal(tension)) sets the cardinal interpolation tension", function(test) { + var l = shape.line().interpolate(shape.cardinal(0.1)); test.equal(l([]), null); test.equal(l([[0, 1]]), "M0,1Z"); test.equal(l([[0, 1], [1, 3]]), "M0,1L1,3"); @@ -52,8 +53,8 @@ tape("line.interpolate(\"cardinal\", tension) sets the cardinal interpolation te test.end(); }); -tape("line.interpolate(\"cardinal\", tension) coerces the specified tension to a number", function(test) { - var l = shape.line().interpolate("cardinal", "0.1"); +tape("line.interpolate(cardinal(tension)) coerces the specified tension to a number", function(test) { + var l = shape.line().interpolate(shape.cardinal("0.1")); test.equal(l([]), null); test.equal(l([[0, 1]]), "M0,1Z"); test.equal(l([[0, 1], [1, 3]]), "M0,1L1,3"); @@ -62,50 +63,24 @@ tape("line.interpolate(\"cardinal\", tension) coerces the specified tension to a test.end(); }); -tape("line.interpolate(\"cardinal\") implicitly uses a tension of zero", function(test) { - var l0 = shape.line().interpolate("cardinal"), - l1 = shape.line().interpolate("cardinal", 0); - test.equal(l1([[0, 1], [1, 3], [2, 1], [3, 3]]), l0([[0, 1], [1, 3], [2, 1], [3, 3]])); +tape("line.interpolate(cardinal()) implicitly uses a tension of zero", function(test) { + var l = shape.line().interpolate(shape.cardinal(0)); + test.equal(shape.line().interpolate(shape.cardinal())([[0, 1], [1, 3], [2, 1], [3, 3]]), l([[0, 1], [1, 3], [2, 1], [3, 3]])); // TODO no empty invocation? + test.equal(shape.line().interpolate(shape.cardinal(null))([[0, 1], [1, 3], [2, 1], [3, 3]]), l([[0, 1], [1, 3], [2, 1], [3, 3]])); + test.equal(shape.line().interpolate(shape.cardinal(undefined))([[0, 1], [1, 3], [2, 1], [3, 3]]), l([[0, 1], [1, 3], [2, 1], [3, 3]])); test.end(); }); -tape("line.interpolate(\"cardinal\", null) implicitly uses a tension of zero", function(test) { - var l0 = shape.line().interpolate("cardinal"), - l1 = shape.line().interpolate("cardinal", null); - test.equal(l1([[0, 1], [1, 3], [2, 1], [3, 3]]), l0([[0, 1], [1, 3], [2, 1], [3, 3]])); +tape("line.interpolate(cardinalOpen()) implicitly uses a tension of zero", function(test) { + var l = shape.line().interpolate(shape.cardinalOpen(0)); + test.equal(shape.line().interpolate(shape.cardinalOpen())([[0, 1], [1, 3], [2, 1], [3, 3]]), l([[0, 1], [1, 3], [2, 1], [3, 3]])); // TODO no empty invocation? + test.equal(shape.line().interpolate(shape.cardinalOpen(null))([[0, 1], [1, 3], [2, 1], [3, 3]]), l([[0, 1], [1, 3], [2, 1], [3, 3]])); + test.equal(shape.line().interpolate(shape.cardinalOpen(undefined))([[0, 1], [1, 3], [2, 1], [3, 3]]), l([[0, 1], [1, 3], [2, 1], [3, 3]])); test.end(); }); -tape("line.interpolate(\"cardinal\", undefined) implicitly uses a tension of zero", function(test) { - var l0 = shape.line().interpolate("cardinal"), - l1 = shape.line().interpolate("cardinal", undefined); - test.equal(l1([[0, 1], [1, 3], [2, 1], [3, 3]]), l0([[0, 1], [1, 3], [2, 1], [3, 3]])); - test.end(); -}); - -tape("line.interpolate(\"cardinal-open\") implicitly uses a tension of zero", function(test) { - var l0 = shape.line().interpolate("cardinal-open"), - l1 = shape.line().interpolate("cardinal-open", 0); - test.equal(l1([[0, 1], [1, 3], [2, 1], [3, 3]]), l0([[0, 1], [1, 3], [2, 1], [3, 3]])); - test.end(); -}); - -tape("line.interpolate(\"cardinal-open\", null) implicitly uses a tension of zero", function(test) { - var l0 = shape.line().interpolate("cardinal-open"), - l1 = shape.line().interpolate("cardinal-open", null); - test.equal(l1([[0, 1], [1, 3], [2, 1], [3, 3]]), l0([[0, 1], [1, 3], [2, 1], [3, 3]])); - test.end(); -}); - -tape("line.interpolate(\"cardinal-open\", undefined) implicitly uses a tension of zero", function(test) { - var l0 = shape.line().interpolate("cardinal-open"), - l1 = shape.line().interpolate("cardinal-open", undefined); - test.equal(l1([[0, 1], [1, 3], [2, 1], [3, 3]]), l0([[0, 1], [1, 3], [2, 1], [3, 3]])); - test.end(); -}); - -tape("line.interpolate(\"linear\")(data) generates the expected path", function(test) { - var l = shape.line().interpolate("linear"); +tape("line.interpolate(linear)(data) generates the expected path", function(test) { + var l = shape.line().interpolate(shape.linear); test.equal(l([]), null); test.equal(l([[0, 1]]), "M0,1Z"); test.equal(l([[0, 1], [2, 3]]), "M0,1L2,3"); @@ -113,8 +88,8 @@ tape("line.interpolate(\"linear\")(data) generates the expected path", function( test.end(); }); -tape("line.interpolate(\"linear-closed\")(data) generates the expected path", function(test) { - var l = shape.line().interpolate("linear-closed"); +tape("line.interpolate(linear-closed)(data) generates the expected path", function(test) { + var l = shape.line().interpolate(shape.linearClosed); test.equal(l([]), null); test.equal(l([[0, 1]]), "M0,1Z"); test.equal(l([[0, 1], [2, 3]]), "M0,1L2,3Z"); @@ -122,8 +97,8 @@ tape("line.interpolate(\"linear-closed\")(data) generates the expected path", fu test.end(); }); -tape("line.interpolate(\"step\")(data) generates the expected path", function(test) { - var l = shape.line().interpolate("step"); +tape("line.interpolate(step)(data) generates the expected path", function(test) { + var l = shape.line().interpolate(shape.step); test.equal(l([]), null); test.equal(l([[0, 1]]), "M0,1Z"); test.equal(l([[0, 1], [2, 3]]), "M0,1L1,1L1,3L2,3"); @@ -131,8 +106,8 @@ tape("line.interpolate(\"step\")(data) generates the expected path", function(te test.end(); }); -tape("line.interpolate(\"step-before\")(data) generates the expected path", function(test) { - var l = shape.line().interpolate("step-before"); +tape("line.interpolate(step-before)(data) generates the expected path", function(test) { + var l = shape.line().interpolate(shape.stepBefore); test.equal(l([]), null); test.equal(l([[0, 1]]), "M0,1Z"); test.equal(l([[0, 1], [2, 3]]), "M0,1L0,3L2,3"); @@ -140,8 +115,8 @@ tape("line.interpolate(\"step-before\")(data) generates the expected path", func test.end(); }); -tape("line.interpolate(\"step-after\")(data) generates the expected path", function(test) { - var l = shape.line().interpolate("step-after"); +tape("line.interpolate(step-after)(data) generates the expected path", function(test) { + var l = shape.line().interpolate(shape.stepAfter); test.equal(l([]), null); test.equal(l([[0, 1]]), "M0,1Z"); test.equal(l([[0, 1], [2, 3]]), "M0,1L2,1L2,3"); @@ -149,8 +124,8 @@ tape("line.interpolate(\"step-after\")(data) generates the expected path", funct test.end(); }); -tape("line.interpolate(\"basis\")(data) generates the expected path", function(test) { - var l = shape.line().interpolate("basis"); +tape("line.interpolate(basis)(data) generates the expected path", function(test) { + var l = shape.line().interpolate(shape.basis); test.equal(l([]), null); test.equal(l([[0, 1]]), "M0,1Z"); test.equal(l([[0, 1], [1, 3]]), "M0,1L1,3"); @@ -158,8 +133,8 @@ tape("line.interpolate(\"basis\")(data) generates the expected path", function(t test.end(); }); -tape("line.interpolate(\"basis-open\")(data) generates the expected path", function(test) { - var l = shape.line().interpolate("basis-open"); +tape("line.interpolate(basis-open)(data) generates the expected path", function(test) { + var l = shape.line().interpolate(shape.basisOpen); test.equal(l([]), null); test.equal(l([[0, 0]]), null); test.equal(l([[0, 0], [0, 10]]), null); @@ -169,8 +144,8 @@ tape("line.interpolate(\"basis-open\")(data) generates the expected path", funct test.end(); }); -tape("line.interpolate(\"basis-closed\")(data) generates the expected path", function(test) { - var l = shape.line().interpolate("basis-closed"); +tape("line.interpolate(basis-closed)(data) generates the expected path", function(test) { + var l = shape.line().interpolate(shape.basisClosed); test.equal(l([]), null); test.equal(l([[0, 0]]), "M0,0Z"); test.equal(l([[0, 0], [0, 10]]), "M0,6.666666666666667L0,3.3333333333333335Z"); @@ -180,8 +155,8 @@ tape("line.interpolate(\"basis-closed\")(data) generates the expected path", fun test.end(); }); -tape("line.interpolate(\"cardinal\")(data) generates the expected path", function(test) { - var l = shape.line().interpolate("cardinal"); +tape("line.interpolate(cardinal)(data) generates the expected path", function(test) { + var l = shape.line().interpolate(shape.cardinal()); // TODO no empty invocation? test.equal(l([]), null); test.equal(l([[0, 1]]), "M0,1Z"); test.equal(l([[0, 1], [1, 3]]), "M0,1L1,3"); @@ -190,8 +165,8 @@ tape("line.interpolate(\"cardinal\")(data) generates the expected path", functio test.end(); }); -tape("line.interpolate(\"cardinal-open\")(data) generates the expected path", function(test) { - var l = shape.line().interpolate("cardinal-open"); +tape("line.interpolate(cardinal-open)(data) generates the expected path", function(test) { + var l = shape.line().interpolate(shape.cardinalOpen()); // TODO no empty invocation? test.equal(l([]), null); test.equal(l([[0, 1]]), null); test.equal(l([[0, 1], [1, 3]]), null); @@ -200,8 +175,8 @@ tape("line.interpolate(\"cardinal-open\")(data) generates the expected path", fu test.end(); }); -tape("line.interpolate(\"cardinal-closed\")(data) generates the expected path", function(test) { - var l = shape.line().interpolate("cardinal-closed"); +tape("line.interpolate(cardinal-closed)(data) generates the expected path", function(test) { + var l = shape.line().interpolate(shape.cardinalClosed()); // TODO no empty invocation? test.equal(l([]), null); test.equal(l([[0, 1]]), "M0,1Z"); test.equal(l([[0, 1], [1, 3]]), "M1,3L0,1Z"); @@ -210,8 +185,8 @@ tape("line.interpolate(\"cardinal-closed\")(data) generates the expected path", test.end(); }); -tape("line.interpolate(\"catmull-rom\")(data) generates the expected path", function(test) { - var l = shape.line().interpolate("catmull-rom"); +tape("line.interpolate(catmull-rom)(data) generates the expected path", function(test) { + var l = shape.line().interpolate(shape.catmullRom()); // TODO no empty invocation? test.equal(l([]), null); test.equal(l([[0, 1]]), "M0,1Z"); test.equal(l([[0, 1], [1, 3]]), "M0,1L1,3"); @@ -220,8 +195,8 @@ tape("line.interpolate(\"catmull-rom\")(data) generates the expected path", func test.end(); }); -tape("line.interpolate(\"catmull-rom-open\")(data) generates the expected path", function(test) { - var l = shape.line().interpolate("catmull-rom-open"); +tape("line.interpolate(catmull-rom-open)(data) generates the expected path", function(test) { + var l = shape.line().interpolate(shape.catmullRomOpen()); // TODO no empty invocation? test.equal(l([]), null); test.equal(l([[0, 1]]), null); test.equal(l([[0, 1], [1, 3]]), null); @@ -230,8 +205,8 @@ tape("line.interpolate(\"catmull-rom-open\")(data) generates the expected path", test.end(); }); -tape("line.interpolate(\"catmull-rom-closed\")(data) generates the expected path", function(test) { - var l = shape.line().interpolate("catmull-rom-closed"); +tape("line.interpolate(catmull-rom-closed)(data) generates the expected path", function(test) { + var l = shape.line().interpolate(shape.catmullRomClosed()); // TODO no empty invocation? test.equal(l([]), null); test.equal(l([[0, 1]]), "M0,1Z"); test.equal(l([[0, 1], [1, 3]]), "M1,3L0,1Z"); @@ -240,8 +215,8 @@ tape("line.interpolate(\"catmull-rom-closed\")(data) generates the expected path test.end(); }); -tape("line.interpolate(\"catmull-rom\", 1)(data) generates the expected path", function(test) { - var l = shape.line().interpolate("catmull-rom", 1); +tape("line.interpolate(catmull-rom, 1)(data) generates the expected path", function(test) { + var l = shape.line().interpolate(shape.catmullRom(1)); test.equal(l([]), null); test.equal(l([[0, 1]]), "M0,1Z"); test.equal(l([[0, 1], [1, 3]]), "M0,1L1,3"); @@ -250,8 +225,8 @@ tape("line.interpolate(\"catmull-rom\", 1)(data) generates the expected path", f test.end(); }); -tape("line.interpolate(\"catmull-rom-open\", 1)(data) generates the expected path", function(test) { - var l = shape.line().interpolate("catmull-rom-open", 1); +tape("line.interpolate(catmull-rom-open, 1)(data) generates the expected path", function(test) { + var l = shape.line().interpolate(shape.catmullRomOpen(1)); test.equal(l([]), null); test.equal(l([[0, 1]]), null); test.equal(l([[0, 1], [1, 3]]), null); @@ -260,8 +235,8 @@ tape("line.interpolate(\"catmull-rom-open\", 1)(data) generates the expected pat test.end(); }); -tape("line.interpolate(\"catmull-rom-closed\", 1)(data) generates the expected path", function(test) { - var l = shape.line().interpolate("catmull-rom-closed", 1); +tape("line.interpolate(catmull-rom-closed, 1)(data) generates the expected path", function(test) { + var l = shape.line().interpolate(shape.catmullRomClosed(1)); test.equal(l([]), null); test.equal(l([[0, 1]]), "M0,1Z"); test.equal(l([[0, 1], [1, 3]]), "M1,3L0,1Z"); @@ -270,8 +245,8 @@ tape("line.interpolate(\"catmull-rom-closed\", 1)(data) generates the expected p test.end(); }); -tape("line.interpolate(\"natural\")(data) generates the expected path", function(test) { - var l = shape.line().interpolate("natural"); +tape("line.interpolate(natural)(data) generates the expected path", function(test) { + var l = shape.line().interpolate(shape.natural); test.equal(l([]), null); test.equal(l([[0, 1]]), "M0,1Z"); test.equal(l([[0, 1], [1, 3]]), "M0,1L1,3"); From 9bf40b4b0680c657775febce115bc09f0f9f04c0 Mon Sep 17 00:00:00 2001 From: Mike Bostock Date: Wed, 18 Nov 2015 21:17:11 -0800 Subject: [PATCH 05/15] Update README. --- README.md | 45 +++++++++++++++++++++++++++++++-------------- 1 file changed, 31 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 88287de..54ab084 100644 --- a/README.md +++ b/README.md @@ -32,7 +32,7 @@ If you use NPM, `npm install d3-shape`. Otherwise, download the [latest release] … -# line.interpolate([interpolate[, t]]) +# line.interpolate([interpolate]) … @@ -80,7 +80,7 @@ If you use NPM, `npm install d3-shape`. Otherwise, download the [latest release] … -# area.interpolate([interpolate[, t]]) +# area.interpolate([interpolate]) … @@ -206,28 +206,45 @@ Note: not implemented by closed interpolators, such as l # symbolTypes -An array containing the set of supported [symbol types](#symbol_type): +An array containing the set of supported [symbol types](#symbol_type): [circle](#circle), [cross](#cross), [diamond](#diamond), [square](#square), [triangleDown](#triangleDown), and [triangleUp](#triangleUp). -* `circle` -* `cross` -* `diamond` -* `square` -* `triangle-down` -* `triangle-up` +# circle + +… + +# cross + +… + +# diamond + +… + +# square + +… + +# triangleDown + +… + +# triangleUp + +… ## Changes from D3 3.x: * You can now render shapes to Canvas by specifying a context (e.g., [*line*.context](#line_context))! -* The interpretation of the Cardinal spline tension parameter has been fixed. The default tension is now 0 (corresponding to a uniform Catmull–Rom spline), not 0.7. Due to a bug in 3.x, the tension parameter was previously only valid in the range [2/3, 1]; this corresponds to the new corrected range of [0, 1]. Thus, the new default value of 0 is equivalent to the old value of 2/3, and the default behavior is only slightly changed. +* The interpretation of the [Cardinal](#cardinal) spline tension parameter has been fixed. The default tension is now 0 (corresponding to a uniform Catmull–Rom spline), not 0.7. Due to a bug in 3.x, the tension parameter was previously only valid in the range [2/3, 1]; this corresponds to the new corrected range of [0, 1]. Thus, the new default value of 0 is equivalent to the old value of 2/3, and the default behavior is only slightly changed. -* To specify a Cardinal interpolation tension of *t*, use `line.interpolate("cardinal", t)` instead of `line.interpolate("cardinal").tension(t)`. +* To specify a [Cardinal](#cardinal) interpolation tension of *t*, use `line.interpolate(cardinal(t))` instead of `line.interpolate("cardinal").tension(t)`. -* The custom interpolator API has changed. +* The custom [interpolator API](#interpolators) has changed. -* Added “natural” cubic spline interpolation. +* Added [natural](#natural) cubic spline interpolation. -* Added “catmull-rom” spline interpolation, parameterized by alpha. If α = 0, produces a uniform Catmull–Rom spline equivalent to a Cardinal spline with zero tension; if α = 0.5, produces a centripetal spline; if α = 1.0, produces a chordal spline. +* Added [Catmull–Rom](#catmullRom) spline interpolation, parameterized by alpha. If α = 0, produces a uniform Catmull–Rom spline equivalent to a Cardinal spline with zero tension; if α = 0.5, produces a centripetal spline; if α = 1.0, produces a chordal spline. * By setting [*area*.x1](#area_x1) or [*area*.y1](#area_y1) to null, you can reuse the [*area*.x0](#area_x0) or [*area*.y0](#area_y0) value, rather than computing it twice. This is useful for nondeterministic values (e.g., jitter). From 7f1c1d4b8a572ba897c7b25f21a7a276a85c7489 Mon Sep 17 00:00:00 2001 From: Mike Bostock Date: Wed, 18 Nov 2015 21:18:48 -0800 Subject: [PATCH 06/15] Update README. --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index 54ab084..8d3697b 100644 --- a/README.md +++ b/README.md @@ -232,6 +232,10 @@ An array containing the set of supported [symbol types](#symbol_type): [circle]( … +# symbolType.draw(context, size) + +… + ## Changes from D3 3.x: * You can now render shapes to Canvas by specifying a context (e.g., [*line*.context](#line_context))! From b33245d6ce3d160aa58b84bb13fc99a9fdb669da Mon Sep 17 00:00:00 2001 From: Mike Bostock Date: Thu, 19 Nov 2015 09:23:57 -0800 Subject: [PATCH 07/15] Simpler default instantiation. --- src/interpolate/bundle.js | 1 + src/interpolate/cardinal-closed.js | 1 + src/interpolate/cardinal-open.js | 1 + src/interpolate/cardinal.js | 3 +- src/interpolate/catmull-rom-closed.js | 1 + src/interpolate/catmull-rom-open.js | 1 + src/interpolate/catmull-rom.js | 1 + test/area-test.js | 40 ++++++++- test/line-test.js | 117 ++++++++++++++++++-------- 9 files changed, 127 insertions(+), 39 deletions(-) diff --git a/src/interpolate/bundle.js b/src/interpolate/bundle.js index 62fcc73..db650a5 100644 --- a/src/interpolate/bundle.js +++ b/src/interpolate/bundle.js @@ -2,6 +2,7 @@ import basis from "./basis"; import linear from "./linear"; function bundle(beta) { + if (beta && beta.moveTo) return basis(beta); return beta == null || (beta = +beta) === 1 ? basis : function(context) { return new Bundle(context, beta); }; } diff --git a/src/interpolate/cardinal-closed.js b/src/interpolate/cardinal-closed.js index 4a984a7..9266857 100644 --- a/src/interpolate/cardinal-closed.js +++ b/src/interpolate/cardinal-closed.js @@ -1,6 +1,7 @@ import {point} from "./cardinal"; function cardinalClosed(tension) { + if (tension && tension.moveTo) return new CardinalClosed(tension, 1 / 6); var k = (tension == null ? 1 : 1 - tension) / 6; return function(context) { return new CardinalClosed(context, k); diff --git a/src/interpolate/cardinal-open.js b/src/interpolate/cardinal-open.js index baba122..bc163d7 100644 --- a/src/interpolate/cardinal-open.js +++ b/src/interpolate/cardinal-open.js @@ -1,6 +1,7 @@ import {point} from "./cardinal"; function cardinalOpen(tension) { + if (tension && tension.moveTo) return new CardinalOpen(tension, 1 / 6); var k = (tension == null ? 1 : 1 - tension) / 6; return function(context) { return new CardinalOpen(context, k); diff --git a/src/interpolate/cardinal.js b/src/interpolate/cardinal.js index 996f84e..d3f7c43 100644 --- a/src/interpolate/cardinal.js +++ b/src/interpolate/cardinal.js @@ -9,9 +9,8 @@ export function point(that, x, y) { ); }; - -// TODO cardinal(context) returns new Cardinal(context, 0)? function cardinal(tension) { + if (tension && tension.moveTo) return new Cardinal(tension, 1 / 6); var k = (tension == null ? 1 : 1 - tension) / 6; return function(context) { return new Cardinal(context, k); diff --git a/src/interpolate/catmull-rom-closed.js b/src/interpolate/catmull-rom-closed.js index 7e938e3..951ef3a 100644 --- a/src/interpolate/catmull-rom-closed.js +++ b/src/interpolate/catmull-rom-closed.js @@ -2,6 +2,7 @@ import cardinalClosed from "./cardinal-closed"; import {point} from "./catmull-rom"; function catmullRomClosed(alpha) { + if (alpha && alpha.moveTo) return cardinalClosed(alpha); return alpha == null || !(alpha = +alpha) ? cardinalClosed(0) : function(context) { return new CatmullRomClosed(context, alpha); }; diff --git a/src/interpolate/catmull-rom-open.js b/src/interpolate/catmull-rom-open.js index 394a0ac..3b8dc68 100644 --- a/src/interpolate/catmull-rom-open.js +++ b/src/interpolate/catmull-rom-open.js @@ -2,6 +2,7 @@ import cardinalOpen from "./cardinal-open"; import {point} from "./catmull-rom"; function catmullRomOpen(alpha) { + if (alpha && alpha.moveTo) return cardinalOpen(alpha); return alpha == null || !(alpha = +alpha) ? cardinalOpen(0) : function(context) { return new CatmullRomOpen(context, alpha); }; diff --git a/src/interpolate/catmull-rom.js b/src/interpolate/catmull-rom.js index 932cf32..e4b6b7e 100644 --- a/src/interpolate/catmull-rom.js +++ b/src/interpolate/catmull-rom.js @@ -26,6 +26,7 @@ export function point(that, x, y) { }; function catmullRom(alpha) { + if (alpha && alpha.moveTo) return cardinal(alpha); return alpha == null || !(alpha = +alpha) ? cardinal(0) : function(context) { return new CatmullRom(context, alpha); }; diff --git a/test/area-test.js b/test/area-test.js index d2ae2cc..6858e62 100644 --- a/test/area-test.js +++ b/test/area-test.js @@ -83,7 +83,7 @@ tape("area.interpolate(basisOpen)(data) generates the expected path", function(t }); tape("area.interpolate(cardinal)(data) generates the expected path", function(test) { - var a = shape.area().interpolate(shape.cardinal()); // TODO no empty invocation? + var a = shape.area().interpolate(shape.cardinal); test.equal(a([]), null); test.equal(a([[0, 1]]), "M0,1L0,0Z"); test.equal(a([[0, 1], [1, 3]]), "M0,1L1,3L1,0L0,0Z"); @@ -93,7 +93,7 @@ tape("area.interpolate(cardinal)(data) generates the expected path", function(te }); tape("area.interpolate(cardinalOpen)(data) generates the expected path", function(test) { - var a = shape.area().interpolate(shape.cardinalOpen()); // TODO no empty invocation? + var a = shape.area().interpolate(shape.cardinalOpen); test.equal(a([]), null); test.equal(a([[0, 1]]), null); test.equal(a([[0, 1], [1, 3]]), null); @@ -158,3 +158,39 @@ tape("area.interpolate(natural)(data) generates the expected path", function(tes test.equal(a([[0, 1], [1, 3], [2, 1], [3, 3]]), "M0,1C0.33333333333333326,2.111111111111111,0.6666666666666665,3.2222222222222223,1,3C1.3333333333333335,2.7777777777777777,1.666666666666667,1.2222222222222223,2,1C2.333333333333333,0.7777777777777778,2.6666666666666665,1.8888888888888888,3,3L3,0C2.666666666666667,0,2.3333333333333335,0,2,0C1.6666666666666665,0,1.3333333333333333,0,1,0C0.6666666666666667,0,0.33333333333333337,0,0,0Z"); test.end(); }); + +tape("area.interpolate(cardinal) uses a default tension of zero", function(test) { + var a = shape.area().interpolate(shape.cardinal(0)); + test.equal(shape.area().interpolate(shape.cardinal)([[0, 1], [1, 3], [2, 1], [3, 3]]), a([[0, 1], [1, 3], [2, 1], [3, 3]])); + test.equal(shape.area().interpolate(shape.cardinal())([[0, 1], [1, 3], [2, 1], [3, 3]]), a([[0, 1], [1, 3], [2, 1], [3, 3]])); + test.equal(shape.area().interpolate(shape.cardinal(null))([[0, 1], [1, 3], [2, 1], [3, 3]]), a([[0, 1], [1, 3], [2, 1], [3, 3]])); + test.equal(shape.area().interpolate(shape.cardinal(undefined))([[0, 1], [1, 3], [2, 1], [3, 3]]), a([[0, 1], [1, 3], [2, 1], [3, 3]])); + test.end(); +}); + +tape("area.interpolate(cardinalOpen) uses a default tension of zero", function(test) { + var a = shape.area().interpolate(shape.cardinalOpen(0)); + test.equal(shape.area().interpolate(shape.cardinalOpen)([[0, 1], [1, 3], [2, 1], [3, 3]]), a([[0, 1], [1, 3], [2, 1], [3, 3]])); + test.equal(shape.area().interpolate(shape.cardinalOpen())([[0, 1], [1, 3], [2, 1], [3, 3]]), a([[0, 1], [1, 3], [2, 1], [3, 3]])); + test.equal(shape.area().interpolate(shape.cardinalOpen(null))([[0, 1], [1, 3], [2, 1], [3, 3]]), a([[0, 1], [1, 3], [2, 1], [3, 3]])); + test.equal(shape.area().interpolate(shape.cardinalOpen(undefined))([[0, 1], [1, 3], [2, 1], [3, 3]]), a([[0, 1], [1, 3], [2, 1], [3, 3]])); + test.end(); +}); + +tape("area.interpolate(catmullRom) uses a default alpha of zero", function(test) { + var a = shape.area().interpolate(shape.catmullRom(0)); + test.equal(shape.area().interpolate(shape.catmullRom)([[0, 1], [1, 3], [2, 1], [3, 3]]), a([[0, 1], [1, 3], [2, 1], [3, 3]])); + test.equal(shape.area().interpolate(shape.catmullRom())([[0, 1], [1, 3], [2, 1], [3, 3]]), a([[0, 1], [1, 3], [2, 1], [3, 3]])); + test.equal(shape.area().interpolate(shape.catmullRom(null))([[0, 1], [1, 3], [2, 1], [3, 3]]), a([[0, 1], [1, 3], [2, 1], [3, 3]])); + test.equal(shape.area().interpolate(shape.catmullRom(undefined))([[0, 1], [1, 3], [2, 1], [3, 3]]), a([[0, 1], [1, 3], [2, 1], [3, 3]])); + test.end(); +}); + +tape("area.interpolate(catmullRomOpen) uses a default alpha of zero", function(test) { + var a = shape.area().interpolate(shape.catmullRomOpen(0)); + test.equal(shape.area().interpolate(shape.catmullRomOpen)([[0, 1], [1, 3], [2, 1], [3, 3]]), a([[0, 1], [1, 3], [2, 1], [3, 3]])); + test.equal(shape.area().interpolate(shape.catmullRomOpen())([[0, 1], [1, 3], [2, 1], [3, 3]]), a([[0, 1], [1, 3], [2, 1], [3, 3]])); + test.equal(shape.area().interpolate(shape.catmullRomOpen(null))([[0, 1], [1, 3], [2, 1], [3, 3]]), a([[0, 1], [1, 3], [2, 1], [3, 3]])); + test.equal(shape.area().interpolate(shape.catmullRomOpen(undefined))([[0, 1], [1, 3], [2, 1], [3, 3]]), a([[0, 1], [1, 3], [2, 1], [3, 3]])); + test.end(); +}); diff --git a/test/line-test.js b/test/line-test.js index 07f8b3b..0eea98c 100644 --- a/test/line-test.js +++ b/test/line-test.js @@ -63,22 +63,6 @@ tape("line.interpolate(cardinal(tension)) coerces the specified tension to a num test.end(); }); -tape("line.interpolate(cardinal()) implicitly uses a tension of zero", function(test) { - var l = shape.line().interpolate(shape.cardinal(0)); - test.equal(shape.line().interpolate(shape.cardinal())([[0, 1], [1, 3], [2, 1], [3, 3]]), l([[0, 1], [1, 3], [2, 1], [3, 3]])); // TODO no empty invocation? - test.equal(shape.line().interpolate(shape.cardinal(null))([[0, 1], [1, 3], [2, 1], [3, 3]]), l([[0, 1], [1, 3], [2, 1], [3, 3]])); - test.equal(shape.line().interpolate(shape.cardinal(undefined))([[0, 1], [1, 3], [2, 1], [3, 3]]), l([[0, 1], [1, 3], [2, 1], [3, 3]])); - test.end(); -}); - -tape("line.interpolate(cardinalOpen()) implicitly uses a tension of zero", function(test) { - var l = shape.line().interpolate(shape.cardinalOpen(0)); - test.equal(shape.line().interpolate(shape.cardinalOpen())([[0, 1], [1, 3], [2, 1], [3, 3]]), l([[0, 1], [1, 3], [2, 1], [3, 3]])); // TODO no empty invocation? - test.equal(shape.line().interpolate(shape.cardinalOpen(null))([[0, 1], [1, 3], [2, 1], [3, 3]]), l([[0, 1], [1, 3], [2, 1], [3, 3]])); - test.equal(shape.line().interpolate(shape.cardinalOpen(undefined))([[0, 1], [1, 3], [2, 1], [3, 3]]), l([[0, 1], [1, 3], [2, 1], [3, 3]])); - test.end(); -}); - tape("line.interpolate(linear)(data) generates the expected path", function(test) { var l = shape.line().interpolate(shape.linear); test.equal(l([]), null); @@ -88,7 +72,7 @@ tape("line.interpolate(linear)(data) generates the expected path", function(test test.end(); }); -tape("line.interpolate(linear-closed)(data) generates the expected path", function(test) { +tape("line.interpolate(linearClosed)(data) generates the expected path", function(test) { var l = shape.line().interpolate(shape.linearClosed); test.equal(l([]), null); test.equal(l([[0, 1]]), "M0,1Z"); @@ -106,7 +90,7 @@ tape("line.interpolate(step)(data) generates the expected path", function(test) test.end(); }); -tape("line.interpolate(step-before)(data) generates the expected path", function(test) { +tape("line.interpolate(stepBefore)(data) generates the expected path", function(test) { var l = shape.line().interpolate(shape.stepBefore); test.equal(l([]), null); test.equal(l([[0, 1]]), "M0,1Z"); @@ -115,7 +99,7 @@ tape("line.interpolate(step-before)(data) generates the expected path", function test.end(); }); -tape("line.interpolate(step-after)(data) generates the expected path", function(test) { +tape("line.interpolate(stepAfter)(data) generates the expected path", function(test) { var l = shape.line().interpolate(shape.stepAfter); test.equal(l([]), null); test.equal(l([[0, 1]]), "M0,1Z"); @@ -133,7 +117,7 @@ tape("line.interpolate(basis)(data) generates the expected path", function(test) test.end(); }); -tape("line.interpolate(basis-open)(data) generates the expected path", function(test) { +tape("line.interpolate(basisOpen)(data) generates the expected path", function(test) { var l = shape.line().interpolate(shape.basisOpen); test.equal(l([]), null); test.equal(l([[0, 0]]), null); @@ -144,7 +128,7 @@ tape("line.interpolate(basis-open)(data) generates the expected path", function( test.end(); }); -tape("line.interpolate(basis-closed)(data) generates the expected path", function(test) { +tape("line.interpolate(basisClosed)(data) generates the expected path", function(test) { var l = shape.line().interpolate(shape.basisClosed); test.equal(l([]), null); test.equal(l([[0, 0]]), "M0,0Z"); @@ -156,7 +140,7 @@ tape("line.interpolate(basis-closed)(data) generates the expected path", functio }); tape("line.interpolate(cardinal)(data) generates the expected path", function(test) { - var l = shape.line().interpolate(shape.cardinal()); // TODO no empty invocation? + var l = shape.line().interpolate(shape.cardinal); test.equal(l([]), null); test.equal(l([[0, 1]]), "M0,1Z"); test.equal(l([[0, 1], [1, 3]]), "M0,1L1,3"); @@ -165,8 +149,8 @@ tape("line.interpolate(cardinal)(data) generates the expected path", function(te test.end(); }); -tape("line.interpolate(cardinal-open)(data) generates the expected path", function(test) { - var l = shape.line().interpolate(shape.cardinalOpen()); // TODO no empty invocation? +tape("line.interpolate(cardinalOpen)(data) generates the expected path", function(test) { + var l = shape.line().interpolate(shape.cardinalOpen); test.equal(l([]), null); test.equal(l([[0, 1]]), null); test.equal(l([[0, 1], [1, 3]]), null); @@ -175,8 +159,8 @@ tape("line.interpolate(cardinal-open)(data) generates the expected path", functi test.end(); }); -tape("line.interpolate(cardinal-closed)(data) generates the expected path", function(test) { - var l = shape.line().interpolate(shape.cardinalClosed()); // TODO no empty invocation? +tape("line.interpolate(cardinalClosed)(data) generates the expected path", function(test) { + var l = shape.line().interpolate(shape.cardinalClosed); test.equal(l([]), null); test.equal(l([[0, 1]]), "M0,1Z"); test.equal(l([[0, 1], [1, 3]]), "M1,3L0,1Z"); @@ -185,8 +169,8 @@ tape("line.interpolate(cardinal-closed)(data) generates the expected path", func test.end(); }); -tape("line.interpolate(catmull-rom)(data) generates the expected path", function(test) { - var l = shape.line().interpolate(shape.catmullRom()); // TODO no empty invocation? +tape("line.interpolate(catmullRom)(data) generates the expected path", function(test) { + var l = shape.line().interpolate(shape.catmullRom); test.equal(l([]), null); test.equal(l([[0, 1]]), "M0,1Z"); test.equal(l([[0, 1], [1, 3]]), "M0,1L1,3"); @@ -195,8 +179,8 @@ tape("line.interpolate(catmull-rom)(data) generates the expected path", function test.end(); }); -tape("line.interpolate(catmull-rom-open)(data) generates the expected path", function(test) { - var l = shape.line().interpolate(shape.catmullRomOpen()); // TODO no empty invocation? +tape("line.interpolate(catmullRomOpen)(data) generates the expected path", function(test) { + var l = shape.line().interpolate(shape.catmullRomOpen); test.equal(l([]), null); test.equal(l([[0, 1]]), null); test.equal(l([[0, 1], [1, 3]]), null); @@ -205,8 +189,8 @@ tape("line.interpolate(catmull-rom-open)(data) generates the expected path", fun test.end(); }); -tape("line.interpolate(catmull-rom-closed)(data) generates the expected path", function(test) { - var l = shape.line().interpolate(shape.catmullRomClosed()); // TODO no empty invocation? +tape("line.interpolate(catmullRomClosed)(data) generates the expected path", function(test) { + var l = shape.line().interpolate(shape.catmullRomClosed); test.equal(l([]), null); test.equal(l([[0, 1]]), "M0,1Z"); test.equal(l([[0, 1], [1, 3]]), "M1,3L0,1Z"); @@ -215,7 +199,7 @@ tape("line.interpolate(catmull-rom-closed)(data) generates the expected path", f test.end(); }); -tape("line.interpolate(catmull-rom, 1)(data) generates the expected path", function(test) { +tape("line.interpolate(catmullRom(1))(data) generates the expected path", function(test) { var l = shape.line().interpolate(shape.catmullRom(1)); test.equal(l([]), null); test.equal(l([[0, 1]]), "M0,1Z"); @@ -225,7 +209,7 @@ tape("line.interpolate(catmull-rom, 1)(data) generates the expected path", funct test.end(); }); -tape("line.interpolate(catmull-rom-open, 1)(data) generates the expected path", function(test) { +tape("line.interpolate(catmullRomOpen(1))(data) generates the expected path", function(test) { var l = shape.line().interpolate(shape.catmullRomOpen(1)); test.equal(l([]), null); test.equal(l([[0, 1]]), null); @@ -235,7 +219,7 @@ tape("line.interpolate(catmull-rom-open, 1)(data) generates the expected path", test.end(); }); -tape("line.interpolate(catmull-rom-closed, 1)(data) generates the expected path", function(test) { +tape("line.interpolate(catmullRomClosed(1))(data) generates the expected path", function(test) { var l = shape.line().interpolate(shape.catmullRomClosed(1)); test.equal(l([]), null); test.equal(l([[0, 1]]), "M0,1Z"); @@ -254,3 +238,66 @@ tape("line.interpolate(natural)(data) generates the expected path", function(tes test.equal(l([[0, 1], [1, 3], [2, 1], [3, 3]]), "M0,1C0.33333333333333326,2.111111111111111,0.6666666666666665,3.2222222222222223,1,3C1.3333333333333335,2.7777777777777777,1.666666666666667,1.2222222222222223,2,1C2.333333333333333,0.7777777777777778,2.6666666666666665,1.8888888888888888,3,3"); test.end(); }); + +tape("line.interpolate(cardinal) uses a default tension of zero", function(test) { + var l = shape.line().interpolate(shape.cardinal(0)); + test.equal(shape.line().interpolate(shape.cardinal)([[0, 1], [1, 3], [2, 1], [3, 3]]), l([[0, 1], [1, 3], [2, 1], [3, 3]])); + test.equal(shape.line().interpolate(shape.cardinal())([[0, 1], [1, 3], [2, 1], [3, 3]]), l([[0, 1], [1, 3], [2, 1], [3, 3]])); + test.equal(shape.line().interpolate(shape.cardinal(null))([[0, 1], [1, 3], [2, 1], [3, 3]]), l([[0, 1], [1, 3], [2, 1], [3, 3]])); + test.equal(shape.line().interpolate(shape.cardinal(undefined))([[0, 1], [1, 3], [2, 1], [3, 3]]), l([[0, 1], [1, 3], [2, 1], [3, 3]])); + test.end(); +}); + +tape("line.interpolate(cardinalOpen) uses a default tension of zero", function(test) { + var l = shape.line().interpolate(shape.cardinalOpen(0)); + test.equal(shape.line().interpolate(shape.cardinalOpen)([[0, 1], [1, 3], [2, 1], [3, 3]]), l([[0, 1], [1, 3], [2, 1], [3, 3]])); + test.equal(shape.line().interpolate(shape.cardinalOpen())([[0, 1], [1, 3], [2, 1], [3, 3]]), l([[0, 1], [1, 3], [2, 1], [3, 3]])); + test.equal(shape.line().interpolate(shape.cardinalOpen(null))([[0, 1], [1, 3], [2, 1], [3, 3]]), l([[0, 1], [1, 3], [2, 1], [3, 3]])); + test.equal(shape.line().interpolate(shape.cardinalOpen(undefined))([[0, 1], [1, 3], [2, 1], [3, 3]]), l([[0, 1], [1, 3], [2, 1], [3, 3]])); + test.end(); +}); + +tape("line.interpolate(cardinalClosed) uses a default tension of zero", function(test) { + var l = shape.line().interpolate(shape.cardinalClosed(0)); + test.equal(shape.line().interpolate(shape.cardinalClosed)([[0, 1], [1, 3], [2, 1], [3, 3]]), l([[0, 1], [1, 3], [2, 1], [3, 3]])); + test.equal(shape.line().interpolate(shape.cardinalClosed())([[0, 1], [1, 3], [2, 1], [3, 3]]), l([[0, 1], [1, 3], [2, 1], [3, 3]])); + test.equal(shape.line().interpolate(shape.cardinalClosed(null))([[0, 1], [1, 3], [2, 1], [3, 3]]), l([[0, 1], [1, 3], [2, 1], [3, 3]])); + test.equal(shape.line().interpolate(shape.cardinalClosed(undefined))([[0, 1], [1, 3], [2, 1], [3, 3]]), l([[0, 1], [1, 3], [2, 1], [3, 3]])); + test.end(); +}); + +tape("line.interpolate(catmullRom) uses a default alpha of zero", function(test) { + var l = shape.line().interpolate(shape.catmullRom(0)); + test.equal(shape.line().interpolate(shape.catmullRom)([[0, 1], [1, 3], [2, 1], [3, 3]]), l([[0, 1], [1, 3], [2, 1], [3, 3]])); + test.equal(shape.line().interpolate(shape.catmullRom())([[0, 1], [1, 3], [2, 1], [3, 3]]), l([[0, 1], [1, 3], [2, 1], [3, 3]])); + test.equal(shape.line().interpolate(shape.catmullRom(null))([[0, 1], [1, 3], [2, 1], [3, 3]]), l([[0, 1], [1, 3], [2, 1], [3, 3]])); + test.equal(shape.line().interpolate(shape.catmullRom(undefined))([[0, 1], [1, 3], [2, 1], [3, 3]]), l([[0, 1], [1, 3], [2, 1], [3, 3]])); + test.end(); +}); + +tape("line.interpolate(catmullRomOpen) uses a default alpha of zero", function(test) { + var l = shape.line().interpolate(shape.catmullRomOpen(0)); + test.equal(shape.line().interpolate(shape.catmullRomOpen)([[0, 1], [1, 3], [2, 1], [3, 3]]), l([[0, 1], [1, 3], [2, 1], [3, 3]])); + test.equal(shape.line().interpolate(shape.catmullRomOpen())([[0, 1], [1, 3], [2, 1], [3, 3]]), l([[0, 1], [1, 3], [2, 1], [3, 3]])); + test.equal(shape.line().interpolate(shape.catmullRomOpen(null))([[0, 1], [1, 3], [2, 1], [3, 3]]), l([[0, 1], [1, 3], [2, 1], [3, 3]])); + test.equal(shape.line().interpolate(shape.catmullRomOpen(undefined))([[0, 1], [1, 3], [2, 1], [3, 3]]), l([[0, 1], [1, 3], [2, 1], [3, 3]])); + test.end(); +}); + +tape("line.interpolate(catmullRomClosed) uses a default alpha of zero", function(test) { + var l = shape.line().interpolate(shape.catmullRomClosed(0)); + test.equal(shape.line().interpolate(shape.catmullRomClosed)([[0, 1], [1, 3], [2, 1], [3, 3]]), l([[0, 1], [1, 3], [2, 1], [3, 3]])); + test.equal(shape.line().interpolate(shape.catmullRomClosed())([[0, 1], [1, 3], [2, 1], [3, 3]]), l([[0, 1], [1, 3], [2, 1], [3, 3]])); + test.equal(shape.line().interpolate(shape.catmullRomClosed(null))([[0, 1], [1, 3], [2, 1], [3, 3]]), l([[0, 1], [1, 3], [2, 1], [3, 3]])); + test.equal(shape.line().interpolate(shape.catmullRomClosed(undefined))([[0, 1], [1, 3], [2, 1], [3, 3]]), l([[0, 1], [1, 3], [2, 1], [3, 3]])); + test.end(); +}); + +tape("line.interpolate(bundle) uses a default beta of one", function(test) { + var l = shape.line().interpolate(shape.bundle(1)); + test.equal(shape.line().interpolate(shape.bundle)([[0, 1], [1, 3], [2, 1], [3, 3]]), l([[0, 1], [1, 3], [2, 1], [3, 3]])); + test.equal(shape.line().interpolate(shape.bundle())([[0, 1], [1, 3], [2, 1], [3, 3]]), l([[0, 1], [1, 3], [2, 1], [3, 3]])); + test.equal(shape.line().interpolate(shape.bundle(null))([[0, 1], [1, 3], [2, 1], [3, 3]]), l([[0, 1], [1, 3], [2, 1], [3, 3]])); + test.equal(shape.line().interpolate(shape.bundle(undefined))([[0, 1], [1, 3], [2, 1], [3, 3]]), l([[0, 1], [1, 3], [2, 1], [3, 3]])); + test.end(); +}); From 719ee790e57523216210e41eaa3de0b17d64b568 Mon Sep 17 00:00:00 2001 From: Mike Bostock Date: Thu, 19 Nov 2015 09:29:20 -0800 Subject: [PATCH 08/15] Shorter. --- src/interpolate/bundle.js | 5 ++--- src/interpolate/cardinal-closed.js | 7 ++----- src/interpolate/cardinal-open.js | 7 ++----- src/interpolate/cardinal.js | 7 ++----- src/interpolate/catmull-rom-closed.js | 7 +++---- src/interpolate/catmull-rom-open.js | 7 +++---- src/interpolate/catmull-rom.js | 7 +++---- 7 files changed, 17 insertions(+), 30 deletions(-) diff --git a/src/interpolate/bundle.js b/src/interpolate/bundle.js index db650a5..8cc44ad 100644 --- a/src/interpolate/bundle.js +++ b/src/interpolate/bundle.js @@ -1,9 +1,8 @@ import basis from "./basis"; -import linear from "./linear"; function bundle(beta) { - if (beta && beta.moveTo) return basis(beta); - return beta == null || (beta = +beta) === 1 ? basis + return beta && beta.moveTo ? basis(beta) + : beta == null || (beta = +beta) === 1 ? basis : function(context) { return new Bundle(context, beta); }; } diff --git a/src/interpolate/cardinal-closed.js b/src/interpolate/cardinal-closed.js index 9266857..a9e6ffd 100644 --- a/src/interpolate/cardinal-closed.js +++ b/src/interpolate/cardinal-closed.js @@ -1,11 +1,8 @@ import {point} from "./cardinal"; function cardinalClosed(tension) { - if (tension && tension.moveTo) return new CardinalClosed(tension, 1 / 6); - var k = (tension == null ? 1 : 1 - tension) / 6; - return function(context) { - return new CardinalClosed(context, k); - }; + return tension && tension.moveTo ? new CardinalClosed(tension, 1 / 6) + : (tension = (tension == null ? 1 : 1 - tension) / 6, function(context) { return new CardinalClosed(context, tension); }); } function CardinalClosed(context, k) { diff --git a/src/interpolate/cardinal-open.js b/src/interpolate/cardinal-open.js index bc163d7..f9f6e5a 100644 --- a/src/interpolate/cardinal-open.js +++ b/src/interpolate/cardinal-open.js @@ -1,11 +1,8 @@ import {point} from "./cardinal"; function cardinalOpen(tension) { - if (tension && tension.moveTo) return new CardinalOpen(tension, 1 / 6); - var k = (tension == null ? 1 : 1 - tension) / 6; - return function(context) { - return new CardinalOpen(context, k); - }; + return tension && tension.moveTo ? new CardinalOpen(tension, 1 / 6) + : (tension = (tension == null ? 1 : 1 - tension) / 6, function(context) { return new CardinalOpen(context, tension); }); } function CardinalOpen(context, k) { diff --git a/src/interpolate/cardinal.js b/src/interpolate/cardinal.js index d3f7c43..b1f6c53 100644 --- a/src/interpolate/cardinal.js +++ b/src/interpolate/cardinal.js @@ -10,11 +10,8 @@ export function point(that, x, y) { }; function cardinal(tension) { - if (tension && tension.moveTo) return new Cardinal(tension, 1 / 6); - var k = (tension == null ? 1 : 1 - tension) / 6; - return function(context) { - return new Cardinal(context, k); - }; + return tension && tension.moveTo ? new Cardinal(tension, 1 / 6) + : (tension = (tension == null ? 1 : 1 - tension) / 6, function(context) { return new Cardinal(context, tension); }); } function Cardinal(context, k) { diff --git a/src/interpolate/catmull-rom-closed.js b/src/interpolate/catmull-rom-closed.js index 951ef3a..7832c1f 100644 --- a/src/interpolate/catmull-rom-closed.js +++ b/src/interpolate/catmull-rom-closed.js @@ -2,10 +2,9 @@ import cardinalClosed from "./cardinal-closed"; import {point} from "./catmull-rom"; function catmullRomClosed(alpha) { - if (alpha && alpha.moveTo) return cardinalClosed(alpha); - return alpha == null || !(alpha = +alpha) ? cardinalClosed(0) : function(context) { - return new CatmullRomClosed(context, alpha); - }; + return alpha && alpha.moveTo ? cardinalClosed(alpha) + : alpha == null || !(alpha = +alpha) ? cardinalClosed(0) + : function(context) { return new CatmullRomClosed(context, alpha); }; } function CatmullRomClosed(context, alpha) { diff --git a/src/interpolate/catmull-rom-open.js b/src/interpolate/catmull-rom-open.js index 3b8dc68..7c3dff7 100644 --- a/src/interpolate/catmull-rom-open.js +++ b/src/interpolate/catmull-rom-open.js @@ -2,10 +2,9 @@ import cardinalOpen from "./cardinal-open"; import {point} from "./catmull-rom"; function catmullRomOpen(alpha) { - if (alpha && alpha.moveTo) return cardinalOpen(alpha); - return alpha == null || !(alpha = +alpha) ? cardinalOpen(0) : function(context) { - return new CatmullRomOpen(context, alpha); - }; + return alpha && alpha.moveTo ? cardinalOpen(alpha) + : alpha == null || !(alpha = +alpha) ? cardinalOpen(0) + : function(context) { return new CatmullRomOpen(context, alpha); }; } function CatmullRomOpen(context, alpha) { diff --git a/src/interpolate/catmull-rom.js b/src/interpolate/catmull-rom.js index e4b6b7e..dcc865d 100644 --- a/src/interpolate/catmull-rom.js +++ b/src/interpolate/catmull-rom.js @@ -26,10 +26,9 @@ export function point(that, x, y) { }; function catmullRom(alpha) { - if (alpha && alpha.moveTo) return cardinal(alpha); - return alpha == null || !(alpha = +alpha) ? cardinal(0) : function(context) { - return new CatmullRom(context, alpha); - }; + return alpha && alpha.moveTo ? cardinal(alpha) + : alpha == null || !(alpha = +alpha) ? cardinal(0) + : function(context) { return new CatmullRom(context, alpha); }; } function CatmullRom(context, alpha) { From 8c20cbe4ac995b921112869c05350b5f0d7b6aae Mon Sep 17 00:00:00 2001 From: Mike Bostock Date: Thu, 19 Nov 2015 10:58:35 -0800 Subject: [PATCH 09/15] Curry optional interpolation parameters. --- README.md | 36 +++++++------- src/area.js | 6 ++- src/interpolate/bundle.js | 8 ++-- src/interpolate/cardinal-closed.js | 5 +- src/interpolate/cardinal-open.js | 5 +- src/interpolate/cardinal.js | 5 +- src/interpolate/catmull-rom-closed.js | 8 ++-- src/interpolate/catmull-rom-open.js | 8 ++-- src/interpolate/catmull-rom.js | 8 ++-- src/interpolate/curry.js | 10 ++++ src/line.js | 4 +- test/area-test.js | 32 ++++++------- test/line-test.js | 69 ++++++++++++--------------- 13 files changed, 100 insertions(+), 104 deletions(-) create mode 100644 src/interpolate/curry.js diff --git a/README.md b/README.md index 8d3697b..41e8de8 100644 --- a/README.md +++ b/README.md @@ -92,71 +92,67 @@ If you use NPM, `npm install d3-shape`. Otherwise, download the [latest release] … -# basis +# basis(context) … -# basisClosed +# basisClosed(context) … -# basisOpen +# basisOpen(context) … -# bundle(beta) +# bundle(context[, beta]) … -# cardinal(tension) +# cardinal(context[, tension]) … -# cardinalClosed(tension) +# cardinalClosed(context[, tension]) … -# cardinalOpen(tension) +# cardinalOpen(context[, tension]) … -# catmullRom(alpha) +# catmullRom(context[, alpha]) … -# catmullRomClosed(alpha) +# catmullRomClosed(context[, alpha]) … -# catmullRomOpen(alpha) +# catmullRomOpen(context[, alpha]) … -# linear +# linear(context) … -# linearClosed +# linearClosed(context) … -# natural +# natural(context) … -# step +# step(context) … -# stepAfter +# stepAfter(context) … -# stepBefore - -… - -# interpolate(context) +# stepBefore(context) … diff --git a/src/area.js b/src/area.js index 63e31ae..a4f2e3f 100644 --- a/src/area.js +++ b/src/area.js @@ -1,6 +1,7 @@ import {path} from "d3-path"; import constant from "./constant"; import linear from "./interpolate/linear"; +import curry from "./interpolate/curry"; import {x as pointX, y as pointY} from "./point"; export default function() { @@ -79,8 +80,9 @@ export default function() { return arguments.length ? (defined = typeof _ === "function" ? _ : constant(!!_), area) : defined; }; - area.interpolate = function(_, a) { - return arguments.length ? (interpolate = _, context != null && (interpolator = _(context)), area) : interpolate; + area.interpolate = function(_) { + var n = arguments.length; + return n ? (interpolate = n > 1 ? curry(_, arguments) : _, context != null && (interpolator = interpolate(context)), area) : interpolate; }; area.context = function(_) { diff --git a/src/interpolate/bundle.js b/src/interpolate/bundle.js index 8cc44ad..a4212e9 100644 --- a/src/interpolate/bundle.js +++ b/src/interpolate/bundle.js @@ -1,9 +1,9 @@ import basis from "./basis"; -function bundle(beta) { - return beta && beta.moveTo ? basis(beta) - : beta == null || (beta = +beta) === 1 ? basis - : function(context) { return new Bundle(context, beta); }; +function bundle(context, beta) { + return beta == null || (beta = +beta) === 1 + ? basis(context) + : new Bundle(context, beta); } function Bundle(context, beta) { diff --git a/src/interpolate/cardinal-closed.js b/src/interpolate/cardinal-closed.js index a9e6ffd..d6d9cdd 100644 --- a/src/interpolate/cardinal-closed.js +++ b/src/interpolate/cardinal-closed.js @@ -1,8 +1,7 @@ import {point} from "./cardinal"; -function cardinalClosed(tension) { - return tension && tension.moveTo ? new CardinalClosed(tension, 1 / 6) - : (tension = (tension == null ? 1 : 1 - tension) / 6, function(context) { return new CardinalClosed(context, tension); }); +function cardinalClosed(context, tension) { + return new CardinalClosed(context, (tension == null ? 1 : 1 - tension) / 6); } function CardinalClosed(context, k) { diff --git a/src/interpolate/cardinal-open.js b/src/interpolate/cardinal-open.js index f9f6e5a..4558c95 100644 --- a/src/interpolate/cardinal-open.js +++ b/src/interpolate/cardinal-open.js @@ -1,8 +1,7 @@ import {point} from "./cardinal"; -function cardinalOpen(tension) { - return tension && tension.moveTo ? new CardinalOpen(tension, 1 / 6) - : (tension = (tension == null ? 1 : 1 - tension) / 6, function(context) { return new CardinalOpen(context, tension); }); +function cardinalOpen(context, tension) { + return new CardinalOpen(context, (tension == null ? 1 : 1 - tension) / 6); } function CardinalOpen(context, k) { diff --git a/src/interpolate/cardinal.js b/src/interpolate/cardinal.js index b1f6c53..58bfdfd 100644 --- a/src/interpolate/cardinal.js +++ b/src/interpolate/cardinal.js @@ -9,9 +9,8 @@ export function point(that, x, y) { ); }; -function cardinal(tension) { - return tension && tension.moveTo ? new Cardinal(tension, 1 / 6) - : (tension = (tension == null ? 1 : 1 - tension) / 6, function(context) { return new Cardinal(context, tension); }); +function cardinal(context, tension) { + return new Cardinal(context, (tension == null ? 1 : 1 - tension) / 6); } function Cardinal(context, k) { diff --git a/src/interpolate/catmull-rom-closed.js b/src/interpolate/catmull-rom-closed.js index 7832c1f..fe299af 100644 --- a/src/interpolate/catmull-rom-closed.js +++ b/src/interpolate/catmull-rom-closed.js @@ -1,10 +1,10 @@ import cardinalClosed from "./cardinal-closed"; import {point} from "./catmull-rom"; -function catmullRomClosed(alpha) { - return alpha && alpha.moveTo ? cardinalClosed(alpha) - : alpha == null || !(alpha = +alpha) ? cardinalClosed(0) - : function(context) { return new CatmullRomClosed(context, alpha); }; +function catmullRomClosed(context, alpha) { + return alpha == null || !(alpha = +alpha) + ? cardinalClosed(context, 0) + : new CatmullRomClosed(context, alpha); } function CatmullRomClosed(context, alpha) { diff --git a/src/interpolate/catmull-rom-open.js b/src/interpolate/catmull-rom-open.js index 7c3dff7..74e3643 100644 --- a/src/interpolate/catmull-rom-open.js +++ b/src/interpolate/catmull-rom-open.js @@ -1,10 +1,10 @@ import cardinalOpen from "./cardinal-open"; import {point} from "./catmull-rom"; -function catmullRomOpen(alpha) { - return alpha && alpha.moveTo ? cardinalOpen(alpha) - : alpha == null || !(alpha = +alpha) ? cardinalOpen(0) - : function(context) { return new CatmullRomOpen(context, alpha); }; +function catmullRomOpen(context, alpha) { + return alpha == null || !(alpha = +alpha) + ? cardinalOpen(context, 0) + : new CatmullRomOpen(context, alpha); } function CatmullRomOpen(context, alpha) { diff --git a/src/interpolate/catmull-rom.js b/src/interpolate/catmull-rom.js index dcc865d..bd4b1d5 100644 --- a/src/interpolate/catmull-rom.js +++ b/src/interpolate/catmull-rom.js @@ -25,10 +25,10 @@ export function point(that, x, y) { that._context.bezierCurveTo(x1, y1, x2, y2, that._x2, that._y2); }; -function catmullRom(alpha) { - return alpha && alpha.moveTo ? cardinal(alpha) - : alpha == null || !(alpha = +alpha) ? cardinal(0) - : function(context) { return new CatmullRom(context, alpha); }; +function catmullRom(context, alpha) { + return alpha == null || !(alpha = +alpha) + ? cardinal(context, 0) + : new CatmullRom(context, alpha); } function CatmullRom(context, alpha) { diff --git a/src/interpolate/curry.js b/src/interpolate/curry.js new file mode 100644 index 0000000..a343371 --- /dev/null +++ b/src/interpolate/curry.js @@ -0,0 +1,10 @@ +var slice = Array.prototype.slice; + +export default function(interpolate, args) { + args = slice.call(args); + args[0] = null; + return function(context) { + args[0] = context; + return interpolate.apply(null, args); + }; +}; diff --git a/src/line.js b/src/line.js index 6f9915d..a097bf4 100644 --- a/src/line.js +++ b/src/line.js @@ -1,6 +1,7 @@ import {path} from "d3-path"; import constant from "./constant"; import linear from "./interpolate/linear"; +import curry from "./interpolate/curry"; import {x as pointX, y as pointY} from "./point"; export default function() { @@ -44,7 +45,8 @@ export default function() { }; line.interpolate = function(_) { - return arguments.length ? (interpolate = _, context != null && (interpolator = _(context)), line) : interpolate; + var n = arguments.length; + return n ? (interpolate = n > 1 ? curry(_, arguments) : _, context != null && (interpolator = interpolate(context)), line) : interpolate; }; line.context = function(_) { diff --git a/test/area-test.js b/test/area-test.js index 6858e62..2b6bf18 100644 --- a/test/area-test.js +++ b/test/area-test.js @@ -103,7 +103,7 @@ tape("area.interpolate(cardinalOpen)(data) generates the expected path", functio }); tape("area.interpolate(catmullRom, 0.5)(data) generates the expected path", function(test) { - var a = shape.area().interpolate(shape.catmullRom(0.5)); + var a = shape.area().interpolate(shape.catmullRom, 0.5); test.equal(a([]), null); test.equal(a([[0, 1]]), "M0,1L0,0Z"); test.equal(a([[0, 1], [1, 3]]), "M0,1L1,3L1,0L0,0Z"); @@ -113,7 +113,7 @@ tape("area.interpolate(catmullRom, 0.5)(data) generates the expected path", func }); tape("area.interpolate(catmullRomOpen, 0.5)(data) generates the expected path", function(test) { - var a = shape.area().interpolate(shape.catmullRomOpen(0.5)); + var a = shape.area().interpolate(shape.catmullRomOpen, 0.5); test.equal(a([]), null); test.equal(a([[0, 1]]), null); test.equal(a([[0, 1], [1, 3]]), null); @@ -160,37 +160,33 @@ tape("area.interpolate(natural)(data) generates the expected path", function(tes }); tape("area.interpolate(cardinal) uses a default tension of zero", function(test) { - var a = shape.area().interpolate(shape.cardinal(0)); + var a = shape.area().interpolate(shape.cardinal, 0); test.equal(shape.area().interpolate(shape.cardinal)([[0, 1], [1, 3], [2, 1], [3, 3]]), a([[0, 1], [1, 3], [2, 1], [3, 3]])); - test.equal(shape.area().interpolate(shape.cardinal())([[0, 1], [1, 3], [2, 1], [3, 3]]), a([[0, 1], [1, 3], [2, 1], [3, 3]])); - test.equal(shape.area().interpolate(shape.cardinal(null))([[0, 1], [1, 3], [2, 1], [3, 3]]), a([[0, 1], [1, 3], [2, 1], [3, 3]])); - test.equal(shape.area().interpolate(shape.cardinal(undefined))([[0, 1], [1, 3], [2, 1], [3, 3]]), a([[0, 1], [1, 3], [2, 1], [3, 3]])); + test.equal(shape.area().interpolate(shape.cardinal, null)([[0, 1], [1, 3], [2, 1], [3, 3]]), a([[0, 1], [1, 3], [2, 1], [3, 3]])); + test.equal(shape.area().interpolate(shape.cardinal, undefined)([[0, 1], [1, 3], [2, 1], [3, 3]]), a([[0, 1], [1, 3], [2, 1], [3, 3]])); test.end(); }); tape("area.interpolate(cardinalOpen) uses a default tension of zero", function(test) { - var a = shape.area().interpolate(shape.cardinalOpen(0)); + var a = shape.area().interpolate(shape.cardinalOpen, 0); test.equal(shape.area().interpolate(shape.cardinalOpen)([[0, 1], [1, 3], [2, 1], [3, 3]]), a([[0, 1], [1, 3], [2, 1], [3, 3]])); - test.equal(shape.area().interpolate(shape.cardinalOpen())([[0, 1], [1, 3], [2, 1], [3, 3]]), a([[0, 1], [1, 3], [2, 1], [3, 3]])); - test.equal(shape.area().interpolate(shape.cardinalOpen(null))([[0, 1], [1, 3], [2, 1], [3, 3]]), a([[0, 1], [1, 3], [2, 1], [3, 3]])); - test.equal(shape.area().interpolate(shape.cardinalOpen(undefined))([[0, 1], [1, 3], [2, 1], [3, 3]]), a([[0, 1], [1, 3], [2, 1], [3, 3]])); + test.equal(shape.area().interpolate(shape.cardinalOpen, null)([[0, 1], [1, 3], [2, 1], [3, 3]]), a([[0, 1], [1, 3], [2, 1], [3, 3]])); + test.equal(shape.area().interpolate(shape.cardinalOpen, undefined)([[0, 1], [1, 3], [2, 1], [3, 3]]), a([[0, 1], [1, 3], [2, 1], [3, 3]])); test.end(); }); tape("area.interpolate(catmullRom) uses a default alpha of zero", function(test) { - var a = shape.area().interpolate(shape.catmullRom(0)); + var a = shape.area().interpolate(shape.catmullRom, 0); test.equal(shape.area().interpolate(shape.catmullRom)([[0, 1], [1, 3], [2, 1], [3, 3]]), a([[0, 1], [1, 3], [2, 1], [3, 3]])); - test.equal(shape.area().interpolate(shape.catmullRom())([[0, 1], [1, 3], [2, 1], [3, 3]]), a([[0, 1], [1, 3], [2, 1], [3, 3]])); - test.equal(shape.area().interpolate(shape.catmullRom(null))([[0, 1], [1, 3], [2, 1], [3, 3]]), a([[0, 1], [1, 3], [2, 1], [3, 3]])); - test.equal(shape.area().interpolate(shape.catmullRom(undefined))([[0, 1], [1, 3], [2, 1], [3, 3]]), a([[0, 1], [1, 3], [2, 1], [3, 3]])); + test.equal(shape.area().interpolate(shape.catmullRom, null)([[0, 1], [1, 3], [2, 1], [3, 3]]), a([[0, 1], [1, 3], [2, 1], [3, 3]])); + test.equal(shape.area().interpolate(shape.catmullRom, undefined)([[0, 1], [1, 3], [2, 1], [3, 3]]), a([[0, 1], [1, 3], [2, 1], [3, 3]])); test.end(); }); tape("area.interpolate(catmullRomOpen) uses a default alpha of zero", function(test) { - var a = shape.area().interpolate(shape.catmullRomOpen(0)); + var a = shape.area().interpolate(shape.catmullRomOpen, 0); test.equal(shape.area().interpolate(shape.catmullRomOpen)([[0, 1], [1, 3], [2, 1], [3, 3]]), a([[0, 1], [1, 3], [2, 1], [3, 3]])); - test.equal(shape.area().interpolate(shape.catmullRomOpen())([[0, 1], [1, 3], [2, 1], [3, 3]]), a([[0, 1], [1, 3], [2, 1], [3, 3]])); - test.equal(shape.area().interpolate(shape.catmullRomOpen(null))([[0, 1], [1, 3], [2, 1], [3, 3]]), a([[0, 1], [1, 3], [2, 1], [3, 3]])); - test.equal(shape.area().interpolate(shape.catmullRomOpen(undefined))([[0, 1], [1, 3], [2, 1], [3, 3]]), a([[0, 1], [1, 3], [2, 1], [3, 3]])); + test.equal(shape.area().interpolate(shape.catmullRomOpen, null)([[0, 1], [1, 3], [2, 1], [3, 3]]), a([[0, 1], [1, 3], [2, 1], [3, 3]])); + test.equal(shape.area().interpolate(shape.catmullRomOpen, undefined)([[0, 1], [1, 3], [2, 1], [3, 3]]), a([[0, 1], [1, 3], [2, 1], [3, 3]])); test.end(); }); diff --git a/test/line-test.js b/test/line-test.js index 0eea98c..e83cb2a 100644 --- a/test/line-test.js +++ b/test/line-test.js @@ -43,8 +43,8 @@ tape("line.interpolate(interpolate) sets the interpolation method", function(tes test.end(); }); -tape("line.interpolate(cardinal(tension)) sets the cardinal interpolation tension", function(test) { - var l = shape.line().interpolate(shape.cardinal(0.1)); +tape("line.interpolate(cardinal, tension) sets the cardinal interpolation tension", function(test) { + var l = shape.line().interpolate(shape.cardinal, 0.1); test.equal(l([]), null); test.equal(l([[0, 1]]), "M0,1Z"); test.equal(l([[0, 1], [1, 3]]), "M0,1L1,3"); @@ -53,8 +53,8 @@ tape("line.interpolate(cardinal(tension)) sets the cardinal interpolation tensio test.end(); }); -tape("line.interpolate(cardinal(tension)) coerces the specified tension to a number", function(test) { - var l = shape.line().interpolate(shape.cardinal("0.1")); +tape("line.interpolate(cardinal, tension) coerces the specified tension to a number", function(test) { + var l = shape.line().interpolate(shape.cardinal, "0.1"); test.equal(l([]), null); test.equal(l([[0, 1]]), "M0,1Z"); test.equal(l([[0, 1], [1, 3]]), "M0,1L1,3"); @@ -199,8 +199,8 @@ tape("line.interpolate(catmullRomClosed)(data) generates the expected path", fun test.end(); }); -tape("line.interpolate(catmullRom(1))(data) generates the expected path", function(test) { - var l = shape.line().interpolate(shape.catmullRom(1)); +tape("line.interpolate(catmullRom, 1)(data) generates the expected path", function(test) { + var l = shape.line().interpolate(shape.catmullRom, 1); test.equal(l([]), null); test.equal(l([[0, 1]]), "M0,1Z"); test.equal(l([[0, 1], [1, 3]]), "M0,1L1,3"); @@ -209,8 +209,8 @@ tape("line.interpolate(catmullRom(1))(data) generates the expected path", functi test.end(); }); -tape("line.interpolate(catmullRomOpen(1))(data) generates the expected path", function(test) { - var l = shape.line().interpolate(shape.catmullRomOpen(1)); +tape("line.interpolate(catmullRomOpen, 1)(data) generates the expected path", function(test) { + var l = shape.line().interpolate(shape.catmullRomOpen, 1); test.equal(l([]), null); test.equal(l([[0, 1]]), null); test.equal(l([[0, 1], [1, 3]]), null); @@ -219,8 +219,8 @@ tape("line.interpolate(catmullRomOpen(1))(data) generates the expected path", fu test.end(); }); -tape("line.interpolate(catmullRomClosed(1))(data) generates the expected path", function(test) { - var l = shape.line().interpolate(shape.catmullRomClosed(1)); +tape("line.interpolate(catmullRomClosed, 1)(data) generates the expected path", function(test) { + var l = shape.line().interpolate(shape.catmullRomClosed, 1); test.equal(l([]), null); test.equal(l([[0, 1]]), "M0,1Z"); test.equal(l([[0, 1], [1, 3]]), "M1,3L0,1Z"); @@ -240,64 +240,57 @@ tape("line.interpolate(natural)(data) generates the expected path", function(tes }); tape("line.interpolate(cardinal) uses a default tension of zero", function(test) { - var l = shape.line().interpolate(shape.cardinal(0)); + var l = shape.line().interpolate(shape.cardinal, 0); test.equal(shape.line().interpolate(shape.cardinal)([[0, 1], [1, 3], [2, 1], [3, 3]]), l([[0, 1], [1, 3], [2, 1], [3, 3]])); - test.equal(shape.line().interpolate(shape.cardinal())([[0, 1], [1, 3], [2, 1], [3, 3]]), l([[0, 1], [1, 3], [2, 1], [3, 3]])); - test.equal(shape.line().interpolate(shape.cardinal(null))([[0, 1], [1, 3], [2, 1], [3, 3]]), l([[0, 1], [1, 3], [2, 1], [3, 3]])); - test.equal(shape.line().interpolate(shape.cardinal(undefined))([[0, 1], [1, 3], [2, 1], [3, 3]]), l([[0, 1], [1, 3], [2, 1], [3, 3]])); + test.equal(shape.line().interpolate(shape.cardinal, null)([[0, 1], [1, 3], [2, 1], [3, 3]]), l([[0, 1], [1, 3], [2, 1], [3, 3]])); + test.equal(shape.line().interpolate(shape.cardinal, undefined)([[0, 1], [1, 3], [2, 1], [3, 3]]), l([[0, 1], [1, 3], [2, 1], [3, 3]])); test.end(); }); tape("line.interpolate(cardinalOpen) uses a default tension of zero", function(test) { - var l = shape.line().interpolate(shape.cardinalOpen(0)); + var l = shape.line().interpolate(shape.cardinalOpen, 0); test.equal(shape.line().interpolate(shape.cardinalOpen)([[0, 1], [1, 3], [2, 1], [3, 3]]), l([[0, 1], [1, 3], [2, 1], [3, 3]])); - test.equal(shape.line().interpolate(shape.cardinalOpen())([[0, 1], [1, 3], [2, 1], [3, 3]]), l([[0, 1], [1, 3], [2, 1], [3, 3]])); - test.equal(shape.line().interpolate(shape.cardinalOpen(null))([[0, 1], [1, 3], [2, 1], [3, 3]]), l([[0, 1], [1, 3], [2, 1], [3, 3]])); - test.equal(shape.line().interpolate(shape.cardinalOpen(undefined))([[0, 1], [1, 3], [2, 1], [3, 3]]), l([[0, 1], [1, 3], [2, 1], [3, 3]])); + test.equal(shape.line().interpolate(shape.cardinalOpen, null)([[0, 1], [1, 3], [2, 1], [3, 3]]), l([[0, 1], [1, 3], [2, 1], [3, 3]])); + test.equal(shape.line().interpolate(shape.cardinalOpen, undefined)([[0, 1], [1, 3], [2, 1], [3, 3]]), l([[0, 1], [1, 3], [2, 1], [3, 3]])); test.end(); }); tape("line.interpolate(cardinalClosed) uses a default tension of zero", function(test) { - var l = shape.line().interpolate(shape.cardinalClosed(0)); + var l = shape.line().interpolate(shape.cardinalClosed, 0); test.equal(shape.line().interpolate(shape.cardinalClosed)([[0, 1], [1, 3], [2, 1], [3, 3]]), l([[0, 1], [1, 3], [2, 1], [3, 3]])); - test.equal(shape.line().interpolate(shape.cardinalClosed())([[0, 1], [1, 3], [2, 1], [3, 3]]), l([[0, 1], [1, 3], [2, 1], [3, 3]])); - test.equal(shape.line().interpolate(shape.cardinalClosed(null))([[0, 1], [1, 3], [2, 1], [3, 3]]), l([[0, 1], [1, 3], [2, 1], [3, 3]])); - test.equal(shape.line().interpolate(shape.cardinalClosed(undefined))([[0, 1], [1, 3], [2, 1], [3, 3]]), l([[0, 1], [1, 3], [2, 1], [3, 3]])); + test.equal(shape.line().interpolate(shape.cardinalClosed, null)([[0, 1], [1, 3], [2, 1], [3, 3]]), l([[0, 1], [1, 3], [2, 1], [3, 3]])); + test.equal(shape.line().interpolate(shape.cardinalClosed, undefined)([[0, 1], [1, 3], [2, 1], [3, 3]]), l([[0, 1], [1, 3], [2, 1], [3, 3]])); test.end(); }); tape("line.interpolate(catmullRom) uses a default alpha of zero", function(test) { - var l = shape.line().interpolate(shape.catmullRom(0)); + var l = shape.line().interpolate(shape.catmullRom, 0); test.equal(shape.line().interpolate(shape.catmullRom)([[0, 1], [1, 3], [2, 1], [3, 3]]), l([[0, 1], [1, 3], [2, 1], [3, 3]])); - test.equal(shape.line().interpolate(shape.catmullRom())([[0, 1], [1, 3], [2, 1], [3, 3]]), l([[0, 1], [1, 3], [2, 1], [3, 3]])); - test.equal(shape.line().interpolate(shape.catmullRom(null))([[0, 1], [1, 3], [2, 1], [3, 3]]), l([[0, 1], [1, 3], [2, 1], [3, 3]])); - test.equal(shape.line().interpolate(shape.catmullRom(undefined))([[0, 1], [1, 3], [2, 1], [3, 3]]), l([[0, 1], [1, 3], [2, 1], [3, 3]])); + test.equal(shape.line().interpolate(shape.catmullRom, null)([[0, 1], [1, 3], [2, 1], [3, 3]]), l([[0, 1], [1, 3], [2, 1], [3, 3]])); + test.equal(shape.line().interpolate(shape.catmullRom, undefined)([[0, 1], [1, 3], [2, 1], [3, 3]]), l([[0, 1], [1, 3], [2, 1], [3, 3]])); test.end(); }); tape("line.interpolate(catmullRomOpen) uses a default alpha of zero", function(test) { - var l = shape.line().interpolate(shape.catmullRomOpen(0)); + var l = shape.line().interpolate(shape.catmullRomOpen, 0); test.equal(shape.line().interpolate(shape.catmullRomOpen)([[0, 1], [1, 3], [2, 1], [3, 3]]), l([[0, 1], [1, 3], [2, 1], [3, 3]])); - test.equal(shape.line().interpolate(shape.catmullRomOpen())([[0, 1], [1, 3], [2, 1], [3, 3]]), l([[0, 1], [1, 3], [2, 1], [3, 3]])); - test.equal(shape.line().interpolate(shape.catmullRomOpen(null))([[0, 1], [1, 3], [2, 1], [3, 3]]), l([[0, 1], [1, 3], [2, 1], [3, 3]])); - test.equal(shape.line().interpolate(shape.catmullRomOpen(undefined))([[0, 1], [1, 3], [2, 1], [3, 3]]), l([[0, 1], [1, 3], [2, 1], [3, 3]])); + test.equal(shape.line().interpolate(shape.catmullRomOpen, null)([[0, 1], [1, 3], [2, 1], [3, 3]]), l([[0, 1], [1, 3], [2, 1], [3, 3]])); + test.equal(shape.line().interpolate(shape.catmullRomOpen, undefined)([[0, 1], [1, 3], [2, 1], [3, 3]]), l([[0, 1], [1, 3], [2, 1], [3, 3]])); test.end(); }); tape("line.interpolate(catmullRomClosed) uses a default alpha of zero", function(test) { - var l = shape.line().interpolate(shape.catmullRomClosed(0)); + var l = shape.line().interpolate(shape.catmullRomClosed, 0); test.equal(shape.line().interpolate(shape.catmullRomClosed)([[0, 1], [1, 3], [2, 1], [3, 3]]), l([[0, 1], [1, 3], [2, 1], [3, 3]])); - test.equal(shape.line().interpolate(shape.catmullRomClosed())([[0, 1], [1, 3], [2, 1], [3, 3]]), l([[0, 1], [1, 3], [2, 1], [3, 3]])); - test.equal(shape.line().interpolate(shape.catmullRomClosed(null))([[0, 1], [1, 3], [2, 1], [3, 3]]), l([[0, 1], [1, 3], [2, 1], [3, 3]])); - test.equal(shape.line().interpolate(shape.catmullRomClosed(undefined))([[0, 1], [1, 3], [2, 1], [3, 3]]), l([[0, 1], [1, 3], [2, 1], [3, 3]])); + test.equal(shape.line().interpolate(shape.catmullRomClosed, null)([[0, 1], [1, 3], [2, 1], [3, 3]]), l([[0, 1], [1, 3], [2, 1], [3, 3]])); + test.equal(shape.line().interpolate(shape.catmullRomClosed, undefined)([[0, 1], [1, 3], [2, 1], [3, 3]]), l([[0, 1], [1, 3], [2, 1], [3, 3]])); test.end(); }); tape("line.interpolate(bundle) uses a default beta of one", function(test) { - var l = shape.line().interpolate(shape.bundle(1)); + var l = shape.line().interpolate(shape.bundle, 1); test.equal(shape.line().interpolate(shape.bundle)([[0, 1], [1, 3], [2, 1], [3, 3]]), l([[0, 1], [1, 3], [2, 1], [3, 3]])); - test.equal(shape.line().interpolate(shape.bundle())([[0, 1], [1, 3], [2, 1], [3, 3]]), l([[0, 1], [1, 3], [2, 1], [3, 3]])); - test.equal(shape.line().interpolate(shape.bundle(null))([[0, 1], [1, 3], [2, 1], [3, 3]]), l([[0, 1], [1, 3], [2, 1], [3, 3]])); - test.equal(shape.line().interpolate(shape.bundle(undefined))([[0, 1], [1, 3], [2, 1], [3, 3]]), l([[0, 1], [1, 3], [2, 1], [3, 3]])); + test.equal(shape.line().interpolate(shape.bundle, null)([[0, 1], [1, 3], [2, 1], [3, 3]]), l([[0, 1], [1, 3], [2, 1], [3, 3]])); + test.equal(shape.line().interpolate(shape.bundle, undefined)([[0, 1], [1, 3], [2, 1], [3, 3]]), l([[0, 1], [1, 3], [2, 1], [3, 3]])); test.end(); }); From 64a2f32e7b838030889deb89a2ee88f683e6472e Mon Sep 17 00:00:00 2001 From: Mike Bostock Date: Thu, 19 Nov 2015 10:59:50 -0800 Subject: [PATCH 10/15] Update README. --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 41e8de8..3452697 100644 --- a/README.md +++ b/README.md @@ -32,7 +32,7 @@ If you use NPM, `npm install d3-shape`. Otherwise, download the [latest release] … -# line.interpolate([interpolate]) +# line.interpolate([interpolate[, parameters…]]) … @@ -80,7 +80,7 @@ If you use NPM, `npm install d3-shape`. Otherwise, download the [latest release] … -# area.interpolate([interpolate]) +# area.interpolate([interpolate[, parameters…]]) … From 0cb2d5fab0ab30fb425d16c009ce52610c852ae5 Mon Sep 17 00:00:00 2001 From: Mike Bostock Date: Thu, 19 Nov 2015 11:01:07 -0800 Subject: [PATCH 11/15] Update README. --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 3452697..d3851d8 100644 --- a/README.md +++ b/README.md @@ -90,6 +90,8 @@ If you use NPM, `npm install d3-shape`. Otherwise, download the [latest release] ### Interpolators +Interpolators are typically not used directly, instead implementing splines for [lines](#lines) and [areas](#areas). + … # basis(context) From ac66e91c51248212143dc1a99b709f5fa5078b47 Mon Sep 17 00:00:00 2001 From: Mike Bostock Date: Thu, 19 Nov 2015 11:12:45 -0800 Subject: [PATCH 12/15] Update README. --- README.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index d3851d8..bc89933 100644 --- a/README.md +++ b/README.md @@ -202,9 +202,15 @@ Note: not implemented by closed interpolators, such as l … +### Symbol Types + +Symbol types are typically not used directly, instead implementing paths for [symbols](#symbols). + +… + # symbolTypes -An array containing the set of supported [symbol types](#symbol_type): [circle](#circle), [cross](#cross), [diamond](#diamond), [square](#square), [triangleDown](#triangleDown), and [triangleUp](#triangleUp). +An array containing the set of all built-in symbol types: [circle](#circle), [cross](#cross), [diamond](#diamond), [square](#square), [triangleDown](#triangleDown), and [triangleUp](#triangleUp). Useful for constructing the range of an [ordinal scale](https://github.com/d3/d3-scale#ordinal-scales) should you wish to use a shape encoding for categorical data. # circle From 90918cf46a5d30c585cc76e94006fe9929662466 Mon Sep 17 00:00:00 2001 From: Mike Bostock Date: Thu, 19 Nov 2015 11:18:47 -0800 Subject: [PATCH 13/15] Update README. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index bc89933..2059e48 100644 --- a/README.md +++ b/README.md @@ -246,7 +246,7 @@ An array containing the set of all built-in symbol types: [circle](#circle), [cr * The interpretation of the [Cardinal](#cardinal) spline tension parameter has been fixed. The default tension is now 0 (corresponding to a uniform Catmull–Rom spline), not 0.7. Due to a bug in 3.x, the tension parameter was previously only valid in the range [2/3, 1]; this corresponds to the new corrected range of [0, 1]. Thus, the new default value of 0 is equivalent to the old value of 2/3, and the default behavior is only slightly changed. -* To specify a [Cardinal](#cardinal) interpolation tension of *t*, use `line.interpolate(cardinal(t))` instead of `line.interpolate("cardinal").tension(t)`. +* To specify a [Cardinal](#cardinal) interpolation tension of *t*, use `line.interpolate(cardinal, t)` instead of `line.interpolate("cardinal").tension(t)`. * The custom [interpolator API](#interpolators) has changed. From 335a728d6f029e259b3a02d919859a6a4c09e5e9 Mon Sep 17 00:00:00 2001 From: Mike Bostock Date: Thu, 19 Nov 2015 11:39:33 -0800 Subject: [PATCH 14/15] =?UTF-8?q?Rename=20=E2=80=9Cinterpolate=E2=80=9D=20?= =?UTF-8?q?to=20=E2=80=9Ccurve=E2=80=9D=20and=20add=20prefixes.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 82 ++++----- index.js | 44 ++--- src/area.js | 34 ++-- src/{interpolate => curve}/basis-closed.js | 0 src/{interpolate => curve}/basis-open.js | 0 src/{interpolate => curve}/basis.js | 0 src/{interpolate => curve}/bundle.js | 0 src/{interpolate => curve}/cardinal-closed.js | 0 src/{interpolate => curve}/cardinal-open.js | 0 src/{interpolate => curve}/cardinal.js | 0 .../catmull-rom-closed.js | 0 .../catmull-rom-open.js | 0 src/{interpolate => curve}/catmull-rom.js | 0 src/{interpolate => curve}/curry.js | 0 src/{interpolate => curve}/linear-closed.js | 0 src/{interpolate => curve}/linear.js | 0 src/{interpolate => curve}/monotone.js | 0 src/{interpolate => curve}/natural.js | 0 src/{interpolate => curve}/step-after.js | 0 src/{interpolate => curve}/step-before.js | 0 src/{interpolate => curve}/step.js | 0 src/line.js | 24 +-- test/area-test.js | 86 +++++----- test/line-test.js | 156 +++++++++--------- test/symbol-test.js | 22 +-- test/symbolTypes-test.js | 12 +- 26 files changed, 231 insertions(+), 229 deletions(-) rename src/{interpolate => curve}/basis-closed.js (100%) rename src/{interpolate => curve}/basis-open.js (100%) rename src/{interpolate => curve}/basis.js (100%) rename src/{interpolate => curve}/bundle.js (100%) rename src/{interpolate => curve}/cardinal-closed.js (100%) rename src/{interpolate => curve}/cardinal-open.js (100%) rename src/{interpolate => curve}/cardinal.js (100%) rename src/{interpolate => curve}/catmull-rom-closed.js (100%) rename src/{interpolate => curve}/catmull-rom-open.js (100%) rename src/{interpolate => curve}/catmull-rom.js (100%) rename src/{interpolate => curve}/curry.js (100%) rename src/{interpolate => curve}/linear-closed.js (100%) rename src/{interpolate => curve}/linear.js (100%) rename src/{interpolate => curve}/monotone.js (100%) rename src/{interpolate => curve}/natural.js (100%) rename src/{interpolate => curve}/step-after.js (100%) rename src/{interpolate => curve}/step-before.js (100%) rename src/{interpolate => curve}/step.js (100%) diff --git a/README.md b/README.md index 2059e48..882fcc5 100644 --- a/README.md +++ b/README.md @@ -32,7 +32,7 @@ If you use NPM, `npm install d3-shape`. Otherwise, download the [latest release] … -# line.interpolate([interpolate[, parameters…]]) +# line.curve([curve[, parameters…]]) … @@ -80,7 +80,7 @@ If you use NPM, `npm install d3-shape`. Otherwise, download the [latest release] … -# area.interpolate([interpolate[, parameters…]]) +# area.curve([curve[, parameters…]]) … @@ -88,97 +88,97 @@ If you use NPM, `npm install d3-shape`. Otherwise, download the [latest release] … -### Interpolators +### Curves -Interpolators are typically not used directly, instead implementing splines for [lines](#lines) and [areas](#areas). +Curves are typically not used directly, instead implementing paths for [lines](#lines) and [areas](#areas). See [*line*.curve](#line_curve) and [*area*.curve](#area_curve). … -# basis(context) +# curveBasis(context) … -# basisClosed(context) +# curveBasisClosed(context) … -# basisOpen(context) +# curveBasisOpen(context) … -# bundle(context[, beta]) +# curveBundle(context[, beta]) … -# cardinal(context[, tension]) +# curveCardinal(context[, tension]) … -# cardinalClosed(context[, tension]) +# curveCardinalClosed(context[, tension]) … -# cardinalOpen(context[, tension]) +# curveCardinalOpen(context[, tension]) … -# catmullRom(context[, alpha]) +# curveCatmullRom(context[, alpha]) … -# catmullRomClosed(context[, alpha]) +# curveCatmullRomClosed(context[, alpha]) … -# catmullRomOpen(context[, alpha]) +# curveCatmullRomOpen(context[, alpha]) … -# linear(context) +# curveLinear(context) … -# linearClosed(context) +# curveLinearClosed(context) … -# natural(context) +# curveNatural(context) … -# step(context) +# curveStep(context) … -# stepAfter(context) +# curveStepAfter(context) … -# stepBefore(context) +# curveStepBefore(context) … -# interpolator.areaStart() +# curve.areaStart() … -Note: not implemented by closed interpolators, such as linearClosed. +Note: not implemented by closed curves, such as curveLinearClosed. -# interpolator.areaEnd() +# curve.areaEnd() … -Note: not implemented by closed interpolators, such as linearClosed. +Note: not implemented by closed curves, such as curveLinearClosed. -# interpolator.lineStart() +# curve.lineStart() … -# interpolator.lineEnd() +# curve.lineEnd() … -# interpolator.point(x, y) +# curve.point(x, y) … @@ -204,35 +204,35 @@ Note: not implemented by closed interpolators, such as l ### Symbol Types -Symbol types are typically not used directly, instead implementing paths for [symbols](#symbols). +Symbol types are typically not used directly, instead implementing paths for [symbols](#symbols). See [*symbol*.type](#symbol_type). … # symbolTypes -An array containing the set of all built-in symbol types: [circle](#circle), [cross](#cross), [diamond](#diamond), [square](#square), [triangleDown](#triangleDown), and [triangleUp](#triangleUp). Useful for constructing the range of an [ordinal scale](https://github.com/d3/d3-scale#ordinal-scales) should you wish to use a shape encoding for categorical data. +An array containing the set of all built-in symbol types: [circle](#symbolCircle), [cross](#symbolCross), [diamond](#symbolDiamond), [square](#symbolSquare), [downwards triangle](#symbolTriangleDown), and [upwards triangle](#symbolTriangleUp). Useful for constructing the range of an [ordinal scale](https://github.com/d3/d3-scale#ordinal-scales) should you wish to use a shape encoding for categorical data. -# circle +# symbolCircle … -# cross +# symbolCross … -# diamond +# symbolDiamond … -# square +# symbolSquare … -# triangleDown +# symbolTriangleDown … -# triangleUp +# symbolTriangleUp … @@ -242,17 +242,17 @@ An array containing the set of all built-in symbol types: [circle](#circle), [cr ## Changes from D3 3.x: -* You can now render shapes to Canvas by specifying a context (e.g., [*line*.context](#line_context))! +* You can now render shapes to Canvas by specifying a context (e.g., [*line*.context](#line_context))! See [d3-path](https://github.com/d3/d3-path) for how it works. -* The interpretation of the [Cardinal](#cardinal) spline tension parameter has been fixed. The default tension is now 0 (corresponding to a uniform Catmull–Rom spline), not 0.7. Due to a bug in 3.x, the tension parameter was previously only valid in the range [2/3, 1]; this corresponds to the new corrected range of [0, 1]. Thus, the new default value of 0 is equivalent to the old value of 2/3, and the default behavior is only slightly changed. +* The interpretation of the [cardinal](#cardinal) spline tension parameter has been fixed. The default tension is now 0 (corresponding to a uniform Catmull–Rom spline), not 0.7. Due to a bug in 3.x, the tension parameter was previously only valid in the range [2/3, 1]; this corresponds to the new corrected range of [0, 1]. Thus, the new default value of 0 is equivalent to the old value of 2/3, and the default behavior is only slightly changed. -* To specify a [Cardinal](#cardinal) interpolation tension of *t*, use `line.interpolate(cardinal, t)` instead of `line.interpolate("cardinal").tension(t)`. +* To specify a [cardinal](#curveCardinal) spline tension of *t*, use `line.curve(curveCardinal, t)` instead of `line.interpolate("cardinal").tension(t)`. -* The custom [interpolator API](#interpolators) has changed. +* To specify a custom line or area interpolator, implement a [curve](#curves). -* Added [natural](#natural) cubic spline interpolation. +* Added [natural](#curveNatural) cubic splines. -* Added [Catmull–Rom](#catmullRom) spline interpolation, parameterized by alpha. If α = 0, produces a uniform Catmull–Rom spline equivalent to a Cardinal spline with zero tension; if α = 0.5, produces a centripetal spline; if α = 1.0, produces a chordal spline. +* Added [Catmull–Rom](#curveCatmullRom) splines, parameterized by alpha. If α = 0, produces a uniform Catmull–Rom spline equivalent to a Cardinal spline with zero tension; if α = 0.5, produces a centripetal spline; if α = 1.0, produces a chordal spline. * By setting [*area*.x1](#area_x1) or [*area*.y1](#area_y1) to null, you can reuse the [*area*.x0](#area_x0) or [*area*.y0](#area_y0) value, rather than computing it twice. This is useful for nondeterministic values (e.g., jitter). diff --git a/index.js b/index.js index 5a007db..e94d740 100644 --- a/index.js +++ b/index.js @@ -1,25 +1,27 @@ export {default as area} from "./src/area"; export {default as line} from "./src/line"; -export {default as basisClosed} from "./src/interpolate/basis-closed"; -export {default as basisOpen} from "./src/interpolate/basis-open"; -export {default as basis} from "./src/interpolate/basis"; -export {default as bundle} from "./src/interpolate/bundle"; -export {default as cardinalClosed} from "./src/interpolate/cardinal-closed"; -export {default as cardinalOpen} from "./src/interpolate/cardinal-open"; -export {default as cardinal} from "./src/interpolate/cardinal"; -export {default as catmullRomClosed} from "./src/interpolate/catmull-rom-closed"; -export {default as catmullRomOpen} from "./src/interpolate/catmull-rom-open"; -export {default as catmullRom} from "./src/interpolate/catmull-rom"; -export {default as linearClosed} from "./src/interpolate/linear-closed"; -export {default as linear} from "./src/interpolate/linear"; -export {default as natural} from "./src/interpolate/natural"; -export {default as stepAfter} from "./src/interpolate/step-after"; -export {default as stepBefore} from "./src/interpolate/step-before"; -export {default as step} from "./src/interpolate/step"; + +export {default as curveBasisClosed} from "./src/curve/basis-closed"; +export {default as curveBasisOpen} from "./src/curve/basis-open"; +export {default as curveBasis} from "./src/curve/basis"; +export {default as curveBundle} from "./src/curve/bundle"; +export {default as curveCardinalClosed} from "./src/curve/cardinal-closed"; +export {default as curveCardinalOpen} from "./src/curve/cardinal-open"; +export {default as curveCardinal} from "./src/curve/cardinal"; +export {default as curveCatmullRomClosed} from "./src/curve/catmull-rom-closed"; +export {default as curveCatmullRomOpen} from "./src/curve/catmull-rom-open"; +export {default as curveCatmullRom} from "./src/curve/catmull-rom"; +export {default as curveLinearClosed} from "./src/curve/linear-closed"; +export {default as curveLinear} from "./src/curve/linear"; +export {default as curveNatural} from "./src/curve/natural"; +export {default as curveStepAfter} from "./src/curve/step-after"; +export {default as curveStepBefore} from "./src/curve/step-before"; +export {default as curveStep} from "./src/curve/step"; export {default as symbol, symbolTypes} from "./src/symbol"; -export {default as circle} from "./src/symbol/circle"; -export {default as cross} from "./src/symbol/cross"; -export {default as diamond} from "./src/symbol/diamond"; -export {default as square} from "./src/symbol/square"; -export {triangleDown, triangleUp} from "./src/symbol/triangle"; + +export {default as symbolCircle} from "./src/symbol/circle"; +export {default as symbolCross} from "./src/symbol/cross"; +export {default as symbolDiamond} from "./src/symbol/diamond"; +export {default as symbolSquare} from "./src/symbol/square"; +export {triangleDown as symbolTriangleDown, triangleUp as symbolTriangleUp} from "./src/symbol/triangle"; diff --git a/src/area.js b/src/area.js index a4f2e3f..c3bed04 100644 --- a/src/area.js +++ b/src/area.js @@ -1,7 +1,7 @@ import {path} from "d3-path"; import constant from "./constant"; -import linear from "./interpolate/linear"; -import curry from "./interpolate/curry"; +import curveLinear from "./curve/linear"; +import curveCurry from "./curve/curry"; import {x as pointX, y as pointY} from "./point"; export default function() { @@ -11,8 +11,8 @@ export default function() { y1 = pointY, defined = constant(true), context = null, - interpolate = linear, - interpolator = null; + curve = curveLinear, + output = null; function area(data) { var i, @@ -25,31 +25,31 @@ export default function() { x0z = new Array(n), y0z = new Array(n); - if (!context) interpolator = interpolate(buffer = path()); + if (!context) output = curve(buffer = path()); for (i = 0; i <= n; ++i) { if (!(i < n && defined(d = data[i], i)) === defined0) { if (defined0 = !defined0) { j = i; - interpolator.areaStart(); - interpolator.lineStart(); + output.areaStart(); + output.lineStart(); } else { - interpolator.lineEnd(); - interpolator.lineStart(); + output.lineEnd(); + output.lineStart(); for (k = i - 1; k >= j; --k) { - interpolator.point(x0z[k], y0z[k]); + output.point(x0z[k], y0z[k]); } - interpolator.lineEnd(); - interpolator.areaEnd(); + output.lineEnd(); + output.areaEnd(); } } if (defined0) { x0z[i] = +x0(d, i), y0z[i] = +y0(d, i); - interpolator.point(x1 ? +x1(d, i) : x0z[i], y1 ? +y1(d, i) : y0z[i]); + output.point(x1 ? +x1(d, i) : x0z[i], y1 ? +y1(d, i) : y0z[i]); } } - if (buffer) return interpolator = null, buffer + "" || null; + if (buffer) return output = null, buffer + "" || null; } area.x = function(_) { @@ -80,13 +80,13 @@ export default function() { return arguments.length ? (defined = typeof _ === "function" ? _ : constant(!!_), area) : defined; }; - area.interpolate = function(_) { + area.curve = function(_) { var n = arguments.length; - return n ? (interpolate = n > 1 ? curry(_, arguments) : _, context != null && (interpolator = interpolate(context)), area) : interpolate; + return n ? (curve = n > 1 ? curveCurry(_, arguments) : _, context != null && (output = curve(context)), area) : curve; }; area.context = function(_) { - return arguments.length ? (_ == null ? context = interpolator = null : interpolator = interpolate(context = _), area) : context; + return arguments.length ? (_ == null ? context = output = null : output = curve(context = _), area) : context; }; return area; diff --git a/src/interpolate/basis-closed.js b/src/curve/basis-closed.js similarity index 100% rename from src/interpolate/basis-closed.js rename to src/curve/basis-closed.js diff --git a/src/interpolate/basis-open.js b/src/curve/basis-open.js similarity index 100% rename from src/interpolate/basis-open.js rename to src/curve/basis-open.js diff --git a/src/interpolate/basis.js b/src/curve/basis.js similarity index 100% rename from src/interpolate/basis.js rename to src/curve/basis.js diff --git a/src/interpolate/bundle.js b/src/curve/bundle.js similarity index 100% rename from src/interpolate/bundle.js rename to src/curve/bundle.js diff --git a/src/interpolate/cardinal-closed.js b/src/curve/cardinal-closed.js similarity index 100% rename from src/interpolate/cardinal-closed.js rename to src/curve/cardinal-closed.js diff --git a/src/interpolate/cardinal-open.js b/src/curve/cardinal-open.js similarity index 100% rename from src/interpolate/cardinal-open.js rename to src/curve/cardinal-open.js diff --git a/src/interpolate/cardinal.js b/src/curve/cardinal.js similarity index 100% rename from src/interpolate/cardinal.js rename to src/curve/cardinal.js diff --git a/src/interpolate/catmull-rom-closed.js b/src/curve/catmull-rom-closed.js similarity index 100% rename from src/interpolate/catmull-rom-closed.js rename to src/curve/catmull-rom-closed.js diff --git a/src/interpolate/catmull-rom-open.js b/src/curve/catmull-rom-open.js similarity index 100% rename from src/interpolate/catmull-rom-open.js rename to src/curve/catmull-rom-open.js diff --git a/src/interpolate/catmull-rom.js b/src/curve/catmull-rom.js similarity index 100% rename from src/interpolate/catmull-rom.js rename to src/curve/catmull-rom.js diff --git a/src/interpolate/curry.js b/src/curve/curry.js similarity index 100% rename from src/interpolate/curry.js rename to src/curve/curry.js diff --git a/src/interpolate/linear-closed.js b/src/curve/linear-closed.js similarity index 100% rename from src/interpolate/linear-closed.js rename to src/curve/linear-closed.js diff --git a/src/interpolate/linear.js b/src/curve/linear.js similarity index 100% rename from src/interpolate/linear.js rename to src/curve/linear.js diff --git a/src/interpolate/monotone.js b/src/curve/monotone.js similarity index 100% rename from src/interpolate/monotone.js rename to src/curve/monotone.js diff --git a/src/interpolate/natural.js b/src/curve/natural.js similarity index 100% rename from src/interpolate/natural.js rename to src/curve/natural.js diff --git a/src/interpolate/step-after.js b/src/curve/step-after.js similarity index 100% rename from src/interpolate/step-after.js rename to src/curve/step-after.js diff --git a/src/interpolate/step-before.js b/src/curve/step-before.js similarity index 100% rename from src/interpolate/step-before.js rename to src/curve/step-before.js diff --git a/src/interpolate/step.js b/src/curve/step.js similarity index 100% rename from src/interpolate/step.js rename to src/curve/step.js diff --git a/src/line.js b/src/line.js index a097bf4..409b51b 100644 --- a/src/line.js +++ b/src/line.js @@ -1,7 +1,7 @@ import {path} from "d3-path"; import constant from "./constant"; -import linear from "./interpolate/linear"; -import curry from "./interpolate/curry"; +import curveLinear from "./curve/linear"; +import curveCurry from "./curve/curry"; import {x as pointX, y as pointY} from "./point"; export default function() { @@ -9,8 +9,8 @@ export default function() { y = pointY, defined = constant(true), context = null, - interpolate = linear, - interpolator = null; + curve = curveLinear, + output = null; function line(data) { var i, @@ -19,17 +19,17 @@ export default function() { defined0 = false, buffer; - if (!context) interpolator = interpolate(buffer = path()); + if (!context) output = curve(buffer = path()); for (i = 0; i <= n; ++i) { if (!(i < n && defined(d = data[i], i)) === defined0) { - if (defined0 = !defined0) interpolator.lineStart(); - else interpolator.lineEnd(); + if (defined0 = !defined0) output.lineStart(); + else output.lineEnd(); } - if (defined0) interpolator.point(+x(d, i), +y(d, i)); + if (defined0) output.point(+x(d, i), +y(d, i)); } - if (buffer) return interpolator = null, buffer + "" || null; + if (buffer) return output = null, buffer + "" || null; } line.x = function(_) { @@ -44,13 +44,13 @@ export default function() { return arguments.length ? (defined = typeof _ === "function" ? _ : constant(!!_), line) : defined; }; - line.interpolate = function(_) { + line.curve = function(_) { var n = arguments.length; - return n ? (interpolate = n > 1 ? curry(_, arguments) : _, context != null && (interpolator = interpolate(context)), line) : interpolate; + return n ? (curve = n > 1 ? curveCurry(_, arguments) : _, context != null && (output = curve(context)), line) : curve; }; line.context = function(_) { - return arguments.length ? (_ == null ? context = interpolator = null : interpolator = interpolate(context = _), line) : context; + return arguments.length ? (_ == null ? context = output = null : output = curve(context = _), line) : context; }; return line; diff --git a/test/area-test.js b/test/area-test.js index 2b6bf18..f837fbf 100644 --- a/test/area-test.js +++ b/test/area-test.js @@ -8,7 +8,7 @@ tape("area() returns a default area shape", function(test) { test.equal(a.y0()([42, 34]), 0); test.equal(a.y1()([42, 34]), 34); test.equal(a.defined()([42, 34]), true); - test.equal(a.interpolate(), shape.linear); + test.equal(a.curve(), shape.curveLinear); test.equal(a.context(), null); test.equal(a([[0, 1], [2, 3], [4, 5]]), "M0,1L2,3L4,5L4,0L2,0L0,0Z"); test.end(); @@ -53,8 +53,8 @@ tape("area.y(y)(data) observes the specified constant", function(test) { test.end(); }); -tape("area.interpolate(linear)(data) generates the expected path", function(test) { - var a = shape.area().interpolate(shape.linear); +tape("area.curve(curveLinear)(data) generates the expected path", function(test) { + var a = shape.area().curve(shape.curveLinear); test.equal(a([]), null); test.equal(a([[0, 1]]), "M0,1L0,0Z"); test.equal(a([[0, 1], [2, 3]]), "M0,1L2,3L2,0L0,0Z"); @@ -62,8 +62,8 @@ tape("area.interpolate(linear)(data) generates the expected path", function(test test.end(); }); -tape("area.interpolate(basis)(data) generates the expected path", function(test) { - var a = shape.area().interpolate(shape.basis); +tape("area.curve(curveBasis)(data) generates the expected path", function(test) { + var a = shape.area().curve(shape.curveBasis); test.equal(a([]), null); test.equal(a([[0, 1]]), "M0,1L0,0Z"); test.equal(a([[0, 1], [1, 3]]), "M0,1L1,3L1,0L0,0Z"); @@ -71,8 +71,8 @@ tape("area.interpolate(basis)(data) generates the expected path", function(test) test.end(); }); -tape("area.interpolate(basisOpen)(data) generates the expected path", function(test) { - var a = shape.area().interpolate(shape.basisOpen); +tape("area.curve(curveBasisOpen)(data) generates the expected path", function(test) { + var a = shape.area().curve(shape.curveBasisOpen); test.equal(a([]), null); test.equal(a([[0, 1]]), null); test.equal(a([[0, 1], [1, 3]]), null); @@ -82,8 +82,8 @@ tape("area.interpolate(basisOpen)(data) generates the expected path", function(t test.end(); }); -tape("area.interpolate(cardinal)(data) generates the expected path", function(test) { - var a = shape.area().interpolate(shape.cardinal); +tape("area.curve(curveCardinal)(data) generates the expected path", function(test) { + var a = shape.area().curve(shape.curveCardinal); test.equal(a([]), null); test.equal(a([[0, 1]]), "M0,1L0,0Z"); test.equal(a([[0, 1], [1, 3]]), "M0,1L1,3L1,0L0,0Z"); @@ -92,8 +92,8 @@ tape("area.interpolate(cardinal)(data) generates the expected path", function(te test.end(); }); -tape("area.interpolate(cardinalOpen)(data) generates the expected path", function(test) { - var a = shape.area().interpolate(shape.cardinalOpen); +tape("area.curve(curveCardinalOpen)(data) generates the expected path", function(test) { + var a = shape.area().curve(shape.curveCardinalOpen); test.equal(a([]), null); test.equal(a([[0, 1]]), null); test.equal(a([[0, 1], [1, 3]]), null); @@ -102,8 +102,8 @@ tape("area.interpolate(cardinalOpen)(data) generates the expected path", functio test.end(); }); -tape("area.interpolate(catmullRom, 0.5)(data) generates the expected path", function(test) { - var a = shape.area().interpolate(shape.catmullRom, 0.5); +tape("area.curve(curveCatmullRom, 0.5)(data) generates the expected path", function(test) { + var a = shape.area().curve(shape.curveCatmullRom, 0.5); test.equal(a([]), null); test.equal(a([[0, 1]]), "M0,1L0,0Z"); test.equal(a([[0, 1], [1, 3]]), "M0,1L1,3L1,0L0,0Z"); @@ -112,8 +112,8 @@ tape("area.interpolate(catmullRom, 0.5)(data) generates the expected path", func test.end(); }); -tape("area.interpolate(catmullRomOpen, 0.5)(data) generates the expected path", function(test) { - var a = shape.area().interpolate(shape.catmullRomOpen, 0.5); +tape("area.curve(curveCatmullRomOpen, 0.5)(data) generates the expected path", function(test) { + var a = shape.area().curve(shape.curveCatmullRomOpen, 0.5); test.equal(a([]), null); test.equal(a([[0, 1]]), null); test.equal(a([[0, 1], [1, 3]]), null); @@ -122,8 +122,8 @@ tape("area.interpolate(catmullRomOpen, 0.5)(data) generates the expected path", test.end(); }); -tape("area.interpolate(step)(data) generates the expected path", function(test) { - var a = shape.area().interpolate(shape.step); +tape("area.curve(curveStep)(data) generates the expected path", function(test) { + var a = shape.area().curve(shape.curveStep); test.equal(a([]), null); test.equal(a([[0, 1]]), "M0,1L0,0Z"); test.equal(a([[0, 1], [2, 3]]), "M0,1L1,1L1,3L2,3L2,0L1,0L1,0L0,0Z"); @@ -131,8 +131,8 @@ tape("area.interpolate(step)(data) generates the expected path", function(test) test.end(); }); -tape("area.interpolate(stepBefore)(data) generates the expected path", function(test) { - var a = shape.area().interpolate(shape.stepBefore); +tape("area.curve(curveStepBefore)(data) generates the expected path", function(test) { + var a = shape.area().curve(shape.curveStepBefore); test.equal(a([]), null); test.equal(a([[0, 1]]), "M0,1L0,0Z"); test.equal(a([[0, 1], [2, 3]]), "M0,1L0,3L2,3L2,0L2,0L0,0Z"); @@ -140,8 +140,8 @@ tape("area.interpolate(stepBefore)(data) generates the expected path", function( test.end(); }); -tape("area.interpolate(stepAfter)(data) generates the expected path", function(test) { - var a = shape.area().interpolate(shape.stepAfter); +tape("area.curve(curveStepAfter)(data) generates the expected path", function(test) { + var a = shape.area().curve(shape.curveStepAfter); test.equal(a([]), null); test.equal(a([[0, 1]]), "M0,1L0,0Z"); test.equal(a([[0, 1], [2, 3]]), "M0,1L2,1L2,3L2,0L0,0L0,0Z"); @@ -149,8 +149,8 @@ tape("area.interpolate(stepAfter)(data) generates the expected path", function(t test.end(); }); -tape("area.interpolate(natural)(data) generates the expected path", function(test) { - var a = shape.area().interpolate(shape.natural); +tape("area.curve(curveNatural)(data) generates the expected path", function(test) { + var a = shape.area().curve(shape.curveNatural); test.equal(a([]), null); test.equal(a([[0, 1]]), "M0,1L0,0Z"); test.equal(a([[0, 1], [1, 3]]), "M0,1L1,3L1,0L0,0Z"); @@ -159,34 +159,34 @@ tape("area.interpolate(natural)(data) generates the expected path", function(tes test.end(); }); -tape("area.interpolate(cardinal) uses a default tension of zero", function(test) { - var a = shape.area().interpolate(shape.cardinal, 0); - test.equal(shape.area().interpolate(shape.cardinal)([[0, 1], [1, 3], [2, 1], [3, 3]]), a([[0, 1], [1, 3], [2, 1], [3, 3]])); - test.equal(shape.area().interpolate(shape.cardinal, null)([[0, 1], [1, 3], [2, 1], [3, 3]]), a([[0, 1], [1, 3], [2, 1], [3, 3]])); - test.equal(shape.area().interpolate(shape.cardinal, undefined)([[0, 1], [1, 3], [2, 1], [3, 3]]), a([[0, 1], [1, 3], [2, 1], [3, 3]])); +tape("area.curve(curveCardinal) uses a default tension of zero", function(test) { + var a = shape.area().curve(shape.curveCardinal, 0); + test.equal(shape.area().curve(shape.curveCardinal)([[0, 1], [1, 3], [2, 1], [3, 3]]), a([[0, 1], [1, 3], [2, 1], [3, 3]])); + test.equal(shape.area().curve(shape.curveCardinal, null)([[0, 1], [1, 3], [2, 1], [3, 3]]), a([[0, 1], [1, 3], [2, 1], [3, 3]])); + test.equal(shape.area().curve(shape.curveCardinal, undefined)([[0, 1], [1, 3], [2, 1], [3, 3]]), a([[0, 1], [1, 3], [2, 1], [3, 3]])); test.end(); }); -tape("area.interpolate(cardinalOpen) uses a default tension of zero", function(test) { - var a = shape.area().interpolate(shape.cardinalOpen, 0); - test.equal(shape.area().interpolate(shape.cardinalOpen)([[0, 1], [1, 3], [2, 1], [3, 3]]), a([[0, 1], [1, 3], [2, 1], [3, 3]])); - test.equal(shape.area().interpolate(shape.cardinalOpen, null)([[0, 1], [1, 3], [2, 1], [3, 3]]), a([[0, 1], [1, 3], [2, 1], [3, 3]])); - test.equal(shape.area().interpolate(shape.cardinalOpen, undefined)([[0, 1], [1, 3], [2, 1], [3, 3]]), a([[0, 1], [1, 3], [2, 1], [3, 3]])); +tape("area.curve(curveCardinalOpen) uses a default tension of zero", function(test) { + var a = shape.area().curve(shape.curveCardinalOpen, 0); + test.equal(shape.area().curve(shape.curveCardinalOpen)([[0, 1], [1, 3], [2, 1], [3, 3]]), a([[0, 1], [1, 3], [2, 1], [3, 3]])); + test.equal(shape.area().curve(shape.curveCardinalOpen, null)([[0, 1], [1, 3], [2, 1], [3, 3]]), a([[0, 1], [1, 3], [2, 1], [3, 3]])); + test.equal(shape.area().curve(shape.curveCardinalOpen, undefined)([[0, 1], [1, 3], [2, 1], [3, 3]]), a([[0, 1], [1, 3], [2, 1], [3, 3]])); test.end(); }); -tape("area.interpolate(catmullRom) uses a default alpha of zero", function(test) { - var a = shape.area().interpolate(shape.catmullRom, 0); - test.equal(shape.area().interpolate(shape.catmullRom)([[0, 1], [1, 3], [2, 1], [3, 3]]), a([[0, 1], [1, 3], [2, 1], [3, 3]])); - test.equal(shape.area().interpolate(shape.catmullRom, null)([[0, 1], [1, 3], [2, 1], [3, 3]]), a([[0, 1], [1, 3], [2, 1], [3, 3]])); - test.equal(shape.area().interpolate(shape.catmullRom, undefined)([[0, 1], [1, 3], [2, 1], [3, 3]]), a([[0, 1], [1, 3], [2, 1], [3, 3]])); +tape("area.curve(curveCatmullRom) uses a default alpha of zero", function(test) { + var a = shape.area().curve(shape.curveCatmullRom, 0); + test.equal(shape.area().curve(shape.curveCatmullRom)([[0, 1], [1, 3], [2, 1], [3, 3]]), a([[0, 1], [1, 3], [2, 1], [3, 3]])); + test.equal(shape.area().curve(shape.curveCatmullRom, null)([[0, 1], [1, 3], [2, 1], [3, 3]]), a([[0, 1], [1, 3], [2, 1], [3, 3]])); + test.equal(shape.area().curve(shape.curveCatmullRom, undefined)([[0, 1], [1, 3], [2, 1], [3, 3]]), a([[0, 1], [1, 3], [2, 1], [3, 3]])); test.end(); }); -tape("area.interpolate(catmullRomOpen) uses a default alpha of zero", function(test) { - var a = shape.area().interpolate(shape.catmullRomOpen, 0); - test.equal(shape.area().interpolate(shape.catmullRomOpen)([[0, 1], [1, 3], [2, 1], [3, 3]]), a([[0, 1], [1, 3], [2, 1], [3, 3]])); - test.equal(shape.area().interpolate(shape.catmullRomOpen, null)([[0, 1], [1, 3], [2, 1], [3, 3]]), a([[0, 1], [1, 3], [2, 1], [3, 3]])); - test.equal(shape.area().interpolate(shape.catmullRomOpen, undefined)([[0, 1], [1, 3], [2, 1], [3, 3]]), a([[0, 1], [1, 3], [2, 1], [3, 3]])); +tape("area.curve(curveCatmullRomOpen) uses a default alpha of zero", function(test) { + var a = shape.area().curve(shape.curveCatmullRomOpen, 0); + test.equal(shape.area().curve(shape.curveCatmullRomOpen)([[0, 1], [1, 3], [2, 1], [3, 3]]), a([[0, 1], [1, 3], [2, 1], [3, 3]])); + test.equal(shape.area().curve(shape.curveCatmullRomOpen, null)([[0, 1], [1, 3], [2, 1], [3, 3]]), a([[0, 1], [1, 3], [2, 1], [3, 3]])); + test.equal(shape.area().curve(shape.curveCatmullRomOpen, undefined)([[0, 1], [1, 3], [2, 1], [3, 3]]), a([[0, 1], [1, 3], [2, 1], [3, 3]])); test.end(); }); diff --git a/test/line-test.js b/test/line-test.js index e83cb2a..c858662 100644 --- a/test/line-test.js +++ b/test/line-test.js @@ -6,7 +6,7 @@ tape("line() returns a default line shape", function(test) { test.equal(l.x()([42, 34]), 42); test.equal(l.y()([42, 34]), 34); test.equal(l.defined()([42, 34]), true); - test.equal(l.interpolate(), shape.linear); + test.equal(l.curve(), shape.curveLinear); test.equal(l.context(), null); test.equal(l([[0, 1], [2, 3], [4, 5]]), "M0,1L2,3L4,5"); test.end(); @@ -36,15 +36,15 @@ tape("line.y(y)(data) observes the specified constant", function(test) { test.end(); }); -tape("line.interpolate(interpolate) sets the interpolation method", function(test) { - var l = shape.line().interpolate(shape.linearClosed); +tape("line.curve(curve) sets the curve method", function(test) { + var l = shape.line().curve(shape.curveLinearClosed); test.equal(l([]), null); test.equal(l([[0, 1], [2, 3]]), "M0,1L2,3Z"); test.end(); }); -tape("line.interpolate(cardinal, tension) sets the cardinal interpolation tension", function(test) { - var l = shape.line().interpolate(shape.cardinal, 0.1); +tape("line.curve(curveCardinal, tension) sets the cardinal spline tension", function(test) { + var l = shape.line().curve(shape.curveCardinal, 0.1); test.equal(l([]), null); test.equal(l([[0, 1]]), "M0,1Z"); test.equal(l([[0, 1], [1, 3]]), "M0,1L1,3"); @@ -53,8 +53,8 @@ tape("line.interpolate(cardinal, tension) sets the cardinal interpolation tensio test.end(); }); -tape("line.interpolate(cardinal, tension) coerces the specified tension to a number", function(test) { - var l = shape.line().interpolate(shape.cardinal, "0.1"); +tape("line.curve(curveCardinal, tension) coerces the specified tension to a number", function(test) { + var l = shape.line().curve(shape.curveCardinal, "0.1"); test.equal(l([]), null); test.equal(l([[0, 1]]), "M0,1Z"); test.equal(l([[0, 1], [1, 3]]), "M0,1L1,3"); @@ -63,8 +63,8 @@ tape("line.interpolate(cardinal, tension) coerces the specified tension to a num test.end(); }); -tape("line.interpolate(linear)(data) generates the expected path", function(test) { - var l = shape.line().interpolate(shape.linear); +tape("line.curve(curveLinear)(data) generates the expected path", function(test) { + var l = shape.line().curve(shape.curveLinear); test.equal(l([]), null); test.equal(l([[0, 1]]), "M0,1Z"); test.equal(l([[0, 1], [2, 3]]), "M0,1L2,3"); @@ -72,8 +72,8 @@ tape("line.interpolate(linear)(data) generates the expected path", function(test test.end(); }); -tape("line.interpolate(linearClosed)(data) generates the expected path", function(test) { - var l = shape.line().interpolate(shape.linearClosed); +tape("line.curve(curveLinearClosed)(data) generates the expected path", function(test) { + var l = shape.line().curve(shape.curveLinearClosed); test.equal(l([]), null); test.equal(l([[0, 1]]), "M0,1Z"); test.equal(l([[0, 1], [2, 3]]), "M0,1L2,3Z"); @@ -81,8 +81,8 @@ tape("line.interpolate(linearClosed)(data) generates the expected path", functio test.end(); }); -tape("line.interpolate(step)(data) generates the expected path", function(test) { - var l = shape.line().interpolate(shape.step); +tape("line.curve(curveStep)(data) generates the expected path", function(test) { + var l = shape.line().curve(shape.curveStep); test.equal(l([]), null); test.equal(l([[0, 1]]), "M0,1Z"); test.equal(l([[0, 1], [2, 3]]), "M0,1L1,1L1,3L2,3"); @@ -90,8 +90,8 @@ tape("line.interpolate(step)(data) generates the expected path", function(test) test.end(); }); -tape("line.interpolate(stepBefore)(data) generates the expected path", function(test) { - var l = shape.line().interpolate(shape.stepBefore); +tape("line.curve(curveStepBefore)(data) generates the expected path", function(test) { + var l = shape.line().curve(shape.curveStepBefore); test.equal(l([]), null); test.equal(l([[0, 1]]), "M0,1Z"); test.equal(l([[0, 1], [2, 3]]), "M0,1L0,3L2,3"); @@ -99,8 +99,8 @@ tape("line.interpolate(stepBefore)(data) generates the expected path", function( test.end(); }); -tape("line.interpolate(stepAfter)(data) generates the expected path", function(test) { - var l = shape.line().interpolate(shape.stepAfter); +tape("line.curve(curveStepAfter)(data) generates the expected path", function(test) { + var l = shape.line().curve(shape.curveStepAfter); test.equal(l([]), null); test.equal(l([[0, 1]]), "M0,1Z"); test.equal(l([[0, 1], [2, 3]]), "M0,1L2,1L2,3"); @@ -108,8 +108,8 @@ tape("line.interpolate(stepAfter)(data) generates the expected path", function(t test.end(); }); -tape("line.interpolate(basis)(data) generates the expected path", function(test) { - var l = shape.line().interpolate(shape.basis); +tape("line.curve(curveBasis)(data) generates the expected path", function(test) { + var l = shape.line().curve(shape.curveBasis); test.equal(l([]), null); test.equal(l([[0, 1]]), "M0,1Z"); test.equal(l([[0, 1], [1, 3]]), "M0,1L1,3"); @@ -117,8 +117,8 @@ tape("line.interpolate(basis)(data) generates the expected path", function(test) test.end(); }); -tape("line.interpolate(basisOpen)(data) generates the expected path", function(test) { - var l = shape.line().interpolate(shape.basisOpen); +tape("line.curve(curveBasisOpen)(data) generates the expected path", function(test) { + var l = shape.line().curve(shape.curveBasisOpen); test.equal(l([]), null); test.equal(l([[0, 0]]), null); test.equal(l([[0, 0], [0, 10]]), null); @@ -128,8 +128,8 @@ tape("line.interpolate(basisOpen)(data) generates the expected path", function(t test.end(); }); -tape("line.interpolate(basisClosed)(data) generates the expected path", function(test) { - var l = shape.line().interpolate(shape.basisClosed); +tape("line.curve(curveBasisClosed)(data) generates the expected path", function(test) { + var l = shape.line().curve(shape.curveBasisClosed); test.equal(l([]), null); test.equal(l([[0, 0]]), "M0,0Z"); test.equal(l([[0, 0], [0, 10]]), "M0,6.666666666666667L0,3.3333333333333335Z"); @@ -139,8 +139,8 @@ tape("line.interpolate(basisClosed)(data) generates the expected path", function test.end(); }); -tape("line.interpolate(cardinal)(data) generates the expected path", function(test) { - var l = shape.line().interpolate(shape.cardinal); +tape("line.curve(curveCardinal)(data) generates the expected path", function(test) { + var l = shape.line().curve(shape.curveCardinal); test.equal(l([]), null); test.equal(l([[0, 1]]), "M0,1Z"); test.equal(l([[0, 1], [1, 3]]), "M0,1L1,3"); @@ -149,8 +149,8 @@ tape("line.interpolate(cardinal)(data) generates the expected path", function(te test.end(); }); -tape("line.interpolate(cardinalOpen)(data) generates the expected path", function(test) { - var l = shape.line().interpolate(shape.cardinalOpen); +tape("line.curve(curveCardinalOpen)(data) generates the expected path", function(test) { + var l = shape.line().curve(shape.curveCardinalOpen); test.equal(l([]), null); test.equal(l([[0, 1]]), null); test.equal(l([[0, 1], [1, 3]]), null); @@ -159,8 +159,8 @@ tape("line.interpolate(cardinalOpen)(data) generates the expected path", functio test.end(); }); -tape("line.interpolate(cardinalClosed)(data) generates the expected path", function(test) { - var l = shape.line().interpolate(shape.cardinalClosed); +tape("line.curve(curveCardinalClosed)(data) generates the expected path", function(test) { + var l = shape.line().curve(shape.curveCardinalClosed); test.equal(l([]), null); test.equal(l([[0, 1]]), "M0,1Z"); test.equal(l([[0, 1], [1, 3]]), "M1,3L0,1Z"); @@ -169,8 +169,8 @@ tape("line.interpolate(cardinalClosed)(data) generates the expected path", funct test.end(); }); -tape("line.interpolate(catmullRom)(data) generates the expected path", function(test) { - var l = shape.line().interpolate(shape.catmullRom); +tape("line.curve(curveCatmullRom)(data) generates the expected path", function(test) { + var l = shape.line().curve(shape.curveCatmullRom); test.equal(l([]), null); test.equal(l([[0, 1]]), "M0,1Z"); test.equal(l([[0, 1], [1, 3]]), "M0,1L1,3"); @@ -179,8 +179,8 @@ tape("line.interpolate(catmullRom)(data) generates the expected path", function( test.end(); }); -tape("line.interpolate(catmullRomOpen)(data) generates the expected path", function(test) { - var l = shape.line().interpolate(shape.catmullRomOpen); +tape("line.curve(curveCatmullRomOpen)(data) generates the expected path", function(test) { + var l = shape.line().curve(shape.curveCatmullRomOpen); test.equal(l([]), null); test.equal(l([[0, 1]]), null); test.equal(l([[0, 1], [1, 3]]), null); @@ -189,8 +189,8 @@ tape("line.interpolate(catmullRomOpen)(data) generates the expected path", funct test.end(); }); -tape("line.interpolate(catmullRomClosed)(data) generates the expected path", function(test) { - var l = shape.line().interpolate(shape.catmullRomClosed); +tape("line.curve(curveCatmullRomClosed)(data) generates the expected path", function(test) { + var l = shape.line().curve(shape.curveCatmullRomClosed); test.equal(l([]), null); test.equal(l([[0, 1]]), "M0,1Z"); test.equal(l([[0, 1], [1, 3]]), "M1,3L0,1Z"); @@ -199,8 +199,8 @@ tape("line.interpolate(catmullRomClosed)(data) generates the expected path", fun test.end(); }); -tape("line.interpolate(catmullRom, 1)(data) generates the expected path", function(test) { - var l = shape.line().interpolate(shape.catmullRom, 1); +tape("line.curve(curveCatmullRom, 1)(data) generates the expected path", function(test) { + var l = shape.line().curve(shape.curveCatmullRom, 1); test.equal(l([]), null); test.equal(l([[0, 1]]), "M0,1Z"); test.equal(l([[0, 1], [1, 3]]), "M0,1L1,3"); @@ -209,8 +209,8 @@ tape("line.interpolate(catmullRom, 1)(data) generates the expected path", functi test.end(); }); -tape("line.interpolate(catmullRomOpen, 1)(data) generates the expected path", function(test) { - var l = shape.line().interpolate(shape.catmullRomOpen, 1); +tape("line.curve(curveCatmullRomOpen, 1)(data) generates the expected path", function(test) { + var l = shape.line().curve(shape.curveCatmullRomOpen, 1); test.equal(l([]), null); test.equal(l([[0, 1]]), null); test.equal(l([[0, 1], [1, 3]]), null); @@ -219,8 +219,8 @@ tape("line.interpolate(catmullRomOpen, 1)(data) generates the expected path", fu test.end(); }); -tape("line.interpolate(catmullRomClosed, 1)(data) generates the expected path", function(test) { - var l = shape.line().interpolate(shape.catmullRomClosed, 1); +tape("line.curve(curveCatmullRomClosed, 1)(data) generates the expected path", function(test) { + var l = shape.line().curve(shape.curveCatmullRomClosed, 1); test.equal(l([]), null); test.equal(l([[0, 1]]), "M0,1Z"); test.equal(l([[0, 1], [1, 3]]), "M1,3L0,1Z"); @@ -229,8 +229,8 @@ tape("line.interpolate(catmullRomClosed, 1)(data) generates the expected path", test.end(); }); -tape("line.interpolate(natural)(data) generates the expected path", function(test) { - var l = shape.line().interpolate(shape.natural); +tape("line.curve(curveNatural)(data) generates the expected path", function(test) { + var l = shape.line().curve(shape.curveNatural); test.equal(l([]), null); test.equal(l([[0, 1]]), "M0,1Z"); test.equal(l([[0, 1], [1, 3]]), "M0,1L1,3"); @@ -239,58 +239,58 @@ tape("line.interpolate(natural)(data) generates the expected path", function(tes test.end(); }); -tape("line.interpolate(cardinal) uses a default tension of zero", function(test) { - var l = shape.line().interpolate(shape.cardinal, 0); - test.equal(shape.line().interpolate(shape.cardinal)([[0, 1], [1, 3], [2, 1], [3, 3]]), l([[0, 1], [1, 3], [2, 1], [3, 3]])); - test.equal(shape.line().interpolate(shape.cardinal, null)([[0, 1], [1, 3], [2, 1], [3, 3]]), l([[0, 1], [1, 3], [2, 1], [3, 3]])); - test.equal(shape.line().interpolate(shape.cardinal, undefined)([[0, 1], [1, 3], [2, 1], [3, 3]]), l([[0, 1], [1, 3], [2, 1], [3, 3]])); +tape("line.curve(curveCardinal) uses a default tension of zero", function(test) { + var l = shape.line().curve(shape.curveCardinal, 0); + test.equal(shape.line().curve(shape.curveCardinal)([[0, 1], [1, 3], [2, 1], [3, 3]]), l([[0, 1], [1, 3], [2, 1], [3, 3]])); + test.equal(shape.line().curve(shape.curveCardinal, null)([[0, 1], [1, 3], [2, 1], [3, 3]]), l([[0, 1], [1, 3], [2, 1], [3, 3]])); + test.equal(shape.line().curve(shape.curveCardinal, undefined)([[0, 1], [1, 3], [2, 1], [3, 3]]), l([[0, 1], [1, 3], [2, 1], [3, 3]])); test.end(); }); -tape("line.interpolate(cardinalOpen) uses a default tension of zero", function(test) { - var l = shape.line().interpolate(shape.cardinalOpen, 0); - test.equal(shape.line().interpolate(shape.cardinalOpen)([[0, 1], [1, 3], [2, 1], [3, 3]]), l([[0, 1], [1, 3], [2, 1], [3, 3]])); - test.equal(shape.line().interpolate(shape.cardinalOpen, null)([[0, 1], [1, 3], [2, 1], [3, 3]]), l([[0, 1], [1, 3], [2, 1], [3, 3]])); - test.equal(shape.line().interpolate(shape.cardinalOpen, undefined)([[0, 1], [1, 3], [2, 1], [3, 3]]), l([[0, 1], [1, 3], [2, 1], [3, 3]])); +tape("line.curve(curveCardinalOpen) uses a default tension of zero", function(test) { + var l = shape.line().curve(shape.curveCardinalOpen, 0); + test.equal(shape.line().curve(shape.curveCardinalOpen)([[0, 1], [1, 3], [2, 1], [3, 3]]), l([[0, 1], [1, 3], [2, 1], [3, 3]])); + test.equal(shape.line().curve(shape.curveCardinalOpen, null)([[0, 1], [1, 3], [2, 1], [3, 3]]), l([[0, 1], [1, 3], [2, 1], [3, 3]])); + test.equal(shape.line().curve(shape.curveCardinalOpen, undefined)([[0, 1], [1, 3], [2, 1], [3, 3]]), l([[0, 1], [1, 3], [2, 1], [3, 3]])); test.end(); }); -tape("line.interpolate(cardinalClosed) uses a default tension of zero", function(test) { - var l = shape.line().interpolate(shape.cardinalClosed, 0); - test.equal(shape.line().interpolate(shape.cardinalClosed)([[0, 1], [1, 3], [2, 1], [3, 3]]), l([[0, 1], [1, 3], [2, 1], [3, 3]])); - test.equal(shape.line().interpolate(shape.cardinalClosed, null)([[0, 1], [1, 3], [2, 1], [3, 3]]), l([[0, 1], [1, 3], [2, 1], [3, 3]])); - test.equal(shape.line().interpolate(shape.cardinalClosed, undefined)([[0, 1], [1, 3], [2, 1], [3, 3]]), l([[0, 1], [1, 3], [2, 1], [3, 3]])); +tape("line.curve(curveCardinalClosed) uses a default tension of zero", function(test) { + var l = shape.line().curve(shape.curveCardinalClosed, 0); + test.equal(shape.line().curve(shape.curveCardinalClosed)([[0, 1], [1, 3], [2, 1], [3, 3]]), l([[0, 1], [1, 3], [2, 1], [3, 3]])); + test.equal(shape.line().curve(shape.curveCardinalClosed, null)([[0, 1], [1, 3], [2, 1], [3, 3]]), l([[0, 1], [1, 3], [2, 1], [3, 3]])); + test.equal(shape.line().curve(shape.curveCardinalClosed, undefined)([[0, 1], [1, 3], [2, 1], [3, 3]]), l([[0, 1], [1, 3], [2, 1], [3, 3]])); test.end(); }); -tape("line.interpolate(catmullRom) uses a default alpha of zero", function(test) { - var l = shape.line().interpolate(shape.catmullRom, 0); - test.equal(shape.line().interpolate(shape.catmullRom)([[0, 1], [1, 3], [2, 1], [3, 3]]), l([[0, 1], [1, 3], [2, 1], [3, 3]])); - test.equal(shape.line().interpolate(shape.catmullRom, null)([[0, 1], [1, 3], [2, 1], [3, 3]]), l([[0, 1], [1, 3], [2, 1], [3, 3]])); - test.equal(shape.line().interpolate(shape.catmullRom, undefined)([[0, 1], [1, 3], [2, 1], [3, 3]]), l([[0, 1], [1, 3], [2, 1], [3, 3]])); +tape("line.curve(curveCatmullRom) uses a default alpha of zero", function(test) { + var l = shape.line().curve(shape.curveCatmullRom, 0); + test.equal(shape.line().curve(shape.curveCatmullRom)([[0, 1], [1, 3], [2, 1], [3, 3]]), l([[0, 1], [1, 3], [2, 1], [3, 3]])); + test.equal(shape.line().curve(shape.curveCatmullRom, null)([[0, 1], [1, 3], [2, 1], [3, 3]]), l([[0, 1], [1, 3], [2, 1], [3, 3]])); + test.equal(shape.line().curve(shape.curveCatmullRom, undefined)([[0, 1], [1, 3], [2, 1], [3, 3]]), l([[0, 1], [1, 3], [2, 1], [3, 3]])); test.end(); }); -tape("line.interpolate(catmullRomOpen) uses a default alpha of zero", function(test) { - var l = shape.line().interpolate(shape.catmullRomOpen, 0); - test.equal(shape.line().interpolate(shape.catmullRomOpen)([[0, 1], [1, 3], [2, 1], [3, 3]]), l([[0, 1], [1, 3], [2, 1], [3, 3]])); - test.equal(shape.line().interpolate(shape.catmullRomOpen, null)([[0, 1], [1, 3], [2, 1], [3, 3]]), l([[0, 1], [1, 3], [2, 1], [3, 3]])); - test.equal(shape.line().interpolate(shape.catmullRomOpen, undefined)([[0, 1], [1, 3], [2, 1], [3, 3]]), l([[0, 1], [1, 3], [2, 1], [3, 3]])); +tape("line.curve(curveCatmullRomOpen) uses a default alpha of zero", function(test) { + var l = shape.line().curve(shape.curveCatmullRomOpen, 0); + test.equal(shape.line().curve(shape.curveCatmullRomOpen)([[0, 1], [1, 3], [2, 1], [3, 3]]), l([[0, 1], [1, 3], [2, 1], [3, 3]])); + test.equal(shape.line().curve(shape.curveCatmullRomOpen, null)([[0, 1], [1, 3], [2, 1], [3, 3]]), l([[0, 1], [1, 3], [2, 1], [3, 3]])); + test.equal(shape.line().curve(shape.curveCatmullRomOpen, undefined)([[0, 1], [1, 3], [2, 1], [3, 3]]), l([[0, 1], [1, 3], [2, 1], [3, 3]])); test.end(); }); -tape("line.interpolate(catmullRomClosed) uses a default alpha of zero", function(test) { - var l = shape.line().interpolate(shape.catmullRomClosed, 0); - test.equal(shape.line().interpolate(shape.catmullRomClosed)([[0, 1], [1, 3], [2, 1], [3, 3]]), l([[0, 1], [1, 3], [2, 1], [3, 3]])); - test.equal(shape.line().interpolate(shape.catmullRomClosed, null)([[0, 1], [1, 3], [2, 1], [3, 3]]), l([[0, 1], [1, 3], [2, 1], [3, 3]])); - test.equal(shape.line().interpolate(shape.catmullRomClosed, undefined)([[0, 1], [1, 3], [2, 1], [3, 3]]), l([[0, 1], [1, 3], [2, 1], [3, 3]])); +tape("line.curve(curveCatmullRomClosed) uses a default alpha of zero", function(test) { + var l = shape.line().curve(shape.curveCatmullRomClosed, 0); + test.equal(shape.line().curve(shape.curveCatmullRomClosed)([[0, 1], [1, 3], [2, 1], [3, 3]]), l([[0, 1], [1, 3], [2, 1], [3, 3]])); + test.equal(shape.line().curve(shape.curveCatmullRomClosed, null)([[0, 1], [1, 3], [2, 1], [3, 3]]), l([[0, 1], [1, 3], [2, 1], [3, 3]])); + test.equal(shape.line().curve(shape.curveCatmullRomClosed, undefined)([[0, 1], [1, 3], [2, 1], [3, 3]]), l([[0, 1], [1, 3], [2, 1], [3, 3]])); test.end(); }); -tape("line.interpolate(bundle) uses a default beta of one", function(test) { - var l = shape.line().interpolate(shape.bundle, 1); - test.equal(shape.line().interpolate(shape.bundle)([[0, 1], [1, 3], [2, 1], [3, 3]]), l([[0, 1], [1, 3], [2, 1], [3, 3]])); - test.equal(shape.line().interpolate(shape.bundle, null)([[0, 1], [1, 3], [2, 1], [3, 3]]), l([[0, 1], [1, 3], [2, 1], [3, 3]])); - test.equal(shape.line().interpolate(shape.bundle, undefined)([[0, 1], [1, 3], [2, 1], [3, 3]]), l([[0, 1], [1, 3], [2, 1], [3, 3]])); +tape("line.curve(curveBundle) uses a default beta of one", function(test) { + var l = shape.line().curve(shape.curveBundle, 1); + test.equal(shape.line().curve(shape.curveBundle)([[0, 1], [1, 3], [2, 1], [3, 3]]), l([[0, 1], [1, 3], [2, 1], [3, 3]])); + test.equal(shape.line().curve(shape.curveBundle, null)([[0, 1], [1, 3], [2, 1], [3, 3]]), l([[0, 1], [1, 3], [2, 1], [3, 3]])); + test.equal(shape.line().curve(shape.curveBundle, undefined)([[0, 1], [1, 3], [2, 1], [3, 3]]), l([[0, 1], [1, 3], [2, 1], [3, 3]])); test.end(); }); diff --git a/test/symbol-test.js b/test/symbol-test.js index bdc5368..2a8ff6b 100644 --- a/test/symbol-test.js +++ b/test/symbol-test.js @@ -3,7 +3,7 @@ var tape = require("tape"), tape("symbol() returns a default symbol shape", function(test) { var s = shape.symbol(); - test.equal(s.type()(), shape.circle); + test.equal(s.type()(), shape.symbolCircle); test.equal(s.size()(), 64); test.equal(s.context(), null); test.equal(s(), "M4.51351666838205,0A4.51351666838205,4.51351666838205,0,1,1,-4.51351666838205,0A4.51351666838205,4.51351666838205,0,1,1,4.51351666838205,0"); @@ -31,37 +31,37 @@ tape("symbol.size(size) observes the specified size constant", function(test) { test.end(); }); -tape("symbol.type(cross) generates the expected path", function(test) { - var s = shape.symbol().type(shape.cross).size(function(d) { return d; }); +tape("symbol.type(symbolCross) generates the expected path", function(test) { + var s = shape.symbol().type(shape.symbolCross).size(function(d) { return d; }); test.equal(s(0), "M0,0L0,0L0,0L0,0L0,0L0,0L0,0L0,0L0,0L0,0L0,0L0,0Z"); test.equal(s(20), "M-3,-1L-1,-1L-1,-3L1,-3L1,-1L3,-1L3,1L1,1L1,3L-1,3L-1,1L-3,1Z"); test.end(); }); -tape("symbol.type(diamond) generates the expected path", function(test) { - var s = shape.symbol().type(shape.diamond).size(function(d) { return d; }); +tape("symbol.type(symbolDiamond) generates the expected path", function(test) { + var s = shape.symbol().type(shape.symbolDiamond).size(function(d) { return d; }); test.equal(s(0), "M0,0L0,0L0,0L0,0Z"); test.equal(s(10), "M0,-2.942830956382712L1.6990442448471226,0L0,2.942830956382712L-1.6990442448471226,0Z"); test.end(); }); -tape("symbol.type(square) generates the expected path", function(test) { - var s = shape.symbol().type(shape.square).size(function(d) { return d; }); +tape("symbol.type(symbolSquare) generates the expected path", function(test) { + var s = shape.symbol().type(shape.symbolSquare).size(function(d) { return d; }); test.equal(s(0), "M0,0h0v0h0Z"); test.equal(s(4), "M-1,-1h2v2h-2Z"); test.equal(s(16), "M-2,-2h4v4h-4Z"); test.end(); }); -tape("symbol.type(triangleUp) generates the expected path", function(test) { - var s = shape.symbol().type(shape.triangleDown).size(function(d) { return d; }); +tape("symbol.type(symbolTriangleUp) generates the expected path", function(test) { + var s = shape.symbol().type(shape.symbolTriangleDown).size(function(d) { return d; }); test.equal(s(0), "M0,0L0,0L0,0Z"); test.equal(s(10), "M0,2.0808957251439084L2.4028114141347543,-2.0808957251439084L-2.4028114141347543,-2.0808957251439084Z"); test.end(); }); -tape("symbol.type(triangleDown) generates the expected path", function(test) { - var s = shape.symbol().type(shape.triangleUp).size(function(d) { return d; }); +tape("symbol.type(symbolTriangleDown) generates the expected path", function(test) { + var s = shape.symbol().type(shape.symbolTriangleUp).size(function(d) { return d; }); test.equal(s(0), "M0,0L0,0L0,0Z"); test.equal(s(10), "M0,-2.0808957251439084L2.4028114141347543,2.0808957251439084L-2.4028114141347543,2.0808957251439084Z"); test.end(); diff --git a/test/symbolTypes-test.js b/test/symbolTypes-test.js index f3786dd..c29c5c1 100644 --- a/test/symbolTypes-test.js +++ b/test/symbolTypes-test.js @@ -3,12 +3,12 @@ var tape = require("tape"), tape("symbolTypes is the array of symbol types", function(test) { test.deepEqual(shape.symbolTypes, [ - shape.circle, - shape.cross, - shape.diamond, - shape.square, - shape.triangleDown, - shape.triangleUp + shape.symbolCircle, + shape.symbolCross, + shape.symbolDiamond, + shape.symbolSquare, + shape.symbolTriangleDown, + shape.symbolTriangleUp ]); test.end(); }); From fd6f6b5697eed05ab32b69107c18740a88e4a538 Mon Sep 17 00:00:00 2001 From: Mike Bostock Date: Thu, 19 Nov 2015 12:50:42 -0800 Subject: [PATCH 15/15] Update README. --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 882fcc5..db7ae75 100644 --- a/README.md +++ b/README.md @@ -90,7 +90,7 @@ If you use NPM, `npm install d3-shape`. Otherwise, download the [latest release] ### Curves -Curves are typically not used directly, instead implementing paths for [lines](#lines) and [areas](#areas). See [*line*.curve](#line_curve) and [*area*.curve](#area_curve). +Curves are typically not used directly, instead implementing paths for [lines](#lines) and [areas](#areas); they are passed to [*line*.curve](#line_curve) and [*area*.curve](#area_curve). … @@ -204,7 +204,7 @@ Note: not implemented by closed curves, such as cur ### Symbol Types -Symbol types are typically not used directly, instead implementing paths for [symbols](#symbols). See [*symbol*.type](#symbol_type). +Symbol types are typically not used directly, instead implementing paths for [symbols](#symbols); they are passed to [*symbol*.type](#symbol_type). …