JavaScript/jQuery Diagram - Diagram Tools
The Diagram UI component allows you to customize its UI tools with the following properties.

jQuery
index.js
- $(function() {
- var diagram = $("#diagram").dxDiagram({
- contextMenu: {
- enabled: true,
- commands: ["bringToFront","sendToBack", "lock", "unlock"]
- },
- contextToolbox: {
- enabled: true,
- category: "flowchart",
- shapeIconsPerRow: 5,
- width: 200
- },
- propertiesPanel: {
- visibility: 'visible',
- tabs: [{
- groups: [ { title: "Page Properties", commands: ["pageSize", "pageOrientation", "pageColor"] } ]
- }]
- },
- historyToolbar: {
- visible: false
- },
- viewToolbar: {
- visible: true,
- commands: ["zoomLevel", "fullScreen", "units",
- {name: "sayHello", text: "Say Hello", icon: "blockquote"},
- {name: "export", icon: "export", items: ["exportSvg","exportPng","exportJpg"]}]
- },
- mainToolbar: {
- visible: true,
- commands: [
- { name: "undo" },
- { name: "redo" },
- { name: "separator" },
- { name: "fontName" },
- { name: "fontSize" },
- { name: "separator" },
- { name: "bold" },
- { name: "italic" },
- { name: "underline" },
- { name: "separator" },
- { name: "fontColor" },
- { name: "lineColor" },
- { name: "fillColor" },
- { name: "separator" },
- { name: "clear", icon: "clearsquare", text: "Clear Diagram" }
- ]
- },
- toolbox: {
- visibility: 'visible',
- groups: [
- "general", { category: "flowchart", title: "Flowchart", expanded: true }
- ],
- showSearch: false,
- shapeIconsPerRow: 4,
- width: 220
- },
- onCustomCommand: function(e) {
- if(e.name === "clear") {
- var result = DevExpress.ui.dialog.confirm(
- "Are you sure you want to clear the diagram? This action cannot be undone.", "Warning");
- result.done(
- function(dialogResult) {
- if(dialogResult) {
- e.component.import("");
- }
- }
- );}
- else if (e.name == "sayHello")
- alert("Hello!")
- }
- }).dxDiagram("instance");
- ...
ASP.NET Core Controls
Diagram.cshtml
- @(Html.DevExtreme().Diagram()
- .ID("diagram")
- .ContextMenu(cm => cm
- .Enabled(true)
- .Commands(new[] {
- DiagramCommand.BringToFront,
- DiagramCommand.SendToBack,
- DiagramCommand.Lock,
- DiagramCommand.Unlock
- })
- )
- .ContextToolbox(ct => ct
- .Enabled(true)
- .Category(DiagramShapeCategory.Flowchart)
- .ShapeIconsPerRow(5)
- .Width(200)
- )
- .PropertiesPanel(pp => pp
- .Visibility(DiagramPanelVisibility.Visible)
- .Tabs(t => {
- t.Add()
- .Groups(g => {
- g.Add()
- .Title("Page Properties")
- .Commands(new[] { DiagramCommand.PageSize, DiagramCommand.PageOrientation,
- DiagramCommand.PageColor });
- });
- })
- )
- .HistoryToolbar(tb => tb
- .Visible(false)
- )
- .ViewToolbar(tb => tb
- .Visible(true)
- .Commands(cmds => {
- cmds.Add().Name(DiagramCommand.ZoomLevel);
- cmds.Add().Name(DiagramCommand.FullScreen);
- cmds.Add().Name(DiagramCommand.Units);
- cmds.Add().Name("sayHello").Text("Say Hello").Icon("blockquote");
- cmds.Add().Name("export").Icon("export").Items(items => {
- items.Add().Name(DiagramCommand.ExportSvg);
- items.Add().Name(DiagramCommand.ExportPng);
- items.Add().Name(DiagramCommand.ExportJpg);
- });
- })
- )
- .MainToolbar(tb => tb
- .Visible(true)
- .Commands(cmds => {
- cmds.Add().Name(DiagramCommand.Undo);
- cmds.Add().Name(DiagramCommand.Redo);
- cmds.Add().Name(DiagramCommand.Separator);
- cmds.Add().Name(DiagramCommand.FontName);
- cmds.Add().Name(DiagramCommand.FontSize);
- cmds.Add().Name(DiagramCommand.Separator);
- cmds.Add().Name(DiagramCommand.Bold);
- cmds.Add().Name(DiagramCommand.Italic);
- cmds.Add().Name(DiagramCommand.Underline);
- cmds.Add().Name(DiagramCommand.Separator);
- cmds.Add().Name(DiagramCommand.FontColor);
- cmds.Add().Name(DiagramCommand.LineColor);
- cmds.Add().Name(DiagramCommand.FillColor);
- cmds.Add().Name(DiagramCommand.Separator);
- cmds.Add().Name("clear").Text("Clear Diagram").Icon("clearsquare");
- })
- )
- .Toolbox(tb => tb
- .Visibility(DiagramPanelVisibility.Visible)
- .Groups(g => {
- g.Add().Category(DiagramShapeCategory.General).Title("General");
- g.Add().Category(DiagramShapeCategory.Flowchart).Title("Flowchart").Expanded(true);
- })
- .ShowSearch(false)
- .ShapeIconsPerRow(4)
- .Width(220)
- )
- .OnCustomCommand(@<text>
- function(e) {
- if(e.name === "clear") {
- var result = DevExpress.ui.dialog.confirm("Are you sure you want to clear the diagram?
- This action cannot be undone.", "Warning");
- result.done(
- function(dialogResult) {
- if(dialogResult) {
- e.component.import("");
- }
- }
- );
- }
- else if (e.name == "sayHello")
- alert("Hello!")
- }
- </text>)
- )
ASP.NET MVC Controls
Diagram.cshtml
- @(Html.DevExtreme().Diagram()
- .ID("diagram")
- .ContextMenu(cm => cm
- .Enabled(true)
- .Commands(new[] {
- DiagramCommand.BringToFront,
- DiagramCommand.SendToBack,
- DiagramCommand.Lock,
- DiagramCommand.Unlock
- })
- )
- .ContextToolbox(ct => ct
- .Enabled(true)
- .Category(DiagramShapeCategory.Flowchart)
- .ShapeIconsPerRow(5)
- .Width(200)
- )
- .PropertiesPanel(pp => pp
- .Visibility(DiagramPanelVisibility.Visible)
- .Tabs(t => {
- t.Add()
- .Groups(g => {
- g.Add()
- .Title("Page Properties")
- .Commands(new[] { DiagramCommand.PageSize, DiagramCommand.PageOrientation,
- DiagramCommand.PageColor });
- });
- })
- )
- .HistoryToolbar(tb => tb
- .Visible(false)
- )
- .ViewToolbar(tb => tb
- .Visible(true)
- .Commands(cmds => {
- cmds.Add().Name(DiagramCommand.ZoomLevel);
- cmds.Add().Name(DiagramCommand.FullScreen);
- cmds.Add().Name(DiagramCommand.Units);
- cmds.Add().Name("sayHello").Text("Say Hello").Icon("blockquote");
- cmds.Add().Name("export").Icon("export").Items(items => {
- items.Add().Name(DiagramCommand.ExportSvg);
- items.Add().Name(DiagramCommand.ExportPng);
- items.Add().Name(DiagramCommand.ExportJpg);
- });
- })
- )
- .MainToolbar(tb => tb
- .Visible(true)
- .Commands(cmds => {
- cmds.Add().Name(DiagramCommand.Undo);
- cmds.Add().Name(DiagramCommand.Redo);
- cmds.Add().Name(DiagramCommand.Separator);
- cmds.Add().Name(DiagramCommand.FontName);
- cmds.Add().Name(DiagramCommand.FontSize);
- cmds.Add().Name(DiagramCommand.Separator);
- cmds.Add().Name(DiagramCommand.Bold);
- cmds.Add().Name(DiagramCommand.Italic);
- cmds.Add().Name(DiagramCommand.Underline);
- cmds.Add().Name(DiagramCommand.Separator);
- cmds.Add().Name(DiagramCommand.FontColor);
- cmds.Add().Name(DiagramCommand.LineColor);
- cmds.Add().Name(DiagramCommand.FillColor);
- cmds.Add().Name(DiagramCommand.Separator);
- cmds.Add().Name("clear").Text("Clear Diagram").Icon("clearsquare");
- })
- )
- .Toolbox(tb => tb
- .Visibility(DiagramPanelVisibility.Visible)
- .Groups(g => {
- g.Add().Category(DiagramShapeCategory.General).Title("General");
- g.Add().Category(DiagramShapeCategory.Flowchart).Title("Flowchart").Expanded(true);
- })
- .ShowSearch(false)
- .ShapeIconsPerRow(4)
- .Width(220)
- )
- .OnCustomCommand(@<text>
- function(e) {
- if(e.name === "clear") {
- var result = DevExpress.ui.dialog.confirm("Are you sure you want to clear the diagram?
- This action cannot be undone.", "Warning");
- result.done(
- function(dialogResult) {
- if(dialogResult) {
- e.component.import("");
- }
- }
- );
- }
- else if (e.name == "sayHello")
- alert("Hello!")
- }
- </text>)
- )
Feedback
Was this page helpful?
How can we improve this page?
Select one or more answers
Additional comments/thoughts:
If you have any questions, submit a ticket to our Support Center.