Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can go about this in two ways you can use tooltips or place the text on the map. These's been plenty of discussion about tooltips such <a href="https://groups.google.com/forum/#!msg/d3-js/-1oLMKUez3M/g3UjfyvKQIsJ" rel="nofollow">this google group conversation</a> and the links with in including these biovisualise links: <a href="http://bl.ocks.org/biovisualize/1016860" rel="nofollow">Simple tooltip</a> and <a href="http://bl.ocks.org/biovisualize/2973775" rel="nofollow">Tooltips as a helper</a>. In the bl.ocks example you've pointed at using the simple tooltips option would require adding 2 lines of code as in:</p> <pre><code> svg.selectAll(".symbol") .data(centroid.features.sort(function(a, b) { return b.properties.population - a.properties.population; })) .enter().append("path") .attr("class", "symbol") .attr("d", path.pointRadius(function(d) { return radius(d.properties.population); })) .append("title") .text(function (d) { return d.properties.name; }); </code></pre> <p>To add text to the map you need to append some svg text elements. So you need to setup something similar to the symbol block above and calculate the x and y for the text. There are probably more elegant way's of doing this but this makes it very explicit what's going on. The x's and y's are calculated by path.centroid which returns the screen coordinates of your point. </p> <pre><code>svg.selectAll("text") .data(centroid.features).enter() .append("text") .attr("x", function (d) { return path.centroid(d)[0]; }) .attr("y", function (d) { return path.centroid(d)[1]; }) .text(function (d) { return d.properties.name; }); </code></pre> <p>Hope this helps </p> <p>You can see both of them in action at this <a href="http://bl.ocks.org/phil-pedruco/7189721" rel="nofollow">bl.ock</a>. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload