{
const domNode = DOM.svg(700, 300);
const svg = SVG.SVG(domNode);
const g = svg.group().transform({
translateY: 150
});
const rootHeight = 200;
const rootWidth = 400;
const straightPincher = (x) => 1;
const hornPincher = (x) => hornSlope + x * (1 - hornSlope);
const zeroShifter = (x) => 0;
function drawNode(
node,
shifter,
pincher,
parentPosition = 0,
position = 0,
depth = 0
) {
const segmentCount = 100;
const newPincher = node.shared
? pincher
: (x) =>
pincher(x) *
growthStep(
depth,
depth + growthPeriod,
x,
depth == 0 ? rootTipSize / hornPincher(0) : 0
);
const yf = (x, side) =>
side * newPincher(x) * node.fraction + position - shifter(x);
const p = d3.path();
p.moveTo(0, (yf(0, 1) * rootHeight) / 2);
for (let i = 1; i <= segmentCount; i++) {
const x = i / segmentCount;
p.lineTo(x * rootWidth, (yf(x, 1) * rootHeight) / 2);
}
for (let i = segmentCount; i >= 0; i--) {
const x = i / segmentCount;
p.lineTo(x * rootWidth, (yf(x, -1) * rootHeight) / 2);
}
const clonePath = g.path(p.toString());
if (typeof node.driftTo === "number") {
clonePath.fill(
svg
.gradient("linear", function (add) {
})
.from(depth, 0)
.to(1, 0)
);
} else {
clonePath.fill(node.color);
}
clonePath.addClass("clone");
clonePath.data("clone", node.data);
const positions = computeChildPositions(node);
for (let i = 0; i < node.children.length; i++) {
const childNode = node.children[i];
console.log(`id: ${childNode.id}: ${positions[i] * 2 - position}`);
drawNode(
childNode,
(y) => positions[i] * 2 * (1 - newPincher(y)) + shifter(y),
newPincher,
position,
position + positions[i] * 2,
depth + depthStep
);
}
}
drawNode(tree, zeroShifter, hornPincher, 0);
return domNode;
}