05.绘制一张时序图

使用Graphviz画一张时序图

digraph sequence{
	graph [rankdir="LR";splines="polyline"]
	
	subgraph client {
		graph [rank="same"]
		node[shape="box";width=0.1;height=0.2;label=""]
		edge[dir="none";style="dashed"]
		
		client_start[shape="plaintext";label="client"]
		client_end [shape="point";width=0;height=0]
		
		client_start->client_01->client_02->client_end
	}
	
	subgraph proxy {
		graph [rank="same"]
		node[shape="box";width=0.1;height=0.2;label=""]
		edge[dir="none";style="dashed"]
		
		proxy_start[shape="plaintext";label="proxy"]
		proxy_end [shape="point";width=0;height=0]
		
		proxy_start->proxy_01->proxy_02->proxy_end
	}
	
	
	subgraph gateway {
		graph [rank="same"]
		node[shape="box";width=0.1;height=0.2;label=""]
		edge[dir="none";style="dashed"]
		
		gateway_start[shape="plaintext";label="gateway"]
		gateway_end [shape="point";width=0;height=0]
		
		gateway_start->gateway_01->gateway_02->gateway_end
	}
	
	subgraph service {
		graph [rank="same";]
		edge[dir="none";style="dashed"]
		node[shape="box";width=0.1;height=0.7;label=""]
		
		service_start[shape="plaintext";label="service"]
		service_end [shape="point";width=0;height=0]
		
		service_start->service_01 ->service_end
	}
	
	client_01->proxy_01 [label="send request"]
	proxy_01->gateway_01 [label="redirect request"]
	gateway_01->service_01:nw [label="redirect request"]
	service_01:sw->gateway_02[label="send response"]
	gateway_02->proxy_02[label="redirect response"]
	proxy_02->client_02[label="redirect response"]
}

Build

dot -T svg -o Testing.svg Testing.dot

001

解释:

service_01:sw->gateway_02[label="send response"] 中的 sw 是定义节点与边缘的连接点位置,取值为:n , ne , e , se , s , sw , w , nw , c , _,默认为_

  • n - north 北,指图形正上方

  • w - west 西,指图形正左方

  • s - south 南,指图形正下方

  • e - east 东,指图形正右方

  • ne - northeast 东北,指图形右上角

  • nw - northwest 西北,指图形左上角

  • se - southeast 东南,指图形右下方

  • sw - southwest 西南,指图形左下方

  • c - Center 中心

  • _ - 默认值 表示图形适当的一侧


graph的 splines 属性指定的边缘的线型取值参见: Node, Edge and Graph Attributes:splines