Graphviz Usage Introduction (Chinese garbled problem)

Source: Internet
Author: User

Graphviz Introduction to use

Graphviz is a dot language based drawing tool that can draw a map, a graph, a diagram, a diagram, a flowchart, and so on. Specific role visible on its official website

Some reference URLs:

Http://www.open-open.com/lib/view/open1455954987933.html

https://www.oschina.net/question/129540_79958

http://blog.csdn.net/xiajian2010/article/details/23748557

If you want to go further, the direct officer Net: http://www.graphviz.org/Documentation.php

Dot draws directed graphs as hierarchies. It runs as a command line program,
Web visualization service, or with a compatible graphical interface.
Its features include well-tuned layout algorithms for placing nodes and edge
splines, Edge labels, "record" shapes with "ports" for drawing data structures;
cluster layouts; and an underlying file language for stream-oriented
Graph tools.

As mentioned above, Graphviz is the gate based on the dot language of the drawing tool, that is, it is not using the mouse to draw, but through the dot this description language to do, and then the command line under the command to generate the corresponding picture, the advantage is not to go to the alignment of hand work coordinates, It can also be a visual solution, but its drawbacks are also significant: the location of each element cannot be controlled in detail. There is a trade-off problem here. It's enough for someone like me to draw a flowchart, and it's better than a Visio tool.

The dot language consists of three objects grahps,nodes,edges, which is a concept with the definition of graphs in discrete mathematics. Here is a concrete example where the first line is the graph name and type, which is created nodes,edges, or subgraphs. In these objects to be created, their names and attributes can be C identifiers, numbers, or quoted C strings, and the quotes function primarily to allow whitespace and punctuation in names and attributes.

Example:

Use the following command at the command line

Dot-tpng Example.dot-o Example.png

-T means that the generated file is in PNG format, Example.dot is the file where the code resides, and-o specifies the generated file name. After successful operation, it will resemble the following figure.

digraph G{edge [FontName= "Nsimsun"];node [FontName= "Nsimsun" size= "15,15", Parse- >, init; printf,printf, main  Compare }}

Display Graphics:

Node will be created the first time it appears, and when multiple node joins using the operator "--", the edge will be built automatically.

If you want the edges to have text, like, you can use a statement like this

Main->parse[label= "ABC"];

Here is a more complicated example:

digraph G {edge [FontName= "Fangsong"];node [Shape=box, fontname= "Fangsong" size= "20,20"]; {Lexical_analyzer [Label= "Lexical Analyzer"]; Syntax_analyzer [Label= "Parser"  ]; Semantic_analyzer [Label= "Semantic Analysis"];intermediate_code_generator [Label= "Intermediate code generator" ]; Machine_independent_code_optimizer [Label= "Machine Independent code Optimizer"   ]; code_generator [Label= "code Generator" ]; Machine_dependent_code_optimizer [Label= "Machine-related code optimizer"  ];} Node[shape=plaintext, fontname= "Kaiti"]{character_stream [Label= "character Stream"];target_machine_code [Label= "Target machine language" ];} Character_stream-Lexical_analyzer; Lexical_analyzer->syntax_analyzer [label= "Symbol stream"]; Syntax_analyzer->semantic_analyzer [label= "Syntax Tree"]; Semantic_analyzer->intermediate_code_generator [label= "Syntax Tree"]; Intermediate_code_generator->machine_independent_code_optimizer [label= "intermediate representation"]; Machine_independent_code_optimizer->code_generator [label= "intermediate representation"]; Code_generator->machine_dependent_code_optimizer [label= "Target machine language"]; Machine_dependent_code_optimizer-Target_machine_code;}

A simple example:

digraph directed {  edge [fontname= "Fangsong"]; {     b;       C, D [color=red,penwidth=3.0];       -e[label= "leaves"];}}

Note Here is the Chinese problem, graphviz default settings are not supported in Chinese, if the dot file directly written in Chinese, will be displayed as garbled, to solve this problem to do two things,

1. Save the source file in UTF-8 format
2, set FontName, that is, the red part,

If you want to know more about Graphviz, you can go to its official website to look at the relevant documents, there are some paper, if interested can also see, in fact Graphviz also use the knowledge of the compiling principle, but there is no innovation so there is no point to say, But the importance of compiling principles from this is visible.

Report

1. The English name of the text body in Windows system

New detail: PMingLiU
Detail: MingLiU
Target: DFKAI-SB
Blackbody: Simhei
Song Body: SimSun
New song body: Nsimsun
Imitation: Fangsong
Italics: Kaiti
Imitation _gb2312:fangsong_gb2312
Italic _gb2312:kaiti_gb2312
Micro-Black: Microsoft Jhenghei
Microsoft Elegance Blackbody: Microsoft Yahei

For more detailed information, see: http://www.yale.edu/chinesemac/pages/fonts.html

Graphviz Usage Introduction (Chinese garbled problem)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.