Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

using Raphael's-library for drawing left aligned text

I am using Raphael's JavaScript library (http://raphaeljs.com/) to draw some graphics into my web-application. I tried the following code:

<html>
<head>
    <title></title>
    <script type="text/javascript" src="raphael/raphael.js"></script>
</head>
<body>    
    <script>
        var paper = Raphael(10, 50, 600, 200);            
        paper.text(300, 50, "first very very long line\nshort line").attr(
            {"font-family":"arial", 
            "font-size":"30",
            "text-align":"left"}
            );
    </script>
</body>
</html>

The result is a graphic with two lines of text that are centered. The css font-family and font-size are displayed correct. But the css text-align is ignored. Why?

(tested with Firefox 8.0 and Chrome 15)

like image 831
user1027167 Avatar asked Dec 04 '22 06:12

user1027167


1 Answers

It seems that Raphael doesn't use text-align property. Instead use the text-anchor property, its possible values are start, middle, end or inherit.

In your example use it like this:

paper.text(300, 50, "first very very long line\nshort line").attr({
    "font-family":"arial", 
    "font-size":"30",
    "text-anchor":"start"
});
like image 81
Spoike Avatar answered Dec 21 '22 02:12

Spoike