NShape Reference
GridLayouter Class

<< Click to Display Table of Contents >>

Navigation:  Class Reference > Namespace Dataweb.NShape.Layouters >

NShape Reference
GridLayouter Class

Previous pageReturn to chapter overviewNext page

Arranges shapes on grid nodes.

Syntax

public class GridLayouter : LayouterBaseILayouter

Description

The grid layouter is used for fine-tuning a diagram, where the shapes are already approximately in place but must be lined up neatly.

Algorithm

The algorithm searches the largest horizontal and a vertical grid distances dh and dv, such that the sum of necessary displacements has a local minimum and all shapes can be placed on different grid nodes. It only operates on non-connectors.

1.Find the grid origin and the largest horizontal grid distance, where the sum of necessary displacements is a local minimum.
2.Find the grid origin and the largest vertical grid distance, where the sum of necessary displacements is a local minimum.
3.Repeat the following steps until there are no more unassigned shapes:
4.Place all shapes on the nearest grid nodes. If more than one shapes want to occupy the same grid node, choose the nearest shape and leave the other shapes unassigned.
5.Calculate the distance sum of the unassigned shapes for the nearest horizontal and vertical lines.
6.Halve the grid distance for which the distance sum is smaller.

The first and second step are identical but for the direction, therefore only the algorithm for the first step is described:

1.Start with the left side of the bounding rectangle of the shapes to layout for the grid origin
2.Start with the width of the diagram for the grid distance.
3.Start with minus one tenth of the grid distance for the distance delta.
4.Calculate the distance sum and the average displacement.
5.Choose 90% of the initial grid distance as the new grid distance and calculate the distance sum.
6.If the new sum is less than the previous one, choose 80% of the initial grid distance.
7.When the new sum is greater than the previous one, choose a tenth of the delta for the new delta and switch the sign (direction).
8.Continue until the delta is 1.

Public Properties

Name

Description

CoarsenessX

Coarseness of the layouting algorithm on X axis.

CoarsenessY

Coarseness of the layouting algorithm on Y axis.

Description

Description of the layouter.

InvariantName

The invariant name of the layouter.

Public Methods

Name

Description

Constructor

Constructs a new instance.

ExecuteStep

Executes one step of the layouting operation.

Prepare

Prepares for layouting.

Unprepare

Resets the layouter to the state before the preparation.

Protected Methods

Name

Description

ArrangeShapes

Add all seleced shapes into the grid.

CalcDistance

 

CalcDistanceSum

 

CalcEnergy

Calculates the optimization value for a given spacing.

FindNextLocalMinimum

 

FindSpacing1

 

FindSpacing2

Calculates the best spacing for the shapes

OptimizeOrigin

 

ReduceLocalMinimum

Searches a quotient, by which the spacing is divided to lead to a distance sum which is almost the distance sum of the current spacing divided by the quotient.

The spacing must be larger than the average shape size.

Requirements

Namespace: Dataweb.NShape.Layouters

Assembly: Dataweb.NShape