有兩種方法可以用圖片代替node的默認形狀
node有兩個屬性 shapefile image,這兩個屬性都可以改變node原有的形狀,變成我們自己加載的圖片。
一、使用shapefile屬性
digraph g
{
B[shapefile="D:/2.png"];
A->B;
}
生成的圖片:
shapefile是圖片存放的路徑,可以看到圖片已經出現了,但是node卻仍有黑色的邊框,下面我們去掉邊框:
digraph g
{
B[shapefile="D:/2.png",color=white,style=filled];
A->B;
}
設置color=white,style=filled的作用是去掉圖片的邊框,將整個矩形區域填充爲白色,這樣就沒有邊框了。
二、使用image屬性
digraph g
{
B[image="D:\2.png",imagescale=both,shape=rectangle,style=filled,color=white;];
A -> B;
}
效果與使用shapefile一樣。
這兩種的區別在於使用shapefile屬性時,節點的形狀被設定爲矩形,而且圖片也必須是矩形的;而使用image屬性時,圖片僅僅是被當做node的填充而並非成爲整個node,所以,image屬性可以被任意形狀的節點填充,而不僅僅是矩形。
舉個例子:
digraph g
{
B[image="D:\2.png",imagescale=both,shape=circle];
A -> B;
}
上面代碼生成的圖片:
圖片被填充在圓形的區域中
而使用如下代碼:
digraph g
{
B[shapefile="D:/2.png",shape=circle];
A->B;
}
生成的圖片爲:
我們可以看到雖然已經形狀設置爲circle圓形,但生成的node依然是box矩形。