Port is not working for rectangle element

50 views
Skip to first unread message

che

unread,
May 20, 2022, 1:52:57 AM5/20/22
to JointJS
Hi there,

Here is my port definition
```````````````````````````````````````````````````````   
// define port details
    var port = {
        label: {
            position: {
                name: 'left'
            },
            markup: [{
                tagName: 'text',
                selector: 'label'
            }]
        },
        attrs: {
            portBody: {
                magnet: true,
                width: 6,
                height: 6
            }
        },
        markup: [{
            tagName: 'rect',
            selector: 'portBody'
        }]
    };
```````````````````````````````````````````````````````   

And rectangle definition

```````````````````````````````````````````````````````   
var rect = new joint.shapes.standard.Rectangle();
        rect.position(100, 30);
        rect.resize(105, 25);
        rect.attr({
            body: {
                fill: 'none',
                strokeWidth: 0
            },
            label: {
                text: realTimeData[0].value,
                fontSize: 18
            }
        });
        rect.ports({
                items: [ port ]
        });
        rect.addTo(graph);

```````````````````````````````````````````````````````   

Everything is working well except the port, following line cause error message 
"rect.ports is not a function at drawSensorValue"
```````````````````````````````
rect.ports({
                items: [ port ]
        });
```````````````````````````````

Is there anything I miss typed? what is the problem here?


Thanks you always!

James Williams

unread,
May 20, 2022, 3:31:48 AM5/20/22
to JointJS
Hi,

The name of the function is incorrect. You could use 'rect.addPort' or rect.addPorts'
https://resources.jointjs.com/docs/jointjs/v3.5/joint.html#dia.Element.prototype.addPort
https://resources.jointjs.com/docs/jointjs/v3.5/joint.html#dia.Element.prototype.addPorts

You can see how they are used in the following tutorial.
https://resources.jointjs.com/tutorial/ports

We've just moved our support to Github, where we answer all questions, so future questions can be asked here.
https://github.com/clientIO/joint/discussions

Thanks
Reply all
Reply to author
Forward
0 new messages