Table Flow Layout Example for Blazor

Nevron NOV Diagram for Blazor ships with hundreds of examples with full source code, as part of the Nevron Open Vision Suite. All Blazor Diagram examples are also available as a stand-alone Visual Studio solution in C#, which you can download from the links below.

Table Flow Layout Example for Blazor Description

The table flow layout arranges cells sequentially in a virtual table. Each lane contains a configurable maximum number of cells, with cells aligned across rows and columns.

The most important properties of this layout are:

  • Direction - determines the flow within each lane: LeftToRight, RightToLeft, TopToBottom, or BottomToTop.
  • Inverted - reverses the order in which lanes are arranged. The default value is false.
  • MaxOrdinal - specifies the maximum number of cells per lane. For horizontal flow, it determines the maximum number of columns. For vertical flow, it determines the maximum number of rows. Additional lanes are created as needed.
  • HorizontalSpacing and VerticalSpacing - specify the minimum horizontal and vertical gaps between table cells.
  • RowFillMode and ColFillMode - control how rows and columns fill the available height and width, respectively. Supported modes are None, Equal, Proportional, First, Last, and Justify. Justify distributes unused space by increasing the gaps between rows or columns.
  • RowFitMode and ColFitMode - control how rows and columns shrink when their combined size exceeds the available height or width, respectively. Supported modes are None, Equal, Proportional, First, and Last.

To experiment with the layout, change its properties in the property grid and click the Layout button.

Change MaxOrdinal to adjust the table structure, or change the drawing width and height to explore the filling and fitting behavior.


Table Flow Layout Example

C# Table Flow Layout Example Code for Nevron Diagram for Blazor
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.Dom;
using Nevron.Nov.Editors;
using Nevron.Nov.Graphics;
using Nevron.Nov.Layout;
using Nevron.Nov.UI;
using Nevron.Nov.Windows.Forms;
using System;
using System.Windows.Forms;

namespace NovWinFormsProject
{
	public partial class Form1 : Form
	{
		#region Constructors

		public Form1()
		{
			InitializeComponent();

			// Set form title
			Text = "NOV WinForms - NTableFlowLayoutExample";

			// 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;

			m_DrawingView.Document.HistoryService.Pause();
			try
			{
				InitDiagram(m_DrawingView.Document);
			}
			finally
			{
				m_DrawingView.Document.HistoryService.Resume();
			}

			return drawingViewWithRibbon;
		}
		public NWidget CreateExampleControls()
		{
			m_Layout.Changed += OnLayoutChanged;

			NStackPanel stack = new NStackPanel();

            // property editor
            NEditor editor = NDesigner.GetDesigner(m_Layout).CreateStandaloneEditor(m_Layout);
			stack.Add(new NGroupBox("Properties", editor));

			NButton arrangeButton = new NButton("Arrange Diagram");
			arrangeButton.Click += OnArrangeButtonClick;
			stack.Add(arrangeButton);

			// items stack
			NStackPanel itemsStack = new NStackPanel();

			// NOTE: For Cells layout we provide the user with the ability to add shapes with different sizes so that he/she can test the layouts
			NButton addSmallItemButton = new NButton("Add Small Shape");
			addSmallItemButton.Click += OnAddSmallItemButtonClick;
			itemsStack.Add(addSmallItemButton);

			NButton addLargeItemButton = new NButton("Add Large Shape");
			addLargeItemButton.Click += OnAddLargeItemButtonClick;
			itemsStack.Add(addLargeItemButton);

			NButton addRandomItemButton = new NButton("Add Random Shape");
			addRandomItemButton.Click += OnAddRandomItemButtonClick;
			itemsStack.Add(addRandomItemButton);

			NButton removeAllItemsButton = new NButton("Remove All Shapes");
			removeAllItemsButton.Click += OnRemoveAllItemsButtonClick;
			itemsStack.Add(removeAllItemsButton);

			stack.Add(new NGroupBox("Items", itemsStack));

			return stack;
		}
		public string GetExampleDescription()
		{
			return @"

The table flow layout arranges cells sequentially in a virtual table. Each lane contains a configurable maximum number of cells, with cells aligned across rows and columns.

The most important properties of this layout are:

  • Direction - determines the flow within each lane: LeftToRight, RightToLeft, TopToBottom, or BottomToTop.
  • Inverted - reverses the order in which lanes are arranged. The default value is false.
  • MaxOrdinal - specifies the maximum number of cells per lane. For horizontal flow, it determines the maximum number of columns. For vertical flow, it determines the maximum number of rows. Additional lanes are created as needed.
  • HorizontalSpacing and VerticalSpacing - specify the minimum horizontal and vertical gaps between table cells.
  • RowFillMode and ColFillMode - control how rows and columns fill the available height and width, respectively. Supported modes are None, Equal, Proportional, First, Last, and Justify. Justify distributes unused space by increasing the gaps between rows or columns.
  • RowFitMode and ColFitMode - control how rows and columns shrink when their combined size exceeds the available height or width, respectively. Supported modes are None, Equal, Proportional, First, and Last.

To experiment with the layout, change its properties in the property grid and click the Layout button.

Change MaxOrdinal to adjust the table structure, or change the drawing width and height to explore the filling and fitting behavior.

"; } /// /// Gets the relevant documentation links for the example /// /// public (string Name, string Url)[] GetDocumentationUrls() { return new[] { ("Table Flow Layout", "https://www.nevron.com/docs/openvision/table-flow-layout.html"), ("Layouts Overview", "https://www.nevron.com/docs/openvision/diagram-drawing-layouts-overview.html"), ("Graph Regions and Regions Layouts", "https://www.nevron.com/docs/openvision/diagram-graph-regions-and-region-layouts.html"), ("Layouts Overview", "https://www.nevron.com/docs/openvision/layouts-overview.html"), }; } private void InitDiagram(NDrawingDocument drawingDocument) { m_Factory = new NBasicShapeFactory(); // Hide ports drawingDocument.Content.ScreenVisibility.ShowPorts = false; // Create some shapes NPage activePage = drawingDocument.Content.ActivePage; NBasicShapeFactory basicShapes = new NBasicShapeFactory(); const int range = 30; Random rnd = new Random(); for (int i = 0; i < 20; i++) { AddShape(rnd.Next(range) + range, rnd.Next(range) + range, false); } // Arrange diagram ArrangeDiagram(drawingDocument); // Fit page drawingDocument.Content.ActivePage.ZoomMode = ENZoomMode.Fit; } #endregion #region Implementation /// /// Arranges the shapes in the active page. /// /// private void ArrangeDiagram(NDrawingDocument drawingDocument) { // get all top-level shapes that reside in the active page NPage activePage = drawingDocument.Content.ActivePage; NList shapes = activePage.GetShapes(false); // create a layout context and use it to arrange the shapes using the current layout NDrawingLayoutContext layoutContext = new NDrawingLayoutContext(drawingDocument, activePage); m_Layout.Arrange(shapes.CastAll(), layoutContext); // size the page to the content size activePage.SizeToContent(); } private void OnAddSmallItemButtonClick(NEventArgs args) { AddShape(25, 25); } private void OnAddLargeItemButtonClick(NEventArgs args) { AddShape(60, 60); } private void OnAddRandomItemButtonClick(NEventArgs args) { int range = 30; Random rnd = new Random(); double width = rnd.Next(range) + range; double height = rnd.Next(range) + range; AddShape(width, height); } private void OnRemoveAllItemsButtonClick(NEventArgs args) { m_DrawingView.Document.StartHistoryTransaction("Remove All Items"); try { m_nCurShape = 1; m_DrawingView.Document.Content.ActivePage.Items.Clear(); } finally { m_DrawingView.Document.CommitHistoryTransaction(); } } private void AddShape(double width, double height, bool arrangeDiagram = true) { NShape shape = m_Factory.CreateShape(ENBasicShape.Rectangle); shape.Width = width; shape.Height = height; shape.HorizontalPlacement = ENHorizontalPlacement.Center; shape.VerticalPlacement = ENVerticalPlacement.Center; shape.Text = m_nCurShape.ToString(); m_nCurShape++; m_DrawingView.ActivePage.Items.Add(shape); if (arrangeDiagram) { ArrangeDiagram(m_DrawingView.Document); } } #endregion #region Event Handlers private void OnLayoutChanged(NEventArgs arg) { ArrangeDiagram(m_DrawingView.Document); } protected virtual void OnArrangeButtonClick(NEventArgs arg) { ArrangeDiagram(m_DrawingView.Document); } #endregion #region Fields private NDrawingView m_DrawingView; private NTableFlowLayout m_Layout = new NTableFlowLayout(ENHVDirection.LeftToRight); private NBasicShapeFactory m_Factory; private int m_nCurShape = 1; #endregion #region Static Methods #endregion #region Constants #endregion #region Nested Types #endregion } }

Download a fully functional C# (.cs) Table Flow Layout Example for Blazor Solution