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:
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
Provides an extended Edge that renders a black arrow
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 Edge 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 Edge 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 Line 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 Edge 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 Edge. However, props
is to be used for storing any passed-in props, and is accessible from all extending classes.
Check out how Line extends the constructor of Base Edge to set defaults for certain props.
Base Edge Class Methods
There are multiple methods within the Base Edge. 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 Edge or extending class. The constructor is where you initialize any of the props passed into the extending class. All of the Base Edge props are already taken care of, so you only need to worry about the new ones. For example, here is the constructor taken from Line:
initialize
The initialize method must be overwritten.
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's 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
The getCoordinates method must be overwritten.
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 Line:
setCoordinates
The setCoordinates method must be overwritten.
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 Line:
getElement
Do not modify or overwrite this function unless you know what you're doing. It is used by the Paper to extract the entire Edge group, and breaking the functionality may cause all of Psiagram to work incorrectly.
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
Do not modify this function unless you know what you're doing. It should be used by all extending classes to insert SVG elements into the Edge group. Breaking the functionality may lead to incorrect rendering of the Edge.
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