How can i update joint.dia.Element.define

35 views
Skip to first unread message

che

unread,
May 5, 2022, 12:59:29 AM5/5/22
to JointJS
Hi there,

Here I have code that drawing img. And I want to update or change img (src) now.

`````````````````````````````````````````````````````````````````````````````````````````
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]);
`````````````````````````````````````````````````````````````````````````````````````````

I tried following line but not working
e1.attrs('image/xlinkHref', src1);

How can I update of chnage 'xlinkHref'?


Many thanks always!



heng fan

unread,
May 5, 2022, 3:00:59 AM5/5/22
to JointJS
Hi,

You can try to use prop rather than attrs.

e1.prop('attrs/image/xlinkHref', 'src1')

Roman Bruckner

unread,
May 5, 2022, 5:14:36 PM5/5/22
to joi...@googlegroups.com
This is fine. `e1.attrs('image/xlinkHref', src1);` (it internally calls e1.prop('attrs/image/xlinkHref', 'src1')).

But tagName 'items' is a not valid SVGElement name (https://developer.mozilla.org/en-US/docs/Web/SVG/Element). Perhaps there is an error in the console even before you call the attrs()?



--

---
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/6f2607bd-7064-48da-8d29-be5f7b531f6en%40googlegroups.com.


--
Reply all
Reply to author
Forward
0 new messages