Class Inspector

GoJS® Diagramming Components
version 3.0.1
by Northwoods Software®

This is an extension and not part of the main GoJS library. Note that the API for this class may change at any time. If you intend to use an extension in production, you should copy the code to your own source directory. See the Extensions intro page for more information.

This class implements an inspector for GoJS model data objects. The constructor takes three arguments:

  • divid string a string referencing the HTML ID of the to-be inspector's div
  • diagram Diagram a reference to a GoJS Diagram
  • options Object an optional JS Object describing options for the inspector

Options:

Options for properties:

  • show boolean | function a boolean value to show or hide the property from the inspector, or a predicate function to show conditionally.
  • readOnly boolean | function whether or not the property is read-only
  • type string a string describing the data type. Supported values: "string|number|boolean|color|arrayofnumber|point|rect|size|spot|margin|select|date|datetime-local|time"
  • defaultValue any a default value for the property. Defaults to the empty string.
  • choices Array | function when type === "select", the Array of choices to use or a function that returns the Array of choices.

Example usage of Inspector:

var inspector = new Inspector("myInspector", myDiagram,
{
includesOwnProperties: false,
properties: {
"key": { show: Inspector.showIfPresent, readOnly: true },
"comments": { show: Inspector.showIfNode },
"LinkComments": { show: Inspector.showIfLink },
"chosen": { show: Inspector.showIfNode, type: "checkbox" },
"state": { show: Inspector.showIfNode, type: "select", choices: ["Stopped", "Parked", "Moving"] }
}
});

This is the basic HTML Structure that the Inspector creates within the given DIV element:

<div id="divid" class="inspector">
<tr>
<td>propertyName</td>
<td><input value=propertyValue /></td>
</tr>
...
</div>

If you want to experiment with this extension, try the Data Inspector sample.

Index

Constructors

  • Constructs an Inspector and sets up properties based on the options provided. Also sets up change listeners on the Diagram so the Inspector stays up-to-date.

    Parameters

    • divid: string

      a string referencing the HTML ID of the to-be Inspector's div

    • diagram: Diagram

      a reference to a GoJS Diagram

    • Optional options: {
          [index: string]: any;
      }

      an optional JS Object describing options for the inspector

      • [index: string]: any

    Returns Inspector

Accessors

  • Gets or sets the go.Diagram associated with this Inspector.

  • This read-only property returns the HTMLElement containing the Inspector.

  • Gets or sets whether the Inspector includes all properties currently on the inspected object.

    The default value is true.

  • Gets or sets whether the Inspector automatically inspects the associated Diagram's selection. When set to false, the Inspector won't show anything until inspectObject is called.

    The default value is true.

  • This read-only property returns the object currently being inspected.

    To set the inspected object, call inspectObject.

  • Gets or sets whether the Inspector displays properties for multiple selected objects or just the first.

    The default value is false, meaning only the first item in the go.Diagram.selection is inspected.

  • Gets or sets the properties that the Inspector will inspect, maybe setting options for those properties. The object should contain string: Object pairs represnting propertyName: propertyOptions. Can be used to include or exclude additional properties.

    The default value is an empty object.

  • Gets or sets the function to be called when a property is modified by the Inspector. The first paremeter will be the property name, the second will be the new value, and the third will be a reference to this Inspector.

    The default value is null, meaning nothing will be done.

  • Gets or sets how many objects will be displayed when multipleSelection is true.

    The default value is 0, meaning all selected objects will be displayed for a given property.

  • Gets or sets whether the Inspector displays the union or intersection of properties for multiple selected objects.

    The default value is false, meaning the intersection of properties is inspected.

Methods

  • This sets inspectedProperties[propertyName] and creates the HTML table row for a given property:

    <tr>
    <td>propertyName</td>
    <td><input value=propertyValue /></td>
    </tr>

    This method can be customized to change how an Inspector row is rendered.

    Parameters

    • propertyName: string

      the property name

    • propertyValue: any

      the property value

    Returns HTMLTableRowElement

    the table row

  • This predicate should be false if the given property should not be editable by the user. Normally it only checks the value of "readOnly" on the property descriptor.

    The default value is true.

    Parameters

    • propertyName: string

      the property name

    • propertyDesc: ObjectData

      the property descriptor

    • inspectedObject: ObjectData

      the data object

    Returns boolean

    whether a particular property should be shown in this Inspector

  • This predicate should be false if the given property should not be shown. Normally it only checks the value of "show" on the property descriptor.

    The default value is true.

    Parameters

    • propertyName: string

      the property name

    • propertyDesc: ObjectData

      the property descriptor

    • inspectedObject: ObjectData

      the data object

    Returns boolean

    whether a particular property should be shown in this Inspector

  • Update the HTML state of this Inspector with the given object.

    If passed an object, the Inspector will inspect that object. If passed null, this will do nothing. If no parameter is supplied, the inspectedObject will be set based on the value of inspectSelection.

    Parameters

    Returns void

  • This predicate function can be used as a value for the show option for properties. When used, the property will only be shown when inspecting a go.Group.

    Parameters

    • part: Part

      the Part being inspected

    Returns boolean

  • This predicate function can be used as a value for the show option for properties. When used, the property will only be shown when inspecting a go.Link.

    Parameters

    • part: Part

      the Part being inspected

    Returns boolean

  • This predicate function can be used as a value for the show option for properties. When used, the property will only be shown when inspecting a go.Node.

    Parameters

    • part: Part

      the Part being inspected

    Returns boolean

  • This predicate function can be used as a value for the show option for properties. When used, the property will only be shown if present. Useful for properties such as key, which will be shown on Nodes and Groups, but normally not on Links

    Parameters

    • data: Part
    • propname: string

      the property to check presence of

    Returns boolean