Class Layer

Layers are how named collections of Parts are drawn in front or behind other collections of Parts in a Diagram.Layers can only contain Parts, such as Nodes and Links. They cannot hold GraphObjects directly.

You put a Part into a Layer by assigning Part.layerName with the name of the Layer.You can use data binding to initialize and remember a Part's layer's name.You can change a Part's layer by modifying its Part.layerName, which changes its Part.layer.

Each Diagram starts off with the following list of Layers:"Grid", "Background", "" (the default layer), "Foreground", "Adornment", "Tool".Parts are normally put in the default layer.The "Grid", "Adornment", and "Tool" layers are considered isTemporary.Changes to objects in temporary layers are not recorded by the UndoManager.Parts in temporary layers are not selected and are not considered to be part of the document.The "Grid" layer is the furthest back; it also contains "temporary" parts that cannot be selected.Furthermore the "Grid" layer has pickable set to false so that mouse or touch eventsand calls to the "find..." methods do not even consider any parts in that layer.

Layers have many properties that control what actions users are permitted to perform involving the parts in the layer.These properties are very much like the similarly named properties on Diagram.

Z-ordering

Layers are drawn and presented in order.You can add your own layers by calling Diagram.addLayerBefore or Diagram.addLayerAfterto insert a new layer at a particular place in the Z-order, or to re-order existing layers.Use Diagram.findLayer to get the Layer with a particular name.Parts can be individually z-ordered within a layer by setting Part.zOrder.

Constructor Summary Details

Name Description
Layer()

This constructs an empty Layer; you should set the name before adding the Layer to a Diagram.

Properties Summary Details

Name, Value Type Description
allowCopy
{boolean}

Gets or sets whether the user may copy objects in this layer.More... The initial value is true.

allowDelete
{boolean}

Gets or sets whether the user may delete objects in this layer.More... The initial value is true.

allowGroup
{boolean}

Gets or sets whether the user may group parts together in this layer.More... The initial value is true.

allowMove
{boolean}

Gets or sets whether the user may move objects in this layer.More... The initial value is true.

allowReshape
{boolean}

Gets or sets whether the user may reshape parts in this layer.More... The initial value is true.

allowResize
{boolean}

Gets or sets whether the user may resize parts in this layer.More... The initial value is true.

allowRotate
{boolean}

Gets or sets whether the user may rotate parts in this layer.More... The initial value is true.

allowSelect
{boolean}

Gets or sets whether the user may select objects in this layer.More... The initial value is true.

allowTextEdit
{boolean}

Gets or sets whether the user may do in-place text editing in this layer.More... The initial value is true.

allowUngroup
{boolean}

Gets or sets whether the user may ungroup existing groups in this layer.More... The initial value is true.

diagram

This read-only property returns the Diagram that is using this Layer.

isTemporary
{boolean}

Gets or sets whether the objects in this layer are considered temporary.More...

Parts in temporary layers are not selectable,and changes to Parts in temporary layers are not recorded in the undo manager.

Temporary layers are excluded from bounds calculations, with the exception of the "Tool" layer,so that temporary objects created while dragging are included in the bounds.

Default value is false.

name
{string}

Gets or sets the name for this layer.More... The initial value is an empty string, which is also the name of the default layer.The name should be unique among the diagram's Diagram.layers.

opacity
{number} 1.1

Gets or sets the opacity for all parts in this layer.More... The value must be between 0.0 (fully transparent) and 1.0 (no additional transparency).This value is multiplicative with any existing transparency,for instance from a Brush or image transparency.The default value is 1.

This property, unlike visible, does not change whether any objects are found by the "find..." methods.

parts
{Iterator.}

This read-only property returns an iterator for this Layer's Parts.More... The Parts can be Nodes, Links, Groups, Adornments, or simple Parts.

partsBackwards
{Iterator.}

This read-only property returns a backwards iterator for this Layer's Parts,for iterating over the parts in reverse order.More... The Parts can be Nodes, Links, Groups, Adornments, or simple Parts.

pickable
{boolean} 1.2

Gets or sets whether methods such as findObjectAt find any of the objects in this layer.More...

The default value is true.When this property is false, all of the "find..." methods will fail to find parts that are in this layer.

Note that setting pickable to false does not prevent users from selecting nodes.It does prevent them from selecting nodes by clicking on them,but does not prevent selection through other mechanisms such as the DragSelectingTool orCommandHandler.selectAll or calls to Diagram.select.

You can control whether individual GraphObjects are "hittable" by setting GraphObject.pickable.

visible
{boolean}

Gets or sets whether the user may view any of the objects in this layer.More...

The default value is true -- all visible Parts are drawn.When this property is false, all of the "find..." methods will fail to find parts that are in this layer.

Method Summary Details

Name, Return Type Description
findObjectAt(p, navig, pred)

Find the front-most GraphObject in this layerat the given point in document coordinates.More...

If visible is false, this method will not find any objects in this layer.However, opacity does not affect this method.

Parameters:
{Point} p
A Point in document coordinates.
{function(GraphObject):GraphObject | null=} navig
A function taking a GraphObject andreturning a GraphObject, defaulting to the identity.
{function(GraphObject):boolean | null=} pred
A function taking the GraphObjectreturned by navig and returning true if that object should be returned,defaulting to a predicate that always returns true.
Returns:
{GraphObject} The first GraphObject in the Z-order, or else null.
findObjectsAt(p, navig, pred, coll)
{Iterable.}

Return a collection of the GraphObjects of this layerat the given point in document coordinates.More...

If visible is false, this method will not find any objects in this layer.However, opacity does not affect this method.

Parameters:
{Point} p
A Point in document coordinates.
{function(GraphObject):GraphObject | null=} navig
A function taking a GraphObject andreturning a GraphObject, defaulting to the identity.If this function returns null, the given GraphObject will not be included in the results.
{function(GraphObject):boolean | null=} pred
A function taking the GraphObjectreturned by navig and returning true if that object should be returned,defaulting to a predicate that always returns true.
{List.|Set.=} coll
An optional collection (List or Set) to add the results to.
Returns:
{Iterable.} a collection of GraphObjects that will contain all GraphObjectslocated at Point p, or else an empty collection.If a List or Set was passed in, it is returned.
findObjectsIn(r, navig, pred, partialInclusion, coll)
{Iterable.}

Returns a collection of all GraphObjects that are inside or that intersecta given Rect in document coordinates.More...

If visible is false, this method will not find any objects in this layer.However, opacity does not affect this method.

Parameters:
{Rect} r
A Rect in document coordinates.
{function(GraphObject):GraphObject | null=} navig
A function taking a GraphObject andreturning a GraphObject, defaulting to the identity.If this function returns null, the given GraphObject will not be included in the results.
{function(GraphObject):boolean | null=} pred
A function taking the GraphObjectreturned by navig and returning true if that object should be returned,defaulting to a predicate that always returns true.
{boolean=} partialInclusion
Whether an object can match if it merely intersects the rectangular area (true) orif it must be entirely inside the rectangular area (false). The default value is false.
{List.|Set.=} coll
An optional collection (List or Set) to add the results to.
Returns:
{Iterable.} a collection of GraphObjects that will contain all GraphObjectslocated in or near Rect r, or else an empty collection.If a List or Set was passed in, it is returned.
findObjectsNear(p, dist, navig, pred, partialInclusion, coll)
{Iterable.}

Returns a collection of all GraphObjects that are within a certain distanceof a given point in document coordinates.More...

If visible is false, this method will not find any objects in this layer.However, opacity does not affect this method.

Parameters:
{Point} p
A Point in document coordinates.
{number} dist
The distance from the point.
{function(GraphObject):GraphObject | null=} navig
A function taking a GraphObject andreturning a GraphObject, defaulting to the identity.If this function returns null, the given GraphObject will not be included in the results.
{function(GraphObject):boolean | null=} pred
A function taking the GraphObjectreturned by navig and returning true if that object should be returned,defaulting to a predicate that always returns true.
{*=} partialInclusion
Whether an object can match if it merely intersects the circular area (true) orif it must be entirely inside the circular area (false). The default value is true.
{List.|Set.=} coll
An optional collection (List or Set) to add the results to.
Returns:
{Iterable.} a collection of GraphObjects that will contain all GraphObjectslocated at Point p, or else an empty collection.If a List or Set was passed in, it is returned.