As I prepare the next htmlwidget
of the week (see Building Widgets), I wanted to demonstrate how we can apply Ian Lunn's very popular and generous Hover Effects to a graphviz diagram drawn with DiagrammeR
. Mouseover the nodes to see them hvr-float
. There are enough effects to easily distract you for a couple of hours. Try them out. I'll paste the code below. You can also find it in code.R.
# use Ian Lunn's hover.css http://ianlunn.github.io/Hover/ on a
# graphviz diagram rendered with the R htmlwidget DiagrammeR
library(DiagrammeR)
library(pipeR)
library(XML)
library(htmltools)
exportSVG(
grViz('
digraph G {
size = "4,4";
main [shape = box]; /* this is a comment */
main -> parse [weight = 8];
parse -> execute;
main -> init [style = dotted];
main -> cleanup;
execute -> { make_string; printf}
init -> make_string;
edge [color = red]; // so is this
main -> printf;
node [shape = box, style = filled, color = ".7 .3 1.0"];
execute -> compare;
}
')
) %>>%
htmlParse %>>%
~svgDiag
svgDiag %>>%
getNodeSet("//g[contains(@class,'node')]") %>>%
lapply(
function(el){
addAttributes( el, "class" = "node hvr-float", "style" = "pointer-events:all;")
if(length(xmlChildren(el)$title)>0){
removeChildren(el, kids = list(xmlChildren(el)$title))
}
return(NULL)
}
)
svgDiag %>>%
saveXML %>>%
HTML() %>>%
attachDependencies(
htmlDependency(
name="hover.css"
,version = "0.1"
,src = c(file=paste0(getwd(),"/css"))
,stylesheet = "hover.css"
)
) %>>%
html_print %>>%
~htF
xxxxxxxxxx
<html>
<head>
<meta charset="utf-8"/>
<link href="hover.css" rel="stylesheet" />
</head>
<body style="background-color:white;">
<!-- Generated by graphviz version 2.28.0 (20140111.2315)
--><!-- Title: G Pages: 1 --><html><body><svg width="288pt" height="247pt" viewbox="0.00 0.00 288.00 247.13" xmlns="https://www.w3.org/2000/svg" xmlns:xlink="https://www.w3.org/1999/xlink"><g id="graph0" class="graph" transform="scale(0.950495 0.950495) rotate(0) translate(4 256)"><title>G</title>
<polygon fill="white" stroke="none" points="-4,4 -4,-256 299,-256 299,4 -4,4"></polygon><!-- main --><g id="node1" class="node hvr-float" style="pointer-events:all;"><polygon fill="none" stroke="black" points="144,-252 90,-252 90,-216 144,-216 144,-252"></polygon><text text-anchor="middle" x="117" y="-229.8" font-family="Times,serif" font-size="14.00">main</text></g><!-- parse --><g id="node2" class="node hvr-float" style="pointer-events:all;"><ellipse fill="none" stroke="black" cx="117" cy="-162" rx="31.1141" ry="18"></ellipse><text text-anchor="middle" x="117" y="-157.8" font-family="Times,serif" font-size="14.00">parse</text></g><!-- main->parse --><g id="edge1" class="edge"><title>main->parse</title>
<path fill="none" stroke="black" d="M117,-215.697C117,-207.983 117,-198.712 117,-190.112"></path><polygon fill="black" stroke="black" points="120.5,-190.104 117,-180.104 113.5,-190.104 120.5,-190.104"></polygon></g><!-- init --><g id="node4" class="node hvr-float" style="pointer-events:all;"><ellipse fill="none" stroke="black" cx="58" cy="-90" rx="27" ry="18"></ellipse><text text-anchor="middle" x="58" y="-85.8" font-family="Times,serif" font-size="14.00">init</text></g><!-- main->init --><g id="edge3" class="edge"><title>main->init</title>
<path fill="none" stroke="black" stroke-dasharray="1,5" d="M100.799,-215.629C92.5088,-205.844 82.9384,-193.003 77,-180 68.0016,-160.297 63.192,-136.173 60.6654,-118.014"></path><polygon fill="black" stroke="black" points="64.1384,-117.579 59.4272,-108.09 57.1923,-118.446 64.1384,-117.579"></polygon></g><!-- cleanup --><g id="node5" class="node hvr-float" style="pointer-events:all;"><ellipse fill="none" stroke="black" cx="207" cy="-162" rx="41.0987" ry="18"></ellipse><text text-anchor="middle" x="207" y="-157.8" font-family="Times,serif" font-size="14.00">cleanup</text></g><!-- main->cleanup --><g id="edge4" class="edge"><title>main->cleanup</title>
<path fill="none" stroke="black" d="M139.247,-215.697C151.46,-206.198 166.706,-194.34 179.641,-184.279"></path><polygon fill="black" stroke="black" points="182.008,-186.872 187.753,-177.97 177.711,-181.346 182.008,-186.872"></polygon></g><!-- printf --><g id="node7" class="node hvr-float" style="pointer-events:all;"><ellipse fill="none" stroke="black" cx="263" cy="-18" rx="32.2356" ry="18"></ellipse><text text-anchor="middle" x="263" y="-13.8" font-family="Times,serif" font-size="14.00">printf</text></g><!-- main->printf --><g id="edge8" class="edge"><title>main->printf</title>
<path fill="none" stroke="red" d="M144.189,-231.319C176.999,-227.681 230.991,-216.196 257,-180 285.4,-140.476 277.966,-80.3022 270.289,-45.8082"></path><polygon fill="red" stroke="red" points="273.668,-44.8905 267.938,-35.9789 266.86,-46.5188 273.668,-44.8905"></polygon></g><!-- execute --><g id="node3" class="node hvr-float" style="pointer-events:all;"><ellipse fill="none" stroke="black" cx="155" cy="-90" rx="40.2858" ry="18"></ellipse><text text-anchor="middle" x="155" y="-85.8" font-family="Times,serif" font-size="14.00">execute</text></g><!-- parse->execute --><g id="edge2" class="edge"><title>parse->execute</title>
<path fill="none" stroke="black" d="M126.005,-144.411C130.483,-136.163 135.995,-126.009 141.007,-116.777"></path><polygon fill="black" stroke="black" points="144.1,-118.415 145.795,-107.956 137.948,-115.075 144.1,-118.415"></polygon></g><!-- make_string --><g id="node6" class="node hvr-float" style="pointer-events:all;"><ellipse fill="none" stroke="black" cx="58" cy="-18" rx="58.1629" ry="18"></ellipse><text text-anchor="middle" x="58" y="-13.8" font-family="Times,serif" font-size="14.00">make_string</text></g><!-- execute->make_string --><g id="edge5" class="edge"><title>execute->make_string</title>
<path fill="none" stroke="black" d="M134.429,-74.1548C121.04,-64.4929 103.344,-51.7225 88.3516,-40.9032"></path><polygon fill="black" stroke="black" points="90.0468,-37.8104 79.8896,-34.7966 85.9505,-43.4867 90.0468,-37.8104"></polygon></g><!-- execute->printf --><g id="edge6" class="edge"><title>execute->printf</title>
<path fill="none" stroke="black" d="M176.855,-74.8345C193.382,-64.123 216.223,-49.3181 234.234,-37.6447"></path><polygon fill="black" stroke="black" points="236.151,-40.5733 242.638,-32.1973 232.343,-34.6993 236.151,-40.5733"></polygon></g><!-- compare --><g id="node8" class="node hvr-float" style="pointer-events:all;"><polygon fill="#c1b2ff" stroke="#c1b2ff" points="199.146,-36 134.854,-36 134.854,-0 199.146,-0 199.146,-36"></polygon><text text-anchor="middle" x="167" y="-13.8" font-family="Times,serif" font-size="14.00">compare</text></g><!-- execute->compare --><g id="edge9" class="edge"><title>execute->compare</title>
<path fill="none" stroke="red" d="M157.966,-71.6966C159.289,-63.9827 160.878,-54.7125 162.352,-46.1124"></path><polygon fill="red" stroke="red" points="165.828,-46.552 164.068,-36.1043 158.928,-45.3692 165.828,-46.552"></polygon></g><!-- init->make_string --><g id="edge7" class="edge"><title>init->make_string</title>
<path fill="none" stroke="black" d="M58,-71.6966C58,-63.9827 58,-54.7125 58,-46.1124"></path><polygon fill="black" stroke="black" points="61.5001,-46.1043 58,-36.1043 54.5001,-46.1044 61.5001,-46.1043"></polygon></g></g></svg></body></html>
</body>
</html>