Custom Edges

Edges are the connective elements within a Psiagram Paper. They could be any connective shape: a simple black line, or a clickable arrow with a title block. This section exposes the API of Edges and describes the steps needed to build your first custom Edge.

But first, some links to various Edge files:

  1. Base Edgearrow-up-right

    • Provides the base implementation of Edge. Every Edge must extend this class

      (or if not, it must at least be in the prototype chain)

    • Must be extended in order to be functional

  2. Linearrow-up-right

    • Provides an extended Edge that renders a black arrow

    • Functional as is (does not need to be extended)

  3. Text Linearrow-up-right

    • Extends Linearrow-up-right (see above) to additionally render a title for the Edge

    • Functional as is (does not need to be extended)

Feel free to check the links out to get a basic idea of some of the Edges provided by Psiagram. They will be referenced later on.

The Base Edgearrow-up-right takes care of a lot of the internal-use scenarios (example: the getElement method is defined already, so that Paper can call it to get the Edge group, which is also pre-defined). However, some of the functionality must be implemented in order for your custom Edge to work. The following are the methods and interfaces within the Edge API.

Base Edge Initialization Properties

The properties of the Base Edgearrow-up-right defined in TypeScript are:

The id, gridSize, uniqueId and paper properties are given by Paper to every Edge. As you can see, there isn't much here to define the look and feel of the Edge. This only serves as a foundation, and provides definitions for the two properties that are passed in from the Paper instance.

See the Text Linearrow-up-right to see how IBaseEdgeProperties is extended to allow for more properties.

Base Edge Class Properties

The properties of the Base Class defined in TypeScript are:

P represents the props given to the Base Edgearrow-up-right or extending class. These props must extend IBaseEdgeProperties - i.e. they must include id and gridSize.

Group is kept private, and should not be touched by any classes extending the Base Edgearrow-up-right. However, props is to be used for storing any passed-in props, and is accessible from all extending classes.

Check out how Linearrow-up-right extends the constructor of Base Edgearrow-up-right to set defaults for certain props.

Base Edge Class Methods

There are multiple methods within the Base Edgearrow-up-right. Many of these should not be touched, or should only be extended if needed.

constructor

Once again, P represents the props given to the Base Edgearrow-up-right or extending class. The constructor is where you initialize any of the props passed into the extending class. All of the Base Edgearrow-up-right props are already taken care of, so you only need to worry about the new ones. For example, here is the constructor taken from Linearrow-up-right:

initialize

circle-exclamation

Initialize is called when the Edge is being mounted into the DOM. You can build visual SVG components and add them to the group using this.addToGroup(element). This function is only called once, so any changes in the future must be done through setters. Here's Line'sarrow-up-right initialize function as an example:

teardown

Teardown is called when the Edge is being removed from the DOM. You can cause transformations, change appearance, and teardown any listeners or processes. If none of these are needed, you do not need to overwrite this function.

getCoordinates

circle-exclamation

External methods need to call ThisEdge.getCoordinates() in order to get the real Edge coordinates. Only the Edge instance knows the true coordinates, as it may choose to manipulate them internally regardless of the input coordinates. Any implementations of this method must return the true coordinates of the Edge.

For example, here is the getCoordinates implementation in Linearrow-up-right:

setCoordinates

circle-exclamation

External methods must call this in order to provide potential coordinates to the Edge. Once these are finalized, they should be stored within the Edge in order to be easily retrieved using getCoordinates.

For example, here is the setCoordinates implementation in Linearrow-up-right:

getElement

triangle-exclamation

This function will always return the Edge group. Any visual components for this Edge should be contained within the Edge group by adding them using addToGroup.

addToGroup

triangle-exclamation

This function allows you to easily append elements into the Edge group. Generally, it is used inside of initialize to add created elements to the Edge group.

Last updated