Skip to content

Commit

Permalink
Fixing bug on processing visual attributes and start working on issue #…
Browse files Browse the repository at this point in the history
  • Loading branch information
gvegayon committed Jan 31, 2020
1 parent 28a4031 commit 3701780
Show file tree
Hide file tree
Showing 7 changed files with 79 additions and 15 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@
*.pdf
.Rproj.user
inst/doc
docs/
32 changes: 24 additions & 8 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,35 @@ language: R
sudo: false
cache: packages

r:
- release
- devel # Not working
matrix:
include:
# - os: linux
# r: oldrel
- os: linux
r: release
env:
- R_CODECOV=true
- BUILD_WWW_HERE=true
- os: linux
r: devel
- os: osx
osx_image: xcode10.2

os:
- linux
- osx

osx_image: xcode11

env:
global:
- CRAN: http://cran.rstudio.com

after_success:
- if [ $TRAVIS_OS_NAME == "linux" ]; then Rscript -e 'covr::codecov()'; fi

# For automatic deploy of the website
before_deploy: Rscript -e 'remotes::install_cran("pkgdown")'
deploy:
provider: script
script: Rscript -e 'pkgdown::deploy_site_github()'
skip_cleanup: true
on:
branch: master
condition: $BUILD_WWW_HERE = true

11 changes: 10 additions & 1 deletion R/bugs.r
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,10 @@ viz_att_checks$color <- function(x, type) {
viz_att_checks$position <- function(x, type) {

# Must be able to be coerced to a matrix
x <- as.matrix(x)
if (is.vector(x))
x <- matrix(x, nrow = 1)
else
x <- as.matrix(x)

# Is it numeric?
if (!is.numeric(x))
Expand All @@ -197,6 +200,12 @@ viz_att_checks$position <- function(x, type) {
# Adding z?
if (ncol(x) == 2)
x <- cbind(x, 0)
if (!(ncol(x) %in% c(2,3)))
stop(
"Positions should be specified with either 2 (X,Y) or 3 (X, Y, Z) coordinates.",
call. = FALSE
)


dimnames(x) <- list(NULL, paste0("viz.position.",c("x", "y", "z")))

Expand Down
16 changes: 16 additions & 0 deletions R/gexf-js.r
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,22 @@ gexf_js_config <- function(
#' as specified by `dir`.
#'
#' @details
#'
#' An important thing for the user to consider is the fact that the function
#' only works if there are `viz` attributes, this is, color, size, and position.
#' If the [gexf] object's XML document does not have viz attributes, users can
#' use the following hack:
#'
#' ```
#' # Turn the object ot igraph and go back
#' x <- igraph.to.gexf(gexf.to.igraph(x))
#'
#' # And you are ready to plot!
#' plot(x)
#' ```
#'
#' More details on this in the [igraph.to.gexf] function.
#'
#' The files are copied directly from
#' \Sexpr{system.file("gexf-js", package="rgexf")}. And the
#' parameters are set up by modifying the following template file:
Expand Down
17 changes: 15 additions & 2 deletions R/read.gexf.r
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,18 @@ read.gexf <- function(x) {
# Extracting attributes
node.vizattr <- XML::xpathApply(
gfile, "/r:gexf/r:graph/r:nodes/r:node", namespaces = c(r=ns, v="viz"),
fun=XML::xmlChildren)
fun=XML::xmlChildren
)

node.attr <- XML::xpathApply(
gfile, "/r:gexf/r:graph/r:nodes/r:node/r:attvalues", namespaces = c(r=ns),
fun=XML::xmlChildren
)

node.attr <- lapply(node.attr, lapply, XML::xmlAttrs)

node.vizattr <- lapply(node.vizattr, lapply, XML::xmlAttrs)
# node.vizattr <- lapply(node.viz)

# Colors
nodesVizAtt$color <- lapply(node.vizattr, function(a) {
Expand All @@ -110,25 +119,29 @@ read.gexf <- function(x) {
})

nodesVizAtt$color <- do.call(rbind, nodesVizAtt$color)

nodesVizAtt$color <- as.data.frame(nodesVizAtt$color)
dimnames(nodesVizAtt$color) <- list(
1L:nrow(nodesVizAtt$color), c("r", "g", "b", "a")
)


# Size
nodesVizAtt$size <- lapply(node.vizattr, function(a) {
if (length(a$size))
return(viz_att_checks$size(as.numeric(a$size)))

check_and_map_color(default_nodeVizAtt$size())
viz_att_checks$size(default_nodeVizAtt$size())
})

nodesVizAtt$size <- do.call(rbind, nodesVizAtt$size)

nodesVizAtt$size <- as.data.frame(nodesVizAtt$size)
dimnames(nodesVizAtt$size) <- list(
1L:nrow(nodesVizAtt$size), "value"
)


# Positions
nodesVizAtt$position <- lapply(node.vizattr, function(a) {
if (length(a$position))
Expand Down
5 changes: 1 addition & 4 deletions R/rgexf.r
Original file line number Diff line number Diff line change
Expand Up @@ -463,10 +463,7 @@ gexf <- function(
b=nodesVizAtt)
} else NULL




nNodesVizAtt <- length(nodesVizAtt)
nNodesVizAtt <- length(nodesVizAtt)

# Checking the number of digits
if (!is.integer(digits)) stop("Invalid number of digits ",digits,
Expand Down
12 changes: 12 additions & 0 deletions man/plot.gexf.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 3701780

Please sign in to comment.