简体   繁体   English

JointJS端口不起作用

[英]JointJS ports are non-functional

Here is a JSFiddle showing the issue: https://jsfiddle.net/Bronzdragon/xpvt214o/399003/ 这是显示问题的JSFiddle: https ://jsfiddle.net/Bronzdragon/xpvt214o/399003/

graph = new joint.dia.Graph;
var paper = new joint.dia.Paper({
    el: document.getElementById('myholder'),
    model: graph,
    width: 800,
    height: 600,
});

var rect = new joint.shapes.basic.Rect({
  attrs: {rect: {fill: 'lightblue'}},
  size: { width: 200, height: 100 },
  ports: {
    groups: {
      'inputs': {
        position: { name: 'left' },
        attrs: {circle: {fill: 'lightgreen'}},
        magnet: 'passive'
      },
      'outputs': {
        position: { name: 'right' },
        attrs: {circle: {fill: 'pink'}},
        magnet: true,
      }
    },
    items:[ { group: 'inputs' }, { group: 'outputs' } ]
  }
});
rect.position(100, 50);
rect.addTo(graph);

var rect2 = rect.clone();
rect2.position(400, 100);
rect2.addTo(graph);

I'm defining an JointJS element (called rect), with two ports on it, and adding them to the graph. 我正在定义一个带有两个端口的JointJS元素(称为rect),并将它们添加到图中。 The elements themselves are functional, but the ports aren't. 元素本身具有功能,但端口没有功能。 When dragging off of an active magnet (the pink circle), it should create a link. 拖动活动的磁铁(粉红色的圆圈)时,它应该创建一个链接。 Instead it moves the element. 相反,它移动元素。

I've followed the JointJS guide in creating a shape, and adding ports. 我遵循JointJS指南创建形状并添加端口。 These ports I've added seem to be completely inactive though. 我添加的这些端口似乎完全不活动。 I do not know what I'm doing wrong. 我不知道我在做什么错。

I have emailed the JointJS team, and they came back to me with the following (Thank you very much, Roman!): 我已经给JointJS团队发送了电子邮件,他们通过以下电子邮件回复了我(非常感谢您,罗马!):

Thank you for reaching out to us! 感谢您与我们联系! You were nearly there. 你快到了 The magnet attribute meant to be set on a specific shape DOM element. magnet属性旨在设置在特定形状的DOM元素上。 Similar to fill , refX , xlinkHref etc. 类似于fillrefXxlinkHref等。

var rect = new joint.shapes.basic.Rect({
  attrs: {rect: {fill: 'lightblue' }, root: {  magnet: false }},
  size: { width: 200, height: 100 },
  ports: {
    groups: {
      'inputs': {
        position: { name: 'left' },
        attrs: {circle: {fill: 'green', magnet: 'passive' }},

      },
      'outputs': {
        position: { name: 'right' },
        attrs: {circle: {fill: 'red', magnet: true }},    
      }
    },
    items:[ { group: 'inputs' }, { group: 'outputs' } ]
  }
});

Also, If you are new to JointJS I recommend you to read our online tutorials ( https://resources.jointjs.com/tutorial ). 另外,如果您不熟悉JointJS,我建议您阅读我们的在线教程( https://resources.jointjs.com/tutorial )。 I suggest using standard shapes over basic , as the standard shapes are newer and reflecting the best JointJS techniques. 我建议在basic之上使用standard形状,因为这些标准形状是较新的并且反映了最好的JointJS技术。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM