From 8fe68eb9046d10ef06f52de632d775654ddb5cca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philippe=20Rivi=C3=A8re?= Date: Wed, 21 Dec 2022 00:02:36 +0100 Subject: [PATCH] bumpRadial could be used with multiple points (#193) * 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 * only increment once * style Co-authored-by: Mike Bostock --- src/curve/bump.js | 5 +++-- test/link-test.js | 12 +++++++++++- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/curve/bump.js b/src/curve/bump.js index 8c5cab1..9b960cf 100644 --- a/src/curve/bump.js +++ b/src/curve/bump.js @@ -48,8 +48,8 @@ class BumpRadial { lineEnd() {} point(x, y) { x = +x, y = +y; - if (this._point++ === 0) { - this._x0 = x, this._y0 = y; + 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); @@ -58,6 +58,7 @@ 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 d7602c1..2292e98 100644 --- a/test/link-test.js +++ b/test/link-test.js @@ -1,6 +1,6 @@ import assert from "assert"; import {pathRound} 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, Math.E], target: [Math.PI, 3]}), undefined); assert.strictEqual(p + "", "M0,2.718282L3.141593,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"); +});