GridLayout
GridLayout
is an object which contains several functions.
Functionsβ
layout()β
Rearrange graph or shapes into a layout, specified by layout options. The function returns special grid metrics object.
GridLayout.layout(graphOrCells: dia.Graph | Array<dia.Cell>, opt?: Options): GridMetrics;
Typesβ
GridMetricsβ
Grid metrics returned by the layout()
function.
type GridMetrics = {
rowHeights: number[];
columnWidths: number[];
gridX: number[];
gridY: number[];
bbox: g.Rect;
};
Properties description:
bbox
- a tight bounding box around the elementsgridX
- an array of x-coordinates of vertical separators between columns.gridY
- an array of y-coordinates of horizontal separators between rows.rowHeights
- an array of row heightscolumnWidths
- an array of column widths
Optionsβ
Type of options parameter of the layout()
function.
interface Options {
resizeToFit?: boolean;
marginX?: number;
marginY?: number;
columns?: number;
columnWidth?: 'compact' | 'auto' | number | string;
rowHeight?: 'compact' | 'auto' | number | string;
verticalAlign?: 'top' | 'middle' | 'bottom';
horizontalAlign?: 'left' | 'middle' | 'right';
columnGap?: number;
rowGap?: number;
deep?: boolean;
parentRelative?: boolean;
setAttributes?: (element: dia.Element, attributes: dia.Element, opt: Options) => void;
}
Properties description:
Name | Description |
---|---|
columns | Number of columns. It defaults to 1 . |
columnWidth |
'auto' . |
rowHeight |
'auto' . |
verticalAlign |
'middle' . |
horizontalAlign |
'middle' . |
columnGap | The horizontal gap between columns. It defaults to 0 . |
rowGap | The vertical gap between rows. It defaults to 0 . |
resizeToFit | Resizes the elements to fit a grid cell, preserving the aspect ratio. It defaults to false . |
marginX | Sets the origin (x coordinate) of the most top-left element. It defaults to 0 . |
marginY | Sets the origin (y coordinate) of the most top-left element. It defaults to 0 . |
deep | Uses deep positioning for elements when set to true . i.e. moves not only the elements but also their descendants. It defaults to false . |
parentRelative | Position the elements relatively to their parents. It defaults to false |
setAttributes() | A callback function to customize how the positions (and sizes when resizeToFit enabled) are set to the elements. |