JSFiddle - React, Tailwind, and code Playground
HTML
<script src="http://mbostock.github.com/d3/d3.js"></script>
<div id="chart"></div>
CSS
.axis text {
font: 10px sans-serif;
}
.axis path, .axis line {
fill: none;
stroke: #000;
shape-rendering: crispEdges;
}
JavaScript
var svg = d3.select("#chart").append("svg")
.attr("width", 500)
.attr("height", 300);
var currentObject = null;
svg.append("circle")
.attr("class","selectme").attr("id","circle")
.attr("cx",50).attr("cy",50).attr("r",45)
.style("fill","lightblue");
svg.append("rect")
.attr("class","selectme").attr("id","rectangle")
.attr({"x":10,"y":150,"width":150,"height":100})
.style("fill","lightgreen");
d3.selectAll(".selectme")
.on("mouseover", function() {
d3.select(this).style("stroke","black");
currentObject = this;
})
.on("mouseout", function() {
d3.select(this).style("stroke","none");
currentObject = null;
});
d3.select("body")
.on("keydown", function() {
svg.append("text")
.attr("x","5")
.attr("y","130")
.style("font-size","20px")
.text("keyCode: " + d3.event.keyCode + " applied to : " + (currentObject===null ? "nothing!" : currentObject.id))
.transition().duration(2000)
.style("font-size","5px")
.style("fill-opacity",".1")
.remove();
});