jquery 流程图_使用 JQuery.Flowchart
這是一個開源的 JQuery 流程圖繪制庫,不是非常著名。
但是這個庫代碼非常簡潔,概念一致性很好。用用就知道 。
它是基于JQuery UI做的一個 Widget。
創(chuàng)建了JQuery 對象后就可以 讓它渲染流程圖。比如有一個 JQuery 對象 $el,$el.flowchart({})就可以開始使用了。
是一片空白,如果什么參數(shù)都沒有提供。因為沒有任何數(shù)據(jù)和配置,主要是沒有數(shù)據(jù)。
基本概念
每個框框,我經(jīng)常叫它節(jié)點是Operator,藍色的連線叫做連接Link,Operator能跟別的Operator相連的叫做 Connector,連過來的是 Input Connector,連出去是 Output Connector。
Operator
Operator 的數(shù)據(jù)結(jié)構(gòu):
- top (in px)
- left (in px)
- type: (optional)
- properties:
- title
- body
- uncontained: (optional, default: false) If true, the operator can be moved outside the container.
- class: css classes added to the operator DOM object. If undefined, default value is the same as defaultOperatorClass.
- inputs: Hash defining the box's input connectors. The keys define the connectors ID and the values define each connector's information as follow:
- label: Label of the connector. If the connector is multiple, '(:i)' is replaced by the subconnector ID.
- multipleLinks: (optional) If true, allow multiple links to this connector.
- multiple: (optional) If true, whenever a link is created on the connector, another connector (called subconnector) is created. See the multiple connectors demo.
- outputs: Hash defining the box's output connectors. Same structure as inputs.
節(jié)點的數(shù)據(jù)非常容易理解,里面有類型(可以任意指定),位置,標題,輸入,輸出。
輸入、輸出叫做 Connector。每個Connector 只有一個必須的字段就是 label 標簽。注意的是有些信息它放在 Properties 中,是為了復用,比如多個節(jié)點共享。可能是為了成千上萬個節(jié)點。
Link
- fromOperator: ID of the operator the link comes from.
- fromConnector: ID of the connector the link comes from.
- fromSubConnector: (optional) If it is a multiple connector, which subconnector is it.
- toOperator: ID of the operator the link goes to.
- toConnector: ID of the connector the link goes to.
- toSubConnector: (optional) If it is a multiple connector, which subconnector is it.
- color: Color of the link. If undefined, default value is the same as defaultLinkColor.
非常清晰,一個 Link,一定是連接了兩個Operator 的Connector,這里面的SubConnector可以不用考慮。如果你真的使用它,可能永遠用不上。SubConnector在界面上也沒有任何顯示的區(qū)別。
添加 Operator 或者 Link
所有的 Flowchart的函數(shù)都 $el.flowchart("func", func_parameter...)這樣使用。如添加 Operator
$el.flowchart("createOperator", operatorId, operator)
提前準備好 operatorId,和 operator的數(shù)據(jù)即可,界面上就會馬上呈現(xiàn)。
添加Link。
$el.flowchart("createLink", linkId, link)
linkId 和 operatorId是啥,就是一個字符串或者數(shù)字都可以,就是別沖突用來分標記這個 Operator 和 Link。
當然它也有接口 addOperator 和 addLink,會動態(tài)分配 id。
初始化的時候就指定 Operator 和 Link
$el.flowchat({data: {operators: {}, links: {}}})
加上 data 參數(shù),其中operators 和 links 都是 hash map,key是id,value 就是 Operator 和 Link 數(shù)據(jù)。
這樣初始化的時候就有時機加載繪制 Operator 和 Link。
Callback 和 Event
增加、刪除 Operator 或者 Link 都能產(chǎn)生響應的事件。可以在初始化的時候設(shè)置Callback,比如 OnOperatorMoved,當Operator移動到一個新位置后會觸發(fā)一個事件_onOperatorMoved,或者直接調(diào)用 onOperatorMoved Callback。
動態(tài)設(shè)置
函數(shù) setOperator 和 setLink 可以根據(jù) id 動態(tài)設(shè)定 Operator 或者 Link 的屬性,比如給 Operator 加個 input connector 等等。
非常高級
函數(shù) getDataRef 可以拿到 Flowchart 內(nèi)部的數(shù)據(jù)結(jié)構(gòu)和HTMLELEMENT,這樣可以為所欲為。但是一般的getOperator或者getData都是一個數(shù)據(jù)的copy,并不是引用。
簡單介紹 Flowchart,其實它的文檔寫的非常好。從來沒有用過這么舒服的一個JS UI庫!!!
總結(jié)
以上是生活随笔為你收集整理的jquery 流程图_使用 JQuery.Flowchart的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: mysql navicat 组合索引_N
- 下一篇: word邮件合并一页8个_办公软件小课堂