Connection Class
Models a Connection. A Connection consists of two Endpoints (each of which belongs to some DOM element), a Connector (the actual path inscribed by the Connection), and zero or more Overlays.
Item Index
Methods
- addClass
- addOverlay
- addType
- bind
- cleanupListeners
- clearTypes
- fire
- getConnector
- getData
- getLabel
- getLabelOverlay
- getOverlay
- getOverlays
- getParameter
- getParameters
- getType
- getUuids
- hasType
- hideOverlay
- hideOverlays
- isDetachable
- isEditable
- isHover
- isReattach
- isSuspendEvents
- isVisible
- jsPlumbUtil.replace
- reapplyTypes
- removeAllOverlays
- removeClass
- removeOverlay
- removeOverlays
- removeType
- setConnector
- setDetachable
- setEditable
- setHover
- setHoverPaintStyle
- setLabel
- setPaintStyle
- setParameter
- setParameters
- setReattach
- setSuspendEvents
- setType
- setVisible
- showOverlay
- showOverlays
- toggleType
- unbind
- updateClasses
Methods
addClass
-
class
Adds a class or some classes to the visual elements for the given component.
Parameters:
-
class
StringThe class(es) to add. The values are appended as given, meaning you can supply a space separated string of several classes if you wish.
addOverlay
-
overlaySpec
Adds an Overlay to the component.
Parameters:
-
overlaySpec
ObjectSpecification of the Overlay to add.
addType
-
typeId
-
[params]
-
[doNotRepaint=false]
Adds a type to the component. Note this is distinct from {@link #setType}, which overrides all current types - this function just adds a type to the existing list.
Parameters:
-
typeId
StringId of the type to add.
-
[params]
Object optionalOptional params to use when applying the type.
-
[doNotRepaint=false]
Boolean optionalTells jsPlumb not to repaint after adding the type.
bind
-
event
-
listener
-
[insertAtStart=false]
Binds a listener to one or more events.
Parameters:
-
event
String | StringName(s) of the event(s) to bind to. Note that if you provide multiple event names they all are bound with the same function.
-
listener
FunctionFunction to execute.
-
[insertAtStart=false]
Boolean optionalWhether or not to insert this listener at the start of the listener list, so it is fired before the other currently registered listeners.
cleanupListeners
()
Removes all listeners.
clearTypes
-
[doNotRepaint=false]
Clears all types
for a given component.
Parameters:
-
[doNotRepaint=false]
Boolean optionalTells jsPlumb not to repaint after clearing the types.
fire
-
event
-
value
-
originalEvent
Fires an update for the given event.
Parameters:
-
event
StringEvent to fire
-
value
ObjectValue to pass to the event listener(s).
-
originalEvent
EventThe original event from the browser
getConnector
()
Connector
Gets the underlying Connector for this Connection. A Connector is the path the user sees between the two Endpoints.
Returns:
The current Connector.
getData
()
Object
Returns the data provided (if any) to this object for populating its types.
Returns:
Data, or null.
getLabel
()
Returns the label text for this component (or a function if you are labelling with a function).
This does not return the overlay itself; this is a convenience method which is a pair with
setLabel
; together they allow you to add and access a Label Overlay without having to create the
Overlay object itself. For access to the underlying label overlay that jsPlumb has created,
use getLabelOverlay
.
getLabelOverlay
()
Overlay
Returns:
The underlying internal label overlay, which will exist if you specified a label on
a connect
call, or have called setLabel
at any stage. Otherwise it will be null.
getOverlay
-
overlayId
Gets an overlay, by ID. Note: by ID. You would pass an 'id' parameter in to the Overlay's constructor arguments, and then use that to retrieve it via this method.
Parameters:
-
overlayId
StringId of the overlay to retrieve.
Returns:
The overlay stored against the given id, null if not found.
getOverlays
()
Array
Gets all the overlays for this component.
Returns:
List of the component's overlays.
getParameter
-
name
Gets a parameter from the component
Parameters:
-
name
StringName of the parameter to get
Returns:
The given parameter's value, null if not found.
getParameters
()
Object
Gets all parameters from the component. Note that you are given the actual parameters object, not a copy, so you can alter their values directly, and if you hold the reference to the parameters object you could cause a memory leak.
Returns:
All of the component's parameters.
getType
()
String
Gets the current type - or types - for this component.
Returns:
The current list of types, empty if none registered.
getUuids
()
String
Gets the UUIDs of the two endpoints, if they are set.
Returns:
An array of [sourceUuid, targetUuid]. Either or both of these values may be null.
hasType
-
typeId
Returns whether or not the component currently has the given type.
Parameters:
-
typeId
StringId of the type to check for
Returns:
True if the component has the type, false if not.
hideOverlay
-
overlayId
Hides the overlay specified by the given id.
Parameters:
-
overlayId
StringId of the overlay to hide.
hideOverlays
()
Hides all Overlays for this component.
isDetachable
()
Boolean
Returns whether or not this Connection can be detached from its target/source endpoint. By default this
is false; use it in conjunction with the reattach
parameter.
Returns:
True if can be detached, false otherwise.
isEditable
()
Boolean
Returns whether or not the Connection is editable.
Returns:
True if editable, false if not.
isHover
()
Boolean
Returns whether or not the object is currently in hover state
Returns:
True if in hover state, false if not.
isReattach
()
Boolean
Returns whether or not this Connection will be reattached after having been detached via the mouse and dropped. By default this
is false; use it in conjunction with the detachable
parameter.
Returns:
True if will reattach, false if not.
isSuspendEvents
()
Boolean
Checks whether or not events are currently suspended.
Returns:
True if events are suspended, false otherwise.
isVisible
()
Boolean
Returns whether or not the Connection is currently visible.
Returns:
True if visible, false if not.
jsPlumbUtil.replace
-
inObj
-
path
-
value
Replaces values inside some JS object according to a given path spec. A path spec is a string in dotted notation, with each component optionally declaring an array index. Some examples are:
foo.bar foo.baz[2] foo.qux[3].baz[3].shwee
The function fails gracefully if the path identifies a non-existent object.
Parameters:
-
inObj
ObjectObject to perform replacements inside.
-
path
StringPath to use for replacements
-
value
ObjectValue to set.
reapplyTypes
-
[params]
Reapplies the current list of types with the given (optional) parameters. See the jsPlumb documentation for a full discussion of types.
Parameters:
-
[params]
Object optionalOptional params to use when reapplying types.
removeAllOverlays
()
Removes all overlays from the component, and then repaints.
removeClass
-
class
Removes a class or some classes from the visual elements for the given component. You can supply a space separated string of several classes if you wish.
Parameters:
-
class
StringThe class(es) to remove.
removeOverlay
-
overlayId
Removes an overlay by ID. Note: by ID. this is a string you set in the overlay spec.
Parameters:
-
overlayId
StringId of the overlay to remove.
removeOverlays
-
overlayIds
Removes a set of overlays by ID. Note: by ID. This is a string you set in the overlay spec.
Parameters:
-
overlayIds
...StringThis function takes an arbitrary number of arguments, each of which is a single overlay id.
removeType
-
typeId
-
[doNotRepaint=false]
Removes the given type from the component.
Parameters:
-
typeId
StringId of the type to remove.
-
[doNotRepaint=false]
Boolean optionalTells jsPlumb not to repaint after removing the type.
setConnector
-
connector
Sets the Connection's connector (eg Bezier
, Flowchart
, etc). You pass a Connector definition into this method, the same
thing that you would set as the connector
property on a jsPlumb.connect
call.
Parameters:
-
connector
String | ObjectConnector definition. See jsPlumb documentation for a discussion.
setDetachable
-
detachable
Sets whether or not this connection is detachable.
Parameters:
-
detachable
BooleanWhether or not to set the Connection to be detachable.
setEditable
-
editable
Sets whether or not the Connection is editable. This will only be honoured if the underlying Connector is editable - not all types are.
Parameters:
-
editable
BooleanWhether or not to set the Connection to be editable.
setHover
-
hover
-
[ignoreAttachedElements=false]
Sets/unsets the hover state of this component.
Parameters:
-
hover
BooleanHover state boolean
-
[ignoreAttachedElements=false]
Boolean optionalIf true, does not notify any attached elements of the change in hover state. Used mostly by jsPlumb internally, to avoid infinite loops.
setHoverPaintStyle
-
style
-
[doNotRepaint]
Sets the paint style to use when the mouse is hovering over the component. This is null by default. The hover paint style is applied as extensions to the paintStyle; it does not entirely replace it. This is because people will most likely want to change just one thing when hovering, say the color for example, but leave the rest of the appearance the same.
Parameters:
-
style
ObjectStyle to use when the mouse is hovering. The allowed values in this object originally come from valid values in an HTML5 canvas.
-
[fillStyle]
String optionalFill style, in valid CSS format (a hex code, name, or rgb value). Note that setting a
fillStyle
on a Connector will cause the browser to fill the connector's path - probably not what you want. -
[strokeStyle]
String optionalStroke style, in valid CSS format (a hex code, name, or rgb value). You can use
strokeStyle
on Endpoints to define a border. -
[lineWidth]
Integer optionalWidth of the stroked line (for Connectors this is the Connector itself; for Endpoints it is the outline)
-
-
[doNotRepaint]
Boolean optionalIf true, the component will not be repainted. Useful when setting things up initially.
setLabel
-
label
Sets the component's label.
Parameters:
-
label
String | Function | ObjectLabel to set. May be a String, a Function that returns a String, or a params object containing { "label", "labelStyle", "location", "cssClass" }. Note that this uses innerHTML on the label div, so keep that in mind if you need escaped HTML.
setPaintStyle
-
style
-
[doNotRepaint=false]
Sets the component's paint style and then repaints the component.
Parameters:
-
style
ObjectStyle to use. The allowed values in this object originally come from valid values in an HTML5 canvas.
-
[fillStyle]
String optionalFill style, in valid CSS format (a hex code, name, or rgb value). Note that setting a
fillStyle
on a Connector will cause the browser to fill the connector's path - probably not what you want. -
[strokeStyle]
String optionalStroke style, in valid CSS format (a hex code, name, or rgb value). You can use
strokeStyle
on Endpoints to define a border. -
[lineWidth]
Integer optionalWidth of the stroked line (for Connectors this is the Connector itself; for Endpoints it is the outline)
-
-
[doNotRepaint=false]
Boolean optionalIf true, the component will not be repainted.
setParameter
-
name
-
value
Sets a parameter on the component
Parameters:
-
name
StringName of the parameter to set
-
value
ObjectValue to set
setParameters
-
params
Sets all parameters on the component.
Parameters:
-
params
ObjectParameters to set.
setReattach
-
reattach
Sets whether or not this connection will reattach after having been detached via the mouse and dropped.
Parameters:
-
reattach
BooleanWhether or not to set the Connection to reattach after it has been dropped in whitespace.
setSuspendEvents
-
val
Sets whether or not events are suspended.
Parameters:
-
val
BooleanWhether or not to suspend events.
setType
-
typeId
-
[params]
-
[doNotRepaint=false]
This function sets a type
for the given component. It replaces all existing types. For a full discussion of the concept
of types, see the jsPlumb documentation.
Parameters:
-
typeId
StringId of the type to set.
-
[params]
Object optionalOptional parameter object to expand.
-
[doNotRepaint=false]
Boolean optionalTells jsPlumb not to repaint after setting the type.
setVisible
-
visible
Sets whether or not the Connection should be visible.
Parameters:
-
visible
BooleanBoolean indicating desired visible state.
showOverlay
-
overlayId
Shows the overlay specified by the given id.
Parameters:
-
overlayId
StringId of the overlay to show.
showOverlays
()
Shows all Overlays for this component.
toggleType
-
typeId
-
[params]
-
[doNotRepaint=false]
Toggles the given type on the component.
Parameters:
-
typeId
StringId of the type to toggle.
-
[params]
Object optionalOptional params to use if the type is not currently set and jsPlumb applies it.
-
[doNotRepaint=false]
Boolean optionalTells jsPlumb not to repaint after toggling the type.
unbind
-
[eventOrListener]
-
[listener]
Clears either all listeners, or listeners for some specific event, or just some listener. You can call this method with zero, one or two arguments: with zero arguments, all listeners are cleared. With one argument that is a string, all listeners for the specified event type are cleared. With one argument that is a function, it is removed from the appropriate event list. With two arguments, the first is an event type, and the second is a function to be unbound. In fact this is perhaps unnecessary given that you can unbind a function just by passing it.
Parameters:
-
[eventOrListener]
String | Function optionalIf a string, constrains the clear to just listeners for the event identified by the string. If a Function, unbinds this function wherever it may have been bound.
-
[listener]
Function optionalIf provided, removes just this listener for the given event.
updateClasses
-
[classesToAdd]
-
[classesToRemove]
Adds/removes classes at the same time, which reduces the number of reflows that occur in the page. Either parameter may be null but of course if you pass only a single parameter to this method then it will be taken to be classesToAdd.
Parameters:
-
[classesToAdd]
String | String optional -
[classesToRemove]
String | String optional
Properties
overlays
ListOverlay
List of Overlays for this component.
scope
String
Scope descriptor for the Connection.
Default: "_jsPlumb_Default_Scope"
source
Element
Source element in the Connection.
sourceId
String
ID of the source element.
target
Element
Target element in the Connection.
targetId
String
ID of the target element.