stores configuration of Diagram shapes
webix.ui({
view: "diagram",
shapes: [
{id: "circle", value: "Start", x: 0, y:80},
{id: "rrect", value: "Search", x: 120, y:80},
{id: "decision", value: "Decision", x: 240, y:80},
]
});
The shapes array stores configurations of Diagram shapes. Via this array you can configure defaults for the already existing shapes:
shapes: [
{
id: "process",
backgroundColor:"#F67B72",
lineColor:"#F67B72",
fontColor:"#fff"
},
// other shapes
]
or add custom shapes for further use:
shapes: [
{
id: "laptop",
template:'<svg width="60" height="60" viewBox="0 0 60 60">...</svg>',
backgroundColor:"#fff"
}
]
Possible fields are listed below:
true
, an item will have the same width and height when its size is changed via form or drag resizetemplate
fieldThe template
field can be used as an HTML string, a function that returns a template, or as a name of a built-in template.
You can pass any HTML string as a value for template (e.g. define it as an image):
$$("diagram1").addShape("laptop", {
template: `<img class="custom-image" src="svg/laptop.svg"></img>`,
// other data
});
Related sample: Diagram Editor: Extra Shapes
Template as a function can be useful when you need to calculate shape size depending on outer size (item size). The function accepts the only parameter:
$$("diagram1").addShape("myshape", {
template: function(obj) {
const rx = obj.width / 2;
const ry = obj.height / 2;
const d = (obj.lineWidth || 1) / 2;
return `
<svg
width='100%'
height='100%'>
<ellipse cx='${rx}' cy='${ry}' rx='${rx -d}' ry='${ry - d}' ></ellipse>
</svg>`;
},
//...
});
Related sample: Diagram Editor: Template as a Function
This option can be useful when you want to use one template for multiple shapes that may have different colors or sizes. For example, "rrect" template (rounded rectangle) can be used as "join" shape with small width/height and as "action" shape with standard size:
shapes:[
{
id: "action",
template: "rrect",
backgroundColor: "#b5d461",
lineColor: "#b5d461",
},
{
id: "join",
template: "rrect",
height: 80,
width: 10,
backgroundColor: "#ffb955",
lineColor: "#ffb955",
},
// ...
]
Related sample: Diagram Editor: Styled Shapes