javascript - Align objects with dynamic width in SVG -
i generating svg needs include dynamic text elements. general structure follows:
-------------------------------------------- | <rect> <text> <rect> <text>| | | | | | | --------------------------------------------
or bit clearer - it's legend @ top of chart:
the rectangles 5px 5px colored boxes, both text elements dynamic in width. 4 elements need aligned right.
is there way somehow 'float' 4 elements next each other. have looked @ far seems indicate each of these elements needs explicit x , y coordinate don't know until text rendered.
i'm aware there javascript options available ('getbbox()' etc) wondered if there using svg dom itself?
here's solution doesn't have javascript. uses font-awesome
<tspan>
draw entire text.
update: added "roboto" font , dy
better alignment.
<link href='http://fonts.googleapis.com/css?family=roboto' rel='stylesheet' type='text/css'> <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css"> <svg viewbox="0 0 400 400" preserveaspectratio="xminymin meet" width="400px" height="400px" > <text text-anchor="end" x="400" y="20"> <tspan dy="1" font-size="8pt" font-family="roboto" class="fa fa-fw" fill="skyblue"> </tspan> <tspan dy="-2" font-size="8pt" font-family="roboto" >gross profit % </tspan> <tspan dy="2" font-size="8pt" font-family="roboto" class="fa fa-fw" fill="green"> </tspan> <tspan dy="-2" font-size="8pt" font-family="roboto" >op. profit % </tspan> <tspan dy="2" font-size="8pt" font-family="roboto" class="fa fa-fw" fill="orange"> </tspan> <tspan dy="-2" font-size="8pt" font-family="roboto" >net profit after tax % </tspan> </text> </svg>
Comments
Post a Comment