After measuring, a Panel must arrange each element, giving the elements a position and size in the Panel's coordinate system. This must call arrangeElement with each Panel element, which will set that element's GraphObject.actualBounds.
For arranging some elements, it is useful to know the total unioned area of every element, which is given as the union
argument.
This Rect can be used to right-align or center-align, etc, elements within an area.
For example, PanelLayoutHorizontal arranges each element sequentially, starting with an x
value of 0
,
and increasing it by each previous element's GraphObject.measuredBounds width
.
The horizontal Panel arranges each element with a y
value determined by the union
argument's height
considering the GraphObject.alignment of the element, and the GraphObject's own measuredBounds.height
.
Panel which called this layout
Array of Panel elements
rectangle, if properly constructed in measure, that contains the expected union bounds of every element in the Panel.
Arranges the GraphObject onto its parent Panel.
The passed-in numbers typically account for GraphObject.margin and other offsets.
The x
and y
coordinates are where GraphObjects will be placed within the Panel's own coordinates
(from the Panel's top-left corner). The width
and height
are the size it will take up within the Panel's coordinates.
This sets the GraphObject.actualBounds of the obj
.
GraphObject to be arranged.
The final x value of actualBounds that the Panel computes for the GraphObject.
The final y value of actualBounds that the Panel computes for the GraphObject.
The final width value of actualBounds that the Panel computes for the GraphObject.
The final height value of actualBounds that the Panel computes for the GraphObject.
an optional area to constrain this actualBounds to when picking and drawing. By default, this is only used with Table Panel elements, which are clipped to their cell sizes.
Given the available size, measure the Panel and determine its expected drawing size.
This must call measureElement with each Panel element, which will set the
GraphObject.measuredBounds of those elements. Depending on how the Panel intends to lay out its elements,
the programmer must construction the union
by setting union.width
and union.height
of the supplied argument.
For example PanelLayoutHorizontal measures its elements and sums their widths to set its union.width
,
and takes the maximum of their heights to set its union.height
.
This union must reflect the measured size of the Panel. After measure is called, the Panel class will modify this union Rect, constraining its size by the Panel's GraphObject.desiredSize, GraphObject.minSize, and GraphObject.maxSize, before passing it to arrange.
Panel which called this layout
expected width of the Panel, informed by any containing Panel and by the Panel's own GraphObject.desiredSize, GraphObject.minSize, and GraphObject.maxSize. Often Infinity.
expected height of the Panel.
Array of Panel elements
rectangle to be modified to contain the expected union bounds of every element in the Panel, to be potentially used in arrange.
expected minimum width of the Panel, informed by any containing Panel. Often zero.
expected minimum height of the Panel.
Given the available size, measure one element of the Panel and determine its expected drawing size. This sets the GraphObject.measuredBounds of the object, which can then be used to determine the arrangement of objects in the PanelLayout.
Panel which called this layout
expected width of the GraphObject
expected height of the GraphObject
minimum width of the GraphObject
minimum height of the GraphObject
This is the abstract base class for all Panel Layouts, which inform the possible Panel types. It is possible to create your own Panel type by creating a subclass of PanelLayout, though this is not common and not recommended for beginners.
By default, GoJS has 12 Panel types, each corresponding to a PanelLayout subclass:
'Position', PanelLayoutPosition
'Horizontal', PanelLayoutHorizontal
'Vertical', PanelLayoutVertical
'Spot', PanelLayoutSpot
'Auto', PanelLayoutAuto
'Table', PanelLayoutTable
'Viewbox', PanelLayoutViewbox
'TableRow', PanelLayoutTableRow
'TableColumn', PanelLayoutTableColumn
'Link', PanelLayoutLink
'Grid', PanelLayoutGrid
'Graduated', PanelLayoutGraduated
These are included by default in builds of
go.js
andgo-debug.js
. When building from source, you can optionally exclude all of them exceptPosition
,Vertical
,Auto
,Link
, andGrid
. This is demonstrated inminimalSource
andmaximalSource
, in the/projects
folder.Adding a new Layout is done by calling the static function, Panel.definePanelLayout:
Each PanelLayout must define a measure and arrange routine. The measure routine must call measureElement with each element of the Panel, which sets each element's GraphObject.measuredBounds. These bounds can be used to determine object layout. The arrange routine must call arrangeElement with each element of the Panel to position the objects relative to the Panel.
There is an example PanelLayout in the PanelLayout sample.
2.0