How to allow users to add ports at any position on a custom element in JointJS? #2933
-
IntroductionBody:Hello, I am working on a custom element in JointJS and I want to allow the users to add ports at any position they like on the element. My goal is to enable users to dynamically add ports by specifying the position using x and y coordinates (absolute position). I have already created a custom element, but I am struggling with how to allow users to add ports anywhere on the element. Here’s a simplified example of how I am trying to add a port: import { dia } from "@jointjs/core";
// Create custom element
const myElement = new dia.Element({
size: { width: 160, height: 300 },
attrs: {
body: {
fill: "#fff",
stroke: "#000",
},
},
});
// Trying to add a port at a specific position
myElement.addPort({
id: "inlet1",
position: {
name: "absolute", // Absolute positioning
args: { x: 50, y: 100 }, // Position of the port
},
attrs: {
portBody: {
r: 6,
fill: "#3498db",
stroke: "#fff",
strokeWidth: 2,
},
portLabel: {
text: "Input",
fontSize: 10,
fill: "#333",
},
},
}); What I want is for users to be able to add a port wherever they want on the element, not just the predefined positions (like left, right, top, bottom). I also want to ensure that when they add a port, it is placed at the specified x, y coordinates relative to the element. Does anyone know how to achieve this? I am using JointJS for building this functionality and the element is a custom one, not a predefined shape. Any help or guidance would be greatly appreciated! Thanks in advance! Steps to reproduceNo response Restrictions & ConstraintsNo response Does your question relate to JointJS or JointJS+. Select both if applicable.JointJS |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 6 replies
-
Hi omoghadasi, In the current version of JointJS, individual ports are positioned by providing myElement.addPort({
id: "inlet1",
args: { x: 50, y: 100 },
attrs: {
portBody: {
r: 6,
fill: "#3498db",
stroke: "#fff",
strokeWidth: 2,
},
portLabel: {
text: "Input",
fontSize: 10,
fill: "#333",
},
},
}); We are planning to change this behavior in a future version of JointJS in order to make it work as you thought ( |
Beta Was this translation helpful? Give feedback.
When I comment out the group and args, the port shows up on the left side by default.
But when I set the group and provide args for absolute positioning, the port doesn’t show up at all.
I'm trying to let the user add a port anywhere they want by specifying exact x, y coordinates.
The element is a custom element I created, and I want to make sure ports can be added at any position dynamically.
Here’s my current code — how can I fix it so that adding ports at custom positions works as expected?