Custom Edges
Last updated
Last updated
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)
Extends (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 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.
The properties of the 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.
The properties of the Base Class defined in TypeScript are:
The initialize method must be overwritten.
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.
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.
The setCoordinates method must be overwritten.
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.
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.
See the to see how IBaseEdgeProperties
is extended to allow for more properties.
P
represents the props given to the 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 . However, props
is to be used for storing any passed-in props, and is accessible from all extending classes.
Check out how extends the constructor of to set defaults for certain props.
There are multiple methods within the . Many of these should not be touched, or should only be extended if needed.
Once again, P
represents the props given to the or extending class. The constructor is where you initialize any of the props passed into the extending class. All of the props are already taken care of, so you only need to worry about the new ones. For example, here is the constructor taken from :
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 initialize function as an example:
For example, here is the getCoordinates
implementation in :
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 .
For example, here is the setCoordinates
implementation in :
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 .