簡體   English   中英

JointJS將多個自定義連接器繪制到一個元素

[英]JointJS drawing multiple custom connectors to an 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(' ');
};

到目前為止,我在函數上下文或VElement下都找不到任何有用的東西。

除非有人有更好的主意,否則我將傳遞每個模型中每個元素的總鏈接,感覺不正確。

提前致謝!

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

您還可以檢查jumpOver 連接器 ,該連接器實現了類似的邏輯。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM