Module: draw

Tools for drawing.

License:
  • MIT
Source:

Classes

Drawing
Layer

Interfaces

DrawCanvasInit

Methods

(static) cloneLayer(name, hrService) → {void}

Creates a new top-level layer in the drawing with the given name, copies all the current layer's contents to it, and then clears the selection. This function then calls the 'changed' handler. This is an undoable action.

Parameters:
Name Type Description
name string

The given name. If the layer name exists, a new name will be generated.

hrService module:history.HistoryRecordingService

History recording service

Source:
Fires:
  • module:svgcanvas.SvgCanvas#event:changed
Returns:
Type
void

(static) createLayer(name, hrService) → {void}

Creates a new top-level layer in the drawing with the given name, sets the current layer to it, and then clears the selection. This function then calls the 'changed' handler. This is an undoable action.

Parameters:
Name Type Description
name string

The given name

hrService module:history.HistoryRecordingService
Source:
Fires:
  • module:svgcanvas.SvgCanvas#event:changed
Returns:
Type
void

(static) deleteCurrentLayer() → {boolean}

Deletes the current layer from the drawing and then clears the selection. This function then calls the 'changed' handler. This is an undoable action.

Source:
Fires:
  • module:svgcanvas.SvgCanvas#event:changed
Returns:

true if an old layer group was found to delete

Type
boolean

(static) identifyLayers() → {void}

Updates layer system.

Source:
Returns:
Type
void

(static) identifyLayers() → {void}

get current index

Source:
Returns:
Type
void

(static) init(canvas) → {void}

Parameters:
Name Type Description
canvas module:draw.DrawCanvasInit
Source:
Returns:
Type
void

(static) leaveContext() → {void}

Return from a group context to the regular kind, make any previously disabled elements enabled again.

Source:
Fires:
  • module:svgcanvas.SvgCanvas#event:contextset
Returns:
Type
void

(static) mergeAllLayers(hrService) → {void}

Parameters:
Name Type Description
hrService module:history.HistoryRecordingService
Source:
Returns:
Type
void

(static) mergeLayer(hrService) → {void}

Parameters:
Name Type Description
hrService module:history.HistoryRecordingService
Source:
Returns:
Type
void

(static) moveSelectedToLayer(layerName) → {boolean}

Moves the selected elements to layerName. If the name is not a valid layer name, then false is returned. Otherwise it returns true. This is an undo-able action.

Parameters:
Name Type Description
layerName string

The name of the layer you want to which you want to move the selected elements

Source:
Returns:

Whether the selected elements were moved to the layer.

Type
boolean

(static) randomizeIds(enableRandomization, currentDrawing) → {void}

Called to ensure that drawings will or will not have randomized ids. The currentDrawing will have its nonce set if it doesn't already.

Parameters:
Name Type Description
enableRandomization boolean

flag indicating if documents should have randomized ids

currentDrawing draw.Drawing
Source:
Returns:
Type
void

(static) renameCurrentLayer(newName) → {boolean}

Renames the current layer. If the layer name is not valid (i.e. unique), then this function does nothing and returns false, otherwise it returns true. This is an undo-able action.

Parameters:
Name Type Description
newName string

the new name you want to give the current layer. This name must be unique among all layer names.

Source:
Fires:
  • module:svgcanvas.SvgCanvas#event:changed
Returns:

Whether the rename succeeded

Type
boolean

(static) setContext(elem) → {void}

Set the current context (for in-group editing).

Parameters:
Name Type Description
elem Element
Source:
Fires:
  • module:svgcanvas.SvgCanvas#event:contextset
Returns:
Type
void

(static) setCurrentLayer(name) → {boolean}

Sets the current layer. If the name is not a valid layer name, then this function returns false. Otherwise it returns true. This is not an undo-able action.

Parameters:
Name Type Description
name string

The name of the layer you want to switch to.

Source:
Returns:

true if the current layer was switched, otherwise false

Type
boolean

(static) setCurrentLayerPosition(newPos) → {boolean}

Changes the position of the current layer to the new value. If the new index is not valid, this function does nothing and returns false, otherwise it returns true. This is an undo-able action.

Parameters:
Name Type Description
newPos Integer

The zero-based index of the new position of the layer. This should be between 0 and (number of layers - 1)

Source:
Returns:

true if the current layer position was changed, false otherwise.

Type
boolean

(static) setLayerVisibility(layerName, bVisible) → {boolean}

Sets the visibility of the layer. If the layer name is not valid, this function return false, otherwise it returns true. This is an undo-able action.

Parameters:
Name Type Description
layerName string

The name of the layer to change the visibility

bVisible boolean

Whether the layer should be visible

Source:
Returns:

true if the layer's visibility was set, false otherwise

Type
boolean

(inner) findLayerNameInGroup(group) → {string}

Find the layer name in a group element.

Parameters:
Name Type Description
group Element

The group element to search in.

Source:
Returns:

The layer name or empty string.

Type
string

(inner) getNewLayerName(existingLayerNames) → {string}

Given a set of names, return a new unique name.

Parameters:
Name Type Description
existingLayerNames Array.<string>

Existing layer names.

Source:
Returns:
  • The new name.
Type
string

(inner) historyRecordingService(hrServiceopt) → {module:history.HistoryRecordingService}

Get a HistoryRecordingService.

Parameters:
Name Type Attributes Description
hrService module:history.HistoryRecordingService <optional>

if exists, return it instead of creating a new service.

Source:
Returns:
Type
module:history.HistoryRecordingService