Skip to content

Commit 5eaa0f6

Browse files
committed
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
1 parent 289b6ca commit 5eaa0f6

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

src/curve/bump.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -48,16 +48,16 @@ class BumpRadial {
4848
lineEnd() {}
4949
point(x, y) {
5050
x = +x, y = +y;
51-
if (this._point++ === 0) {
52-
this._x0 = x, this._y0 = y;
53-
} else {
51+
if (this._point++ > 0) {
5452
const p0 = pointRadial(this._x0, this._y0);
5553
const p1 = pointRadial(this._x0, this._y0 = (this._y0 + y) / 2);
5654
const p2 = pointRadial(x, this._y0);
5755
const p3 = pointRadial(x, y);
5856
this._context.moveTo(...p0);
5957
this._context.bezierCurveTo(...p1, ...p2, ...p3);
6058
}
59+
this._x0 = x;
60+
this._y0 = y;
6161
}
6262
}
6363

test/link-test.js

+11-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import assert from "assert";
22
import {path} from "d3-path";
3-
import {link, linkHorizontal, linkVertical} from "../src/index.js";
3+
import {link, linkHorizontal, linkVertical, linkRadial} from "../src/index.js";
44
import {curveLinear, curveBumpX, curveBumpY} from "../src/index.js";
55
import {assertPathEqual} from "./asserts.js";
66

@@ -112,3 +112,13 @@ it("link.context(context) sets the context", () => {
112112
assert.strictEqual(l({source: [0, 1], target: [2, 3]}), undefined);
113113
assertPathEqual(p, "M0,1L2,3");
114114
});
115+
116+
it("linkRadial() works as expected", () => {
117+
const l = linkRadial(), l2 = link();
118+
assert.strictEqual(l.source(), l2.source());
119+
assert.strictEqual(l.target(), l2.target());
120+
assert.strictEqual(l.angle(), l2.x());
121+
assert.strictEqual(l.radius(), l2.y());
122+
assert.strictEqual(l.context(), l2.context());
123+
assertPathEqual(l({source: [0, 1], target: [Math.PI/2, 3]}), "M0,-1C0,-2,2,0,3,0");
124+
});

0 commit comments

Comments
 (0)