dg.graphedges-class: Class dg.graphedges

Description Objects from the Class Slots Methods Author(s) See Also Examples

Description

The representation of a graph for dynamicGraph. Vertices, blocks, viewType, edges, etc. are here the dynamicGraph objects.

Objects from the Class

Objects can be created by calls of the form new("dg.graphedges", ...).

Slots

viewType:

Object of class "character" with the type of view.

visibleVertices:

Object of class "numeric": Numeric vector of the indices of the vertices of vertexList to plot.

visibleBlocks:

Object of class "numeric": Numeric vector of the indices of the blocks of blockList to plot.

oriented:

Object of class "logical": If TRUE (or FALSE) then edges are oriented (or not), also when blocks are missing. If NA then the edges are directed according to the blocks of the edge.

edgeList:

Object of class "dg.VertexEdgeList": List of edges (of class containing dg.Edge) created by returnEdgeList or exported from dynamicGraphMain.

blockEdgeList:

Object of class "dg.BlockEdgeList": List of blockedges (of class containing the class dg.BlockEdge) created by returnBlockEdgeList or exported from dynamicGraphMain.

factorVertexList:

Object of class "dg.FactorVertexList": List of secondary vertices, called factor vertices, for, e.g., the generators of the model, (each of class containing dg.FactorVertex) created by returnFactorVerticesAndEdges or exported from dynamicGraphMain.

factorEdgeList:

Object of class "dg.FactorEdgeList": List of bipartite graph edges, called factor edges, (each of class containing dg.FactorEdge) created by the function returnFactorEdgeList or exported from dynamicGraphMain. Factor edges are edges between vertices and factor vertices.

extraList:

Object of class "dg.VertexList": List of vertices (of class containing the class dg.Vertex) created by the function returnVertexList or exported from the function dynamicGraphMain, for, e.g., additional titles in the plot.

extraEdgeList:

Object of class "dg.ExtraEdgeList": List of edges between extra vertices and vertices.

Methods

addModel

signature(object = "dg.graphedges"): ...

addView

signature(object = "dg.graphedges"): ...

replaceModel

signature(object = "dg.graphedges"): ...

replaceView

signature(object = "dg.graphedges"): ...

show

signature(object = "dg.graphedges"): ...

Str

signature(object = "dg.graphedges"): ...

blockEdgeList<-

signature(x = "dg.graphedges"): ...

blockEdgeList

signature(object = "dg.graphedges"): ...

blockList<-

signature(x = "dg.graphedges"): ...

blockList

signature(object = "dg.graphedges"): ...

edgeList<-

signature(x = "dg.graphedges"): ...

edgeList

signature(object = "dg.graphedges"): ...

extraEdgeList<-

signature(x = "dg.graphedges"): ...

extraEdgeList

signature(object = "dg.graphedges"): ...

extraList<-

signature(x = "dg.graphedges"): ...

extraList

signature(object = "dg.graphedges"): ...

factorEdgeList<-

signature(x = "dg.graphedges"): ...

factorEdgeList

signature(object = "dg.graphedges"): ...

factorVertexList<-

signature(x = "dg.graphedges"): ...

factorVertexList

signature(object = "dg.graphedges"): ...

oriented

signature(object = "dg.graphedges"): ...

viewType<-

signature(x = "dg.graphedges"): ...

viewType

signature(object = "dg.graphedges"): ...

visibleBlocks<-

signature(x = "dg.graphedges"): ...

visibleBlocks

signature(object = "dg.graphedges"): ...

visibleVertices<-

signature(x = "dg.graphedges"): ...

visibleVertices

signature(object = "dg.graphedges"): ...

Author(s)

Jens Henrik Badsberg

See Also

dg.simple.graph-class, dg.graph-class, and dynamicGraphMain.

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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
# The use of "addModel"  and "addModel"
# in the example "usermenus" of demo:

your.DrawModel <- function(object, slave = FALSE, viewType = "Simple", ...) {

    dots <- list(...)
    localArguments    <- dots$Arguments

    # Here you should make your new model.
    # A copy is made by the following:

    ModelObject <- object

    title <- ModelObject@name

    # and compute graph edges:

    dgEdges <- graphEdges(ModelObject, viewType, Arguments = localArguments)

    show(dgEdges)

    if (slave) {
      # Drawing ''an other model'' in a new window:
      addModel(dgEdges, 
               frameModels =        localArguments$frameModels, 
               modelObject =        ModelObject, 
               modelObjectName =    ModelObject@name)
    }
    else {
      # Overwriting with ''an other model'' in same view:
      replaceModel(dgEdges,
                   frameModels     = localArguments$frameModels, 
                   modelIndex      = localArguments$modelIndex, 
                   viewIndex       = localArguments$viewIndex, 
                   modelObject     = ModelObject, 
                   modelObjectName = ModelObject@name) 
    }
}

your.LabelAllEdges <- function(object, slave = FALSE, ...) 
 {

  dots           <- list(...)
  localArguments <-      dots$Arguments
  dg             <-      localArguments$dg

  # browser()

  getNodeName <- function(index, type)
    if (type == "Vertex")
      name(localArguments$frameModel@vertices[[index]])
    else if (type == "Factor")
      name(localArguments$dg@factorVertexList[[abs(index)]])
    else if (type == "Extra")
      name(localArguments$dg@extraList[[abs(index)]])
    else if (type == "Block")
      label(localArguments$dg@blockList[[abs(index)]])
    else
      NULL

  visitEdges <- function(edges) {
    for (i in seq(along = edges)) {
      vertices <- nodeIndicesOfEdge(edges[[i]])
      types    <- nodeTypesOfEdge(edges[[i]])

      name.f <- getNodeName(vertices[1], types[1])
      name.t <- getNodeName(vertices[2], types[2])

      R <- testEdge(object, action = "remove",
                    name.1 = name.f, name.2 = name.t,
                    from = vertices[1], to = vertices[2],
                    from.type = types[1], to.type = types[2],
                    edge.index = i, force = force, Arguments = localArguments)

      if (!is.null(R)) {
        if (TRUE || (hasMethod("label", class(R))))
          label(edges[[i]]) <- label(R)
        if (TRUE || (hasMethod("width", class(R))))
          width(edges[[i]]) <- width(R)
      }
    }
    return(edges)
  }

  dg@edgeList       <- visitEdges(dg@edgeList)
  dg@factorEdgeList <- visitEdges(dg@factorEdgeList)
  dg@blockEdgeList  <- visitEdges(dg@blockEdgeList)

  if (slave) {
    # Drawing ''an other model'' in a new window:
    addModel(dg, 
             frameModels     = localArguments$frameModels, 
             modelObject     = localArguments$object, 
             modelObjectName = localArguments$object@name)
  }
  else {
    # Overwriting with ''an other model'' in same view:
    replaceModel(dg,
                 frameModels     = localArguments$frameModels, 
                 frameViews      = localArguments$frameViews, 
                 graphWindow     = localArguments$graphWindow, 
                 modelObject     = localArguments$object, 
                 modelObjectName = localArguments$object@name)
  }

}

 test.function <- function(...) print("Test.Function")
 test.function <- function(...) print(list(...)$Arguments$object@name)

 Menus <- 
 list(MainUser = 
      list(label = 
      "Transformation by 'prcomp' on position of \"vertices\", and redraw",
           command = function(object, ...) {
             localArguments <- list(...)$Arguments
             transformation <- 
                  t(prcomp(Positions(localArguments$vertexList))$rotation)
             control <- localArguments$control
             control$transformation <- transformation
             replaceControls(control, 
                             frameModels = localArguments$frameModels, 
                             modelIndex  = localArguments$modelIndex,
                             viewIndex   = localArguments$viewIndex,
                             Arguments   = localArguments)
             }),
      MainUser = 
      list(label = "Position of \"vertices\" by 'cmdscale', and redraw",
           command = function(object, ...) {
             localArguments <- list(...)$Arguments
             Vertices <- localArguments$dg@vertexList
             Edges <- localArguments$dg@edgeList
             positions <- Positions(localArguments$dg@vertexList)
             N <- dim(positions)[2]
             e <- NodeIndices(Edges)
             n <- Names(Vertices)
             X <- matrix(rep(-1, length(n)^2), ncol = length(n))
             for (i in 1:length(e)) {
               suppressWarnings(w <- as.numeric(names(e)[i]))
               if (is.na(w)) w <- .5
               X[e[[i]][1], e[[i]][2]] <- w
               X[e[[i]][2], e[[i]][1]] <- w
             }
             dimnames(X) <- list(n, n)
             d <- 1.25
             X[X==-1] <- d
             X <- X - d * diag(length(n))
             mdsX <- cmdscale(X, k = N, add = TRUE, eig = TRUE, x.ret = TRUE)
             # mdsX <- isoMDS(X, k = N)
             M <- max(abs(mdsX$points))
             Positions(localArguments$dg@vertexList) <<- mdsX$points / M * 45

             # replaceVertexList(localArguments$vertexList, 
             #                   frameModels = localArguments$frameModels, 
             #                   modelIndex  = localArguments$modelIndex,
             #                   viewIndex   = localArguments$viewIndex,
             #                   Arguments   = localArguments)

             vertices(localArguments$frameModels) <- 
                                                localArguments$dg@vertexList
             }),
      MainUser = 
      list(label = "Position of \"vertices\"",
           command = function(object, ...) 
             print(Positions(list(...)$Arguments$vertexList))),
      MainUser = 
      list(label = "Label all edges, in this window",
           command = function(object, ...) 
                       your.LabelAllEdges(object, slave = FALSE, ...)),
      MainUser = 
      list(label = "Label all edges, in slave window",
           command = function(object, ...) 
                       your.LabelAllEdges(object, slave = TRUE, ...)),
      MainUser = 
      list(label = "Draw model, in this window",
           command = function(object, ...) 
                       your.DrawModel(object, slave = FALSE, ...)),
      MainUser = 
      list(label = "Draw model, in slave window",
           command = function(object, ...) 
                       your.DrawModel(object, slave = TRUE, ...)),
      MainUser = 
      list(label = "Call of function 'modalDialog', result on 'title' at top",
           command = function(object, ...) 
           {
             localArguments <- list(...)$Arguments
             ReturnVal <- modalDialog("Test modalDialog Entry",
                                      "Enter name", 
                                      localArguments$control$title, 
                                      top = localArguments$top)
             print(ReturnVal)
             if (ReturnVal == "ID_CANCEL")
               return()
             tktitle(localArguments$top) <- ReturnVal
           }
          ),
      MainUser = 
      list(label = 
           "Call of function 'test.function', result on 'viewLabel' at bottom",
           command = function(object, ...)
           {
             localArguments <- list(...)$Arguments
             tkconfigure(localArguments$viewLabel, 
                         text = paste(localArguments$dg@viewType, " | ", 
                                      test.function(...))) } ),
      MainUser = 
      list(label = 
           "Test of 'Arguments'",
           command = function(object, ...)
           {

             dots              <- list(...)
             localArguments    <- list(...)$Arguments

             print(names(dots))
             print(names(localArguments))

             # Only the nine values
             # "frameModels", "modelIndex", "viewIndex",
             # "object", "objectName",
             # "selectedNodes", "selectedEdges",
             # "closedBlock", and "hiddenBlock "
             # should be extracted from "list(...)$Arguments":

             frameModels       <- localArguments$frameModels

             modelIndex        <- localArguments$modelIndex
             viewIndex         <- localArguments$viewIndex

             object            <- localArguments$object
             objectName        <- localArguments$objectName

             selectedNodes     <- localArguments$selectedNodes
             selectedEdges     <- localArguments$selectedEdges
             closedBlock       <- localArguments$closedBlock
             hiddenBlock       <- localArguments$hiddenBlock

             #  "control" can alse be extracted from "framModels"

             Control           <- localArguments$control

             control           <- frameModels@control

             # These 3 are 'deprecated':

             drawModel         <- localArguments$drawModel   #
             redrawView        <- localArguments$redrawView  #

             envir             <- localArguments$envir       #

             # The following are currently retained in "list(...)$Arguments", 
             # but can be extracted from the above teen values:

             frameViews        <- frameModels@models[[modelIndex]]
             graphWindow       <- frameViews@graphs[[viewIndex]]

             vertexList        <- frameModels@vertices
             blockList         <- frameModels@blocks

             dg                <- graphWindow@dg

             visibleVertices   <- visibleVertices(dg)
             visibleBlocks     <- visibleBlocks(dg)
             edgeList          <- edgeList(dg)
             oriented          <- oriented(dg)
             blockEdgeList     <- blockEdgeList(dg)
             factorVertexList  <- factorVertexList(dg)
             factorEdgeList    <- factorEdgeList(dg)
             extraList         <- extraList(dg)
             extraEdgeList     <- extraEdgeList(dg)

             viewType          <- viewType(dg)

             top               <- top(graphWindow)
             box               <- vbox(graphWindow)
             canvas            <- canvas(graphWindow)
             viewLabel         <- viewLabel(graphWindow)
             tags              <- tags(graphWindow)

             # The values now in 'control' are no longer 
             # avaliable in "list(...)$Arguments":

             title             <- control$label # bad example since the  
                                                # name "title" has been  
                                                # change to "label".

             vertexColor       <- control$vertexColor

             print(names(control))

             browser()

             } ),

      Vertex = 
      list(label = "Test of user popup menu for vertices: Label",
           command = function(object, name, ...) 
           {
             # print(name)
             dots <- list(...)
             # print(names(dots))
             # print(c(dots$type))
             # print(c(dots$index))
             localArguments <- dots$Arguments
             # print(names(localArguments))
             # str(localArguments$selectedNodes)
             # str(localArguments$selectedEdges)
             print(localArguments$dg@vertexList[[dots$index]]@label)
           }
          ),
      Edge = 
      list(label = "Test of user popup menu for edges: Class",
           command = function(object, name1, name2, ...) 
           {
             dots           <- list(...)
             localArguments <-      dots$Arguments

             # print(c(name1, name2))
             # print(c(dots$edge.index, dots$which.edge, dots$from, dots$to))
             # print(c(dots$from.type, dots$to.type, dots$edge.type))
             # print(names(localArguments))
             # str(localArguments$selectedNodes)
             # str(localArguments$selectedEdges)

             ReturnVal <- selectDialog("Test selectDialog Entry", 
                                       "Select name", 
                                       localArguments$control$edgeClasses[,1], 
                                       top = localArguments$top)
             print(ReturnVal)
             if (ReturnVal == "ID_CANCEL")
               return()
             if ((dots$from > 0) && (dots$to > 0)) {
               dg <- localArguments$dg
               class(dg@edgeList[[dots$edge.index]]) <- 
                           localArguments$control$edgeClasses[ReturnVal, 2]
               # replaceView ?
               replaceModel(dg,
                   frameModels     = localArguments$frameModels, 
                   modelIndex      = localArguments$modelIndex, 
                   viewIndex       = localArguments$viewIndex, 
                   modelObject     = localArguments$object, 
                   modelObjectName = localArguments$objectName) 
             }
           }
          ),
      ClosedBlock = 
      list(label = "Test of user popup menu for blocks",
           command = function(object, name, ...) 
           {
             print(name)
             print(c(list(...)$index))
           }
          )
     )

dynamicGraph documentation built on May 2, 2019, 6:38 a.m.