When you're working with graph theory or Discrete Event Systems, you're going to want to make graphs. Which are usually pretty visual things for analysis before you write an algorithm to deal with that for you, so then you want a way to draw your graph of arbitrary composition. Enter: GraphViz, a supremely useful tool for creating .jpg images of your graphs. The only caveat is making the conversions between how you encode your Graphs and how GraphViz draws them, but that's not a super tough one to figure out once you get your hands on GraphViz's api.
However: What if you want to do a fancy formal paper, and you need it in a slightly different format that lets you tweak things and, generally, jives well with an Academic Paper kind of setting? It turns out that when you look closely at a GraphViz .jpg, it gets kinda grainy, and when you print out that paper with its grainy images, it's just a bad time for professionalism.
So how about a different image file format that looks better? Like a(n) .svg? But then comes that second problem of being tweakable and just, in general, being usable with, say, LaTEX, the very useful software for writing Academic Papers. It has its own whole language for formatting, so instead of plopping a static image down inside there, why not translate it a bit?
I'm gonna put a read-more break here, because the point I'm leading to is that the file formatting is not pretty.
![]()
| ![]()
|
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<!-- Generated by graphviz version 2.38.0 (20140413.2041)
-->
<!-- Title: G Pages: 1 -->
<svg width="472pt" height="815pt"
viewBox="0.00 0.00 241.00 416.00" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<g id="graph0" class="graph" transform="scale(1.95833 1.95833) rotate(0) translate(4 412)">
<title>G</title>
<polygon fill="white" stroke="none" points="-4,4 -4,-412 237,-412 237,4 -4,4"/>
<!-- 0 -->
<g id="node1" class="node"><title>0</title>
<ellipse fill="none" stroke="orange" cx="157" cy="-204" rx="18" ry="18"/>
<ellipse fill="none" stroke="orange" cx="157" cy="-204" rx="22" ry="22"/>
<text text-anchor="middle" x="157" y="-200.3" font-family="Times New Roman,serif" font-size="14.00">0</text>
</g>
<!-- 3 -->
<g id="node4" class="node"><title>3</title>
<ellipse fill="none" stroke="black" cx="157" cy="-109" rx="18" ry="18"/>
<ellipse fill="none" stroke="black" cx="157" cy="-109" rx="22" ry="22"/>
<text text-anchor="middle" x="157" y="-105.3" font-family="Times New Roman,serif" font-size="14.00">3</text>
</g>
\draw [color = red, thick, ] (0.5577563559322034,4.1591249999999995)
to (0.6101652542372882,4.0155449999999995)
to (0.6781927966101695,3.8291699999999995)
to (0.7430190677966102,3.6515699999999995)
;
\draw [color = red, thick, fill=red] (0.8809279661016949,3.48357)
to (0.862146186440678,3.3251999999999997)
to (0.7373411016949153,3.4572899999999995)
to (0.8809279661016949,3.48357)
;
\draw [color = red, thick, fill=red] (0.745521186440678,3.6447)
to (0.6952775423728814,3.54255)
to (0.809135593220339,3.47043)
to (0.8593792372881356,3.57258)
to (0.745521186440678,3.6447)
;
\draw [black](0.826271186440678,3.717225) node {b};
\draw [color = black, thick, ] (0.39087923728813556,4.15497)
to (0.30664194915254234,3.8215199999999996)
to (0.20361673728813556,3.2222099999999996)
to (0.3813559322033898,2.730225)
to (0.7275190677966102,1.7720399999999998)
to (1.0813559322033897,1.57314)
to (1.9703389830508473,0.810225)
to (1.9746927966101695,0.8064885)
to (1.9790783898305082,0.802746)
to (1.9834915254237289,0.798999)
;
\draw [color = black, thick, fill=black] (2.329449152542373,0.6133740000000001)
to (2.4197457627118646,0.4678755)
to (2.220995762711864,0.5417535)
to (2.329449152542373,0.6133740000000001)
;
\draw [color = black, thick, fill=black] (1.9862012711864405,0.7969425)
to (2.010936440677966,0.6902024999999999)
to (2.1596186440677965,0.6653159999999999)
to (2.1348728813559323,0.7720545)
to (1.9862012711864405,0.7969425)
;
I also didn't have access to the API's for either .svg or .tikZ files, so... it was a lot of experimentation to get this working. But it is, and it does! After digging through so many other projects working on this same problem and not knowing how to implement them, it was very refreshing to just... make it, and have it work.
If you wanted to use this, you'd just have to somehow implement the method 'convertSVGToTikZ(File, String)' in another project; which is to say, include that file in your project, import it into the file you're going to run, and then provide it the .svg file and a filepath to save the new .tikZ to. (This is all documented in the program itself with relevant details.)
And to check out what the .tikZ looks like, there's a handy site called shareLatex which will basically run/process your tikZ stuff so you can see how it looks! You can just include the .tikz file in your LaTEX project and call up that file using something like:
\begin{document}
\input{temp.tikz}
\end{document}
So yeah! I'm proud of this one, and it's a stand-alone bit of a larger project which I'll get around to talking about eventually. This can definitely use some work to be more generalizable to any .svg file, but within its context for existence its very good. Hope you enjoyed reading a bit about this, have yourself a lovely day, and see you Monday for something else!