Skip to content

Commit 1ef860a

Browse files
[js/doc] Add display using a browser and documentation
1 parent 483a2b9 commit 1ef860a

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed

doc/additionalDoc/writeGraph.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,8 @@ dot -Tpdf /tmp/my_dynamic_graph.dot > /tmp/my_dynamic_graph.pdf
1919
It provides the following output:
2020
\image html my_dynamic_graph.png
2121
22+
\section fromdottojs Viewing in a browser
23+
To view the dot file you can simply use the view_sot_dg.html file.
24+
Click on the "Choose File" to specify the filem and click on "Rendering" to display the graph.
25+
2226
*/

js/view_sot_dg.html

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<html>
2+
3+
<body>
4+
<script src="https://github.com/mdaines/viz.js/releases/download/v2.1.2/viz.js"></script>
5+
<script src="https://github.com/mdaines/viz.js/releases/download/v2.1.2/full.render.js"></script>
6+
<script>
7+
function renderDOTFile() {
8+
var fileInputElement = document.getElementById("fileInputElement");
9+
10+
var reader = new FileReader();
11+
var graphtextres = ""
12+
reader.onloadend = function(e) {
13+
graphtextres = e.target.result
14+
var viz = new Viz();
15+
16+
viz.renderSVGElement(graphtextres)
17+
.then(function(element) {
18+
19+
elementToRemove=document.getElementById("displaysvgzone")
20+
if (elementToRemove != null)
21+
{
22+
document.body.removeChild(elementToRemove)
23+
}
24+
document.body.appendChild(element)
25+
element.id="displaysvgzone"
26+
})
27+
.catch(error => {
28+
// Create a new Viz instance (@see Caveats page for more info)
29+
viz = new Viz();
30+
31+
// Possibly display the error
32+
console.error(error);
33+
});
34+
}
35+
reader.readAsText(fileInputElement.files[0]);
36+
};
37+
38+
39+
</script>
40+
<input type="file" id="fileInputElement">
41+
<input id="Rendering" type="button" value="Rendering" onclick="renderDOTFile();" />
42+
<script>
43+
var el = document.getElementById("Rendering");
44+
if (el.addEventListener)
45+
el.addEventListener("click", renderDOTFile, false);
46+
else if (el.attachEvent)
47+
el.attachEvent('onclick', renderDOTFile);
48+
</script>
49+
</body>
50+
51+
</html>
52+

0 commit comments

Comments
 (0)