 Okay, so today we're going to take a look at GraphVis, and what GraphVis is, is a Graph Visualization software. So what you can do with GraphVis is you can take nodes, you can define your nodes, you can define your edges, and what GraphVis does for you is it generates from those nodes and edges a picture that you can look at visually. And the reason why you want to do that is because sometimes when you're looking at data, it's kind of hard to see the relationships between your data points. You can have it so that you can explain to other people how certain things interact in your program or how certain things interact in just nature in general. Anyways, let's actually get started with this. Most likely when you use GraphVis, you're going to make one of the graphs, either a directed graph or an undirected graph. And the difference between the two is fairly simple. A directed graph has directed edges and undirected graph doesn't have directed edges, and that's pretty much it. So for example, if I want to make an undirected graph, I would type graph, and then give it some name. I'm just going to call it G. And we are going to define a node in a relation in this graph. So let's say we have a node A, and this A is connected to B. So there we go. We have our first relation A is connected to B via undirected edge. Then we're going to close this, and we're going to save our GraphVis file. So now how do we actually render out that picture? And we render out that picture using the dot command. So we're going to type dot followed by the argument t, png. And I'm specifying tpng because I want to make a png file. If you want to make any other format, look at the man page and see the appropriate command for that file format. And we have to specify the GraphVis data file. So our GraphVis data file is g.gv. And we are going to output to a file called file.png. Now when we do that, we're going to use our image viewer to view that file. So we're going to look at file.png. And as you can see, here we have our graph. We have A, which is connected to B, and B is connected to A. And that is the first graph that you made. Congratulations. Now to make a directed graph, we can go in here and we can change the graph to a digraph. Now digraph I think stands for directional graph or directed graph. And to make a directed edge, we are going to basically change this character here to this grid and sign. And now what we're telling GraphVis is A is connected to B by this directed edge. And if we save that and we run that same command again, we can see now that A is connected to B. And there is a clear flow from A to B instead of just being directed. Now we can also have multiple nodes. So for example, if we want, we can have A be connected to C. And then we can have B being connected to C also. And if we run that, we see that now we have A is connected to B. And then B is connected to C and A is also connected to C. Now here's the thing. We see here that A is connected to B and A is also connected to C. We can actually avoid typing out multiple lines like this by having A connect to B and C on a single line. You have a shorthand for defining which nodes are connected to which nodes. So we can say A is going to be connected to both B and C. And if we save that and we generate our file again, we see that we get the same end graph, but we had to write one less line. And this is actually really convenient. And you can also do this on both sides. Let's say you want to make a graph where nodes A, B, and C are connected to nodes D, E, and F. We can do that on one line in graphics. So in graphics, to do that, to make that graph. All we type is A and C. And then we're going to make a directional relation with this to the nodes. And if we make this file, as you can see, a graph is connected all of these things for us automatically. So instead of having to define a connection for each node, we can just use that shorthand to connect multiple nodes together. Now that we have this graph on our screen, we see that it's not really that impressive. And it's not impressive because it's all the same color and the only difference between the nodes are their basically contents, like what they're called, this A, B, C, D, E, F. We can actually style these nodes. Now to style these nodes, we have to specify a node style. And we specify a node style like this. We type node and then we are going to set the style to be filled. And we're going to set the color of these nodes to be yellow. So if we save this and run our program again, we see that the nodes in our graph are all yellow now. We can also do the same for the edges. So if we want, we can style these edges to be, let's make them dotted. And we're going to set their color to be red. And now we have a graph that has yellow nodes and it has dotted edges, which are directional. Now we can also edit the shape of our nodes. So for example, we can say that the shape of our nodes is going to be square. And if we run this, we see that our nodes are square now. Now here's the thing, you can actually style these nodes individually. And I'm going to make this a little smaller so you guys can see the whole thing without it being squished like that. So in this graph, we can specify an individual node and we can specify a style for this individual node. So have A and I want to style this A node and I want to set its color to be red. I can specify color is red. If we run this, we see that now individually A is red. We can do the same for B if you want. We can say B color is blue. And you can just go on forever with this kind of styling. I think you can even use HTML styling in the styles so you can build really sophisticated looking nodes. Okay, so let's make a new type of graph. We're going to make a new graph which isn't going to be that sophisticated actually. It's going to be pretty much what we have now. It's just that I want to show you a problem that you may face when you use a graph is. So for example, let's say I have the node A and it's connected to B and A is also connected to C. It's also connected to D and it's also connected to F. It's also connected to G and it's also connected to H. And if we run this and we make this graph, you may start to see a problem here. And the problem is that this node, well, I should say graph isn't really making good use of its space. So for example, you don't really want to have a graph is spread out your nodes like this. So with A being at the top, but then having everything else below it, maybe you want to have it in a circular pattern or something. And this is something that can really get to you if you're making a graph with a lot of nodes. And you can fix this by setting layout to be Nito. So we can say layout is equal to Nito. And when we run this, we can see that a graph is now making better use of the space available to it. So if you're ever making a graph and you're getting this problem where graph is basically laying out all of your nodes on one row, you can actually change the layout style to try to fix that problem. Okay, so now that we have the basics of a graph is down, I'm going to show you a little script that I made to basically it's going to take all of the links on a website and it's going to graph them in relation to the website itself. Okay, so this is my script. It's fairly simple. All it's doing is it's taking the first argument to be a website. I'm not really doing any checking on this because this is my script and I don't really intend to put it out there for general use. But basically what I'm doing is I'm getting a URL and then I'm double getting that URL and I'm parsing out all of the links on that site. So on a single page, you're getting all of the links out of it. Then I'm just tiering and sorting to make sure that it's unique. Like all the links are unique because you don't want to just have duplicate nodes in your graph that become annoying. Then I'm going into outfiled.gv, this string which basically indicates that this is a directional graph and then I have a couple of options set here. So my layout style is fdp and my overlap is false. I set overlap to false because if you have a website with a lot of nodes and edges, then you can have problems with overlapping nodes and edges to the point where you can't even read your graph anymore. But I think it increases the time it takes to render the graph too. So it has kind of like a trade-off. Then what I'm doing is I'm looping over every link and for every link I'm echoing into outfiled.gv the original website. So my website and then the whatever link it has to whatever other website. And finally closing we have a swilly bracket and we render it out as the final line in the script. Now this is pretty simple. It's not really meant to be anything impressive, but this is the kind of stuff that you can do with graphics. So to run this script, I'm going to use my own website, but you can use whatever you want, I think. And here we go. We have this picture. This is my website and here are all the links to that website. So yeah, I hope you enjoyed watching this video and I hope that this was very informative to you. And thanks for watching.