Hi Mark,

This comes down to the way that GTK+ allocates size to its widgets. The
allocation of a widget is initialized to have a width and height of 1. When
a child is added to a visible parent, the parent will execute its lay out
algorithm and allocate a certain amount of space to the widget. The widget
is notified of this change via an event that arrives after an iteration of
the event loop. An event loop iteration may be forced in a number of ways;
you've discovered the Sys.sleep() method.

However, it is generally not good practice to show a container before
adding its children, unless widgets are being added in the middle of a
session, which is rare. If you were to instead do something like this:

win = gtkWindow(show = FALSE)
win$setDefaultSize(500, 500)
da = gtkDrawingArea()
asCairoDevice(da)
win$add(da)
win$showAll()
plot(1:10)

Then GTK+ will correctly initialize the allocation of the widget, I think
even before a configure event is received. The above approach is my
recommended solution to your problem.

Thanks,
Michael

On Fri, Mar 9, 2012 at 1:39 AM, Mark Heckmann <mark.heckm...@gmx.de> wrote:

> Thanks, Peter.
> I did the following: restart R and run the same code with and without a
> minimal system pause (Sys.sleep) after the line that adds the device to the
> GTK window.
> Adding a pause will make it work, though I do not understand what is
> happening here. Note the different settings of par("din").
> This is probably not the expected behavior, I guess.
> Any ideas why this is the case? It seems as if "din" is not adjusted on
> time? Might that be?
>
>
> > library(RGtk2)
> > library(cairoDevice)
> >
> > win = gtkWindow()
> > da = gtkDrawingArea()
> > asCairoDevice(da)
> [1] TRUE
> > win$add(da)
> > plot(1:10)
> Fehler in plot.new() : Grafikränder zu groß
> > par(c("din", "mai"))
> $din
> [1] 0.01388889 0.01388889
>
> $mai
> [1] 0.7791667 0.6263889 0.6263889 0.3208333
>
>
> > win = gtkWindow()
> > da = gtkDrawingArea()
> > asCairoDevice(da)
> [1] TRUE
> > win$add(da)
> > Sys.sleep(.1)
> > plot(1:10)
> > par(c("din", "mai"))
> $din
> [1] 2.777778 2.777778
>
> $mai
> [1] 0.7791667 0.6263889 0.6263889 0.3208333
>
>
> Thanks in advance
> --- Mark
>
>
> Am 09.03.2012 um 00:01 schrieb peter dalgaard:
>
> >
> > On Mar 8, 2012, at 23:25 , Mark Heckmann wrote:
> >
> >> Peter, thanks for the answer!
> >> Indeed, it does work if I set par(mar=c(0,0,0,0)) but not when it is
> set to the default values mar=c(5.1, 4.1, 4.1, 2.1).
> >> The par settings returned in the example are the defaults, so no
> extraordinary big mar settings or char size (see below).
> >> Also, it does not matter what size the drawing area is set to (e.g.
> 1000x 1000). The error always occurs.
> >> Any idea?
> >>
> >
> > The other parameters...
> >
> > What about "din" and "mai"? The margin problem usually means that the
> sum of the relevant margins is bigger than the device size. E.g.
> >
> >> quartz()
> >> par(mai=rep(4,4))
> >> plot(0)
> > Error in plot.new() : figure margins too large
> >
> >
> >
> >> examples:
> >>
> >>> win = gtkWindow()
> >>> da = gtkDrawingArea()
> >>> win$add(da)
> >>> asCairoDevice(da)
> >> [1] TRUE
> >>> par(c("mar", "cra", "oma"))
> >> $mar
> >> [1] 5.1 4.1 4.1 2.1
> >>
> >> $cra
> >> [1]  7 11
> >>
> >> $oma
> >> [1] 0 0 0 0
> >>
> >>> plot(1:10)
> >> Fehler in plot.new() : Grafikränder zu groß  ###ERROR###
> >>
> >> Thanks
> >> Mark
> >>
> >>
> >> Am 08.03.2012 um 22:48 schrieb peter dalgaard:
> >>
> >>>
> >>> On Mar 8, 2012, at 20:27 , Mark Heckmann wrote:
> >>>
> >>>> When using a gtkDrawingArea as a Cairo device I very often encounter
> the error: "figure margins too large"
> >>>> Even for the below "getting started" example from
> http://www.ggobi.org/rgtk2/ this is the case.
> >>>>
> >>>>> win = gtkWindow()
> >>>>> da = gtkDrawingArea()
> >>>>> win$add(da)
> >>>>> asCairoDevice(da)
> >>>> [1] TRUE
> >>>>> plot(1:10)
> >>>> Fehler in plot.new() : Grafikränder zu groß
> >>>>>
> >>>>
> >>>> Also enlarging the drawing area does not help.
> >>>>
> >>>>> win = gtkWindow()
> >>>>> da = gtkDrawingArea()
> >>>>> win$add(da)
> >>>>> asCairoDevice(da)
> >>>> [1] TRUE
> >>>>> da$setSizeRequest(700, 700)
> >>>>> plot(1:10)
> >>>> Fehler in plot.new() : Grafikränder zu groß
> >>>>
> >>>> Any ideas?
> >>>
> >>> I'd check the par() settings for the device. Especially mar/mai and
> cra/cin to see whether margins are set unusually large and/or character
> sizes are unusually big, but check help(par) yourself.
> >>>
> >>> --
> >>> Peter Dalgaard, Professor,
> >>> Center for Statistics, Copenhagen Business School
> >>> Solbjerg Plads 3, 2000 Frederiksberg, Denmark
> >>> Phone: (+45)38153501
> >>> Email: pd....@cbs.dk  Priv: pda...@gmail.com
> >>>
> >>>
> >>>
> >>>
> >>>
> >>>
> >>>
> >>>
> >>
> >> ––––––––––––––––––––––––––––––––––––
> >> Mark Heckmann
> >> Blog: www.markheckmann.de
> >> R-Blog: http://ryouready.wordpress.com
> >>
> >>
> >>
> >>
> >>
> >>
> >>
> >>
> >>
> >>
> >
> > --
> > Peter Dalgaard, Professor,
> > Center for Statistics, Copenhagen Business School
> > Solbjerg Plads 3, 2000 Frederiksberg, Denmark
> > Phone: (+45)38153501
> > Email: pd....@cbs.dk  Priv: pda...@gmail.com
> >
> >
> >
> >
> >
> >
> >
> >
>
> ––––––––––––––––––––––––––––––––––––
> Mark Heckmann
> Blog: www.markheckmann.de
> R-Blog: http://ryouready.wordpress.com
>
>
>
>
>
>
>
>
>
>
>
>         [[alternative HTML version deleted]]
>
>
> ______________________________________________
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
>

        [[alternative HTML version deleted]]

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to