viewof icicle = {
const root = partition(data);
const svg = d3.create("svg");
const element = svg.node();
element.value = { sequence: [], percentage: 0.0 };
svg
.attr("viewBox", `0 0 ${width} ${height}`)
.style("font", "12px sans-serif");
svg
.append("rect")
.attr("width", width)
.attr("height", height)
.attr("fill", "none");
const segment = svg
.append("g")
.attr("transform", d =>
narrow ? `translate(${-root.y1}, 0)` : `translate(0, ${-root.y1})`
)
.selectAll("rect")
.data(
root.descendants().filter(d => {
return d.depth && segmentWidth(d) >= 0.1;
})
)
.join("rect")
.attr("fill", d => color(d.data.name))
.attr("x", segmentX)
.attr("y", segmentY)
.attr("width", segmentWidth)
.attr("height", segmentHeight)
.on("mouseenter", (event, d) => {
const sequence = d
.ancestors()
.reverse()
.slice(1);
segment.attr("fill-opacity", node =>
sequence.indexOf(node) >= 0 ? 1.0 : 0.3
);
const percentage = ((100 * d.value) / root.value).toPrecision(3);
element.value = { sequence, percentage };
element.dispatchEvent(new CustomEvent("input"));
});
svg.on("mouseleave", () => {
segment.attr("fill-opacity", 1);
element.value = { sequence: [], percentage: 0.0 };
element.dispatchEvent(new CustomEvent("input"));
});
return element;
}