@@ -24,44 +24,112 @@ gexf_js_install <- function(path, overwrite = FALSE) {
24
24
25
25
}
26
26
27
+
28
+
27
29
# ' @rdname plot.gexf
28
- # ' @param config List of parameters to be written in \code{config.js}.
29
30
# ' @export
30
- gexf_js_make_config <- function (
31
+ # ' @param showEdges Logical scalar. Default state of the "show edges" button (nullable).
32
+ # ' @param useLens Logical scalar. Default state of the "use lens" button (nullable).
33
+ # ' @param zoomLevel Numeric scalar. Default zoom level. At zoom = 0, the graph
34
+ # ' should fill a 800x700px zone
35
+ # ' @param curvedEdges Logical scalar. False for curved edges, true for straight
36
+ # ' edges this setting can't be changed from the User Interface.
37
+ # ' @param edgeWidthFactor Numeric scalar. Change this parameter for wider or
38
+ # ' narrower edges this setting can't be changed from the User Interface.
39
+ # ' @param minEdgeWidth Numeric scalar.
40
+ # ' @param maxEdgeWidth Numeric scalar.
41
+ # ' @param textDisplayThreshold Numeric scalar.
42
+ # ' @param nodeSizeFactor Numeric scalar. Change this parameter for smaller or
43
+ # ' larger nodes this setting can't be changed from the User Interface.
44
+ # ' @param replaceUrls Logical scalar. Enable the replacement of Urls by
45
+ # ' Hyperlinks this setting can't be changed from the User Interface.
46
+ # ' @param showEdgeWeight Logical scalar. Show the weight of edges in the list
47
+ # ' this setting can't be changed from the User Interface.
48
+ # ' @param showEdgeLabel Logical scalar.
49
+ # ' @param sortNodeAttributes Logical scalar. Alphabetically sort node attributes.
50
+ # ' @param showId Logical scalar. Show the id of the node in the list
51
+ # ' this setting can't be changed from the User Interface.
52
+ # ' @param showEdgeArrow Logical scalar. Show the edge arrows when the edge is
53
+ # ' directed this setting can't be changed from the User Interface.
54
+ # ' @param language Either \code{FALSE}, or a character scalar with any of the
55
+ # ' supported languages.
56
+ # '
57
+ # ' @details
58
+ # ' Currently, the only languages supported are:
59
+ # ' \Sexpr[results=text]{paste(names(rgexf:::gexf_js_languages), " (", rgexf:::gexf_js_languages, ")", sep="", collapse=", ")}.
60
+ # '
61
+ gexf_js_config <- function (
31
62
dir ,
32
- graphFile = " network.gexf" ,
33
- config = list (
34
- showEdges = " true" ,
35
- useLens = " false" ,
36
- zoomLevel = " 0" ,
37
- curvedEdges = " true" ,
38
- edgeWidthFactor = " 1" ,
39
- minEdgeWidth = " 1" ,
40
- maxEdgeWidth = " 50" ,
41
- textDisplayThreshold = " 9" ,
42
- nodeSizeFactor = " 1" ,
43
- replaceUrls = " true" ,
44
- showEdgeWeight = " true" ,
45
- showEdgeLabel = " true" ,
46
- sortNodeAttributes = " true" ,
47
- showId = " true" ,
48
- showEdgeArrow = " true" ,
49
- language = " false"
50
- )
63
+ graphFile = " network.gexf" ,
64
+ showEdges = TRUE ,
65
+ useLens = FALSE ,
66
+ zoomLevel = 0 ,
67
+ curvedEdges = TRUE ,
68
+ edgeWidthFactor = 1 ,
69
+ minEdgeWidth = 1 ,
70
+ maxEdgeWidth = 50 ,
71
+ textDisplayThreshold = 9 ,
72
+ nodeSizeFactor = 1 ,
73
+ replaceUrls = TRUE ,
74
+ showEdgeWeight = TRUE ,
75
+ showEdgeLabel = TRUE ,
76
+ sortNodeAttributes = TRUE ,
77
+ showId = TRUE ,
78
+ showEdgeArrow = TRUE ,
79
+ language = FALSE
80
+
51
81
) {
52
82
53
83
doc <- readLines(system.file(" gexf-js/config.js.template" , package = " rgexf" ))
54
-
55
- # Validating language
56
- if (config $ language != " false" && ! (config $ language %in% gexf_js_languages ))
84
+
85
+ # Getting the name of the environment
86
+ env <- environment()
87
+
88
+ # Validating parameters ------------------------------------------------------
89
+ if (! is.logical(language ) && ! (language %in% gexf_js_languages ))
57
90
stop(" The specified language is not available. See ?gexf_js" )
91
+ else if (is.logical(language ) && ! language )
92
+ language <- " false"
93
+ else if (! is.logical(language ))
94
+ language <- paste0(" \" " , language , " \" " )
95
+
96
+ # Logical values
97
+ bool <- c(" curvedEdges" , " replaceUrls" , " showEdgeWeight" ,
98
+ " showEdgeLabel" , " sortNodeAttributes" , " showId" , " showEdgeArrow" )
99
+
100
+ for (p in bool ) {
101
+ if (! is.logical(env [[p ]])) stop(" The parameter -" , p ," - should be logical scalar." )
102
+ env [[p ]] <- if (env [[p ]]) " true" else " false"
103
+ }
104
+
105
+ # Nullable
106
+ null <- c(" showEdges" , " useLens" )
107
+
108
+ for (p in null ) {
109
+ if (! length(env [[p ]])) {
110
+ env [[p ]] <- " null"
111
+ } else if (! is.logical(env [[p ]])) stop(" The parameter -" , p ," - should be logical scalar or NULL." )
112
+ else
113
+ env [[p ]] <- if (env [[p ]]) " true" else " false"
114
+ }
115
+
116
+ # Numeric values
117
+ num <- c(" zoomLevel" , " edgeWidthFactor" , " minEdgeWidth" , " maxEdgeWidth" ,
118
+ " textDisplayThreshold" , " nodeSizeFactor" )
119
+
120
+ for (p in num ) {
121
+ env [[p ]] <- as.character(env [[p ]])
122
+ if (is.na(env [[p ]])) stop(" The parameter -" , p ," - should be numeric." )
123
+ }
124
+
125
+
58
126
59
127
# Name of the graph file
60
128
doc <- gsub(" $graphFile$" , paste0(" \" " , graphFile , " \" " ), doc , fixed = TRUE )
61
129
62
130
# Parameters
63
- for (p in names( config ))
64
- doc <- gsub(paste0(" $" ,p ," $" ), config [[ p ]] , doc , fixed = TRUE )
131
+ for (p in c( bool , num , null , " language " ))
132
+ doc <- gsub(paste0(" $" ,p ," $" ), get( p ) , doc , fixed = TRUE )
65
133
66
134
write(doc , file = paste0(dir ," /config.js" ))
67
135
@@ -103,7 +171,10 @@ gexf_js_make_config <- function(
103
171
# '
104
172
# ' }
105
173
# '
106
- # ' @references gexf-js project website \url{https://github.com/raphv/gexf-js}.
174
+ # ' @references
175
+ # ' gexf-js project website \url{https://github.com/raphv/gexf-js}.
176
+ # '
177
+ # '
107
178
plot.gexf <- function (
108
179
x ,
109
180
y = NULL ,
@@ -120,7 +191,7 @@ plot.gexf <- function(
120
191
gexf_js_install(dir , overwrite = overwrite )
121
192
122
193
# Step 2: Setup file
123
- gexf_js_make_config (dir , graphFile , ... )
194
+ gexf_js_config (dir , graphFile , ... )
124
195
125
196
# Step 4: Lunch the server
126
197
if (! copy.only )
0 commit comments