Skip to content

@feds01/graphika


@feds01/graphika / core/drawing

core/drawing

Classes

default

Defined in: core/drawing.ts:28

Utility class for drawing items on the canvas.

Constructors

Constructor
ts
new default(
   canvas, 
   context, 
   options): default;

Defined in: core/drawing.ts:29

Parameters
ParameterType
canvasHTMLCanvasElement
contextCanvasRenderingContext2D
optionsDrawerOptions
Returns

default

Accessors

ctx
Get Signature
ts
get ctx(): CanvasRenderingContext2D;

Defined in: core/drawing.ts:129

Returns

CanvasRenderingContext2D

height
Get Signature
ts
get height(): number;

Defined in: core/drawing.ts:125

Returns

number

width
Get Signature
ts
get width(): number;

Defined in: core/drawing.ts:121

Returns

number

Methods

_coordinateSafetyCheck()
ts
_coordinateSafetyCheck(x, y): void;

Defined in: core/drawing.ts:35

Parameters
ParameterType
xnumber
ynumber
Returns

void

circle()
ts
circle(
   x, 
   y, 
   rad): void;

Defined in: core/drawing.ts:40

Parameters
ParameterType
xnumber
ynumber
radnumber
Returns

void

horizontalLine()
ts
horizontalLine(
   x, 
   y, 
   len): void;

Defined in: core/drawing.ts:50

Parameters
ParameterType
xnumber
ynumber
lennumber
Returns

void

text()
ts
text(
   text, 
   x, 
   y, 
   size, 
   colour, 
   alignment): void;

Defined in: core/drawing.ts:109

Parameters
ParameterTypeDefault valueDescription
textstringundefinedthe actual label
xnumberundefinedx-coordinate of where to draw the string
ynumberundefinedx-coordinate of where to draw the string
sizenumberundefinedThe font size of the text
colourstringundefinedRGBA style colour string
alignmentCanvasTextAlign"center"One of the specified alignments for text
Returns

void

nothing, just changes the drawing context

Since

v0.0.1 Function to draw text on the canvas at a given location with a particular colour and alignment.

toTextMode()
ts
toTextMode(
   size, 
   colour, 
   alignment): void;

Defined in: core/drawing.ts:84

Parameters
ParameterTypeDefault valueDescription
sizenumberundefinedThe font size of the text
colourstringconfig.axisColourRGBA style colour string
alignmentCanvasTextAlign"center"One of the specified alignments for text
Returns

void

nothing, just changes the drawing context

Since

v0.0.1 This simply switches the canvas context to be text mode ready, set the font size and style, set text alignment to middle, and change stroke colour to the axis' colour.

verticalLine()
ts
verticalLine(
   x, 
   y, 
   len): void;

Defined in: core/drawing.ts:61

Parameters
ParameterType
xnumber
ynumber
lennumber
Returns

void

Type Aliases

CanvasTextAlign

ts
type CanvasTextAlign = "center" | "end" | "left" | "right" | "start";

Defined in: core/drawing.ts:23

Released under the ISC License.