function collapsibleIndent(data, options = {}) {
const {
duration = 300,
radius = 6,
height = 1500,
width = 1500,
minHeight = 20,
boxSize = 9.5,
ease = d3.easeQuadInOut,
marginLeft = Math.round(boxSize/2)+1,
marginRight = 120,
marginTop = 10,
marginBottom = 10,
} = options;
let plus = {shapeFill: "black", shapeStroke: "black", textFill:"white", text: "+"}
let minus = {shapeFill: "white", shapeStroke: "black", textFill:"black", text: "−"}
let tree = d3.tree()
.nodeSize([lineSpacing, indentSpacing])
let root = d3.hierarchy(taskindex);
root.x0 = 0;
root.y0 = 0;
root.descendants().forEach((d, i) => {
d.id = i;
d._children = d.children;
if (d.depth && d.data.name.length !== 7) d.children = null;
});
let index = -1;
root.eachBefore(function(n) {++index})
const svg = d3.create("svg")
.attr("width", width + margin.left + margin.right)
.attr("height", height + margin.top + margin.bottom)
.style("font", "10px sans-serif")
.style("user-select", "none");
const gLink = svg.append("g")
.attr("fill", "none")
.attr("stroke", "#AAA")
.attr("stroke-width", .75);
const gNode = svg.append("g")
.attr("cursor", "pointer")
.attr("pointer-events", "all");
let indexLast
function update(source) {
const nodes = root.descendants().reverse();
const links = root.links();
tree(root);
index = -1;
root.eachBefore(function(n) {
n.x = ++index * lineSpacing;
n.y = n.depth * indentSpacing;
});
const height = Math.max(minHeight, index * lineSpacing + marginTop + marginBottom );
svg.transition().delay(indexLast<index ? 0 : duration).duration(0)
.attr("viewBox", [-marginLeft, - marginTop, width, height])
const node = gNode.selectAll("g")
.data(nodes, d => d.id);
const nodeEnter = node.enter().append("g")
.attr("transform", d => `translate(${d.y},${source.x0})`)
.attr("fill-opacity", 0)
.attr("stroke-opacity", 0)
.on("click", (event, d) => {
d.children = d.children ? null : d._children;
update(d);
charge
.attr("fill", d => d._children ? ( d.children ? minus.textFill : plus.textFill ) : "none")
.text(d => d._children ? ( d.children ? minus.text : plus.text ) : "");
box.attr("fill", d => d._children ? ( d.children ? minus.shapeFill : plus.shapeFill ) : "none")
});
let box = nodeEnter.append("rect")
.attr("width", boxSize)
.attr("height", boxSize)
.attr("x", -boxSize/2)
.attr("y", -boxSize/2)
.attr("fill", d => d._children ? ( d.children ? minus.shapeFill : plus.shapeFill ) : "none")
.attr("stroke", d => d._children ? "black" : "none")
.attr("stroke-width", .5);
let charge = nodeEnter.append("text")
.attr("x", 0 )
.attr("text-anchor", "middle")
.attr("alignment-baseline", "central")
.attr("fill", d => d._children ? ( d.children ? minus.textFill : plus.textFill ) : "none")
.text(d => d._children ? ( d.children ? "−" : "+" ) : "");
let image = nodeEnter.append("image")
.attr("x", 10+boxSize/2)
.attr('y', -icon_size / 2 - boxSize / 2)
.attr("dy", -icon_size)
.attr("xlink:href", function(d) { return (prefix + shape + d.data.icon + ".svg");})
.attr("width", function(d) { return icon_size + 5;})
.attr("height", function(d) { return icon_size + 5;});
let label = nodeEnter.append("text")
.attr("x", icon_size+20+boxSize/2)
.attr("text-anchor", "start")
.attr("dy", "0.32em")
.text(d => d.data.name);
const nodeUpdate = node.merge(nodeEnter).transition().duration(duration).ease(ease)
.attr("transform", d => `translate(${d.y},${d.x})`)
.attr("fill-opacity", 1)
.attr("stroke-opacity", 1)
const nodeExit = node.exit().transition().duration(duration).ease(ease).remove()
.attr("transform", d => `translate(${d.y},${source.x})`)
.attr("fill-opacity", 0)
.attr("stroke-opacity", 0);
const link = gLink.selectAll("path")
.data(links, d => d.target.id);
const linkEnter = link.enter().append("path")
.attr("stroke-opacity", 0)
.attr("d", d => makeLink([d.source.y,source.x] , [d.target.y + (d.target._children ? 0 : boxSize/2 ), source.x] , radius) );
link.merge(linkEnter).transition().duration(duration).ease(ease)
.attr("stroke-opacity", 1)
.attr("d", d => makeLink([d.source.y,d.source.x] , [d.target.y + (d.target._children ? 0 : boxSize/2 ), d.target.x] , radius));
link.exit().transition().duration(duration).ease(ease).remove()
.attr("stroke-opacity", 0)
.attr("d", d => makeLink([d.source.y, source.x] , [d.target.y + (d.target._children ? 0 : boxSize/2 ), source.x] , radius) );
root.eachBefore(d => {
d.x0 = d.x;
d.y0 = d.y;
});
indexLast = index
}
update(root);
return svg.node();
}