Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

generate diagram

21 views
Skip to first unread message

Roman Cheplyaka

unread,
Feb 27, 2007, 6:32:48 PM2/27/07
to
I've found some Tcl packages that allow drawing diagram in Tk. But is
there any which allow generating diagram (without displaying it) and
saving it to the file (e.g. png)?

Stéphane A.

unread,
Mar 6, 2007, 1:56:49 AM3/6/07
to

Dear Tcler,

I had to produce graphical reports and created my own generating
program. As this was intended to print diagrams, I got right to Tk
[canvas], and use the Postscript export function.

I was on Linux, but the .eps files my program made were not well
supported by my system. Moreover, I was thinking about to use my
program on MS Windows. I tried "Trampoline!" to convert my canvases to
PDF files, but I could not get it work.

Then I grabbed the "pdf4tcl" package, and I did not go back since. It
is fine for producing not-too-complex diagrams without displaying them
on the GUI. And printing them on Linux works as with .ps files with
one command:
lpr myreport.pdf

I can see your requirements are to save your diagrams as
(eventually .png) files, but actually I cannot provide you other
than .pdf files. (and, of course, .eps that are exported from Tk
canvases)

I hope this will help you much.

Regards,
Stephane A.

Alastair Davies

unread,
Mar 6, 2007, 11:19:57 AM3/6/07
to

package require Tk
package require img::window
package require img::png

pack [canvas .c]
.c create text 0 0 -anchor nw -text "Hello World" -font "Arial 36"
set picture [image create photo -data .c]
$picture write "picture.png" -format png

See http://wiki.tcl.tk/img for details of the Img package. You need to
map the window to the screen unfortunately, so this does not exactly
meet your requirements. It might be useful in other ways however. (You
can grab your image from any window, not just a canvas. You can also
use your picture in other ways than writing it to a file.)

Alternatively, you can manipulate the pixels of a photo in any way you
like, treating them as raw data. For an example of that approach, see
http://wiki.tcl.tk/15163 -- drawing lines on a photo

HTH, Alastair

suchenwi

unread,
Mar 6, 2007, 12:14:59 PM3/6/07
to
On 6 Mrz., 17:19, Alastair Davies <alast...@simulistics.com> wrote:
> Alternatively, you can manipulate the pixels of a photo in any way you
> like, treating them as raw data. For an example of that approach, seehttp://wiki.tcl.tk/15163-- drawing lines on a photo

I added a routine for drawing rectangles to that page, which may be
useful for diagrams. However, for rendering text into a photo, some
more work is needed... (e.g. starting from "strimj")

Roman Cheplyaka

unread,
Mar 26, 2007, 3:27:25 PM3/26/07
to
On Mar 6, 9:56 am, "Stéphane A." <stephanearn...@yahoo.fr> wrote:
> Then I grabbed the "pdf4tcl" package, and I did not go back since. It
> is fine for producing not-too-complex diagrams without displaying them
> on the GUI. And printing them on Linux works as with .ps files with
> one command:
> lpr myreport.pdf
>
> I can see your requirements are to save your diagrams as
> (eventually .png) files, but actually I cannot provide you other
> than .pdf files. (and, of course, .eps that are exported from Tk
> canvases)

Stéphane A., great thanks! PDF drawing excellently fits my needs.

Bezoar

unread,
Mar 27, 2007, 9:24:42 AM3/27/07
to
On Feb 27, 6:32 pm, "Roman Cheplyaka" <roman.cheply...@gmail.com>
wrote:

> I've found some Tcl packages that allow drawing diagram in Tk. But is
> there any which allow generating diagram (without displaying it) and
> saving it to the file (e.g. png)?

Graphviz also has a tcl extension , http://www.graphviz.org It
allows you to
draw diagrams quite easily as it handles all the placement chores for
you. Also there is
another extension for the plplot library. http://plplot.sourceforge.net
: heres the intro:

PLplot is a library of functions that are useful for making scientific
plots.
PLplot can be used from within compiled languages such as C, C++,
FORTRAN
and Java, and interactively from interpreted languages such as Octave,
Python, Perl and Tcl.
The PLplot library can be used to create standard x-y plots, semilog
plots, log-log plots,
contour plots, 3D surface plots, mesh plots, bar charts and pie
charts. Multiple graphs
(of the same or different sizes) may be placed on a single page with
multiple lines in each graph.
A variety of output file devices such as Postscript, png, jpeg and
others, as well as
interactive devices such as xwin, tk, xterm and Tektronics devices
are supported.
New devices can be easily added by writing a small number of device
dependent routines.
There are almost 2000 characters in the extended character set. This
includes
four different fonts, the Greek alphabet and a host of mathematical,
musical, and
other symbols. Some devices supports its own way of dealing with
text, such
as the Postscript driver, or the png and jpeg drivers that uses the
Freetype library.

0 new messages