Skip to content

Commit

Permalink
Make changes for CRAN resubmission
Browse files Browse the repository at this point in the history
  • Loading branch information
rich-iannone committed Jan 16, 2020
1 parent 681f564 commit 5644261
Show file tree
Hide file tree
Showing 17 changed files with 251 additions and 254 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Type: Package
Package: DiagrammeR
Title: Graph/Network Visualization
Version: 1.0.4
Version: 1.0.5
Authors@R:
person("Richard", "Iannone", , "riannone@me.com", c("aut", "cre"),
comment = c(ORCID = "0000-0003-3925-190X"))
Expand Down
2 changes: 1 addition & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# DiagrammeR 1.0.4
# DiagrammeR 1.0.5

* Removes the ability to save a DiagrammeR graph object as a Gephi file (.gexf) since the **rgexf** package is no longer maintained

Expand Down
16 changes: 10 additions & 6 deletions R/add_full_graph.R
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@
#' graph <-
#' create_graph() %>%
#' add_full_graph(
#' n = 3, keep_loops = TRUE)
#' n = 3, keep_loops = TRUE
#' )
#'
#' # Get node information
#' # from this graph
Expand All @@ -58,7 +59,8 @@
#' n = 3,
#' type = "connected",
#' label = c("1st", "2nd", "3rd"),
#' rel = "connected_to")
#' rel = "connected_to"
#' )
#'
#' # Show the graph's node
#' # data frame (ndf)
Expand All @@ -82,9 +84,10 @@
#' sample(9, FALSE) %>%
#' round(2) %>%
#' matrix(
#' nc = 3,
#' nr = 3,
#' dimnames = list(c("a", "b", "c")))
#' ncol = 3,
#' nrow = 3,
#' dimnames = list(c("a", "b", "c"))
#' )
#'
#' # Create the fully-connected
#' # graph (without loops however)
Expand Down Expand Up @@ -118,7 +121,8 @@
#' label = TRUE,
#' rel = "related_to",
#' edge_wt_matrix = edge_wt_matrix,
#' keep_loops = FALSE) %>%
#' keep_loops = FALSE
#' ) %>%
#' get_edge_df()
#'
#' @export
Expand Down
4 changes: 1 addition & 3 deletions R/display_metagraph.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
#' condition of being a property graph, otherwise the function yields an
#' error.
#' @examples
#' \dontrun{
#' # Create a randomized property
#' # graph with 1000 nodes and 1350 edges
#' property_graph <-
Expand Down Expand Up @@ -73,8 +72,7 @@
#' # Display this graph's
#' # metagraph, or, the underlying
#' # graph model for a property graph
#' display_metagraph(property_graph)
#' }
#' # display_metagraph(property_graph)
#'
#' @export
display_metagraph <- function(graph) {
Expand Down
10 changes: 6 additions & 4 deletions R/from_adj_matrix.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@
#' @examples
#' # Create an adjacency matrix
#' adj_matrix <-
#' sample(0:1, 100,
#' replace = TRUE,
#' prob = c(0.9,0.1)) %>%
#' matrix(nc = 10)
#' sample(
#' 0:1, 100,
#' replace = TRUE,
#' prob = c(0.9,0.1)
#' ) %>%
#' matrix(ncol = 10)
#'
#' # Create a graph from the adjacency matrix
#' graph <- from_adj_matrix(adj_matrix)
Expand Down
60 changes: 19 additions & 41 deletions R/grViz.R
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ grViz <- function(diagram = "",
diagram = diagram,
config = list(
engine = engine,
options = options))
options = options
)
)

# Only use the Viewer for newer versions of RStudio,
# but allow other, non-RStudio viewers
Expand All @@ -73,7 +75,8 @@ grViz <- function(diagram = "",
width = width,
height = height,
package = "DiagrammeR",
htmlwidgets::sizingPolicy(viewer.suppress = viewer.suppress))
htmlwidgets::sizingPolicy(viewer.suppress = viewer.suppress)
)
}

#' Widget output function for use in Shiny
Expand All @@ -83,45 +86,19 @@ grViz <- function(diagram = "",
#' coerced to a string and have `px` appended.
#' @param height A valid CSS unit for the height or a number, which will be
#' coerced to a string and have `px` appended.
#' @examples
#' \dontrun{
#' library(shiny)
#' library(shinyAce)
#'
#' ui = shinyUI(fluidPage(fluidRow(
#' column(
#' width=4
#' , aceEditor("ace", selectionId = "selection", value="digraph {A;}")
#' ),
#' column(
#' width = 6
#' , grVizOutput('diagram' )
#' )
#' )))
#'
#' server = function(input, output) {
#' output$diagram <- renderGrViz({
#' grViz(
#' input$ace
#' )
#' })
#'
#' }
#'
#' shinyApp(ui = ui, server = server)
#' }
#'
#' @export
grVizOutput <- function(outputId,
width = '100%',
height = '400px') {
width = "100%",
height = "400px") {

shinyWidgetOutput(
htmlwidgets::shinyWidgetOutput(
outputId = outputId,
'grViz',
width,
height,
package = 'DiagrammeR')
name = "grViz",
width = width,
height = height,
package = "DiagrammeR"
)
}

#' Widget render function for use in Shiny
Expand All @@ -138,11 +115,12 @@ renderGrViz <- function(expr,

if (!quoted) expr <- substitute(expr)

shinyRenderWidget(
expr,
grVizOutput,
env,
quoted = TRUE)
htmlwidgets::shinyRenderWidget(
expr = expr,
outputFunction = grVizOutput,
evn = env,
quoted = TRUE
)
}

#' Add MathJax-formatted equation text
Expand Down
162 changes: 82 additions & 80 deletions R/mermaid.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,103 +19,104 @@
#' Markdown documents, and within Shiny output bindings.
#'
#' @examples
#' \dontrun{
#' \donttest{
#' # Create a simple graph running left to right (note
#' # that the whitespace is not important)
#' DiagrammeR("
#' graph LR
#' A-->B
#' A-->C
#' C-->E
#' B-->D
#' C-->D
#' D-->F
#' E-->F
#' ")
#' # DiagrammeR("
#' # graph LR
#' # A-->B
#' # A-->C
#' # C-->E
#' # B-->D
#' # C-->D
#' # D-->F
#' # E-->F
#' # ")
#'
#' # Create the equivalent graph but have it running
#' # from top to bottom
#' DiagrammeR("
#' graph TB
#' A-->B
#' A-->C
#' C-->E
#' B-->D
#' C-->D
#' D-->F
#' E-->F
#' ")
#' # DiagrammeR("
#' # graph TB
#' # A-->B
#' # A-->C
#' # C-->E
#' # B-->D
#' # C-->D
#' # D-->F
#' # E-->F
#' # ")
#'
#' # Create a graph with different node shapes and
#' # provide fill styles for each node
#' DiagrammeR("graph LR;A(Rounded)-->B[Squared];B-->C{A Decision};
#' C-->D[Square One];C-->E[Square Two];
#' style A fill:#E5E25F; style B fill:#87AB51; style C fill:#3C8937;
#' style D fill:#23772C; style E fill:#B6E6E6;"
#' )
#' # DiagrammeR("graph LR;A(Rounded)-->B[Squared];B-->C{A Decision};
#' # C-->D[Square One];C-->E[Square Two];
#' # style A fill:#E5E25F; style B fill:#87AB51; style C fill:#3C8937;
#' # style D fill:#23772C; style E fill:#B6E6E6;"
#' # )
#'
#' # Load in the 'mtcars' dataset
#' data(mtcars)
#' connections <- sapply(
#' 1:ncol(mtcars)
#' ,function(i) {
#' paste0(
#' i
#' ,"(",colnames(mtcars)[i],")---"
#' ,i,"-stats("
#' ,paste0(
#' names(summary(mtcars[,i]))
#' ,": "
#' ,unname(summary(mtcars[,i]))
#' ,collapse="<br/>"
#' )
#' ,")"
#' )
#' }
#' )
#' # data(mtcars)
#' # connections <- sapply(
#' # 1:ncol(mtcars)
#' # ,function(i) {
#' # paste0(
#' # i
#' # ,"(",colnames(mtcars)[i],")---"
#' # ,i,"-stats("
#' # ,paste0(
#' # names(summary(mtcars[,i]))
#' # ,": "
#' # ,unname(summary(mtcars[,i]))
#' # ,collapse="<br/>"
#' # )
#' # ,")"
#' # )
#' # }
#' # )
#'
#' # Create a diagram using the 'connections' object
#' DiagrammeR(
#' paste0(
#' "graph TD;", "\n",
#' paste(connections, collapse = "\n"),"\n",
#' "classDef column fill:#0001CC, stroke:#0D3FF3, stroke-width:1px;" ,"\n",
#' "class ", paste0(1:length(connections), collapse = ","), " column;"
#' )
#' )
#' # DiagrammeR(
#' # paste0(
#' # "graph TD;", "\n",
#' # paste(connections, collapse = "\n"),"\n",
#' # "classDef column fill:#0001CC, stroke:#0D3FF3, stroke-width:1px;" ,"\n",
#' # "class ", paste0(1:length(connections), collapse = ","), " column;"
#' # )
#' # )
#'
#' # Also with `DiagrammeR()`, you can use tags
#' # from `htmltools` (just make sure to use
#' # `class = "mermaid"`)
#' library(htmltools)
#' diagramSpec = "
#' graph LR;
#' id1(Start)-->id2(Stop);
#' style id1 fill:#f9f,stroke:#333,stroke-width:4px;
#' style id2 fill:#ccf,stroke:#f66,stroke-width:2px,stroke-dasharray: 5, 5;
#' "
#' html_print(tagList(
#' tags$h1("R + mermaid.js = Something Special")
#' ,tags$pre(diagramSpec)
#' ,tags$div(class="mermaid",diagramSpec)
#' ,DiagrammeR()
#' ))
#' # diagramSpec = "
#' # graph LR;
#' # id1(Start)-->id2(Stop);
#' # style id1 fill:#f9f,stroke:#333,stroke-width:4px;
#' # style id2 fill:#ccf,stroke:#f66,stroke-width:2px,stroke-dasharray: 5, 5;
#' # "
#' # html_print(tagList(
#' # tags$h1("R + mermaid.js = Something Special")
#' # ,tags$pre(diagramSpec)
#' # ,tags$div(class="mermaid", diagramSpec)
#' # ,DiagrammeR()
#' # ))
#'
#' # Create a sequence diagram
#' DiagrammeR("
#' sequenceDiagram;
#' customer->>ticket seller: ask for a ticket;
#' ticket seller->>database: seats;
#' alt tickets available
#' database->>ticket seller: ok;
#' ticket seller->>customer: confirm;
#' customer->>ticket seller: ok;
#' ticket seller->>database: book a seat;
#' ticket seller->>printer: print a ticket;
#' else sold out
#' database->>ticket seller: none left;
#' ticket seller->>customer: sorry;
#' end
#' ")
#' # DiagrammeR("
#' # sequenceDiagram;
#' # customer->>ticket seller: ask for a ticket;
#' # ticket seller->>database: seats;
#' # alt tickets available
#' # database->>ticket seller: ok;
#' # ticket seller->>customer: confirm;
#' # customer->>ticket seller: ok;
#' # ticket seller->>database: book a seat;
#' # ticket seller->>printer: print a ticket;
#' # else sold out
#' # database->>ticket seller: none left;
#' # ticket seller->>customer: sorry;
#' # end
#' # ")
#' }
#'
#' @import htmlwidgets
Expand Down Expand Up @@ -157,5 +158,6 @@ mermaid <- function(diagram = "",
x = x,
width = width,
height = height,
package = "DiagrammeR")
package = "DiagrammeR"
)
}
2 changes: 1 addition & 1 deletion R/render_graph.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#' @param height An optional parameter for specifying the height of the
#' resulting graphic in pixels.
#' @examples
#' \dontrun{
#' \donttest{
#' # Render a graph that's a
#' # balanced tree
#' create_graph() %>%
Expand Down
Loading

0 comments on commit 5644261

Please sign in to comment.