2016-07-06 104 views
0

我正在使用自己的自定義連接器實現,並且希望能夠將其他連接器考慮到相同的元素,以便更好地計算源點和目標點。JointJS將多個自定義連接器繪製到元素上

joint.connectors.custom = function (sourcePoint, targetPoint, vertices) { 

    // I want to calculate the "middle" point while considering other links that might interrupt 
    var sourceMiddleX = this.sourceBBox.x + this.sourceBBox.width/2; 

    var d = ['M', sourcePoint.x, sourcePoint.y, targetPoint.x, targetPoint.y]; 

    return d.join(' '); 
}; 

到目前爲止,我無法找到任何在功能方面也沒有VElement下有用..

除非有人有更好的主意,我會通過在每個模型每個單元的總哪個環節感覺不對。

在此先感謝!

回答

0

JointJS中的連接器函數被調用的值爲this等於joint.dia.LinkView實例。每個linkView訪問它在渲染的文件。

var paper = this.paper; // an instance of `joint.dia.Paper` 
var graph = this.paper.model; // an instance of `joint.dia.Graph` 
var link = this.model; // an instance of `joint.dia.Link` 

// an instance of `joint.dia.Element` or `null` 
var sourceElement = link.getSourceElement(); 
var sourceElementLinks = sourceElement 
    // an array of `joint.dia.Link` including the link 
    // these are connecting the same source element as the link 
    ? graph.getConnectedLinks(sourceElement, { outbound: true }) 
    // the link is not connected to a source element 
    : []; 

// an instance of `joint.dia.Element` or `null` 
var targetElement = link.getTargetElement(); 
var targetElementLinks = targetElement 
    // an array of `joint.dia.Link` including the link 
    // these are connecting the same target element as the link 
    ? graph.getConnectedLinks(targetElement, { inbound: true }) 
    // the link is not connected to a target element 
    : []; 

您還可以檢查jumpOverconnector,實現了一個類似的邏輯。