I am working with this icicle visual on D3 Observable. I need to add a tooltip, so that it works faster and looks better than native browser version.
I tried this:
var tooltip = d3.select("body")
.append("div")
.style("opacity", 0)
.attr("class", "tooltip")
.style("background-color", "white")
.style("border", "solid")
.style("border-width", "1px")
.style("border-radius", "5px")
.style("padding", "10px");
var mouseover = function(d) {
tooltip
.style("opacity", 1)
};
var mousemove = function(d) {
tooltip
.html("hello")
.style("left", (d3.mouse(this)[0]+90) + "px")
.style("top", (d3.mouse(this)[1]) + "px")
};
var mouseleave = function(d) {
tooltip
.transition()
.duration(200)
.style("opacity", 0)
};
And adding the events onto the rect:
.on("mouseover", mouseover)
.on("mousemove", mousemove )
.on("mouseleave", mouseleave)
Nothing shows up at all when you hover over the rects of the visual. Can elements be appended to the body in D3 observable?
Copyright Notice:Content Author:「Cybernetic」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/59205214/add-tooltip-to-d3-icicle-visual-observable