2013-07-31 123 views
2

我用viz.js製作了這個圖。如何在D3.js中使用強制定向圖表創建圖表?

enter image description here

點代碼非常簡單:

<script type="text/vnd.graphviz" id="myDiagram"> 
digraph G { 
graph [ 
    fontname = "Arial", 
    fontsize = 18, 
    label = "Digest Email Flow Chart", 
    size = "4,4" ]; 

node [ 
    shape = ellipse, 
    sides = 4, 
    distortion = "0.0", 
    orientation = "0.0", 
    skew = "0.0", 
    bgcolor = lightgray, 
    style = filled, 
    fontname = "Arial" ]; 

"Email Notification" [shape=ellipse, shape = "Mrecord" label="Digest Email\n(scheduled)"]; 
"Sentiment Analysis" [shape=ellipse, shape = "Mrecord" label="Sentiment Analysis\n(triggered)"]; 
"Google News"   [shape=ellipse, shape = "Mrecord" label="Google News\n(scheduled)"]; 
"Dilbert Daily Comics" [shape=ellipse, shape = "Mrecord" label="Dilbert Daily Comics\n(scheduled)"]; 
"Time Series Chart" [shape=ellipse, shape = "Mrecord" label="Time Series Chart\n(triggered)"]; 
"Twitter Stream"  [shape=ellipse, shape = "Mrecord" label="Twitter Stream\n(scheduled)"]; 

"Email Notification" -> "Time Series Chart" [dir = "back"]; 
"Email Notification" -> "Dilbert Daily Comics" [dir = "back"]; 
"Time Series Chart" -> "Twitter Stream" [dir = "back"]; 
"Sentiment Analysis" -> "Google News" [dir = "back"]; 
"Email Notification" -> "Sentiment Analysis" [dir = "back"]; 
} 
</script> 

但viz.js庫是2.3 MB!這太大了。

是否可以像D3.js中的強制定向圖那樣執行相同的操作?

+0

的力導向佈局是不是你在這種情況下所需要的 - 你正在尋找的東西,計算該佈局靜態。在D3中沒有任何東西會爲你開箱。 –

+0

謝謝你的建議。我決定去jsPlumb。這個API有很好的文檔記錄,這是一個很好的獎勵,你可以使用預定義的DIV和節點的固定位置。 – user1707810

回答

0

最終我決定自己編寫圖表代碼,因爲jsPlumb在某些區域與jQuery Mobile js和css衝突。在html5畫布上進行自己的繪製並不難,最終得到一個「更輕」的應用程序。

這個結果:

Link to chart