Line
Represents a line shape that extends the generic Shape class. It uses LineDefinition for defining the start and end points, LineStyle for styling, and LineOptions for additional options.
Extends
Constructors
new Line()
new Line(
start
,end
,style
?,options
?):Line
Creates an instance of the Line
class.
The Line
can be created either by passing two Point
objects representing the start and end of the line,
or by providing the individual coordinates for the start and end points.
Parameters
• start: Point
The starting Point
of the line.
• end: Point
The ending Point
of the line.
• style?: ILineStyle
Defines the styling of the line.
• options?: ILineOptions
The configuration options for the line.
Returns
Throws
InvalidConstructorArgumentsError if invalid arguments are passed.
Overrides
Defined in
new Line()
new Line(
startX
,startY
,endX
,endY
,style
?,options
?):Line
Creates an instance of the Line
class.
The Line
can be created either by passing two Point
objects representing the start and end of the line,
or by providing the individual coordinates for the start and end points.
Parameters
• startX: number
The X-coordinate of the starting point.
• startY: number
The Y-coordinate of the starting point.
• endX: number
The X-coordinate of the ending point.
• endY: number
The Y-coordinate of the ending point.
• style?: ILineStyle
Defines the styling of the line.
• options?: ILineOptions
The configuration options for the line.
Returns
Throws
InvalidConstructorArgumentsError if invalid arguments are passed.
Overrides
Shape<LineDefinition, LineStyle, LineOptions>.constructor
Defined in
Properties
_definition
protected
_definition:LineDefinition
The shape definition, proxied to trigger observer notifications on change.
Inherited from
Defined in
_options
protected
_options:LineOptions
The options for configuring the shape, proxied to trigger observer notifications on change.
Inherited from
Defined in
_state
protected
_state:ShapeState
=ShapeState.Default
The current state of the shape, representing its visual or interactive status.
Inherited from
Defined in
_style
protected
_style:LineStyle
The style settings for the shape, proxied to trigger observer notifications on change.
Inherited from
Defined in
observers
protected
observers: () =>void
[] =[]
List of observer functions to be notified on shape changes.
Inherited from
Defined in
Accessors
end
get
end():Point
Gets the ending point of the line.
set
end(end
):void
Sets the ending point of the line.
Parameters
• end: Point
The new ending point of the line.
Returns
The ending point of the line.
Defined in
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.
Inherited from
Defined in
start
get
start():Point
Gets the starting point of the line.
set
start(start
):void
Sets the starting point of the line.
Parameters
• start: Point
The new starting point of the line.
Returns
The starting point of the line.
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.
Inherited from
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.
Inherited from
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.
Inherited from
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
Inherited from
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
.
Inherited from
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
Inherited from
Defined in
isMouseOver()
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.
Overrides
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.
Inherited from
Defined in
moveEnd()
moveEnd(
deltaX
,deltaY
):void
Moves the end point of the line by the specified deltas along the x and y axes.
Parameters
• deltaX: number
= 0
The amount to move the end point along the x-axis.
• deltaY: number
= 0
The amount to move the end point along the y-axis.
Returns
void
Defined in
moveStart()
moveStart(
deltaX
,deltaY
):void
Moves the start point of the line by the specified deltas along the x and y axes.
Parameters
• deltaX: number
= 0
The amount to move the start point along the x-axis.
• deltaY: number
= 0
The amount to move the start point along the y-axis.
Returns
void
Defined in
removeObserver()
removeObserver(
observer
):void
Removes a previously added observer function.
Parameters
• observer
The observer callback function to be removed.
Returns
void
Inherited from
Defined in
render()
render(
context
):void
Renders the line on a canvas context.
Parameters
• context: CanvasRenderingContext2D
The canvas rendering context to draw the line.
Returns
void
Overrides
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
Inherited from
Defined in
toArray()
toArray():
any
[]
Converts the shape's definition to an array.
Returns
any
[]
An array representation of the shape's definition.
Inherited from
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.