Skip to content

Commit 76906e2

Browse files
committed
Working on gexf-js and adding contributors in the DESCRIPTION file
1 parent 2b0a4f9 commit 76906e2

File tree

7 files changed

+165
-46
lines changed

7 files changed

+165
-46
lines changed

DESCRIPTION

+3-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ Date: 2017-11-05
77
Authors@R: c(
88
person("George", "Vega Yon", email="[email protected]", role=c("aut", "cre")),
99
person("Jorge", "Fábrega Lacoa", role=c("ctb")),
10-
person("Joshua", "Kunst", role=c("ctb")))
10+
person("Joshua", "Kunst", role=c("ctb")),
11+
person("Raphaël", "Velt", role=c("ctb", "cph"), comment="gexf-js library"),
12+
person(family="Gephi Consortium", role=c("ctb", "cph"), comment="GEXF language"))
1113
Description: Create, read and write GEXF (Graph Exchange XML Format) graph
1214
files (used in Gephi and others). Using the XML package, it allows the user to
1315
easily build/read graph files including attributes, GEXF viz attributes (such

NAMESPACE

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export(checkTimes)
1212
export(edge.list)
1313
export(gexf)
1414
export(gexf.to.igraph)
15-
export(gexf_js_make_config)
15+
export(gexf_js_config)
1616
export(igraph.to.gexf)
1717
export(new.gexf.graph)
1818
export(read.gexf)

R/gexf-js.r

+99-28
Original file line numberDiff line numberDiff line change
@@ -24,44 +24,112 @@ gexf_js_install <- function(path, overwrite = FALSE) {
2424

2525
}
2626

27+
28+
2729
#' @rdname plot.gexf
28-
#' @param config List of parameters to be written in \code{config.js}.
2930
#' @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(
3162
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+
5181
) {
5282

5383
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))
5790
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+
58126

59127
# Name of the graph file
60128
doc <- gsub("$graphFile$", paste0("\"", graphFile, "\""), doc, fixed = TRUE)
61129

62130
# 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)
65133

66134
write(doc, file = paste0(dir,"/config.js"))
67135

@@ -103,7 +171,10 @@ gexf_js_make_config <- function(
103171
#'
104172
#' }
105173
#'
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+
#'
107178
plot.gexf <- function(
108179
x,
109180
y = NULL,
@@ -120,7 +191,7 @@ plot.gexf <- function(
120191
gexf_js_install(dir, overwrite = overwrite)
121192

122193
# Step 2: Setup file
123-
gexf_js_make_config(dir, graphFile, ...)
194+
gexf_js_config(dir, graphFile, ...)
124195

125196
# Step 4: Lunch the server
126197
if (!copy.only)

R/rgexf-package.r

+4-3
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ NULL
126126
#' position), network dynamics (for both edges and nodes) and edge weighting.
127127
#'
128128
#' Users can build/handle graphs element-by-element or massively through
129-
#' data-frames, visualize the graph on a web browser through "sigmajs" (a
129+
#' data-frames, visualize the graph on a web browser through "gexf-js" (a
130130
#' javascript library) and interact with the igraph package.
131131
#'
132132
#' Finally, the functions \code{igraph.to.gexf} and \code{gexf.to.igraph}
@@ -145,8 +145,9 @@ NULL
145145
#' @references \itemize{ \item rgexf project site:
146146
#' \url{https://github.com/gvegayon/rgexf} \item Gephi project site:
147147
#' \url{https://gephi.org/} \item GEXF project site: \url{http://gexf.net/}
148-
#' \item Sigmasj project site :
149-
#' \url{http://sigmajs.org/} }
148+
#' \item gexf-js project website: \url{https://github.com/raphv/gexf-js}
149+
#' \item Sigmasj project site: \url{http://sigmajs.org/}
150+
#' }
150151
#' @keywords package
151152
#' @examples
152153
#'

demo/gexfrandom.R

+3-1
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ for (i in 2:n) {
5959
pos[i,2] <- pos[i-1,2] + sin(2*pi*(i-1)/n)
6060
}
6161

62+
pos[,2] <- pos[,2] - mean(pos[,2])
63+
6264
pos <- pos/(max(pos)-min(pos))*500
6365
pos2 <- pos
6466
pos2[,1] <- pos2[,1] + max(pos2[,1])-min(pos[,1])
@@ -81,4 +83,4 @@ graph <- gexf(
8183

8284
pause()
8385

84-
plot(graph)
86+
plot(graph, edgeWidthFactor=2)

man/plot.gexf.Rd

+51-9
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/rgexf-package.Rd

+4-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)