Debian

如何為 graphviz 圖形節點添加顏色?

  • August 10, 2020

這是我目前擁有的圖表的程式碼:

graph Budget {
   Country_Budget -- Profit_and_Loss_Account  [type=s];
   Country_Budget -- Balance_Sheet [type=s];
    Profit_and_Loss_Account -- Income [type=s];
    Profit_and_Loss_Account -- Expenditure [type=s];
    Income -- Revenue_Income [type=s];
    Income -- Capital_Income [type=s];
    Expenditure -- Revenue_Expenditure [type=s];
    Expenditure -- Capital_Expenditure [type=s]; 
    Balance_Sheet -- Assets [type=s]; 
    Balance_Sheet -- Liabilities [type=s];
}

這是使用dotty工具時的渲染 -

國家預算的粗略草圖

雖然它提供了細節和結構,但有沒有人知道如何讓它更加豐富多彩?

在 Debian 上執行 graphviz 2.38.0-16。

您可以執行以下操作:

graph Budget {
  subgraph tier1 {
     node [color="lightgreen",style="filled",group="tier1"]
     Country_Budget
  }
  
  subgraph tier2 {
     node [color="green",style="filled",group="tier2"]
     Profit_and_Loss_Account
     Balance_Sheet
  }
  
  subgraph tier3 {
     node [color="lightblue",style="filled",group="tier3"]
     Income
     Expenditure
     Assets
     Liabilities
  }
  
  subgraph tier4 {
     node [color="yellow",style="filled",group="tier4"]
     Revenue_Income
     Capital_Income
     Revenue_Expenditure
     Capital_Expenditure
  }
  
  Country_Budget -- {Profit_and_Loss_Account Balance_Sheet}
  Profit_and_Loss_Account -- {Income Expenditure}
  Income -- {Revenue_Income Capital_Income}
  Expenditure -- {Revenue_Expenditure Capital_Expenditure}
  Balance_Sheet -- {Assets Liabilities}
}

範例輸出

引用自:https://unix.stackexchange.com/questions/339603