2013-04-25 25 views
0

我是jsplumb的新手。我需要你的幫助來完成這個例子。如何使用jsplumb爲源和目標端點設置不同的顏色

如何使用jsplumb爲源和目標端點設置不同的顏色?

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
    <title></title> 


    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.1/jquery.min.js"></script> 
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.23/jquery-ui.min.js"></script> 
    <script type="text/javascript" src="../js/jquery.jsPlumb-1.3.16-all-min.js"></script> 
    <script type="text/javascript"> 


     jsPlumb.bind("ready", function() { 

      var source= jsPlumb.addEndpoint("source", { 
       overlays: [["Label", { label: "SOURCE", id: "labelsource"}]], 
       paintStyle: { fillStyle: 'red' }, 
     //endpointStyle: { fillStyle: '#808000' }, 
       endpoint: ["Dot", { radius: 15}] 
      }); 
      var secure = jsPlumb.addEndpoint("target", { 
       overlays: [["Label", { label: "TARGET", id: "labeltarget"}]], 
       paintStyle: { fillStyle: 'green' }, 
       endpoint: ["Dot", { radius: 15}] 
      }); 
jsPlumb.connect({ 
       source: 'source', target: 'target', paintStyle: { lineWidth: 10, strokeStyle: '#66CCFF' }, 
       sourceEndpointStyle: { fillStyle: '#808000' }, 
       targetEndpointStyle: { fillStyle: '#800000' }, 
endpoint: ["Dot", { radius: 15}], anchor: "BottomCenter", 
       //connector: [ "Bezier", 0 ], 
       connector: "Straight", 
       detachable: false, 
       overlays: [ 
     ["Label", { 
      fillStyle: "rgba(100,100,100,80)", 
      color: "white", 
      font: "12px sans-serif", 
      //label:"Static label", 
      borderStyle: "black", 
      borderWidth: 2 
     }], 
     ["Arrow", { location: 0.5}] 
    ] 

      }) 
}); 


    </script> 
</head> 
<body> 
    <div id="source" style="position: absolute; left: 100px; top: 250px;"> 
    </div> 
    <div id="target" style="position: absolute; left: 600px; top: 250px;"> 
    </div> 
</body> 
</html> 

上面的代碼並未將適當的顏色應用於源節點和目標節點。

回答

2

您可以使用下面的方法來設置連接的顏色,當創建連接

jsPlumb.bind("jsPlumbConnection", function (conn) { 
    var source = conn.source; 
    var target = conn.target; 

    conn.connection.setPaintStyle({ 
      strokeStyle: getConnectionColor(source, target), 
      lineWidth: 3 
    });     
}); 

實現getConnectionColor(源,目標)方法根據源得到的顏色和目標

相關問題