Extra text space in joint.dia.Element.define

47 views
Skip to first unread message

che

unread,
May 8, 2022, 9:47:25 PM5/8/22
to JointJS
Hi there,

I draw a image icon using below code.
```````````````````````````````````````````````````````````````````````````````````````````````
const r5 = joint.dia.Element.define('example.Sensor', {
            size: {
                width: 120,
                height: 48
            },
            attrs: {
                image: {
                xlinkHref: src,
                width: 'calc(w - 6)',
                height: 'calc(h - 6)'
                }
            },
            ports: {
                items: [ port ] // add a port in constructor
            }
        }, {
            markup: [{
                tagName: 'image',
                selector: 'image'
            }, {
                tagName: 'items',
                selector: 'ports'
            }]
        });
        // draw elements
        const e1 = new r5();
        e1.position(100, 100);

        graph.addCells([e1]);
```````````````````````````````````````````````````````````````````````````````````````````````


And I saved that image icon history using toJSON() method
``````````````````````````````````````````````````````````````````````````````````````````````
jsonObject = graph.toJSON();
``````````````````````````````````````````````````````````````````````````````````````````````

what I found here, the element id is changing every time when I do toJSON().
Capture.JPG

This can be a problem when I identify elements based on this id. So, I'm trying to save another id in this object. Is there any space where I can add some text in cells[0]?
May be cells[0]['unique']?


Many thanks

Roman Bruckner

unread,
May 9, 2022, 3:47:41 AM5/9/22
to joi...@googlegroups.com
Hi,

if an `id` is provided it will never change.

new El({ id: ''my-id }); // this will always be `my-id`

If no `id` is provided it is automatically generated

const el  = new El({});
el.id // an id was generated and it will never change

Note that If you overriding lifecycle methods e.g. initialize() of the model please make sure you are calling super(). I've seen issues with `ID` when the inheritance is done wrong.

Could you share a code that would demonstrate the issue?

Best,
Roman







--

---
You received this message because you are subscribed to the Google Groups "JointJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jointjs+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jointjs/b8e478c3-86da-45b9-aa89-d486d7be8b24n%40googlegroups.com.


--

che

unread,
May 10, 2022, 1:06:59 AM5/10/22
to JointJS
Hi Roman,

Appreciate for your reply, it is too large and complex code to share. It includes php, js, Azure at the same time.
But I've solved this issue using label section. I added unique Azure ID there and identify the element and uploaded image and custom element.

Many thanks!

Roman Bruckner

unread,
May 10, 2022, 3:37:36 AM5/10/22
to joi...@googlegroups.com
You'd have to create a simplified example (e.g. jsfiddle) that demonstrates the issue.

Reply all
Reply to author
Forward
0 new messages