The block tree

Share:

Description

Create a block tree with positioning the vertices in to blocks.

Usage

1
2
3
4
setTreeBlocks(block.tree, vertices, root.label = "", N = 3,
              delta = ifelse(overlaying, 1, 0), 
              Delta = ifelse(overlaying, 0, 1.5),
              d = 5, f = 1/4, blockColors = NULL, overlaying = FALSE)

Arguments

block.tree

A structure with the blocks in a block.tree. See below.

vertices

The list of vertices, each containing the class dg.Vertex. Returned with positions set in the interval of the blocks.

root.label

A text string with the root.label of the root block.

N

Integer, N is the number of coordinates of the vertices and block corners.

delta

Numeric. Decrement of block size for nested blocks, and space between blocks when overlaying is TRUE. The decrement is delta divided by 100, times the the size of the window canvas, width or height.

Delta

Numeric. Decrement of block size for nested blocks, and space between blocks when overlaying is FALSE. The decrement is Delta divided by 100, times the the size of the window canvas, width or height.

d

Numeric. If not d is given in block.tree, see below: The heading bar (with the label) has a height of (d + 2) divided by 100, times height of the window canvas.

f

Numeric. If not f or g is given in block.tree, see below: The the vertices of the block are placed in an array with a height (width if horizontal is set to FALSE) of f divided by 100, times height (width) of the block. Thus this size is relative to the block size.

blockColors

Vector of text string with the blockColors of the blocks.

overlaying

Logical. If overlaying is set to FALSE then children blocks of a block are not drawn inside the block.

Details

A recursive definition: Block.tree is a list with the vertices of the "current" blocks, some parameters for controlling the layout, and possible some block.trees:

  • ...\$Vertices The vertices of the block.

  • ...\$label A text string for the label of the block. Will overwrite "block-name" and root.label.

  • ...\$d Numeric. The heading bar (with the label) has a height of (d + 2) divided by 100, times the height of the window canvas.

  • ...\$g Numeric. The vertices of the block are placed in an array with a height (width if horizontal is set to FALSE) of g divided by 100, times the height (width) of the window canvas. Thus this size will not decrease with the block size.

  • ...\$f Numeric. If not g is given: The the vertices of the block are placed in an array with a height (width if horizontal is set to FALSE) of f divided by 100, times the height (width) of the block. Thus this size is relative to the block size.

  • ...\$G Numeric. (If the height of the block is 100 we are now left with 100 - 2 * delta - d - 2 - g for the blocks. ) The sub blocks (apart from common.children) then have a of height (width, if horizontal is set to FALSE) of G divided by 100, times the height (width) of the window canvas. Thus the sub block size will not decrease with the block size. (If the height of the block is 100 we are now left with 100 - 2 * delta - d - 2 - g - G for the common.children. )

  • ...\$F Numeric. If not G is given: The proportion G of the remaining space are used for sub blocks (apart from common.children) and the proportion G of the space for blocks are used for common.children.

  • ...\$horizontal Logical. If horizontal is set to TRUE, then the sub blocks, but common.children, are placed side by side, else the blocks are placed vertically.

  • ...\$closed Logical. If closed is set to TRUE, then the block is initially drawn "closed", and the vertices and sub blocks of the block are not visible.

  • ...\$vertices.last Logical. If vertices.last then the vertices of the block are placed after the sub blocks.

  • ...\$"block-name"= list(...) Repeated zero, one or more times for sub blocks. "block-name" is the label of the block, and list(...) is a Block.tree.

  • ...\$common.children= list(...) Omitted, or a list with common children of the other sub blocks of the block. The list is again a Block.tree.

Value

A list with components

BlockTree

A tree of blocks, each of class dg.Block.

Vertices

The list of vertices, with the positions updated such the vertices has positions within the blocks.

Note

Ancestors and descendants are set in setTreeBlocks. Ancestors are used in the function returnBlockEdgeList to find the edges between blocks and between blocks and vertices.

Descendants are used in dynamicGraphMain when closing, opening and moving blocks, and when adding or dropping edges from and to blocks.

The methods NodeAncestors, NodeAncestors<- NodeDescendants and NodeDescendants<- can be used on the block list resulting of blockTreeToList on the block tree.

Author(s)

Jens Henrik Badsberg

Examples

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
# Example 1:

Block.tree <- list(label = "W", Vertices = c("country"),
                   X = list(Vertices = c("race", "sex"),
                            A = list(Vertices = c("hair", "eye"),
                                     horizontal = FALSE),
                            B = list(Vertices = c("education"),
                                     C = list(Vertices = c("age")))))
V.Names <- unlist(Block.tree)
vertices <- returnVertexList(V.Names[grep("Vertices", names(V.Names))])
blocktree <- setTreeBlocks(Block.tree, vertices)

Positions(blockTreeToList(blocktree$BlockTree))
Positions(blocktree$Vertices)
NodeAncestors(blockTreeToList(blocktree$BlockTree))
NodeDescendants(blockTreeToList(blocktree$BlockTree))

vertexStrata <- Strata(blocktree$Vertices)
vertexStrata
vertexNames <- Names(blocktree$Vertices)
names(vertexNames) <- NULL
vertexNames

# Indices of the vertices in blocks:

indicesInBlock <- vector("list", max(vertexStrata))
for (i in seq(along = vertexStrata))
  indicesInBlock[[vertexStrata[i]]] <- 
    append(indicesInBlock[[vertexStrata[i]]], i) 
str(indicesInBlock)

# Names of the vertices in blocks:

vertexNamesInblock <- vector("list", max(vertexStrata))
for (i in seq(along = vertexStrata))
  vertexNamesInblock[[vertexStrata[i]]] <- 
    append(vertexNamesInblock[[vertexStrata[i]]], vertexNames[i]) 
str(vertexNamesInblock)

# A useful function, replace "k" (block index k) 
# in block "i" by "x[k]", the content "x[k]" of block "k":

f <- function(A, x) {
  result <- vector("list", length(A))
  names(result) <- names(A)
  for (i in seq(along = A))
    if ((length(A[[i]]) > 0) && (A[[i]] != 0))
      for (k in A[[i]])
        result[[i]] <- append(result[[i]], x[k])
  return(result)
}

# For each block, names of vertices in ancestor blocks:

vertexAncOfBlock <- f(NodeAncestors(blockTreeToList(blocktree$BlockTree)), 
                      vertexNamesInblock)
str(vertexAncOfBlock)

for (i in seq(along = vertexAncOfBlock))
  if (length(vertexAncOfBlock[[i]]) > 0)
    vertexAncOfBlock[[i]] <- unlist(vertexAncOfBlock[[i]])
str(vertexAncOfBlock)

# For each block, names of vertices in descendant blocks:

vertexDesOfBlock <- f(NodeDescendants(blockTreeToList(blocktree$BlockTree)),
                      vertexNamesInblock)
str(vertexDesOfBlock)

for (i in seq(along = vertexDesOfBlock))
  if (length(vertexDesOfBlock[[i]]) > 0)
    vertexDesOfBlock[[i]] <- unlist(vertexDesOfBlock[[i]])
str(vertexDesOfBlock)


# Example 2:

Block.tree <-
  list(g = 0, G = 54, label = "Pedegree.G",
       Male.Side = 
       list(g = 0, G = 33,
            Father = 
            list(g = 0, G = 12,
                 P.G.Father = list(Vertices = c("P.G.Father.1")),
                 P.G.Mother = list(Vertices = c("P.G.Mother.1")),
                 common.children = list(g = 0, label = "Father.1",
                                        Vertices = c("Father.1"))),
            Mother = 
            list(g = 0, G = 12,
                 M.G.Father = list(Vertices = c("M.G.Father.1")),
                 M.G.Mother = list(Vertices = c("M.G.Mother.1")),
                 common.children = list(g = 0, label = "Mother.1",
                                        Vertices = c("Mother.1"))),
            common.children = list(g = 2, Vertices = c("Male"))),
  Female.Side = list(g = 0, G = 12,
    P.G.Father = list(Vertices = c("P.G.Father.2")),
    P.G.Mother = list(Vertices = c("P.G.Mother.2")),
    M.G.Father = list(Vertices = c("M.G.Father.2")),
    M.G.Mother = list(Vertices = c("M.G.Mother.2")),
    common.children = list(g = 0, G = 12, label = "Female",
      Father = list(Vertices = c("Father.2")),
      Mother = list(Vertices = c("Mother.2")),
      common.children = list(g = 2, Vertices = c("Female")))),
  common.children = list(Vertices = c("Marriage"), g = 3, label = "Children",
    Son = list(Vertices = c("Son"), g = 3, 
       P.G.Son = list(Vertices = c("P.G.Son"), g = 2),
       P.G.Dat = list(Vertices = c("P.G.Dat"), g = 1)),
    Dat = list(Vertices = c("Dat"), g = 2,
       M.G.Son = list(Vertices = c("M.G.Son")),
       M.G.Dat = list(Vertices = c("M.G.Dat")))
    )
)

v <- unlist(Block.tree)
V.Names <- v[grep("Vertices", names(v))]
rm(v)

FromTo <- matrix(c("P.G.Father.1", "Father.1", "P.G.Father.2", "Father.2", 
                   "P.G.Mother.1", "Father.1", "P.G.Mother.2", "Father.2", 
                   "M.G.Father.1", "Mother.1", "M.G.Father.2", "Mother.2", 
                   "M.G.Mother.1", "Mother.1", "M.G.Mother.2", "Mother.2", 
                   "Father.1",     "Male",     "Father.2",     "Female",   
                   "Mother.1",     "Male",     "Mother.2",     "Female",   
                   "Male",         "Marriage", "Female",       "Marriage",
                   "Marriage",     "Son",      "Marriage",     "Dat",
                   "Son",          "P.G.Son",  "Dat",          "M.G.Son", 
                   "Son",          "P.G.Dat",  "Dat",          "M.G.Dat"), 
                   byrow = TRUE, ncol = 2)

From <- match(FromTo[,1], V.Names)
To   <- match(FromTo[,2], V.Names)

V.Types <- rep("Discrete", length(V.Names))

Object <- NULL

graph <- new("dg.simple.graph", vertex.names = V.Names, types = V.Types,
             from = From, to = To, block.tree = Block.tree)

W <- dg(graph,
        control = dg.control(width = 600, height = 600, 
                             drawblocks = TRUE, drawBlockFrame = TRUE, 
                             overlaying = TRUE, title = "Pedegree.G"))

Want to suggest features or report bugs for rdrr.io? Use the GitHub issue tracker.