Skip to main content

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​

Line

Throws​

InvalidConstructorArgumentsError if invalid arguments are passed.

Overrides​

Shape.constructor

Defined in​

shapes/Line.ts:22

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​

Line

Throws​

InvalidConstructorArgumentsError if invalid arguments are passed.

Overrides​

Shape<LineDefinition, LineStyle, LineOptions>.constructor

Defined in​

shapes/Line.ts:32

Properties​

_definition​

protected _definition: LineDefinition

The shape definition, proxied to trigger observer notifications on change.

Inherited from​

Shape._definition

Defined in​

shapes/Shape.ts:22


_options​

protected _options: LineOptions

The options for configuring the shape, proxied to trigger observer notifications on change.

Inherited from​

Shape._options

Defined in​

shapes/Shape.ts:28


_state​

protected _state: ShapeState = ShapeState.Default

The current state of the shape, representing its visual or interactive status.

Inherited from​

Shape._state

Defined in​

shapes/Shape.ts:31


_style​

protected _style: LineStyle

The style settings for the shape, proxied to trigger observer notifications on change.

Inherited from​

Shape._style

Defined in​

shapes/Shape.ts:25


observers​

protected observers: () => void[] = []

List of observer functions to be notified on shape changes.

Inherited from​

Shape.observers

Defined in​

shapes/Shape.ts:34

Accessors​

end​

Get Signature​

get end(): Point

Gets the ending point of the line.

Returns​

Point

The ending point of the line.

Set Signature​

set end(end): void

Sets the ending point of the line.

Parameters​

• end: Point

The new ending point of the line.

Returns​

void

Defined in​

shapes/Line.ts:90


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

Inherited from​

Shape.options

Defined in​

shapes/Shape.ts:220


start​

Get Signature​

get start(): Point

Gets the starting point of the line.

Returns​

Point

The starting point of the line.

Set Signature​

set start(start): void

Sets the starting point of the line.

Parameters​

• start: Point

The new starting point of the line.

Returns​

void

Defined in​

shapes/Line.ts:81


state​

Get Signature​

get state(): ShapeState

Gets the current state of the shape.

Returns​

ShapeState

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

Inherited from​

Shape.state

Defined in​

shapes/Shape.ts:238


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.

Inherited from​

Shape.stateStyle

Defined in​

shapes/Shape.ts:260


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

Inherited from​

Shape.style

Defined in​

shapes/Shape.ts:202

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​

Shape.addObserver

Defined in​

shapes/Shape.ts:171


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​

Shape.hasBorder

Defined in​

shapes/Shape.ts:297


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​

Shape.hide

Defined in​

shapes/Shape.ts:127


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.

Inherited from​

Shape.isDraggable

Defined in​

shapes/Shape.ts:147


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​

Shape.isMouseOver

Defined in​

shapes/Line.ts:170


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​

Shape.isVisible

Defined in​

shapes/Shape.ts:137


move()​

move(deltaX, deltaY): void

Moves the start & end point of the line by the specified deltas along the x and y axes.

Parameters​

• deltaX: number = 0

The amount to move the start & end point along the x-axis.

• deltaY: number = 0

The amount to move the start & end point along the y-axis.

Returns​

void

Defined in​

shapes/Line.ts:140


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​

shapes/Line.ts:130


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​

shapes/Line.ts:120


onDrag()​

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

Overrides​

Shape.onDrag

Defined in​

shapes/Line.ts:209


removeObserver()​

removeObserver(observer): void

Removes a previously added observer function.

Parameters​

• observer

The observer callback function to be removed.

Returns​

void

Inherited from​

Shape.removeObserver

Defined in​

shapes/Shape.ts:182


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​

Shape.render

Defined in​

shapes/Line.ts:150


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​

Shape.show

Defined in​

shapes/Shape.ts:118


toArray()​

toArray(): any[]

Converts the shape's definition to an array.

Returns​

any[]

An array representation of the shape's definition.

Inherited from​

Shape.toArray

Defined in​

shapes/Shape.ts:100


toJson()​

toJson(): string

Converts the shape's definition to a JSON string.

Returns​

string

A JSON string representation of the shape's definition.

Inherited from​

Shape.toJson

Defined in​

shapes/Shape.ts:109