Cell
The basic model for diagram cells. It's an mvc.Model with a few additional properties and methods. Most importantly, every cell has a unique ID that is stored in the id property.
To learn about cells and their features in detail, see the Cells learn section.
constructor
new Cell([attributes], [options])
When creating an instance of a cell, you can pass in the initial values of the attributes, which will be set on the model.
If you pass a { mergeArrays: true } as the options, all the arrays defined as class defaults will be merged instead of overridden.
const MyRect = shapes.standard.Rectangle.define('Rect', { array: [1,2] });
const rect1 = new MyRect({ array: [3] });
console.log(rect1.get('array')); // [3] array was overridden
const rect2 = new MyRect({ array: [3] }, { mergeArrays: true });
console.log(rect2.get('array')); // [3,2] array was merged
Methods
addTo()
cell.addTo(graph)
Add the cell to the graph (an instance of dia.Graph). This is equivalent to calling graph.addCell(cell).
attr()
cell.attr(path);
cell.attr(path, value [, opt]);
cell.attr(attrs [, opt])
Set presentation attributes (SVG and JointJS attributes) on view subelements. attrs can either be an object or string representing a path to a nested attribute. If it is an object, the keys of the attrs object are selectors (JSON Markup Selector or CSS Selector) matching the subelements. The values are objects containing SVG attributes and their values. attrs object will be mixed with attrs property of the shape model. This is a convenient way of rewriting only some of the attributes of the subelements. For overwriting all attributes of all subelements, use cell.set('attrs', attrs).
element.attr({
// selectors as defined in the JSON markup
body: { width: 'calc(w)', height: 'calc(h)' },
label: { text: 'My Label' },
// using CSS selectors is significantly slower
rect: { fill: 'blue' },
text: { fill: 'white', fontSize: 15 },
'.myrect2': { fill: 'red' }
});
link.attr({
// selector as defined in JSON markup
line: {
stroke: 'red',
targetMarker: {
type: 'circle',
r: 5
}
}
});
The method is not suitable for storing custom data on the model. For that, use prop() or set() methods. You can learn about it more in the following learn section.
shape.set('confirmed', true);
shape.prop('data/count', 10);