library(SVGAnnotation) library(graph) library(Rgraphviz) set.seed(123) V <- letters[1:10] M <- 1:4 g1 <- randomGraph(V, M, 0.8) x <- layoutGraph(g1) xx = agopen(g1, layoutType = "dot", name = "bob") svgPlot("graphvizDot.svg", plot(xx)) doc = xmlParse("graphvizDot.svg") ids = addGraphIds(doc, xx) els = getNodeElements(doc) # get the SVG elements corresponding to the nodes sapply(seq(along = els), function(i) addAttributes(els[[i]], onmouseover = paste("highlightEdges(evt, ", i - 1, ", 'red');"), onmouseout = paste("highlightEdges(evt, ", i - 1, ");"))) # Setup the "hiding" the other edges when we highlight these ones. # info = getEdgeInfo(g1) # from the graph package. otherEdges = lapply(info, function(x) setdiff(ids$edgeIds, x)) # add hyper-links to the nodes. mapply(addLink, els, ids$nodeIds) addECMAScripts(doc, "~/Books/XMLTechnologies/Rpackages/SVGAnnotation/tests/highlightEdges.js", TRUE, # These are R variables that are converted to JavaScript via our toJSON overloading. edgeTable = structure(info, names = NULL), edgeDiff = structure(otherEdges, names = NULL)) saveXML(doc, docName(doc))