Types serve to express the purpose of each block. Each type is a set of properties that will be applied to each individual block that uses this or that type.
From this article you will learn how to use predefined types, style them and create custom ones.
By default a block has a simple rectangular shape with no styling:
There are two stylistic types:
Related sample: Diagram: Built-in Style Types
On the picture below you can find the set of predefined SVG shapes (types).
Related sample: Diagram: Built-in Shapes
You can set a stylistic or an SVG type (shape) for each block individually or define them globally for all the blocks at once. To define types individually, you need to add the type field to the corresponding block object and set the ID of the desired type as its value.
view: "diagram",
data: [
{
id: "start",
value: "start",
x: 0,
y: 80,
type: "disk", },
// other blocks
]
In case your project requires all blocks to be of the same type, you can define it globally via the item property:
webix.ui({
view: "diagram",
data: [/* item blocks */],
item: {
// all blocks will have the heptagon type
type: "heptagon" }
});
There are 2 ways to style blocks both SVG-based and default ones:
Text styles
SVG styles
You can style blocks that use SVG-based types directly within the data items:
webix.ui({
view: "diagram",
data: [
{
id: "process",
backgroundColor:"#F67B72",
lineColor:"#F67B72",
fontColor:"#fff"
},
// other blocks
],
});
You can provide the defaults settings for each SVG-based type in the shapes configuration array.
The shapes property takes an array of type objects, so you can provide the defaults for several SVG-based types at once.
view:"diagram",
shapes: [
// customize styles for the action shape
{
id: "process",
backgroundColor:"#F67B72",
fontColor: "magenta"
},
// other shapes
]
Now all the blocks that use the "action" type will have the defined background and font colors, unless they have these colors of their own.
You can also use the setShape method to provide defaults for a particular SVG-based type.
$$("diagram1").setShape("dot", {
lineColor: "#2d9bf0"
});
Related sample: Diagram: Shape Styling
Now all the blocks that use a "dot" type will have the defined line color, unless they have a line color of their own.
You can style blocks globally or individually. To style them all the same way, define the item object inside the Diagram constructor and set CSS class name as a value for the css
field:
{
view: "diagram",
data: [/* blocks data */],
item: {
css: "common_blocks"
}
}
When styling blocks and their content (shape and text) you need to define a custom class for that block via the $css
field in its data object:
{
id: 1,
// can be any class name
$css: "my_css"
}
Below we cover how to access and style block shape and text.
You can think of a block item as of a container with a shape and text inside. So to style the inner shape of a default stylistic block you need to add a CSS rule depending on a shape template. Block shape possesses its own CSS class, that you can access:
<!-- css classes for the "default" block-->
<div class="webix_diagram_shape webix_diagram_shape_default"></div>
<!-- css classes for the "org" block-->
<div class="webix_diagram_shape webix_diagram_shape_org"></div>
CSS rules for the "org" shape would look like the following:
.my_css .webix_diagram_shape_org { border-color: orange; }
SVG-based shapes are styled the same way, however you you need to refer to the SVG element itself (not a CSS class):
.my_css svg { stroke: orange; }
Related sample: Diagram: Built-in Block Styles
The block text is rendered above the shape element and has the "webix_diagram_text" CSS class. So to style the block text you need to refer to this class as follows:
.my_css .webix_diagram_text {
font-weight: 500;
background: transparent !important;
}
Related sample: Diagram: Decision Tree
Diagram allows you to create and utilize custom SVG shape (type) to meet your needs.
You can provide custom shapes in the shapes array in the configuration:
{
view: "diagram",
shapes: [
{
id: "internet",
// used for tooltips in Diagram editor
name: "Network",
// used to group shapes in Diagram editor
group: "device",
template: '<svg width="60" height="60" viewBox="0 0 60 60">...</svg>',
lineColor: "98E4ED",
backgroundColor:"#fff",
altBackgroundColor:"#98E4ED",
textVAlign:"bottom"
},
// other custom and predefined shapes
]
}
Or via by the addShape method:
$$("diagram").addShape("internet", {
template: '<svg width="60" height="60" viewBox="0 0 60 60">...</svg>',
name: "Network",
group: "device",
lineColor: "98E4ED",
backgroundColor:"#fff",
altBackgroundColor:"#98E4ED",
textVAlign:"bottom"
});
Related sample: Diagram: Custom Shapes
Note that for custom shapes, you need to specify the following fields:
If you are adding an SVG with the path elements that need to be filled via altBackgroundColor, the elements must have the webix_diagram_shape_alt class.
<svg width="60" height="60" viewBox="0 0 60 60" fill="none" >
<rect width="60" height="60" />
<path class="webix_diagram_shape_alt" .../> </svg>`
Also make sure the shape ID is unique and does not coincide with any shape IDs from the predefined set. Otherwise the built-in shape will be overwritten with a custom one.
You can get a data object of a particular shape. For that call the getShape method on the diagram passing the shape ID as a parameter. The method returns a configuration object of the specified shape.
$$("diagram1").getShape("plus");
/*
{
id: "plus",
name: "Plus",
svg: "...svgCode"
}
*/
Back to top