[cairo] howto draw a line-graph

calmar mac at calmar.ws
Thu Apr 17 19:24:23 PDT 2008


Hi all,

maybe someone happens to have just a good idea about this :)

what could be the best way to draw a line-style-graph with width
about 1.0 or so - ... - where to exactly construct the path with
what kind of cairo options?

Something like the thing at the top there:
http://www.calmar.ws/awesome/awesome-wm.png

0     1     2     3     4     5     6     7
------------------------------------------- 0
|     |     |     |     |     |     |     |
|     |     |     |     |     |     |     |
|     |     |     |     |     |     |     |
------------------------------------------- 1
|     |     |.....|     |     |     |     |
|     |     X.....|     |     |     |     |
|     |     |.....|     |     |     |     |
------------------------------------------- 2
|     |     |.....|     |     |     |.....|
|     |     |.....|     |     |     X.....|
|     |     |.....|     |     |     |.....|
------------------------------------------- 3
|     |.....|     |.....|     |.....|     |
|     |.....|     |.....|     |.....|     |
|     |.....|     |.....|     |.....|     |
------------------------------------------- 4
|     |.....|     |.....|     |.....|     |
|     X.....|     |.....|     X.....|     |
|     |.....|     |.....|     |.....|     |
------------------------------------------- 5
|.....|     |     |.....|.....|     |     |
|.....|     |     X.....|.....|     |     |
|.....|     |     |.....|.....|     |     |
------------------------------------------- 6
|.....|     |     |     |.....|     |     |
X.....|     |     |     X.....|     |     |
|.....|     |     |     |.....|     |     |
------------------------------------------- 7

I think, actually I have a path like noted above, when
the values to draw through are X, what it fills (monitor-pixels)
are marked with ....

I placed the line_to's to the pixel's borders, and the height to
the center of them.

It actually matters when I would move the X's 0.5 pixels more to
the right - it seems to draw more like straight lines to the other
X.

I have something like this actually:

,-----------------------------------------------
| cairo_set_antialias(ctx->cr, CAIRO_ANTIALIAS_NONE);
| cairo_set_line_width(ctx->cr, 1.0);
| /* without it, it can draw over the path on sharp angles (...too long lines) */
| cairo_set_miter_limit(ctx->cr, 0.0);
| cairo_set_line_join(ctx->cr, CAIRO_LINE_JOIN_MITER);
|
| x = rect.x;
| y = rect.y + 0.5; /* center of a pixel */
| w = rect.width;
|
| cairo_move_to(ctx->cr, x, y - value]);
| ...next value_int...
|
| for(i = 0; i < w; i++)
| {
|     cairo_line_to(ctx->cr, ++x, y - value_int);
|
|     ...next value_int...
| }
|
| cairo_stroke(ctx->cr);
`-----------------------------------------------

Well, hints/idea welcomed :)

cheers
marco

-- 
   (o_  It rocks: LINUX + Command-Line-Interface
   //\
   V_/_                     http://www.calmar.ws
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://lists.cairographics.org/archives/cairo/attachments/20080418/4aee1c2c/attachment.pgp 


More information about the cairo mailing list