How to set background image for a rectangle in JointJs?

橙三吉。 提交于 2019-12-25 05:32:22

问题


How to set background image attribute for a rectangle in my JointJs application ?


回答1:


Rectangle object doesn't have that attribute perse....what you can do it's create an image object itself:

var image = new joint.shapes.basic.Image({
    position : {
        x : 50,
        y : 40
    },
    size : {
        width : 16,
        height : 16
    },
    attrs : {
        image : {
            "xlink:href" : "images/background.png",
            width : 16,
            height : 16
        }
    }
});

graph.addCell(image);

Then you can play as you need with the attrs of it, you can even create ports and set arrows later if you wish to do diagrams. Other way it's to create a rectangle object and then create this image object above as a cover (in case you need specific attrs from rectangle to code).Tell me how it goes.



来源:https://stackoverflow.com/questions/41851548/how-to-set-background-image-for-a-rectangle-in-jointjs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!