views:

45

answers:

2

I want to be able to draw a fitted rectangle around text labels (person's full name). The margin isn't terribly important, but I can't just draw fixed-sized rectangles because the labels vary in lengths. How do I do this?

Here's the code that draws the text labels:

var ctx = document.getElementById('map').getContext('2d');
for (i=0; i < num_people; i++) {
    var pos = get_position(i, num_people);
    ctx.fillText(names[i], pos.x, pos.y);
}
A: 

You can get the size of the drawn text with measureText().

thejh
A: 

Useful links for canvas text:

kanaka