@visx/shape
Version:
visx shape
78 lines (77 loc) • 2.02 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = LinkRadialCurve;
exports.pathRadialCurve = pathRadialCurve;
var _classnames = _interopRequireDefault(require("classnames"));
var _d3Path = require("@visx/vendor/d3-path");
var _accessors = require("../../../util/accessors");
var _jsxRuntime = require("react/jsx-runtime");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
function pathRadialCurve(_ref) {
let {
source,
target,
x,
y,
percent
} = _ref;
return link => {
const sourceData = source(link);
const targetData = target(link);
const sa = x(sourceData) - Math.PI / 2;
const sr = y(sourceData);
const ta = x(targetData) - Math.PI / 2;
const tr = y(targetData);
const sc = Math.cos(sa);
const ss = Math.sin(sa);
const tc = Math.cos(ta);
const ts = Math.sin(ta);
const sx = sr * sc;
const sy = sr * ss;
const tx = tr * tc;
const ty = tr * ts;
const dx = tx - sx;
const dy = ty - sy;
const ix = percent * (dx + dy);
const iy = percent * (dy - dx);
const path = (0, _d3Path.path)();
path.moveTo(sx, sy);
path.bezierCurveTo(sx + ix, sy + iy, tx + iy, ty - ix, tx, ty);
return path.toString();
};
}
function LinkRadialCurve(_ref2) {
let {
className,
children,
data,
innerRef,
path,
percent = 0.2,
x = _accessors.getX,
y = _accessors.getY,
source = _accessors.getSource,
target = _accessors.getTarget,
...restProps
} = _ref2;
const pathGen = path || pathRadialCurve({
source,
target,
x,
y,
percent
});
if (children) return /*#__PURE__*/(0, _jsxRuntime.jsx)(_jsxRuntime.Fragment, {
children: children({
path: pathGen
})
});
return /*#__PURE__*/(0, _jsxRuntime.jsx)("path", {
ref: innerRef,
className: (0, _classnames.default)('visx-link visx-link-radial-curve', className),
d: pathGen(data) || '',
...restProps
});
}