When you click the bubble, the g-selected
class is added to the nodes. That changes the css that applies from
.g-node .g-democrat {
fill: #c5d7ea;
}
.g-node .g-republican {
fill: #f9caca;
}
to
.g-node.g-selected .g-democrat {
fill: #99c0e5;
stroke: #6081a3;
stroke-width: 1.5px;
}
.g-node.g-selected .g-republican {
fill: #fda4a7;
stroke: #af5e61;
stroke-width: 1.5px;
}
Adding a class to a clicked element is pretty straightforward. The class is added using the selection.classed
method.
node.classed("g-selected", function(d) { return d === topic; });
If you are looking at the source, look at the updateActiveTopic
function.
The code in your fiddle is quite a bit simpler than the example you linked. I would change the part where you create the circle elements so that it uses css, rather than inline style, i.e.
circle {
fill: green;
}
instead of
.style("fill", function (d, i) {
return "green";
})
Now, you'll add a click handler to the circles:
circle.on("click", function(d) {
// remove selected class from all circles that have it
circle.classed('selected', false);
//add the selected class to the element that was clicked
d3.select(this).classed('selected', true)
});
and a style to highlight the circle when it is selected
circle.selected {
fill: blue;
stroke: black;
stroke-width: 1.5px;
}
See the fiddle for the complete example.