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
实例。每个链接视图都可以访问呈现它的纸张。
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
连接器。
相关文章:
- 使用clickToggle并在单击另一个元素时关闭元素
- 表追加而不附加最后一个元素
- 滚动到容器中的下一个元素-几乎到了
- 使用CSS或js,使用动态选择器选择任意li的下一个元素
- 按我自己的类克隆另一个元素的内容和顺序
- Javascript获取上一个元素的内容
- 如何通过HTML+CSS中的另一个元素Selector更改元素的属性值
- 在数组中的一个元素上设置多个值
- 无法选择除一个元素外的所有元素
- 使用jquery contains获取一个元素并添加类
- $(.class).empty总是缺少一个元素
- jQuery-将列表项的一个元素移动到同一项的另一个元素中+对我的列表中的每个项执行此操作
- 如何在一个元素动画之后延迟
- jQuery转盘下一个元素没有滑入
- jquery从另一个元素中移除移除
- DIV怎么能像Javascript中的另一个元素一样工作呢
- 当知道同一hiearch中至少有一个元素时,遍历到元素.结构使用jquery
- 使用数据属性将HTML数据复制到另一个元素
- 如何选择给定类的上一个元素
- 动态修改一个元素,使其与给定的选择器匹配