[cairo] Contributing pyCairoChart

Martin Lesser ml-cairo at bettercom.de
Thu May 25 05:26:19 PDT 2006

Steven Chaplin <stevech1097 at yahoo.com.au> writes:

> Here's how I would modify it to support output to PNG/PS/PDF/SVG:
> Make the draw_bars/data/dots/grid/lines methods private, so the public
> API is just to create a Chart, set its attributes, and output the chart.
> draw_*() methods are not explicitly called, the drawing is done
> automatically by the out2png() method.

There are some parameters I want to keep in the draw_*() methods
(i.e. "dotting" a data-line) so at the moment I think about an instance
member "drawn" as list which contains the parts of the chart which are
already drawn so an explicit call to the draw-methods is no longer

> Modify Chart.__init__ so it does not create the cairo surface, context
> and matrix.

That looks impossible for me: I need the cairo_t at an early stage
especially for accessing the [text|font]_extents methods of pycairo and
calculating the drawable area for the data. Additionally it could be an
option to produce a warning if the text in title and/or legend would be
too large for the given size of a chart.

> Rename out2png() to output() and use something like:

That's a good idea, I did that. But the filename (or fileobject) are now
part of __init__ which then does a call of _cairosetup.

The current version is available at

(The documentation has to be updated but this will be done next week)

> def output (self, _file):
>     ...
>     elif _file.endswith('.svg'):
>         if not cairo.HAS_SVG_SURFACE:
>             raise SystemExit ('cairo was not compiled with SVG support')
>         self.img = cairo.SVGSurface (_file, width_in_points, 
>                                      height_in_points)

My pycairo does not have the *SVG* members/methods also I compiled with
SVG-support. But I can import cairo.svg which does not have the needed
members/methods too. I'm using pycairo-1.0.2 built against cairo-1.1.6
Did I miss something?


http://bettercom.de/auctiontools/ and http://bettercom.de/

More information about the cairo mailing list