Shape
Abstract class representing a generic shape with observer functionality.
Extended by
Type Parameters
• TDefinition extends IShapeDefinition
The type of shape definition implementing IShapeDefinition.
• TStyle extends IShapeStyle
The type of shape style implementing IShapeStyle.
• TOptions extends IShapeOptions
The type of shape options implementing IShapeOptions.
Implements
Constructors
new Shape()
new Shape<
TDefinition
,TStyle
,TOptions
>(definition
,style
?,options
?):Shape
<TDefinition
,TStyle
,TOptions
>
Constructs a Shape instance and wraps the definition, style, and options in a Proxy to handle change notifications.
Parameters
• definition: TDefinition
The shape definition instance to be wrapped in a Proxy.
• style?: TStyle
Optional style settings for the shape.
• options?: TOptions
Optional configuration options for the shape.
Returns
Shape
<TDefinition
, TStyle
, TOptions
>
Defined in
Properties
_definition
protected
_definition:TDefinition
The shape definition, proxied to trigger observer notifications on change.
Defined in
_options
protected
_options:TOptions
The options for configuring the shape, proxied to trigger observer notifications on change.
Defined in
_state
protected
_state:ShapeState
=ShapeState.Default
The current state of the shape, representing its visual or interactive status.
Defined in
_style
protected
_style:TStyle
The style settings for the shape, proxied to trigger observer notifications on change.
Defined in
observers
protected
observers: () =>void
[] =[]
List of observer functions to be notified on shape changes.
Defined in
Accessors
options
Get Signature
get options():
TOptions
Gets the configuration options of the shape.
Returns
TOptions
The current options.
Set Signature
set options(
options
):void
Updates the configuration options of the shape and notifies observers.
Parameters
• options: TOptions
The new options to apply.
Returns
void
Defined in
state
Get Signature
get state():
ShapeState
Gets the current state of the shape.
Returns
The current state of the shape.
Set Signature
set state(
state
):void
Sets a new state for the shape.
Parameters
• state: ShapeState
The new state to assign to the shape.
Returns
void
Implementation of
Defined in
stateStyle
Get Signature
get stateStyle():
TStyle
Retrieves the effective style of the shape based on its current state.
Returns
TStyle
The computed style object for the current shape state, with state-specific overrides merged in as necessary.
Implementation of
Defined in
style
Get Signature
get style():
TStyle
Gets the style settings of the shape.
Returns
TStyle
The current style settings.
Set Signature
set style(
style
):void
Updates the style settings of the shape and notifies observers.
Parameters
• style: TStyle
The new style settings to apply.
Returns
void
Defined in
Methods
addObserver()
addObserver(
observer
):void
Adds an observer function that will be called when the shape's state changes.
Parameters
• observer
The observer callback function.
Returns
void
Implementation of
Defined in
hasBorder()
protected
hasBorder():boolean
Determines if the current state style includes a visible border.
Returns
boolean
true
if borderColor
and borderWidth
are defined and indicate a visible border; otherwise, false
.
Defined in
hide()
hide():
void
Hides the shape, preventing it from being rendered on the canvas.
The shape will still exist and retain its properties, but it will not
appear during rendering until show()
is called.
Returns
void
Implementation of
Defined in
isDraggable()
isDraggable():
boolean
Checks whether the shape is draggable or not.
Returns
boolean
Returns true if the shape is draggable. Returns false if the shape is not draggable.
Implementation of
Defined in
isMouseOver()
abstract
isMouseOver(mousePosition
):boolean
Determines if the mouse is currently over the shape.
Parameters
• mousePosition: Point
The current mouse position.
Returns
boolean
True if the mouse is over the shape, false otherwise.
Implementation of
Defined in
isVisible()
isVisible():
boolean
Checks whether the shape is currently visible.
Returns
boolean
Returns true if the shape is visible and will be rendered on the canvas. Returns false if the shape is hidden and will not be rendered.
Implementation of
Defined in
onDrag()
abstract
onDrag(delta
):void
Handles the drag operation by applying the given delta to the current position.
Parameters
• delta: Point
The change in position represented as a Point
.
Returns
void
Implementation of
Defined in
removeObserver()
removeObserver(
observer
):void
Removes a previously added observer function.
Parameters
• observer
The observer callback function to be removed.
Returns
void
Implementation of
Defined in
render()
abstract
render(context
):void
Abstract method to render the shape on the canvas.
Parameters
• context: CanvasRenderingContext2D
The 2D rendering context for the canvas.
Returns
void
Implementation of
Defined in
show()
show():
void
Makes the shape visible, allowing it to be rendered on the canvas. If the shape was previously hidden, calling this method will make it appear during the next rendering cycle.
Returns
void
Implementation of
Defined in
toArray()
toArray():
any
[]
Converts the shape's definition to an array.
Returns
any
[]
An array representation of the shape's definition.
Implementation of
Defined in
toJson()
toJson():
string
Converts the shape's definition to a JSON string.
Returns
string
A JSON string representation of the shape's definition.