PathDrawer
PathDrawer
allows users to draw <path>
elements.
Learn more about the PathDrawer plugin.
constructorβ
constructor(options: PathDrawer.Options);
The ui.PathDrawer
constructor accepts several parameters:
targetβ
[required] The drawing area. Any paths drawn by the user are appended to this <svg>
element. They are not removed
when the PathDrawer
is removed.
pathAttributesβ
[optional] An object with CSS attributes of the new path. The default values are:
{
'class': null,
'fill': '#ffffff',
'stroke': '#000000',
'stroke-width': 1,
'pointer-events': 'none'
}
If your pathAttributes
object sets the 'class'
attribute (e.g. to 'example-path'
), you can access the path for
further styling through the #example-canvas .example-path
CSS selector.
startPointMarkupβ
[optional] The SVG markup of control point overlay elements. The default is '<circle r="5"/>'
. (CSS styling should
use the .joint-path-drawer .start-point
CSS selector.)
snapRadiusβ
[optional] If set to a number greater than zero, the endpoint of the current segment snaps to the x- and y-values of previously drawn segment endpoints. The number determines the distance for snapping.
enableCurvesβ
[optional] true
by default. If set to false
, only straight paths can be drawn.
Methodsβ
render()β
pathDrawer.render(): this;
Renders the path drawer. Called automatically after object is instantiated.
remove()β
pathDrawer.remove(): this;
Removes the path drawer.
Eventsβ
clearβ
Triggered when the path drawer is cleared.
path:createβ
Triggered when a new path is created. The handler is passed a reference to the svgPath
SVGPathElement.
path:finishβ
Triggered when a path is finished in a valid manner. The handler is passed a reference to the svgPath
SVGPathElement.
The following specific events are triggered alongside this generic event:
path:closeβ
Triggered when a path is finished by being reconnected with the start point. The handler is passed a reference to the
svgPath
SVGPathElement.
path:stopβ
Triggered when a path is finished by being stopped without reconnecting with the start point (e.g. due to a double
click or a right click). The handler is passed a reference to the svgPath
SVGPathElement.
path:abortβ
Triggered when a path is finished in an invalid manner (e.g. closed with only one anchor point). The handler is passed
a reference to the svgPath
SVGPathElement.
path:segment:addβ
Triggered when the user adds a new segment to the path segment list. The handler is passed a reference to the svgPath
SVGPathElement. The following specific events are triggered alongside this generic event:
path:move-segment:addβ
Triggered when the user adds a moveto
segment to the path segment list. The handler is passed a reference to the
svgPath
SVGPathElement.
path:line-segment:addβ
Triggered when the user adds a lineto
segment to the path segment list. The handler is passed a reference to the
svgPath
SVGPathElement.
path:curve-segment:addβ
Triggered when the user adds a curveto
segment to the path segment list. The handler is passed a reference to the
svgPath
SVGPathElement.
path:editβ
Triggered when the user edits the path. The handler is passed a reference to the svgPath
SVGPathElement. The following
specific events are triggered alongside this generic event:
path:last-segment:adjustβ
Triggered when the user adjusts the last added segment. (This happens, for example, when the user specifies a control
point after having added a curveto segment.) The handler is passed a reference to the svgPath
SVGPathElement.
path:last-segment:replace-with-curveβ
Triggered when the user replaces the last added line segment with a curved segment. (This happens, for example, when
the user begins to specify a control point after having added a lineto
segment.) The handler is passed a reference to
the svgPath
SVGPathElement.
path:last-segment:removeβ
Triggered when the user removes last added segment. (This happens, for example, when the user stops drawing with a
right-click). The handler is passed a reference to the svgPath
SVGPathElement.
path:interactβ
Triggered when the user interacts with drawer overlay elements. The handler is passed a reference to the svgPath
SVGPathElement. The following specific events are triggered alongside this generic event:
path:control:adjustβ
Triggered when the user adjusts a control path. (This happens when the user specifies a control for a curveto
segment.)
The handler is passed a reference to the svgPath
SVGPathElement.
path:control:removeβ
Triggered when a control path is removed from the drawer interface. (This happens when the user is finished drawing a curve.)
The handler is passed a reference to the svgPath
SVGPathElement.
Typesβ
Optionsβ
interface Options extends mvc.ViewOptions<undefined> {
target: SVGSVGElement,
pathAttributes?: attributes.NativeSVGAttributes,
startPointMarkup?: string,
snapRadius?: number,
enableCurves?: boolean
}