I am designing a graphical interface for electrical circuits and I want to check the operation of a light bulb that I have defined as an object. The definition of the bulb object is as follows:
/* Función para crear una bombilla */
joint.shapes.electrics.elements.define('electrics.light', {
attrs: {
'.input': {ref: '.body', 'ref-x': 1, 'ref-y': 0.5, magnet: true, port:
'in'},
'.output': {ref: '.body', 'ref-dx': -0.5, 'ref-y': 0.5, magnet: true,
port: 'out'},
circle: {r: 5, stroke: 'black', fill: 'transparent', 'stroke-width': 1},
image: {'xlink:href': 'Imágenes/bombilla.off.jpg'}}
}, {
markup: '<g class="rotatable"><g class="scalable"><image class="body"/>
</g><circle class="input"/><circle class="output"/></g>', },
{
operation: function(input) {
return input;
}});
I would like to know how I could change the image defined to this object "bombilla.off.jpg" to another that I have called "bombilla.on.jpg".
Greetings.
I tried to test your program but it does not do anything to me hahaha I guess I'll be doing something wrong since I'm not really into javascript and html. Although I have found out a way to modify attributes of some objects, for example, if I want to modify a characteristic such as the position (I am going to take as a reference object the light bulb defined above) it would be something like this:
var light = joint.shapes.basic.Generic.define('electrics.light', {
size: {width: 80, height: 40},
attrs: {
'.': {magnet: false},
'.body': {width: 50, height: 25},
'.input': {ref: '.body', 'ref-x': 1, 'ref-y': 0.5, magnet: true, port: 'in'},
'.output': {ref: '.body', 'ref-dx': -0.5, 'ref-y': 0.5, magnet: true, port: 'out'},
circle: {r: 5, stroke: 'black', fill: 'transparent', 'stroke-width': 1},
image: {'xlink:href': 'bombilla.off.jpg'}}
}, {
markup: '<g class="rotatable"><g class="scalable"><image class="body"/></g><circle class="input"/><circle class="output"/></g>',
}, {
operation: function(input) {
return input;
}});
**var light_off = (new light).position(50,0);**
graph.addCell(light_off);
I tried to use the same structure but changing the image, something like this:
var light_on = (new light).position(50,50).attr("xlink:href","bombilla.on.jpg") ;
graph.addCell(light_on);
However, it does not generate the same object with the changed image, it generates two objects with the same image. I tried to use the structure of the function that you mentioned above but I do not know how it could be for my object. Greetings:)