Class Layer

GoJS® Diagramming Components
version 3.0.12
by Northwoods Software®

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.

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.

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. A Part cannot be in more than one Layer at a time.

Each Diagram starts off with the following list of Layers:

  • "Grid"
  • "ViewportBackground"
  • "Background"
  • "" (the default layer)
  • "Foreground"
  • "ViewportForeground"
  • "Adornment"
  • "Tool"

Layers are drawn and presented in order. Parts are normally put in the default layer.

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 events and calls to the "find..." hit-testing methods do not even consider any parts in that layer.

The "Grid", "Adornment", "Tool", and both "Viewport..." layers are considered isTemporary. Changes to objects in temporary layers are not recorded by the UndoManager. Parts in temporary layers are not selected. Objects in temporary layers do not receive click events unless you set their GraphObject.isActionable to true.

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

Index

Constructors

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

    Parameters

    • Optional init: Partial<Layer>

      Optional properties to initialize.

    Returns Layer

Accessors

  • Gets or sets whether the user may draw new links in this layer. The initial value is true.

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

  • Gets or sets whether or not a layer is included in the Diagram.documentBounds computation.

    Default value is true. All of the predefined temporary Layers have this property false, except for the "Tool" Layer.

    since

    2.2

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

    Parts in temporary layers are not selectable, and changes to Parts in temporary layers are not recorded in the UndoManager. Objects in temporary layers do not receive click events unless you set their GraphObject.isActionable to true.

    Default value is false.

    As of v3.0, setting this property to true no longer sets isInDocumentBounds on this layer set to false. You may want to set this property to false on temporary Layers.

  • Gets or sets whether this layer enforces its Parts to remain in viewport coordinates. Diagrams have two default layers with this set to true: "ViewportBackground" and "ViewportForeground". These layers also have isInDocumentBounds set to false and isTemporary set to true. If you set this property on a layer, you may wish to set those properties also.

    Parts in viewport coordinate layers will get their positions and scales set automatically, to remain invariantly placed and sized in the viewport.

    Instead of position, Parts are placed by setting their GraphObject.alignment and GraphObject.alignmentFocus values in the same way they are used in a Spot Panel. However, the alignment spot, if it is Spot.Default as it is by default, will be treated as Spot.BottomRight rather than Spot.Center as a "Spot" Panel does. The alignmentFocus spot, if it is Spot.Default as it is by default, will be treated as the same Spot as the alignment without any offset. This is convenient for aligning Parts along the sides of the viewport. If you wish to arrange a Part to be near the side of the viewport at a certain distance, specify that in the alignment Spot. For example, the following code places the red circle near the bottom right corner, but inset by 10 units from both the right and the bottom sides.

    myDiagram.add(
    new go.Part({
    layerName: "ViewportBackground",
    alignment: new go.Spot(1, 1, -10, -10)
    }).add(
    new go.Shape("Circle", { fill: "red", width: 20, height: 20 })
    )
    );

    For example usage, see Legends and Titles.

    Parts in viewport coordinate layers may have unexpected interactions if they are connected to Parts in non-viewport coordinate layers. Setting this value to true automatically sets isInDocumentBounds to false.

    since

    3.0

    defaultValue

    false

  • Gets or sets the name for this layer. 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.

  • Gets or sets the opacity for all parts in this layer. 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.

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

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

    When this property is false, all of the "find..." methods will fail to find parts that are in this layer. The default value is true. All of the predefined Layers have this property true, except for the "Grid" 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 or CommandHandler.selectAll or calls to Diagram.select.

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

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

    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.

Methods

  • Find the front-most GraphObject in this layer at the given point in document coordinates.

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

    Type Parameters

    Parameters

    • p: Point

      A Point in document coordinates.

    • Optional navig: ((a: GraphObject) => T)

      A function taking a GraphObject and returning a GraphObject, defaulting to the identity.

    • Optional pred: ((a: T) => boolean)

      A function taking the GraphObject returned by navig and returning true if that object should be returned, defaulting to a predicate that always returns true.

        • (a: T): boolean
        • Parameters

          • a: T

          Returns boolean

    Returns T

    The first GraphObject in the Z-order, or else null.

  • Return a collection of the GraphObjects of this layer at the given point in document coordinates.

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

    Type Parameters

    Parameters

    • p: Point

      A Point in document coordinates.

    • Optional navig: ((a: GraphObject) => T)

      A function taking a GraphObject and returning a GraphObject, defaulting to the identity. If this function returns null, the given GraphObject will not be included in the results.

    • Optional pred: ((a: T) => boolean)

      A function taking the GraphObject returned by navig and returning true if that object should be returned, defaulting to a predicate that always returns true.

        • (a: T): boolean
        • Parameters

          • a: T

          Returns boolean

    • Optional coll: S

      An optional collection (List or Set) to add the results to.

    Returns S

    a collection of GraphObjects that will contain all GraphObjects located at Point p, or else an empty collection. If a List or Set was passed in, it is returned.

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

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

    Type Parameters

    Parameters

    • r: Rect

      A Rect in document coordinates.

    • Optional navig: ((a: GraphObject) => T)

      A function taking a GraphObject and returning a GraphObject, defaulting to the identity. If this function returns null, the given GraphObject will not be included in the results.

    • Optional pred: ((a: T) => boolean)

      A function taking the GraphObject returned by navig and returning true if that object should be returned, defaulting to a predicate that always returns true.

        • (a: T): boolean
        • Parameters

          • a: T

          Returns boolean

    • Optional partialInclusion: boolean

      Whether an object can match if it merely intersects the rectangular area (true) or if it must be entirely inside the rectangular area (false). The default value is false.

    • Optional coll: S

      An optional collection (List or Set) to add the results to.

    Returns S

    a collection of GraphObjects that will contain all GraphObjects located in or near Rect r, or else an empty collection. If a List or Set was passed in, it is returned.

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

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

    Type Parameters

    Parameters

    • p: Point

      A Point in document coordinates.

    • dist: number

      The distance from the point.

    • Optional navig: ((a: GraphObject) => T)

      A function taking a GraphObject and returning a GraphObject, defaulting to the identity. If this function returns null, the given GraphObject will not be included in the results.

    • Optional pred: ((a: T) => boolean)

      A function taking the GraphObject returned by navig and returning true if that object should be returned, defaulting to a predicate that always returns true.

        • (a: T): boolean
        • Parameters

          • a: T

          Returns boolean

    • Optional partialInclusion: boolean | S

      Whether an object can match if it merely intersects the circular area (true) or if it must be entirely inside the circular area (false). The default value is true.

    • Optional coll: S

      An optional collection (List or Set) to add the results to.

    Returns S

    a collection of GraphObjects that will contain all GraphObjects located at Point p, or else an empty collection. If a List or Set was passed in, it is returned.