Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Line width in raphaeljs

Tags:

svg

raphael

Is it real to make line with 1px weight in SVG or raphaeljs?

The follow code

 var p = Paper.path("M1 1 L50 1");
 p.attr("stroke", "#D7D7D7");
 p.attr("stroke-width", "1");
 p.attr("opacity", 0.5);

draw line which looks like 2px or 3px. Any alternative?

like image 662
Neir0 Avatar asked Nov 07 '11 12:11

Neir0


1 Answers

When SVG lines lie at their apparently correct coordinates they actually lie inbetween pixels, so when you state M1 1 L50 1 it paints half a pixel on the top and the other half in the bottom of the pixel, making it look like a thick, semitransparent line.

To solve this problem you need to either paint at half pixels, or translate your elements half a pixel, ie. element.translate(0.5, 0.5)

You can see the blurry and sharp lines here: http://jsfiddle.net/k8AKy/

like image 180
methodofaction Avatar answered Sep 27 '22 23:09

methodofaction