From 5eaa0f6955810497fa5ee0d2c4530f747506141a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philippe=20Rivi=C3=A8re?= <fil@rezo.net> Date: Mon, 21 Feb 2022 10:21:40 +0100 Subject: [PATCH 1/3] bumpRadial could be used with multiple points fixes #191 since bumpRadial is not exported, a visual test is available at https://observablehq.com/@d3/bumpradial-191 --- src/curve/bump.js | 6 +++--- test/link-test.js | 12 +++++++++++- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/curve/bump.js b/src/curve/bump.js index 8c5cab1..cf8d47b 100644 --- a/src/curve/bump.js +++ b/src/curve/bump.js @@ -48,9 +48,7 @@ class BumpRadial { lineEnd() {} point(x, y) { x = +x, y = +y; - if (this._point++ === 0) { - this._x0 = x, this._y0 = y; - } else { + if (this._point++ > 0) { const p0 = pointRadial(this._x0, this._y0); const p1 = pointRadial(this._x0, this._y0 = (this._y0 + y) / 2); const p2 = pointRadial(x, this._y0); @@ -58,6 +56,8 @@ class BumpRadial { this._context.moveTo(...p0); this._context.bezierCurveTo(...p1, ...p2, ...p3); } + this._x0 = x; + this._y0 = y; } } diff --git a/test/link-test.js b/test/link-test.js index df93a34..4837fa2 100644 --- a/test/link-test.js +++ b/test/link-test.js @@ -1,6 +1,6 @@ import assert from "assert"; import {path} from "d3-path"; -import {link, linkHorizontal, linkVertical} from "../src/index.js"; +import {link, linkHorizontal, linkVertical, linkRadial} from "../src/index.js"; import {curveLinear, curveBumpX, curveBumpY} from "../src/index.js"; import {assertPathEqual} from "./asserts.js"; @@ -112,3 +112,13 @@ it("link.context(context) sets the context", () => { assert.strictEqual(l({source: [0, 1], target: [2, 3]}), undefined); assertPathEqual(p, "M0,1L2,3"); }); + +it("linkRadial() works as expected", () => { + const l = linkRadial(), l2 = link(); + assert.strictEqual(l.source(), l2.source()); + assert.strictEqual(l.target(), l2.target()); + assert.strictEqual(l.angle(), l2.x()); + assert.strictEqual(l.radius(), l2.y()); + assert.strictEqual(l.context(), l2.context()); + assertPathEqual(l({source: [0, 1], target: [Math.PI/2, 3]}), "M0,-1C0,-2,2,0,3,0"); +}); From fd229246e8675ce8b686973b232fc1364427f86d Mon Sep 17 00:00:00 2001 From: Mike Bostock <mbostock@gmail.com> Date: Tue, 20 Dec 2022 15:01:18 -0800 Subject: [PATCH 2/3] only increment once --- src/curve/bump.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/curve/bump.js b/src/curve/bump.js index cf8d47b..fec3b69 100644 --- a/src/curve/bump.js +++ b/src/curve/bump.js @@ -48,7 +48,9 @@ class BumpRadial { lineEnd() {} point(x, y) { x = +x, y = +y; - if (this._point++ > 0) { + if (this._point === 0) { + this._point = 1; + } else { const p0 = pointRadial(this._x0, this._y0); const p1 = pointRadial(this._x0, this._y0 = (this._y0 + y) / 2); const p2 = pointRadial(x, this._y0); From 8ffe47119cb43646a72994cb393b840f737a3730 Mon Sep 17 00:00:00 2001 From: Mike Bostock <mbostock@gmail.com> Date: Tue, 20 Dec 2022 15:01:45 -0800 Subject: [PATCH 3/3] style --- src/curve/bump.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/curve/bump.js b/src/curve/bump.js index fec3b69..9b960cf 100644 --- a/src/curve/bump.js +++ b/src/curve/bump.js @@ -58,8 +58,7 @@ class BumpRadial { this._context.moveTo(...p0); this._context.bezierCurveTo(...p1, ...p2, ...p3); } - this._x0 = x; - this._y0 = y; + this._x0 = x, this._y0 = y; } }