Usually work always need to draw some flow chart, flow chart in the process of drawing, if you want to insert a step in the middle, or delete a step is more troublesome, need to adjust some other nodes, so how to solve this problem?

A: Using Graphviz, drawing with code, it’s a lot easier to change things together, focus on the flow, the idea comes, the graph comes, you don’t have to spend a lot of time adjusting the graph, adjusting the arrow.

Introduction to the

Graphviz (Short for Graph Visualization Software) is an open source toolkit started by AT&T LABS that can be used to draw graphs described by DOT language scripts.

DOT is a text graphic description language that provides a simple way to describe graphics and can be understood by humans and computer programs. DOT language files usually have a. Gv or. DOT file extension.

Use Graphviz in vscode

Brew Install Graphviz can also be downloaded directly from the official website.

brew install graphviz
Copy the code

2. Use examples

1. Simple examples:

digraph G{ size = "5, 5"; [shape=box]; /* shape */ main->parse; parse->execute; main->init[style = dotted]; The main - > / / dotted line cleanup; edge[color = green]; Execute ->{make_string; Printf}// connect two init->make_string; main->printf[style=bold, label="100 times"]; Make_string [label = "make a\nstring"]// \n, the label of this node, Node [shape = box, style = filled, color = ".7.3 1.0"]; Execute ->compare; {rank=same; parse, init} }Copy the code

2. View visualizations

Right-click and select Open Preview to the SIde as shown below:

3. Generate pictures

The first step is to create a text file with the command x.dot.

Second, use commands to convert text content to images.

dot demo.dot -T png -o demo.png
Copy the code

-t indicates the output type. You can specify JPG, GIF, or SVG. -o specifies the output file name.

3. Instructions for use

  • Specify the shape
    "box"[shape=box]
    "polygon"[shape=polygon,sides=7] 
    "ellipse"[shape=ellipse]
    "circle"[shape=circle]
    "point"[shape=point]
    "triangle"[shape=triangle]
    "invtriangle"[shape=invtriangle]
    "plaintext"[shape=plaintext]
    "diamond"[shape=diamond]
Copy the code

  • Label and BGColor are defined image attributes
  • Graph is used to describe undirected graphs, relationships are used to describe –, digraph is used to describe directed graphs, and relationships are used to describe ->
  • Node and edge, where node defines the default properties for nodes and edge defines the default properties for edges. The scope is intercepted from this definition to the next. Properties for specific node/edge Settings override the default values.
  • The relationship of excute corresponds to two nodes in curly braces
  • []. Properties can be set for graphs, nodes, and edges.
  • Rank defines how the nodes are placed on the same row to help render the image.

Graphviz website

Graphviz is at www.graphviz.org/, and there are lots of examples of how you can draw a lot of graphics, even complex graphics, depending on your configuration.