2016-07-06 4 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, который реализует подобную логику.