Demonstrates how to create an organization chart diagram (org chart) of a business company using the following NOV Diagram features:

| Language: C# |
using Nevron.Nov;
using Nevron.Nov.DataStructures;
using Nevron.Nov.Diagram;
using Nevron.Nov.Diagram.Layout;
using Nevron.Nov.Diagram.Shapes;
using Nevron.Nov.Diagram.Shapes.Business.OrgChart;
using Nevron.Nov.Diagram.Themes;
using Nevron.Nov.Dom;
using Nevron.Nov.Graphics;
using Nevron.Nov.Layout;
using Nevron.Nov.UI;
using Nevron.Nov.Windows.Forms;
using System.Windows.Forms;
namespace NovWinFormsProject
{
public partial class Form1 : Form
{
#region Constructors
public Form1()
{
InitializeComponent();
// Set form title
Text = "NOV WinForms - NOrgChartBusinessCompanyExample";
// Create the NOV example and its controls
NWidget exampleContent = CreateExampleContent();
NWidget exampleControls = CreateExampleControls();
if (exampleControls != null)
{
exampleControls.PreferredWidth = 300;
}
// Place the example and its controls in a pair box
NPairBox pairBox = new NPairBox(exampleContent, exampleControls);
pairBox.FillMode = ENStackFillMode.First;
pairBox.FitMode = ENStackFitMode.First;
pairBox.Margins = new NMargins(NDesign.HorizontalSpacing, NDesign.VerticalSpacing);
// Host the example in the form
NNovWidgetHost host = new NNovWidgetHost(pairBox);
host.Dock = DockStyle.Fill;
Controls.Add(host);
}
#endregion
#region Example
public NWidget CreateExampleContent()
{
// Create a simple drawing
NDrawingViewWithRibbon drawingViewWithRibbon = new NDrawingViewWithRibbon();
m_DrawingView = drawingViewWithRibbon.View;
// hide grid and ports
m_DrawingView.Content.ScreenVisibility.ShowGrid = false;
m_DrawingView.Content.ScreenVisibility.ShowPorts = false;
m_DrawingView.Document.HistoryService.Pause();
try
{
InitDiagram(m_DrawingView.Document);
}
finally
{
m_DrawingView.Document.HistoryService.Resume();
}
return drawingViewWithRibbon;
}
public NWidget CreateExampleControls()
{
return null;
}
public string GetExampleDescription()
{
return @"Demonstrates how to create an organization chart diagram (org chart) of a business company using the following NOV Diagram features:
- Theme-based colors for the title - change the page theme from the ""Design"" tab to see how the style of the title will change, too.
- Organization chart shapes - used to represent the employees of the business company.
- Tip Over Tree Layout - used to arrange the org chart shapes in a compact way, placing leaf shapes in a column instead of in a row.
";
}
///
/// Gets the relevant documentation links for the example
///
///
public (string Name, string Url)[] GetDocumentationUrls()
{
return new[]
{
("Layered Tree Layout", "https://www.nevron.com/docs/openvision/diagram-layered-tree-layout.html"),
("Shapes", "https://www.nevron.com/docs/openvision/diagram-shapes.html"),
("Routable Connectors", "https://www.nevron.com/docs/openvision/diagram-routable-connectors.html"),
("Text Block", "https://www.nevron.com/docs/openvision/diagram-text-block.html"),
};
}
private void InitDiagram(NDrawingDocument drawingDocument)
{
NPage page = drawingDocument.Content.ActivePage;
// Create a title shape
NShape titleShape = CreateTitleShape("Business Company");
page.Items.Add(titleShape);
// Recursively create the org chart shapes
CreateOrgShape(page, ExecutiveEmployee);
// Arrange the shapes using a Layered Graph Layout
NTipOverTreeLayout layout = new NTipOverTreeLayout();
layout.LeafsPlacement = ENTipOverChildrenPlacement.ColRight;
layout.RegionLayout.VerticalSpacing = 25; // Controls the spacing between the title and the diagram
NList shapes = page.GetShapes(false, NDiagramFilters.ShapeType2D);
layout.Arrange(shapes.CastAll | Language: VB.NET |
Imports Nevron.Nov
Imports Nevron.Nov.Diagram
Imports Nevron.Nov.Diagram.Layout
Imports Nevron.Nov.Diagram.Shapes.Business.OrgChart
Imports Nevron.Nov.Diagram.Themes
Imports Nevron.Nov.Dom
Imports Nevron.Nov.Graphics
Imports Nevron.Nov.Layout
Imports Nevron.Nov.UI
Imports Nevron.Nov.Windows.Wpf
Class MainWindow
#Region "Constructors"
Public Sub New()
' This call is required by the designer.
InitializeComponent()
' Add any initialization after the InitializeComponent() call.
' Set form title
Title = "NOV WPF - NOrgChartBusinessCompanyExample"
' Create the NOV example and its controls
Dim exampleContent As NWidget = CreateExampleContent()
Dim exampleControls As NWidget = CreateExampleControls()
If Not exampleControls Is Nothing Then
exampleControls.PreferredWidth = 300
End If
' Place the example and its controls in a pair box
Dim pairBox As NPairBox = New NPairBox(exampleContent, exampleControls)
pairBox.FillMode = ENStackFillMode.First
pairBox.FitMode = ENStackFitMode.First
pairBox.Margins = New NMargins(NDesign.HorizontalSpacing, NDesign.VerticalSpacing)
' Host the example in the form
Dim host As NNovWidgetHost(Of NWidget) = New NNovWidgetHost(Of NWidget)(pairBox)
Content = host
End Sub
#End Region
#Region "Example"
Public Function CreateExampleContent() As NWidget
' Create a simple drawing
Dim drawingViewWithRibbon As NDrawingViewWithRibbon = New NDrawingViewWithRibbon()
m_DrawingView = drawingViewWithRibbon.View
' hide grid and ports
m_DrawingView.Content.ScreenVisibility.ShowGrid = False
m_DrawingView.Content.ScreenVisibility.ShowPorts = False
m_DrawingView.Document.HistoryService.Pause()
Try
InitDiagram(m_DrawingView.Document)
Finally
m_DrawingView.Document.HistoryService.Resume()
End Try
Return drawingViewWithRibbon
End Function
Public Function CreateExampleControls() As NWidget
Return Nothing
End Function
Public Function GetExampleDescription() As String
Return "Demonstrates how to create an organization chart diagram (org chart) of a business company using the following NOV Diagram features:
- Theme-based colors for the title - change the page theme from the ""Design"" tab to see how the style of the title will change, too.
- Organization chart shapes - used to represent the employees of the business company.
- Tip Over Tree Layout - used to arrange the org chart shapes in a compact way, placing leaf shapes in a column instead of in a row.
"
End Function
'''
''' Gets the relevant documentation links for the example
'''
'''
Public Function GetDocumentationUrls() As (String, String)()
Return {("Layered Tree Layout", "https://www.nevron.com/docs/openvision/diagram-layered-tree-layout.html"), ("Shapes", "https://www.nevron.com/docs/openvision/diagram-shapes.html"), ("Routable Connectors", "https://www.nevron.com/docs/openvision/diagram-routable-connectors.html"), ("Text Block", "https://www.nevron.com/docs/openvision/diagram-text-block.html")}
End Function
Private Sub InitDiagram(drawingDocument As NDrawingDocument)
Dim page = drawingDocument.Content.ActivePage
' Create a title shape
Dim titleShape = CreateTitleShape("Business Company")
page.Items.Add(titleShape)
' Recursively create the org chart shapes
CreateOrgShape(page, ExecutiveEmployee)
' Arrange the shapes using a Layered Graph Layout
Dim layout As NTipOverTreeLayout = New NTipOverTreeLayout()
layout.LeafsPlacement = ENTipOverChildrenPlacement.ColRight
layout.RegionLayout.VerticalSpacing = 25 ' Controls the spacing between the title and the diagram
Dim shapes = page.GetShapes(False, NDiagramFilters.ShapeType2D)
layout.Arrange(shapes.CastAll(Of Object)(), New NDrawingLayoutContext(page))
page.SizeToContent()
End Sub
#End Region
#Region "Implementation"
Private Function CreateTitleShape(title As String) As NShape
Dim theme = NDrawingTheme.MyDrawNature
Dim titleShape As NShape = New NShape()
titleShape.SetBounds(0, 0, 500, 50)
titleShape.Text = title
Dim titleTextBlock = CType(titleShape.TextBlock, NTextBlock)
titleTextBlock.ResizeMode = ENTextBlockResizeMode.ShapeSize
titleTextBlock.FontSize = 28
titleTextBlock.FontStyleBold = True
' Set theme-based colors to the title text, so that it changes when the user changes the theme
Dim strokeColor = theme.ColorPalette.Variants(0)(0)
strokeColor.Tag = New NThemeVariantColorInfo(0)
titleTextBlock.Stroke = New NStroke(strokeColor)
Dim fillColor = theme.ColorPalette.Variants(0)(4)
fillColor.Tag = New NThemeVariantColorInfo(4)
titleTextBlock.Fill = New NColorFill(fillColor)
' Alternatively, you can also use fixed colors (uncomment the 2 lines below)
'titleTextBlock.Stroke = new NStroke(NColor.DarkBlue);
'titleTextBlock.Fill = new NColorFill(NColor.LightBlue);
' Set an expression to center the title horizontally in the page
titleShape.SetFx(NShape.PinXProperty, New NFormulaFx("$ParentSheet.X + $ParentSheet.Width / 2", True))
Return titleShape
End Function
Private Function CreateOrgShape(page As NPage, employee As Employee) As NShape
Dim shape As NShape = m_OrgChartShapeFactory.CreateShape(employee.Position)
shape.Text = employee.Name
shape.ImageBlock.Image = If(employee.Gender Is ENGender.Male, Nevron.Nov.Graphics.NImage.FromBytes(Nevron.Nov.NConvert.FromBase64String("PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSI0My42IiBoZWlnaHQ9IjYzLjQiIGZpbGw9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00LTktMy0xLTQtOS0xLTciIGZpbGw9InVybCgjRSkiLz48L2c+PGcgY2xpcC1wYXRoPSJ1cmwoI0cpIj48cGF0aCBkPSJNMTQuNDY3IDMwLjZoM2M0IDIgNiAxIDcgMHYxYzAgMSAwIDYgMSA4LTIgMi02IDEtNyAxLTEtMS00LTYtNC0xMCIgZmlsbD0iI2RlYjg4NyIvPjwvZz48ZyBjbGlwLXBhdGg9InVybCgjSCkiPjxwYXRoIGQ9Ik0yMy40NjcgNTguNmMyLTQgMi0xNCAyLTE5LTEtMi0xLTctMS04IDEzIDMgMTYgMTIgMTUgMjEtMTMgMTEtNDAgNy0zOS0yLTEtOSAzLTE3IDE0LTIwIDAgNCAzIDkgNCAxMCAxIDMgNSAxMSA1IDE4IiBmaWxsPSIjNzg5Ii8+PC9nPjxnIGNsaXAtcGF0aD0idXJsKCNJKSI+PHBhdGggZD0iTTE4LjQ2NyA0MC42YzEgMCA1IDEgNy0xIDAgNSAwIDE1LTIgMTkgMC03LTQtMTUtNS0xOCIgZmlsbD0iI2ZmZiIvPjwvZz48L2c+PC9zdmc+")))
page.Items.Add(shape)
If employee.SubordinateEmployees IsNot Nothing Then
For i = 0 To employee.SubordinateEmployees.Length - 1
Dim childShape = CreateOrgShape(page, employee.SubordinateEmployees(i))
ConnectShapes(shape, childShape)
Next
End If
Return shape
End Function
Private Sub ConnectShapes(shape1 As NShape, shape2 As NShape)
Dim connector As NRoutableConnector = New NRoutableConnector()
shape1.OwnerPage.Items.Add(connector)
connector.GlueBeginToShape(shape1)
connector.GlueEndToShape(shape2)
End Sub
#End Region
#Region "Event Handlers"
#End Region
#Region "Fields"
Private m_DrawingView As NDrawingView
Private m_OrgChartShapeFactory As NOrganizationChartShapeFactory = New NOrganizationChartShapeFactory() With {
.DefaultSize = New NSize(120, 70)
}
#End Region
#Region "Static Methods"
#End Region
#Region "Constants"
#End Region
#Region "Nested Types"
Public Class Employee
Public Sub New(gender As ENGender, position As ENOrganizationShape, name As String, ParamArray subordinateEmployees As Employee())
Me.Gender = gender
Me.Position = position
Me.Name = name
Me.SubordinateEmployees = subordinateEmployees
End Sub
Public Gender As ENGender
Public Position As ENOrganizationShape
Public Name As String
Public SubordinateEmployees As Employee()
End Class
#End Region
End Class