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
options():TOptions
Gets the configuration options of the shape.
set
options(options
):void
Updates the configuration options of the shape and notifies observers.
Parameters
• options: TOptions
The new options to apply.
Returns
TOptions
The current options.
Defined in
state
get
state():ShapeState
Gets the current state of the shape.
set
state(state
):void
Sets a new state for the shape.
Parameters
• state: ShapeState
The new state to assign to the shape.
Returns
The current state of the shape.
Implementation of
Defined in
stateStyle
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
style():TStyle
Gets the style settings of the shape.
set
style(style
):void
Updates the style settings of the shape and notifies observers.
Parameters
• style: TStyle
The new style settings to apply.
Returns
TStyle
The current style settings.
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
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
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.