Skip to main content
Version: 4.2

GraphLayerCollection

This is a collection of dia.GraphLayer instances which implements instantiation of dia.GraphLayer objects from JSON using layerNamespace option. It inherits from mvc.Collection. This collection is created by dia.Graph and can be accessed using layerCollection property.

const collection = graph.layerCollection;

constructor

constructor(
models?: Array<dia.Graph.LayerInit>,
options?: {
layerNamespace?: Record<string, typeof dia.GraphLayer>,
cellNamespace?: any,
graph?: dia.Graph,
}
);

As a descendant of mvc.Collection, the dia.GraphLayerCollection constructor accepts two arguments: models and options.

  • The models argument is an array that can contain any model instances or JSONs you want to have in the collection.

  • The options argument is an object that contains options you want to set on the collection:

cellNamespace

cellNamespace?: any;

A dictionary of dia.Cell classes available for creating model instances from JSON. This namespace will be passed to each layer in the collection. Look at cellNamespace option in dia.Graph for more details.

layerNamespace

layerNamespace?: Record<string, typeof dia.GraphLayer>;

A dictionary of dia.GraphLayer classes available for creating model instances from JSON. This namespace will be merged with the default namespace which will be used if no namespace is provided:

Default namespace:

{
'GraphLayer': dia.GraphLayer,
}

Methods

addCellToLayer()

graphLayerCollection.addCellToLayer(cell: dia.Cell, layerId: dia.GraphLayer.ID, opt?: dia.ObjectHash): void;

Add a cell to the specified layer.

getCell()

graphLayerCollection.getCell(cellRef: dia.Graph.CellRef): dia.Cell | undefined;

Find and return a cell by its id from all layers.

getCells()

graphLayerCollection.getCells(): dia.Cell[];

Return all cells in all layers in the correct order.

insert()

graphLayerCollection.insert(layer: dia.Graph.LayerInit, beforeLayerId: dia.GraphLayer.ID | null, opt?: dia.ObjectHash): void;

Insert a layer before another layer, or at the end if beforeId is null.

moveCellBetweenLayers()

graphLayerCollection.moveCellBetweenLayers(cell: dia.Cell, targetLayerId: dia.GraphLayer.ID, opt?: dia.ObjectHash): void;

Move a cell from its current layer to a target layer.

removeCell()

graphLayerCollection.removeCell(cell: dia.Cell, opt?: dia.ObjectHash): void;

Remove a cell from its current layer.

Properties

cellNamespace

graphLayerCollection.cellNamespace: any;

A dictionary of dia.Cell classes available for creating model instances from JSON.

graph

graphLayerCollection.graph: dia.Graph;

A reference to the dia.Graph instance this collection belongs to.

layerNamespace

graphLayerCollection.layerNamespace: any;

A dictionary of dia.GraphLayer classes available for creating model instances from JSON.