@dfnivo/sankey
Version:
<a href="https://nivo.rocks"><img alt="nivo" src="https://raw.githubusercontent.com/plouc/nivo/master/nivo.png" width="216" height="68"/></a>
107 lines (106 loc) • 6.3 kB
JavaScript
import { line, curveMonotoneX, curveMonotoneY } from "d3-shape";
export var sankeyLinkHorizontal = function() {
var lineGenerator = line().curve(curveMonotoneX);
return function(link, contract) {
var target = link.target;
var source = link.source;
var thickness = Math.max(1, link.thickness - contract * 2);
var halfThickness = thickness / 2;
var _target_x0, _source_x1;
var linkLength = ((_target_x0 = target.x0) !== null && _target_x0 !== void 0 ? _target_x0 : 0) - ((_source_x1 = source.x1) !== null && _source_x1 !== void 0 ? _source_x1 : 0);
var padLength = linkLength * 0.12;
var _source_x11, _link_pos0, _source_x12, _link_pos01, _target_x01, _link_pos1, _target_x02, _link_pos11, _target_x03, _link_pos12, _target_x04, _link_pos13, _source_x13, _link_pos02, _source_x14, _link_pos03, _source_x15, _link_pos04;
var dots = [
[
(_source_x11 = source.x1) !== null && _source_x11 !== void 0 ? _source_x11 : 0,
((_link_pos0 = link.pos0) !== null && _link_pos0 !== void 0 ? _link_pos0 : 0) - halfThickness
],
[
((_source_x12 = source.x1) !== null && _source_x12 !== void 0 ? _source_x12 : 0) + padLength,
((_link_pos01 = link.pos0) !== null && _link_pos01 !== void 0 ? _link_pos01 : 0) - halfThickness
],
[
((_target_x01 = target.x0) !== null && _target_x01 !== void 0 ? _target_x01 : 0) - padLength,
((_link_pos1 = link.pos1) !== null && _link_pos1 !== void 0 ? _link_pos1 : 0) - halfThickness
],
[
(_target_x02 = target.x0) !== null && _target_x02 !== void 0 ? _target_x02 : 0,
((_link_pos11 = link.pos1) !== null && _link_pos11 !== void 0 ? _link_pos11 : 0) - halfThickness
],
[
(_target_x03 = target.x0) !== null && _target_x03 !== void 0 ? _target_x03 : 0,
((_link_pos12 = link.pos1) !== null && _link_pos12 !== void 0 ? _link_pos12 : 0) + halfThickness
],
[
((_target_x04 = target.x0) !== null && _target_x04 !== void 0 ? _target_x04 : 0) - padLength,
((_link_pos13 = link.pos1) !== null && _link_pos13 !== void 0 ? _link_pos13 : 0) + halfThickness
],
[
((_source_x13 = source.x1) !== null && _source_x13 !== void 0 ? _source_x13 : 0) + padLength,
((_link_pos02 = link.pos0) !== null && _link_pos02 !== void 0 ? _link_pos02 : 0) + halfThickness
],
[
(_source_x14 = source.x1) !== null && _source_x14 !== void 0 ? _source_x14 : 0,
((_link_pos03 = link.pos0) !== null && _link_pos03 !== void 0 ? _link_pos03 : 0) + halfThickness
],
[
(_source_x15 = source.x1) !== null && _source_x15 !== void 0 ? _source_x15 : 0,
((_link_pos04 = link.pos0) !== null && _link_pos04 !== void 0 ? _link_pos04 : 0) - halfThickness
]
];
return lineGenerator(dots) + "Z";
};
};
export var sankeyLinkVertical = function() {
var lineGenerator = line().curve(curveMonotoneY);
return function(link, contract) {
var target = link.target;
var source = link.source;
var thickness = Math.max(1, link.thickness - contract * 2);
var halfThickness = thickness / 2;
var _target_y0, _source_y1;
var linkLength = ((_target_y0 = target.y0) !== null && _target_y0 !== void 0 ? _target_y0 : 0) - ((_source_y1 = source.y1) !== null && _source_y1 !== void 0 ? _source_y1 : 0);
var padLength = linkLength * 0.12;
var _link_pos0, _source_y11, _link_pos01, _source_y12, _link_pos1, _target_y01, _link_pos11, _target_y02, _link_pos12, _target_y03, _link_pos13, _target_y04, _link_pos02, _source_y13, _link_pos03, _source_y14, _link_pos04, _source_y15;
var dots = [
[
((_link_pos0 = link.pos0) !== null && _link_pos0 !== void 0 ? _link_pos0 : 0) + halfThickness,
(_source_y11 = source.y1) !== null && _source_y11 !== void 0 ? _source_y11 : 0
],
[
((_link_pos01 = link.pos0) !== null && _link_pos01 !== void 0 ? _link_pos01 : 0) + halfThickness,
((_source_y12 = source.y1) !== null && _source_y12 !== void 0 ? _source_y12 : 0) + padLength
],
[
((_link_pos1 = link.pos1) !== null && _link_pos1 !== void 0 ? _link_pos1 : 0) + halfThickness,
((_target_y01 = target.y0) !== null && _target_y01 !== void 0 ? _target_y01 : 0) - padLength
],
[
((_link_pos11 = link.pos1) !== null && _link_pos11 !== void 0 ? _link_pos11 : 0) + halfThickness,
(_target_y02 = target.y0) !== null && _target_y02 !== void 0 ? _target_y02 : 0
],
[
((_link_pos12 = link.pos1) !== null && _link_pos12 !== void 0 ? _link_pos12 : 0) - halfThickness,
(_target_y03 = target.y0) !== null && _target_y03 !== void 0 ? _target_y03 : 0
],
[
((_link_pos13 = link.pos1) !== null && _link_pos13 !== void 0 ? _link_pos13 : 0) - halfThickness,
((_target_y04 = target.y0) !== null && _target_y04 !== void 0 ? _target_y04 : 0) - padLength
],
[
((_link_pos02 = link.pos0) !== null && _link_pos02 !== void 0 ? _link_pos02 : 0) - halfThickness,
((_source_y13 = source.y1) !== null && _source_y13 !== void 0 ? _source_y13 : 0) + padLength
],
[
((_link_pos03 = link.pos0) !== null && _link_pos03 !== void 0 ? _link_pos03 : 0) - halfThickness,
(_source_y14 = source.y1) !== null && _source_y14 !== void 0 ? _source_y14 : 0
],
[
((_link_pos04 = link.pos0) !== null && _link_pos04 !== void 0 ? _link_pos04 : 0) + halfThickness,
(_source_y15 = source.y1) !== null && _source_y15 !== void 0 ? _source_y15 : 0
]
];
return lineGenerator(dots) + "Z";
};
};
//# sourceMappingURL=links.js.map