ShapeLibraryImpl
Default ShapeLibrary implementation. Use one of these to manage a set of shapes for rendering into your vertices and/or for rendering as a palette from which the user can drag new objects.
Type Parameters
T
T extends ObjectData
Constructors
Constructor
new ShapeLibraryImpl<
T>(shapeSets,options?):ShapeLibraryImpl<T>
ShapeLibrary constructor.
Parameters
shapeSets
One or more shape sets to include in the library.
options?
Options for the library.
Returns
ShapeLibraryImpl<T>
Methods
getCompiledShape()
getCompiledShape(
type,category?):ShapeGeneratorFunction
Gets a compiled version of the given shape, creating and caching it if it does not already exist.
Parameters
type
string
Shape type.
category?
string
Category to use. Defaults to the ID of the first category provided in the shape list.
Returns
getShapeDefinition()
getShapeDefinition(
type,set?):RealisedShapeType
Gets the definition for some combination of type and category. May return null.
Parameters
type
string
set?
string
Returns
RealisedShapeType
Implementation of
ShapeLibrary.getShapeDefinition
getShapeTemplate()
getShapeTemplate(
type,set):string
Gets the template for the given shape type in the given set. If no template is resolved then we return DEFAULT_TEMPLATE (and log the issue to the console).
Parameters
type
string
Shape type
set
string
Name of set. If not provided, the value of DEFAULT_SET is used as the set name.
Returns
string
refresh()
refresh(
el,data,labelAttribute,labelPosition):void
Renders any icons found and applies multiline labels, if necessary.
Parameters
el
data
labelAttribute
string
labelPosition
LabelPosition
Returns
void
Implementation of
ShapeLibrary.refresh
renderCompiledShape()
renderCompiledShape(
data,strokeWidth?,typeParameter?,categoryParameter?):HTMLElement|SVGElement
Render the given data with the appropriate template. A fill value is set on the resulting element, and the vector-effect attribute is set to 'non scaling stroke', ie. when the shape is scaled due to the element dimensions differing from the viewbox, the stroke does not change.
Parameters
data
strokeWidth?
number
Stroke width to use. This is passed to the underlying template and is taken into account by the shape template (or at least, it should be, because it has a bearing on the quality of the result)
typeParameter?
string
Optional key to use to look up an object's type. When not provided, the typeParameter from the class is used.
categoryParameter?
string
Optional key to use to look up an object's category. When not provided, the categoryParameter from the class is used.
Returns
HTMLElement | SVGElement
Implementation of
ShapeLibrary.renderCompiledShape