knitr::opts_chunk$set( collapse = TRUE, comment = "#>" )
#library(umlr2) files.r = list.files("../R", pattern="*\\.R$", full.names=TRUE, ignore.case=F) xx = sapply(files.r, source) plant = UMLR$new(plantuml="C:\\SDK\\plantuml\\plantuml.jar")
El paquete provee una clase para generar definiciones UML de objetos R. Actualmente es posible procesar:
El proceso general consiste en crear un objeto UMLR y ejecutar el metodo plotClass
:
# obj = Objeto$new() # Object to plot # uml = UMLR$new() # Get an instance of UMLR # uml$plotClass(obj, detail=level_of_detail, deep=deep_level)
Este parametro define el detalle que se quiere generar de la clase.
Supongamos la siguiente clase sencilla
CLASS0 = R6::R6Class("R6CLASS0", public = list( initialize = function(...) { } ,method0 = function() { } ) ,active = list ( var0 = function(value) { } ) ,private = list ( .var0 = NA ,.method0 = function(data) {} ) ) c0 = CLASS0$new()
En funcion del tipo de detalle requerido el gráfico es diferente.
Nota que dado que no tiene herencia basic
y simple
son equivalentes
| basic | simple | complete |
|:-:|:-:|:-:|
| r plant$plotClass(c0, UMLShow$basic)
|r plant$plotClass(c0, UMLShow$simple)
|r plant$plotClass(c0, UMLShow$complete)
|
Creemos otra clase:
CLASS01 = R6::R6Class("R6CLASS01", inherit=CLASS0, public = list( attr11 = NULL ,attr12 = NULL ,initialize = function() {} ,finalize = function() {} ,method11 = function() {} ) ,private = list( .priv11 = 1 ,.method11 = function(dato) {} ) ) c01 = CLASS01$new()
| basic | simple | complete |
|:-:|:-:|:-:|
|r plant$plotClass(c01, UMLShow$basic)
|r plant$plotClass(c01, UMLShow$simple)
|r plant$plotClass(c01, UMLShow$complete)
|
Incluimos las superclasses en el diagrama. Para esto es necesario contemplar:
basic
con classSimple
o classComplete
deep
Ejemplo: plant$plotClass(clase, c(UMLShow$complete,UMLShow$parents,UMLShow$simple), deep=1)
base = UMLShow$complete + UMLShow$parents
| classBasic | classSimple | classComplete |
|:-:|:-:|:-:|
|r plant$plotClass(c01, base)
|r plant$plotClass(c01, c(base,UMLShow$classSimple))
|r plant$plotClass(c01,c(base,UMLShow$classComplete))
|
Ahora creamos una clase con composicion y agregacion. La composicion se interpreta como las clases que se instancian junto con la propia clase La aregacion se interpreta como que la clase es instanciada en algun otro momento.
CLASS20 = R6::R6Class("R6CLASS20", public = list( attr201 = NULL ,attr202 = NULL ,initialize = function() {} ,finalize = function() {} ,method201 = function() {} ) ,private = list( .priv201 = 1 ,.method201 = function(dato) {} ) ) CLASS21 = R6::R6Class("R6CLASS21", public = list( attr211 = NULL ,attr212 = NULL ,initialize = function() {} ,finalize = function() {} ,method211 = function() {} ) ,private = list( .priv211 = 1 ,.method211 = function(dato) {} ) ) CLASS22 = R6::R6Class("R6CLASS22", public = list( attr221 = NULL ,attr222 = NULL ,initialize = function() {} ,finalize = function() {} ,method221 = function() {} ) ,private = list( .priv221 = 1 ,.method221 = function(dato) {} ) ) CLASS1 = R6::R6Class("R6CLASS1", public = list( cls20 = NULL ,attr12 = NULL ,initialize = function() {cls20 = CLASS20$new()} ,finalize = function() {} ,method11 = function() { cls = CLASS22$new()} ) ,private = list( .cls21 = CLASS21$new() ,.method11 = function(dato) {} ) ) c1 = CLASS1$new()
base = UMLShow$complete + UMLShow$subclasses
plant$plotClass(c1, base)
plant$plotClass(c1, c(base,UMLShow$classSimple))
plant$plotClass(c1,c(base,UMLShow$classComplete))
Caso completo
CLASS20 = R6::R6Class("R6CLASS20", public = list( attr201 = NULL ,attr202 = NULL ,initialize = function() {} ,finalize = function() {} ,method201 = function() {} ) ,private = list( .priv201 = 1 ,.method201 = function(dato) {} ) ) CLASS21 = R6::R6Class("R6CLASS21", inherit = CLASS20, public = list( attr211 = NULL ,attr212 = NULL ,initialize = function() {} ,finalize = function() {} ,method211 = function() {} ) ,private = list( .priv211 = 1 ,.method211 = function(dato) {} ) ) CLASS22 = R6::R6Class("R6CLASS22", public = list( attr221 = NULL ,attr222 = NULL ,initialize = function() {} ,finalize = function() {} ,method221 = function() {} ) ,private = list( .priv221 = 1 ,.method221 = function(dato) {} ) ) CLASS1 = R6::R6Class("R6CLASS1", inherit = CLASS0, public = list( cls20 = NULL ,attr12 = NULL ,initialize = function() {cls20 = CLASS20$new()} ,finalize = function() {} ,method11 = function() { cls = CLASS22$new()} ) ,private = list( .cls21 = CLASS21$new() ,.method11 = function(dato) {} ) ) c1 = CLASS1$new()
base = UMLShow$complete + UMLShow$subclasses + UMLShow$parents
plant$plotClass(c1, c(base,UMLShow$classSimple), deep=5)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.