I am trying to implement annotation functionality on my spread that I created with d3.js v3. When I click on each data point, a text box appears where I enter the text. Once the text has been added, it will appear as a tooltip for that particular data point. The way I do this is:
eventGroup.select("circle")
.attr("class", "dot")
.attr("r", 4)
.attr("cx", 10)
.attr("cy", 10)
.attr("fill", function(d) {
return d.evtColor ? d.evtColor : "#229ae5";
})
.attr("stroke", function(d) {
return d.evtColor ? d.evtColor : "#229ae5";
})
.attr("stroke-width", 2)
.on("contextmenu", function() {
var position = d3.mouse(this.parentNode);
d3.select("#context-menu")
.style("position", "absolute")
.style("left", (d3.event.pageX - 220) + "px")
.style("top", (d3.event.pageY - 70) + "px")
.style("display", "inline-block")
.on("click", function() {
d3.select("#context-menu").style("display", "none");
d3.select("#annotateBox")
.style("position", "absolute")
.style("left", (d3.event.pageX - 220) + "px")
.style("top", (d3.event.pageY - 70) + "px")
.style("display", "inline-block");
});
});
And in the HTML file, I define the button addAnnotation
and textarea
, where I will add the text:
<ul id="context-menu" class="menu" style="display:none;">
<li class="addAnnotation"><a href="">Add Annotation</a></li>
</ul>
<div id="annotateBox" style="display:none;">
<div class="annotateInput" style="display:table-caption">
<textarea rows="3" cols="50" maxlength="100" style="color:black" ng-model="vm.annotateText" autofocus></textarea>
<button type="button" class="btn btn-primary pull-right" ng-click="vm.removeButton()">Done</button>
</div>
</div>
, , - , , , , , . , , . , , .