1
#' Export
2
#' 
3
#' Export graph to SVG.
4
#' 
5
#' @inheritParams sg_nodes
6
#' @param proxy An object of class \code{sigmajsProxy} as returned by \code{\link{sigmajsProxy}}.
7
#' @param download set to \code{TRUE} to download.
8
#' @param file Name of file.
9
#' @param size Size of the SVG in pixels.
10
#' @param width,height Width and height of the SVG in pixels.
11
#' @param labels Whether the labels should be included in the svg file.
12
#' @param format Format of image, takes \code{png}, \code{jpg}, \code{gif} or \code{tiff}.
13
#' @param background Background color of image.
14
#' @param data Whether additional data (node ids for instance) should be included in the svg file.
15
#' 
16
#' @examples 
17
#' nodes <- sg_make_nodes() 
18
#' edges <- sg_make_edges(nodes, 17)
19
#' 
20
#' sigmajs() %>% 
21
#'   sg_nodes(nodes, id, size) %>% 
22
#'   sg_edges(edges, id, source, target) %>% 
23
#'   sg_export_svg() %>% 
24
#'   sg_button("export_svg", "download")
25
#' 
26
#' @return An object of class \code{htmlwidget} which renders the visualisation on print.
27
#' Functions ending in \code{_p} return the \code{proxy}.
28
#' 
29
#' @rdname export
30
#' @export
31
sg_export_svg <- function(sg, download = TRUE, file = "graph.svg", size = 1000,
32
                      width = 1000, height = 1000, labels = FALSE, data = FALSE){
33
  
34 1
  if(missing(sg))
35 1
    stop("must pass sg", call. = FALSE)
36
  
37 1
  .test_sg(sg)
38
  
39 1
  sg$x$exportSVG <- list(
40 1
    download = download, 
41 1
    filename = file, 
42 1
    size = 1000,
43 1
    width = width,
44 1
    height = height,
45 1
    labels = labels,
46 1
    data = data
47
  )
48
  
49 1
  sg
50
}
51

52
#' @rdname export
53
#' @export
54
sg_export_img <- function(sg, download = TRUE, file = "graph.png", background = "white",
55
                          format = "png", labels = FALSE){
56
  
57 1
  if(missing(sg))
58 1
    stop("must pass sg", call. = FALSE)
59
  
60 1
  .test_sg(sg)
61
  
62 1
  sg$x$exportIMG <- list(
63 1
    format = format,
64 1
    download = download, 
65 1
    filename = file, 
66 1
    background = background,
67 1
    labels = labels
68
  )
69
  
70 1
  sg
71
}
72

73
#' @rdname export
74
#' @export
75
sg_export_img_p <- function(proxy, download = TRUE, file = "graph.png", background = "white",
76
                          format = "png", labels = FALSE){
77
  
78 0
  if (missing(proxy))
79 0
    stop("must pass proxy", call. = FALSE)
80
  
81 0
  .test_proxy(proxy)
82
  
83 0
  df <- list(
84 0
    format = format,
85 0
    download = download, 
86 0
    filename = file, 
87 0
    background = background,
88 0
    labels = labels
89
  )
90
  
91 0
  message <- list(id = proxy$id, data = df) # create message
92
  
93 0
  proxy$session$sendCustomMessage("sg_export_img_p", message)
94
  
95 0
  return(proxy)
96
}
97

98
#' @rdname export
99
#' @export
100
sg_export_svg_p <- function(proxy, download = TRUE, file = "graph.svg", size = 1000,
101
                      width = 1000, height = 1000, labels = FALSE, data = FALSE){
102
  
103 0
  if (missing(proxy))
104 0
    stop("must pass proxy", call. = FALSE)
105
  
106 0
  .test_proxy(proxy)
107
  
108
  # build data
109 0
  df <- list(
110 0
    download = download, 
111 0
    filename = file, 
112 0
    size = 1000,
113 0
    width = width,
114 0
    height = height,
115 0
    labels = labels,
116 0
    data = data
117
  )
118
  
119 0
  message <- list(id = proxy$id, data = df) # create message
120
  
121 0
  proxy$session$sendCustomMessage("sg_export_svg_p", message)
122
  
123 0
  return(proxy)
124
}

Read our documentation on viewing source code .

Loading