2016-07-06 11 views
0

Ich benutze meine eigene benutzerdefinierte Konnektor-Implementierung und ich möchte in der Lage sein, andere Konnektoren zu den gleichen Elementen zu berücksichtigen, um die Quell- und Zielpunkte besser zu berechnen.JointJS Zeichnen von mehreren benutzerdefinierten Konnektoren zu einem Element

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(' '); 
}; 

Bisher habe ich nichts hilfreich unter der Funktion Kontext noch unter dem VElement finden konnten ..

Es sei denn, jemand eine bessere Idee hat, ich werde die Anzahl der Links pro Element in jedem Modell passieren die fühlt sich nicht richtig an.

Vielen Dank im Voraus!

Antwort

0

Connector Funktionen in JointJS werden mit einem Wert von this gleich einer joint.dia.LinkView Instanz aufgerufen. Jeder Linkview hat Zugriff auf das Papier, um es in übertragenem wird.

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 
    : []; 

Sie können auch die jumpOverconnector überprüfen, die eine ähnliche Logik implementiert.