Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting text background color in Raphael

I am using Raphael-js to position text on a canvas. Is it possible to have a background color for the text? I would like different text elements to have different backgrounds colors.

Thanks,

like image 821
Farhat Avatar asked Dec 07 '22 21:12

Farhat


1 Answers

Yes, there is no way to specify background for text, here is how to create rectangle that will serve as a background:

var text = canvas.text(p.x, p.y, poly.title).attr(textAttr);
var box = text.getBBox();
var rect = canvas.rect(box.x, box.y, box.width, box.height).attr('fill', 'black');
text.toFront();
like image 75
Andrey Avatar answered Dec 25 '22 14:12

Andrey