source: node_modules/d3-shape/src/link.js@ e4c61dd

Last change on this file since e4c61dd was e4c61dd, checked in by istevanoska <ilinastevanoska@…>, 6 months ago

Prototype 1.1

  • Property mode set to 100644
File size: 1.8 KB
Line 
1import {slice} from "./array.js";
2import constant from "./constant.js";
3import {bumpX, bumpY, bumpRadial} from "./curve/bump.js";
4import {withPath} from "./path.js";
5import {x as pointX, y as pointY} from "./point.js";
6
7function linkSource(d) {
8 return d.source;
9}
10
11function linkTarget(d) {
12 return d.target;
13}
14
15export function link(curve) {
16 let source = linkSource,
17 target = linkTarget,
18 x = pointX,
19 y = pointY,
20 context = null,
21 output = null,
22 path = withPath(link);
23
24 function link() {
25 let buffer;
26 const argv = slice.call(arguments);
27 const s = source.apply(this, argv);
28 const t = target.apply(this, argv);
29 if (context == null) output = curve(buffer = path());
30 output.lineStart();
31 argv[0] = s, output.point(+x.apply(this, argv), +y.apply(this, argv));
32 argv[0] = t, output.point(+x.apply(this, argv), +y.apply(this, argv));
33 output.lineEnd();
34 if (buffer) return output = null, buffer + "" || null;
35 }
36
37 link.source = function(_) {
38 return arguments.length ? (source = _, link) : source;
39 };
40
41 link.target = function(_) {
42 return arguments.length ? (target = _, link) : target;
43 };
44
45 link.x = function(_) {
46 return arguments.length ? (x = typeof _ === "function" ? _ : constant(+_), link) : x;
47 };
48
49 link.y = function(_) {
50 return arguments.length ? (y = typeof _ === "function" ? _ : constant(+_), link) : y;
51 };
52
53 link.context = function(_) {
54 return arguments.length ? (_ == null ? context = output = null : output = curve(context = _), link) : context;
55 };
56
57 return link;
58}
59
60export function linkHorizontal() {
61 return link(bumpX);
62}
63
64export function linkVertical() {
65 return link(bumpY);
66}
67
68export function linkRadial() {
69 const l = link(bumpRadial);
70 l.angle = l.x, delete l.x;
71 l.radius = l.y, delete l.y;
72 return l;
73}
Note: See TracBrowser for help on using the repository browser.