Since 8.4
The widget comes in one package with the Diagram component. The package requires Webix Pro edition and can be purchased as part of any license pack.
Diagram Editor is a complementary tool designed for users to plot clean, performant and scalable charts via the user-friendly interface. The editor can also communicate with the Diagram itself making charting with the library even more flexible and smooth. Capabilities of the editor include:
After installing Diagram, you can instantiate Diagram Editor in the usual way:
As a Webix view:
webix.ready(function() {
// use custom scrolls, optional
if (webix.env.mobile) webix.ui.fullScreen();
webix.CustomScroll.init();
webix.ui({
view: "diagram-editor",
data: base_data,
links: base_links
});
});
Related sample: Diagram Editor: Webix View Initialization
Or as an instance of Jet App class and render it in the document body (or in any other HTML container):
webix.ready(function() {
webix.CustomScroll.init();
const app = new diagram.App({
data: base_data,
links: base_links
});
app.render(document.body);
});
Related sample: Diagram Editor: JetApp Initialization
Below you can find a set of properties specific for the Editor:
Editor basic configuration
webix.ui({
view:"diagram-editor",
data: base_data,
links: base_links,
zoom: 2,
gridStep: 15,
});
Related sample: Diagram Editor: Setting Zoom and Grid Step
To populate the editor with the predefined data use the dedicated data and links properties. The rules and formats are the same as for the Diagram Library.
webix.ui({
view: "diagram-editor",
data: [/* blocks */],
links: [/* links */],
shapes: [/* shapes */]
});
You can check the possible fields for each object in the blocks, links, and shapes data sets.
Reactive properties store global state of the app and let developers track their changes. Diagram Editor has several reactive properties:
You can get the current state of the widget with the help of the getState() method:
webix.ui({
view: "diagram-editor",
id: "editor",
data: base_data,
links: base_links,
gridStep: 20,
zoom: 5,
});
const state = $$("editor").getState();
/*
{
gridStep: 20,
zoom: 20,
selected: {
id: 100
}
}
*/
If a selected element is a link, the selected object has the link field:
{
selected: {
id: 25,
link: true
}
}
You can listen to the changes of the reactive properties and provide custom handlers for them via the $observe method of the state:
webix.ui({
view:"diagram-editor",
on: {
onInit: function() {
const state = this.getState();
// creates message with the selected element
state.$observe("zoom", zoom => webix.message("Current zoom is: " + zoom));
},
}
});
Related sample: Diagram Editor: Listening to State Changes
Diagram and Diagram editor can be connected to each other by a set of API methods to retrieve and pass the required data.
To get the full Diagram data, call its serialize() method with the all parameter. To pass these data to the Editor, use its setValues() method passing the serialized data as a parameter.
const full_data = $$("diagram").serialize(true);
$$("editor").setValues(full_data);
The serialize() method with the passed all parameter returns the full data set including the following entities:
// full_data
{
data: [
{ id: "start", type: "circle", value: "start", x: 0, y: 80 },
// other blocks
],
links: [
{ source: "start", target: "search", id: 132 },
// other links
],
shapes: [
{
backgroundColor: "#65C0B7", fontColor: "#fff",
group: "block", id: "circle",
lineColor: "#65C0B7", name: "Circle",
svg: "svg_code"
},
// other shapes
],
item: {
height: 50, width: 100
},
linkItem: {
arrowSize: 6, arrow: false,
mode: "edges", backgroundColor: "magenta"
},
}
To access the editor data, call the getValues() method on the editor instance. To load these values back to Diagram, use its parse() method:
const diagram = $$("diagram");
// clear old data
diagram.clearAll();
diagram.getLinks().clearAll();
//get and parse new data
const data = $$("editor").getValues();
diagram.parse(data);
If autoplacement was enabled for Diagram, make sure to switch it off to apply real block coordinates provided by the editor:
diagram.config.autoplace = false;
Related sample: Diagram Editor: Live Editing
Back to top