[RQt-devel] par(xpd=NA) and the layout approach in qtpaint

Michael Lawrence lawrence.michael at gene.com
Wed Sep 1 17:31:50 CEST 2010


On Wed, Sep 1, 2010 at 6:54 AM, Yihui Xie <xie at yihui.name> wrote:

> Thanks! That was my guess, but it does not seem to work, e.g.:
>
>
I would suggest turning off caching, i.e., pass cache=FALSE to qlayer, at
least for the two axes. The issue, I think, is that Qt will only allocate a
buffer large enough for the layer. You're then drawing outside of the cache,
and it never makes it to the screen. I might make clip and cache both
default to FALSE.  Caching usually only makes sense when there is a dynamic
overlay on the layer. This is usually not the case for axes.

Michael


> # all layers with clip=FALSE but still get clipped
> library(qtpaint)
> scene = qscene()
> figLayer = qlayer(scene, clip = FALSE)
> titlePainter = function(item, painter) {
>    qdrawText(painter, paste(rep("The Useless Title", 5), collapse = " - "),
>        300, 10, "center", "center")
> }
> yAxisPainter = function(item, painter) {
>    qdrawText(painter, as.character(pretty(1:400)), 37.5, pretty(1:400))
> }
> plotPainter = function(item, painter) {
>    qdrawPoint(painter, runif(1000, 0, 600), runif(1000, 0, 400))
>    qdrawRect(painter, 1, 1, 600 - 1, 400 - 1)
> }
> xAxisPainter = function(item, painter) {
>    qdrawText(painter, as.character(pretty(1:600)), pretty(1:600),
>        37.5)
> }
> mouseLocator = function(item, event) {
>    print(as.numeric(event$pos()))
> }
> titleLayer = qlayer(figLayer, titlePainter, mousePressFun = mouseLocator,
>     limits = qrect(0, 0, 600, 20), clip = FALSE, row = 0, col = 1)
> yaxis = qlayer(figLayer, yAxisPainter, mousePressFun = mouseLocator,
>     limits = qrect(0, 0, 75, 400), clip = FALSE, row = 1, col = 0)
> plotLayer = qlayer(figLayer, plotPainter, mousePressFun = mouseLocator,
>     limits = qrect(0, 0, 600, 400), clip = FALSE, row = 1, col = 1)
> xaxis = qlayer(figLayer, xAxisPainter, mousePressFun = mouseLocator,
>     limits = qrect(0, 0, 600, 75), clip = FALSE, row = 2, col = 1)
>
> layout = figLayer$gridLayout()
>
> layout$setRowStretchFactor(0, 1)
> layout$setRowStretchFactor(1, 5)
> layout$setRowStretchFactor(2, 1)
> layout$setColumnStretchFactor(0, 1)
> layout$setColumnStretchFactor(1, 5)
>
> print(view <- qplotView(scene = scene))
>
>
> Regards,
> Yihui
> --
> Yihui Xie <xieyihui at gmail.com>
> Phone: 515-294-6609 Web: http://yihui.name
> Department of Statistics, Iowa State University
> 2215 Snedecor Hall, Ames, IA
>
>
>
> On Wed, Sep 1, 2010 at 7:26 AM, Hadley Wickham <hadley at rice.edu> wrote:
> > For the answer to your first question, turning clipping off for that
> layer.
> >
> > Hadley
> >
> > On Wednesday, September 1, 2010, Yihui Xie <xie at yihui.name> wrote:
> >> Hi all,
> >>
> >> I'm wondering if there are any approaches to completely show the
> >> graphical elements on the boundaries under a layout containing several
> >> layers. This is like the functionality par(xpd=NA) in base R graphics.
> >> See the example below that the texts for the origin (0,0) on the axes
> >> are partially hidden.
> >>
> >> My another problem is, I don't really understand the layout approach,
> >> although I've been reading the qtpaint vignette and digging the Nokia
> >> Qt documentations. Specifically, how should we define the coordinate
> >> system in each layer in a layout? (I experimented with mouse clicking
> >> to get locations but got even more confused) With a single layer, I
> >> can plot the data using its range to define the limits and everything
> >> is fine. Besides, does anyone have a working demo to draw a simplest
> >> plot with the layout approach? I struggled with
> >> set(Column|Row)(Maximum|Minimum|Preferred)(Width|Height) and
> >> set(Column|Row)StretchFactor, but they do not behave as we expect them
> >> to, e.g. the stretch factor being 0 will not restrict the height/width
> >> of a layer to be a fixed value -- they change as we resize the window.
> >>
> >> Below is the R code:
> >>
> >> # I need hints on how to split the root layer into several regions
> >> # and what are their coordinate systems
> >> library(qtpaint)
> >> scene = qscene()
> >> figLayer = qlayer(scene,limits=qrect(0,0,675,550))
> >> titlePainter = function(item, painter) {
> >>     qdrawText(painter, 'The Useless Title', 300, 0,'center','bottom')
> >>     tmp=as.matrix(titleLayer$boundingRect())
> >>     qdrawRect(painter, tmp[1,1],tmp[1,2],tmp[2,1],tmp[2,2])
> >> }
> >> yAxisPainter = function(item, painter) {
> >>     qdrawText(painter, as.character(pretty(1:400)), 37.5, pretty(1:400))
> >> }
> >> plotPainter = function(item, painter) {
> >>     qdrawPoint(painter, runif(1000, 0, 600), runif(1000, 0, 400))
> >>     qdrawRect(painter, 1, 1, 600-1, 400-1)
> >> }
> >> xAxisPainter = function(item, painter) {
> >>     qdrawText(painter, as.character(pretty(1:600)), pretty(1:600), 37.5)
> >> }
> >> mouseLocator = function(item, event){
> >>     print(as.numeric(event$pos()))
> >> }
> >> titleLayer = qlayer(figLayer, titlePainter,
> >> mousePressFun=mouseLocator, row=2,col=1)
> >> yaxis = qlayer(figLayer, yAxisPainter,mousePressFun=mouseLocator,row =
> 1,col=0)
> >> plotLayer = qlayer(figLayer, plotPainter,
> >> mousePressFun=mouseLocator,row = 1, col = 1)
> >> xaxis = qlayer(figLayer, xAxisPainter, mousePressFun=mouseLocator,row
> >> = 0, col = 1)
> >>
> >> layout = figLayer$gridLayout()
> >>
> >> layout$setRowMaximumHeight(0, 75)
> >> layout$setRowMinimumHeight(0, 60)
> >> # main plot region: 400x600
> >> layout$setRowPreferredHeight(1, 400)
> >> layout$setRowMaximumHeight(2, 75)
> >> layout$setRowMinimumHeight(2, 60)
> >>
> >> layout$setColumnMaximumWidth(0, 75)
> >> layout$setColumnMinimumWidth(0, 60)
> >> layout$setColumnPreferredWidth(1, 600)
> >> layout$setRowStretchFactor(0, 0)
> >> layout$setRowStretchFactor(1, 1)
> >> layout$setRowStretchFactor(2, 0)
> >> layout$setColumnStretchFactor(0, 0)
> >> layout$setColumnStretchFactor(1, 1)
> >>
> >> print(view<-qplotView(scene = scene))
> >>
> >>
> >> #################################################
> >>
> >>> sessionInfo()
> >> R version 2.11.1 (2010-05-31)
> >> x86_64-pc-linux-gnu
> >>
> >> locale:
> >> [1] en_US.utf8
> >>
> >> attached base packages:
> >> [1] stats     graphics  grDevices utils     datasets  methods   base
> >>
> >> other attached packages:
> >> [1] qtpaint_0.7.9
> >>
> >> loaded via a namespace (and not attached):
> >> [1] qtbase_0.8-4 tools_2.11.1
> >>
> >>
> >> Thanks a lot!
> >>
> >> Regards,
> >> Yihui
> >> --
> >> Yihui Xie <xieyihui at gmail.com>
> >> Phone: 515-294-6609 Web: http://yihui.name
> >> Department of Statistics, Iowa State University
> >> 3211 Snedecor Hall, Ames, IA
> >> _______________________________________________
> >> Qtinterfaces-devel mailing list
> >> Qtinterfaces-devel at lists.r-forge.r-project.org
> >>
> https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/qtinterfaces-devel
> >>
> >
> > --
> > Assistant Professor / Dobelman Family Junior Chair
> > Department of Statistics / Rice University
> > http://had.co.nz/
> >
> _______________________________________________
> Qtinterfaces-devel mailing list
> Qtinterfaces-devel at lists.r-forge.r-project.org
>
> https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/qtinterfaces-devel
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/qtinterfaces-devel/attachments/20100901/a3d0f531/attachment.htm>


More information about the Qtinterfaces-devel mailing list