igraph-help
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [igraph] vertex.frame.width? vertex.frame.size?


From: Gábor Csárdi
Subject: Re: [igraph] vertex.frame.width? vertex.frame.size?
Date: Thu, 10 Sep 2009 16:54:24 +0200

Yannick,

the logo was not actually made with igraph. :( But anyway, you can
change the edge width by giving 'edge.width' to plot, or setting the
'width' edge attribute. You cannot currently change the width of the
frame, at least not easily, you need to define a new vertex shape for
this, slightly modifying the current 'circle' shape.

.igraph.shape.circle2 <- function(coords, el=NULL, v=NULL,
mode=c("clip", "plot"),
                                 params, end=c("both", "from", "to")) {

  mode=match.arg(mode)
  end =match.arg(end)

  #####################################################################
  ## clipping mode

  if (mode=="clip") {
    if (length(coords)==0) { return (coords) }

    vertex.size <- 1/200 * params("vertex", "size")

    if (end=="from") {
      phi <- atan2(coords[,4] - coords[,2], coords[,3] - coords[,1])
      vsize.from <- if (length(vertex.size)==1) {
        vertex.size
      } else {
        vertex.size[ el[,1]+1 ]
      }
      res <- cbind(coords[,1] + vsize.from*cos(phi),
                   coords[,2] + vsize.from*sin(phi) )
    } else if (end=="to") {
      phi <- atan2(coords[,4] - coords[,2], coords[,3] - coords[,1])
      r <- sqrt( (coords[,3] - coords[,1])^2 + (coords[,4] - coords[,2])^2 )
      vsize.to <- if (length(vertex.size)==1) {
        vertex.size
      } else {
        vertex.size[ el[,2]+1 ]
      }
      res <- cbind(coords[,1] + (r-vsize.to)*cos(phi),
                   coords[,2] + (r-vsize.to)*sin(phi) )
    } else if (end=="both") {
      phi <- atan2(coords[,4] - coords[,2], coords[,3] - coords[,1])
      r <- sqrt( (coords[,3] - coords[,1])^2 + (coords[,4] - coords[,2])^2 )
      vsize.from <- if (length(vertex.size)==1) {
        vertex.size
      } else {
        vertex.size[ el[,1]+1 ]
      }
      vsize.to <- if (length(vertex.size)==1) {
        vertex.size
      } else {
        vertex.size[ el[,2]+1 ]
      }
      res <- cbind(coords[,1] + vsize.from*cos(phi),
                   coords[,2] + vsize.from*sin(phi),
                   coords[,1] + (r-vsize.to)*cos(phi),
                   coords[,2] + (r-vsize.to)*sin(phi) )
    }

    res

   #####################################################################
  ## plotting mode

  } else if (mode=="plot") {
    vertex.color       <- params("vertex", "color")
    if (length(vertex.color) != 1 && !is.null(v)) {
      vertex.color <- vertex.color[v+1]
    }
    vertex.frame.color <- params("vertex", "frame.color")
    if (length(vertex.frame.color) != 1 && !is.null(v)) {
      vertex.frame.color <- vertex.frame.color[v+1]
    }
    vertex.size        <- 1/200 * params("vertex", "size")
    if (length(vertex.size) != 1 && !is.null(v)) {
      vertex.size <- vertex.size[v+1]
    }
    vertex.size <- rep(vertex.size, length=nrow(coords))

    vertex.frame.width <- params("vertex", "frame.width")
    vertex.frame.width <- rep(vertex.frame.width, length=nrow(coords))

    vertex.color <- rep(vertex.color, length=nrow(coords))
    vertex.frame.color <- rep(vertex.frame.color, length=nrow(coords))
    vertex.size <- rep(vertex.size, length=nrow(coords))

    for (i in seq_len(nrow(coords))) {
      symbols(x=coords[i,1], y=coords[i,2], bg=vertex.color[i],
fg=vertex.frame.color[i],
               circles=vertex.size[i], add=TRUE, inches=FALSE,
lwd=vertex.frame.width[i])
    }
  }

}

.igraph.shapes <- get( ".igraph.shapes", asNamespace("igraph"))
.igraph.shapes[["circle2"]] <- .igraph.shape.circle2
unlockBinding(".igraph.shapes", asNamespace("igraph"))
assign(".igraph.shapes", .igraph.shapes, envir=asNamespace("igraph"))

i.default.values <- get("i.default.values", asNamespace("igraph"))
i.default.values$vertex$frame.width=1
unlockBinding("i.default.values", asNamespace("igraph"))
assign("i.default.values", i.default.values, envir=asNamespace("igraph"))

and then you can do something like this:

plot(graph.ring(10), layout=layout.circle, vertex.shape="circle2",
vertex.frame.width=5, edge.width=1:10)

We should have an API for adding new vertex shapes soon.....

Best,
Gabor

On Thu, Sep 10, 2009 at 2:09 PM, Yannick Rochat
<address@hidden> wrote:
> Dear Gábor and Tamás,
>
> I'm plotting some graphs for a poster and I would like to increase the width
> of the edges and the vertices' frames in order to have it equal everywhere.
> How can I do that? It seems possible to do it with igraph:
> http://igraph.sourceforge.net/images/igraph2.png if that was produced with
> igraph :)
>
> Thanks!
>
>
> Yannick Rochat - IMA - Université de Lausanne
> http://www.unil.ch/unisciences/YannickRochat
>
> _______________________________________________
> igraph-help mailing list
> address@hidden
> http://lists.nongnu.org/mailman/listinfo/igraph-help
>
>



-- 
Gabor Csardi <address@hidden>     UNIL DGM




reply via email to

[Prev in Thread] Current Thread [Next in Thread]