Beginner here. How can I create a text box (from text from a JSON file) with D3 that appears when you click a node that already has mouseover events? Here's the fiddle. I've done it using "alert," but obviously that's awful. From reading several related but different questions, I tried creating and styling a class related to the pop-up text, but it just caused all the text on the visualization to disappear. Any and all help is appreciated!
Here's my code right now (adapted from this block):
var diameter = 960;
var tree = d3.layout.tree()
.size([360, diameter / 2 - 200])
.separation(function(a, b) { return (a.parent == b.parent ? 1 : 2) / a.depth; });
var diagonal = d3.svg.diagonal.radial()
.projection(function(d) { return [d.y, d.x / 180 * Math.PI]; });
var svg = d3.select("body").append("svg")
.attr("width", diameter)
.attr("height", diameter - 50)
.append("g")
.attr("transform", "translate(" + diameter / 2 + "," + diameter / 2 + ")");
d3.json("https://api.myjson.com/bins/3yuxo", function(error, root) {
var nodes = tree.nodes(root),
links = tree.links(nodes);
var link = svg.selectAll(".link")
.data(links)
.enter().append("path")
.attr("class", "link")
.attr("d", diagonal);
var node = svg.selectAll(".node")
.data(nodes)
.enter().append("g")
.attr("class", "node")
.attr("transform", function(d) { return "rotate(" + (d.x - 90) + ")translate(" + d.y + ")"; })
.on("mouseover", mouseover)
.on("mouseout", mouseout)
.on("click", function(d) {
d3.select(this)
console.log(d.context);
});
node.append("circle")
.attr("r", 4.5);
node.append("text")
.attr("dy", ".31em")
.attr("text-anchor", function(d) { return d.x < 180 ? "start" : "end"; })
.attr("transform", function(d) { return d.x < 180 ? "translate(8)" : "rotate(180)translate(-8)"; })
.text(function(d) { return d.name; });
});
d3.select(self.frameElement).style("height", diameter - 150 + "px");
function mouseover() { //makes the text size increase on mouseover
d3.select(this).select("text").transition()
.duration(750)
.style("font-size", "40px");
}
function mouseout() { //returns text to original size
d3.select(this).select("text").transition()
.duration(750)
.style("font-size", "15px");
}