Edge
Last updated
Last updated
Edges dictate flow within Psiagram. They can often be thought of as lines connecting the Nodes within a diagram. Edge classes detail all the rendering information for Edge lines rendered onto Paper, such as color and title.
This section will address the input required to create an Edge within the Paper, and details the output Edge given by Paper.
This is the input given to Paper to create an Edge within Psiagram. This can be given in the edges
array in the initialConditions
object when initializing Paper, or in the addEdge
method call. See the for more on the initialization details or method definitions.
Here is the Paper Input Edge interface defined in TypeScript:
This defines the shape of the object that must be given to Paper to create an Edge. Let's take a look into what each of those potential properties mean.
string
This is the unique ID of the Edge. These must be unique amongst other Edges on the instance of Paper.
string
edgeEndPoint
This is the source from which the Edge extends. This has the type edgeEndPoint
, which is an object that contains either an id of a Node, or a set of coordinates. If id
is given, the Edge will point to the Node with that ID. If no Node matches the given ID, the Edge will not be added.
edgeEndPoint:
iCoordinates:
edgeEndPoint
This is the target from which the Edge points to. This has the type edgeEndPoint
, which is an object that contains either an id of a Node, or a set of coordinates. If id
is given, the Edge will point to the Node with that ID. If no Node matches the given ID, the Edge will not be added.
ICoordinates[]
An array of coordinates that the Edge path should pass through in order. These will snap to the nearest grid point.
Object
Properties is where you define any properties to pass into Edge when it's initialized. These will be entirely dependent on what properties your custom Edge accepts. For example, a basic TextLine may have most of the style built in, but may accept a title to display:
Here's an example of how to add an Edge to the Paper using the Paper Input Edge object. In this case, Paper would have been initialized with a custom Edge class inside of edgeComponentMap
initial properties, with the key 'text-edge'
. This custom Edge will be initialized with the provided properties upon calling addEdge.
While the Paper Input Edge is the input to the Paper, the Paper Edge is the output. In many ways, you can think of it as an initialized Edge class. Whichever custom Edge class was specified by the component property of the Paper Input Edge, will now be passed back as the Paper Edge.
However, there are three additional properties added to a Paper Edge.
source
- The ID of the source Node, or a coordinate point.
target
- The ID of the target Node, or a coordinate point.
coords
- An array of additional coordinate points for the Edge to pass through.
Of course, these are in addition to any properties defined by the custom Edge (example: a title
property or a strokeWidth
property).
We will run through some of the potential uses for PaperEdge.
Now that you have your Edge, you can manipulate the additional properties:
Because this uses getters and setters to wrap the DOM manipulation logic, you must re-assign the properties entirely. You can't do something like:
This just changes the x-property of the object without calling the set method. Since the object itself remains the same, the set method for target will not be triggered and none of the DOM manipulation logic will fire. Notice that for yourEdge.coords
, the array spread operator (or concat) was used when adding a new element to the end of the array rather than using push. This is so that a new array is assigned to coords in order to trigger the set method.
This string maps to an Edge class within the initialConditions.edgeComponentMap
object that the Paper was initialized with. This allows you to map different Paper Input Edges to different Edge classes, allowing for each Edge to have different colors and widths. Information on Paper's initial conditions can be found , and custom Edge information is .
For more information visit the .
Each of these changes will update in the DOM automatically, and will also fire a move-edge
event. More detail on events can be found in the .