Skip to content

Commit

Permalink
bumpRadial could be used with multiple points (#193)
Browse files Browse the repository at this point in the history
* 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 <mbostock@gmail.com>
  • Loading branch information
Fil and mbostock authored Dec 20, 2022
1 parent 6f05305 commit 8fe68eb
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
5 changes: 3 additions & 2 deletions src/curve/bump.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -58,6 +58,7 @@ class BumpRadial {
this._context.moveTo(...p0);
this._context.bezierCurveTo(...p1, ...p2, ...p3);
}
this._x0 = x, this._y0 = y;
}
}

Expand Down
12 changes: 11 additions & 1 deletion test/link-test.js
Original file line number Diff line number Diff line change
@@ -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";

Expand Down Expand Up @@ -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");
});

0 comments on commit 8fe68eb

Please sign in to comment.