[RQt-devel] par(xpd=NA) and the layout approach in qtpaint
Yihui Xie
xie at yihui.name
Wed Sep 1 08:31:23 CEST 2010
That's great and it helped me a lot! Thanks!
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 1:13 AM, Tengfei Yin <yintengfei at gmail.com> wrote:
> Hi
>
> I just made a simple demo below, I hope it could help a little bit.
>
> 1. I don't set limits on root layer. so you can put every thing in order,
> like title the row 0, (I don't always put labels and axis in the different
> layer, because I think they use the same coordinate with data ),but I set
> limits to each layer above root layer, reverse y-axis, like usual.
> 2. you can use location function to see the system capture the right
> coordinates, in these two layer.
> 3. I only use gridLayout()$setRowStretchFactor()
> 4. I guess the text in your code is not shown because the place
> row=0,column=0, has a blank layer. and there is no extra space for showing
> the text in that layer, you can set limits to that layer to make the text
> shown.
>
> Regards
>
> Tengfei
>
> ###
> library(qtpaint)
> s <- qscene()
> mypainter1 <- function(layer,painter){
> qdrawCircle(painter,rnorm(100,50,20),rnorm(100,50,20),r=5,fill='black')
> }
> mypainter2 <- function(layer,painter){
> qdrawCircle(painter,rnorm(100,750,100),rnorm(100,750,100),r=5,fill='red')
> }
> mouseLocator <- function(layer,event){
> print(as.numeric(event$pos()))
> }
> rootLayer <- qlayer(s)
> l1 <-
> qlayer(rootLayer,mypainter1,limits=qrect(0,0,100,100),mouseDoubleClickFun=mouseLocator)
> l2 <-
> qlayer(rootLayer,mypainter2,row=1,limits=qrect(500,500,1000,1000),mouseDoubleClickFun=mouseLocator)
> rootLayer$gridLayout()$setRowStretchFactor(0,1)
> rootLayer$gridLayout()$setRowStretchFactor(1,5)
> qplotView(s)$show()
>
> ###
>
> On Wed, Sep 1, 2010 at 12:11 AM, 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
>
>
>
> --
> Tengfei Yin
> MCDB PhD student
> 1620 Howe Hall, 2274,
> Iowa State University
> Ames, IA,50011-2274
> Homepage: www.tengfei.name
>
>
>
More information about the Qtinterfaces-devel
mailing list