673 views|1 replies

80

Posts

0

Resources
The OP
 

【VisionFive 2: RISC-V single-board computer with integrated 3D GPU】+11. Drawing (Graphviz/Dot) test (zmj) [Copy link]

 

【VisionFive 2: RISC-V single-board computer with integrated 3D GPU】+11. Drawing (Graphviz/Dot) test (zmj)

DOT is a scripting language for drawing graphs on the open source toolkit Graphviz. The layout engine parses the script to get the image, and then the image can be exported to various formats to meet the needs. With it, we can easily draw various structural diagrams and flow charts by writing scripts.

The file extension of Graphviz is .gv. Each .gv file represents a graph. We can generate images through the command line of dot -Tpng example.dot -o example.png, or use the tool gvedit provided by Graphviz to edit and run scripts.

For someone like me who is not good at drawing, the DOT language and Graphviz tool are really Very-Good.

1. Description and Installation

Graphviz is an open source drawing toolkit developed by Bell Labs. It uses a specific DSL (domain-specific language): DOT as the scripting language. It uses a layout engine to parse DOT scripts and complete automatic layout. It supports a variety of export formats, such as PNG, JPG, PostScript, SVG, PDF, etc.

We will not elaborate on Dot syntax and Graphviz tools here. For beginners, just focus on the official website documentation.

References and installation are as follows:

//------官网:Graphviz
https://www.graphviz.org/
//------官网文档:Graphviz-Documentation★★★★★
https://www.graphviz.org/documentation/
//------源码:Graphviz-Gitlab
https://gitlab.com/graphviz/graphviz/
//------源码使用
git clone https://gitlab.com/graphviz/graphviz.git

注:重点内容/主要内容还是在文档Doc区域。

//------安装及依赖
//---graphviz
sudo apt install graphviz
//---实际需要多个依赖项
sudo apt install graphviz* libghc-graphviz* libgraph-writer-graphviz-perl libgraphviz* python-pygraphviz* python3-pygraphviz*
sudo apt install libghc-base-dev libghc-bytestring-dev libghc-colour-dev libghc-containers-dev libghc-directory-dev

//------文件转换指令(仅供参考)
dot -Tpng dot_demo.gv -o demo.png
	或者
dot -Tpng dot_demo.gv  > demo.png

2. Test Example

2.1 Example 1

Draw a flowchart

//------DOT source code

digraph show{ 
//node 
// rankdir = LR; 
  
node[shape="box" ,fontname="SimSun" fontsize=16 size="60,60" color="gray" distortion=.7] 
edge[ fontname="SimSun"  fontsize=15 fontcolor="black" color="brown" style="filled"] 
  
"node" [style="filled", color="black", fillcolor="chartreuse"]; 
Graphviz使用教程[shape="Mdiamond",fillcolor="chartreuse"] 
  
基本概念[shape="doubleoctagon"] 
  
Graphviz使用教程->基本概念[arrowhead="vee" color ="steelblue"] 

基本概念->"1.node(节点)" 
基本概念->"2.mapEdge(路径)" 
基本概念->"3.atrribute(属性)" 

"1.node(节点)"->"可作为对象,设置属性(颜色,形状,大小,格式)" 
"2.mapEdge(路径)"->"也可作为对象,设置属性(颜色,形状,大小,格式)" 
"3.atrribute(属性)"->"node" 

"1.shape"->"doubleoctagon=>双环8边型" 
"1.shape"->"egg=>蛋形" 
"1.shape"->"box=>方形" 
"1.shape"->"Mdiamond=>菱形" 

"2.color"->"red:重点" 
"2.color"->"green:要点" 
"2.color"->"black:普通" 

"node"->"1.shape"[arrowhead="vee" color="green"] 
"node"->"2.color"[arrowhead="vee" color="green"] 
"node"->"3.size"[arrowhead="vee" color="green"] 
"node"->"4.fontsize"[arrowhead="vee" color="green"] 
"node"->"5.fontname"[arrowhead="vee" color="green"] 
"node"->"7.fillcolor\n设置节点填充色(背景色)"[arrowhead="vee",label="设置fillcolor为#4b8bf4蓝色"  color="#4b8bf4"] 
"node"->"连接多个": 
"node"->"startNode"
"node"->"6.distortion"[arrowhead="vee" color="green"] 

"startNode"->"{endNode1;endNode2;endNode3;...}"[arrowhead="vee" color="steelblue"] 

"5.fontname"->"DFKai-SB" 

"3.atrribute(属性)"->"edge" 

"edge"->"属性设置在路径的结束点的节点作为其属性\n以『node』节点为例\n设置颜色为green,箭头格式为vee" 
"edge"->"属性" 

"color=设置路径线段颜色"->"颜色值可使用\n1.颜色名\n2.颜色16进制值"[color=yellow]

"dir=格式"->"both=>双向箭头"[dir="both"] 

  
//   style=样式 
"style=样式"->"dotted=>虚线"[style=dotted] 
"style=样式"->"bold=>加粗"[style=bold] 

// 属性

"属性"->"label\n路径标签\nstartNode->endNode[label=这是一个路径标注]"[color = "green" label=这是一个路径标注] 
"属性"->"style=样式"[color="blue"] 
"属性"->"dir=格式"[color="blue"] 
"属性"->"color=设置路径线段颜色"[color="blue"] 
} 

//------Effect picture

2.2 Example 2

Draw a schematic diagram of the highway node relationships.

//------DOT source code

digraph {
 
    edge[fontname="SimSun",fontcolor=red];
    node[fontname="SimSun",size="20,20"];
 
    北京[shape=doublecircle];
    湘潭[shape=plaintext]
 
    //高速公路节点关系
    北京->石家庄->郑州->武汉->长沙->广州[label=京港澳高速,color=red];
    北京->天津->沈阳->长春->哈尔滨[label=京哈高速,color=lawngreen];
    北京->呼和浩特->银川->兰州->西宁->拉萨[label=京藏高速,color=purple];
    郑州->西安->兰州->乌鲁木齐[label=连霍高速,color=blue]
    上海->杭州->南昌->湘潭->贵阳->昆明[label=沪昆高速,color=orange];
    福州->南昌->武汉->西安->银川[label=福银高速,color=brown];
    湘潭->长沙[style=dotted];
}

//------Effect picture

3. Personal understanding

My personal understanding of DOT & Graphviz is as follows:

1. Graphviz工具
   graphviz是一个开源软件包,dot和gvedit等工具都在该软件包中,或者可以说graphviz是处理该DOT语言文件的一个集成化的工具。
2. DOT语言
   DOT是一种文本图形描述语言。DOT语言文件通常具有.gv或是.dot的文件扩展名。它借助Graphviz等工具完成图形渲染生成.png、.jpg、.pdf等多种类型的图片。
3. DOT & graphviz的局限性
   Graphviz中有很多工具可以将DOT语言的文本渲染成为图片,但正如我们所见,我们在享受方便的编码的同时,将图片的布局等任务交给了这些工具,虽然这些工具有很不错的布局算法支持,但仍不一定能满足我们的要求,所以当对图片的布局有特殊要求时,DOT & graphviz就显示出了它的局限性。当然,我们可以再使用其他图片编辑器校正DOT语言生成的图片,但这种时候,DOT & graphviz的方便性或许早就消失殆尽了。
4. DOT & graphviz的适用群体
   就我个人体会而言,DOT & graphviz适合这些群体使用:
   a> 绘图小白,像我一样的画图小白并且喜欢操作键盘远胜于鼠标;
   b> 技能小白,没有熟练的掌握其他作图工具;
   c> 布局需求低,对图片布局等没有特殊要求;
   d> 流程图及结构图,要绘制的是流程图结构图之类的图而不是画小狗小猫山山水水。

//-----END

This post is from Domestic Chip Exchange

Latest reply

DOT language and Graphviz tool are great for drawing   Details Published on 2023-8-18 07:22
 
 

1663

Posts

0

Resources
2
 

DOT language and Graphviz tool are great for drawing

This post is from Domestic Chip Exchange
 
 
 

Guess Your Favourite
Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list