###### tags: `Golang Package` # Memviz 將結構變成可視化圖表 ## example ```go= type tree struct { id int left *tree right *tree } func main() { root := &tree{ id: 0, left: &tree{ id: 1, }, right: &tree{ id: 2, }, } leaf := &tree{ id: 3, } root.left.right = leaf root.right.left = leaf buf := &bytes.Buffer{} memviz.Map(buf, &root) err := ioutil.WriteFile("example-tree-data", buf.Bytes(), 0644) if err != nil { panic(err) } } ``` 運行後會得到一個檔案 example-tree-data 再透過`graphviz`產生圖片 ``` dot -Tpng example-tree-data -o diagram.png ``` 結果 ![](https://i.imgur.com/ScuR1Y1.png) ## 用Item的結構 ![](https://i.imgur.com/zBP5QzD.png) [大圖](https://i.imgur.com/zBP5QzD.png) # [Graphviz](https://zh.wikipedia.org/wiki/Graphviz) 用於繪製DOT語言指令碼描述的圖形 ``` graph graphname { a -- b -- c; b -- d; } ``` ![](https://i.imgur.com/9lhMc6h.png) [更多範例](http://www.graphviz.org/gallery/) [貝爾實驗室](https://www.bell-labs.com/#gref) [wiki](https://en.wikipedia.org/wiki/Bell_Labs) ![](https://i.imgur.com/67xIn3u.png) {%hackmd theme-dark %}