Line

Line

A Line is a line segment from its start point to end point, stored as x1, y1, and x2, y2 respectively.

Constructor

new Line(x1, y1, x2, y2)

Source:
Parameters:
Name Type Description
x1 number x coordinate of starting point of line.
y1 number y coordinate of starting point of line.
x2 number x coordinate of end point of line.
y2 number y coordinate of end point of line.

Extends

Members

layer

Source:
Overrides:
Sets the layer of the Thing and marks the sortInvalidated flag so any Graphics instances drawing it know to re-sort.

Methods

containsPoint(x, y)

Source:
Overrides:
Checks if a given point is contained in the line.
Parameters:
Name Type Description
x number x coordinate of the point being tested.
y number y coordinate of the point being tested.

describe()

Source:
Overrides:
Describes the element for use with screen readers. This isn't something you should need to call manually, but you can if you'd like to print a text descriptino of the Thing.

focus()

Source:
Overrides:
Focuses the element for use with screen readers. This isn't something you should need to call manually, but you can if you'd like to provide focus to an element even if it wasn't navigated to with the keyboard.

getAnchor() → {Object}

Source:
Overrides:
Gets the element's anchor.
Returns:
Type
Object

getBorderColor() → {Color}

Source:
Overrides:
Gets the border color of a Thing.
Example
// this method is on every Shape
let thing = new Thing();
thing.getBorderColor();
Returns:
The color of the Thing's border.
Type
Color

getBorderWidth() → {number}

Source:
Overrides:
Gets the width of the Thing's border.
Example
// this method is on every Shape
let thing = new Thing();
thing.getBorderWidth();
Returns:
The width of the Thing's border.
Type
number

getBounds() → {Object}

Source:
Overrides:
Get the elements bounds. This is an internal property that you shouldn't need to use, but it can be useful for doing quick calculations for the bounding box of a shape.
Example
// this method is on every Shape
let thing = new Thing();
let height = thing.getBounds().bottom - this.getBounds().top;
Returns:
Type
Object

getColor() → {Color}

Source:
Overrides:
Gets the color of a line.
Returns:
Color of the line.
Type
Color

getEndX() → {number}

Source:
Gets the x coordinate of the Line's end point.
Returns:
The x coordinate of the Line's end point.
Type
number

getEndY() → {number}

Source:
Gets the y coordinate of the Line's end point.
Returns:
The y coordinate of the Line's end point.
Type
number

getHeight() → {number}

Source:
Returns the height of the line.
Returns:
The width of the line.
Type
number

getStartX() → {number}

Source:
Gets the x coordinate of the Line's start point.
Returns:
The x coordinate of the Line's start point.
Type
number

getStartY() → {number}

Source:
Gets the y coordinate of the Line's start point.
Returns:
The y coordinate of the Line's start point.
Type
number

getType() → {string}

Source:
Overrides:
Get the .type of the Thing
Returns:
Type
string

getWidth() → {number}

Source:
Returns the width of the line.
Returns:
The width of the line.
Type
number

getX() → {number}

Source:
Overrides:
Gets the x coordinate of the Line's start point.
Returns:
The x coordinate of the Line's start point.
Type
number

getY() → {number}

Source:
Overrides:
Gets the y coordinate of the Line's start point.
Returns:
The y coordinate of the Line's start point.
Type
number

hasBorder() → {boolean}

Source:
Overrides:
Returns if a Thing has a border.
Example
// this method is on every Shape
let thing = new Thing();
thing.hasBorder();
Returns:
True if the Thing has a border.
Type
boolean

isFilled() → {boolean}

Source:
Overrides:
Returns if a Thing is filled.
Example
// this method is on every Shape
let thing = new Thing();
thing.isFilled();
Returns:
True if the Thing is filled.
Type
boolean

move(dx, dy)

Source:
Overrides:
Moves the entire line.
Parameters:
Name Type Description
dx number The change in x coordinate of both starting and ending points.
dy number The change in y coordinate of both starting and ending points.

rotate(degrees, angleUnit)

Source:
Overrides:
Rotates a Thing an additional amount of degrees.
Example
// this method is on every Shape
let thing = new Thing();
thing.rotate(90);
thing.rotate(Math.PI / 2, Thing.RADIANS);
Parameters:
Name Type Description
degrees number The degrees to rotate degrees.
angleUnit number Whether it is degrees or radians. Defaults to degrees.

setAnchor(anchor)

Source:
Overrides:
Sets the Anchor for the object. This alters how the shape will draw relative to its position. An anchor of 0, 0 will cause the shape to draw with its position at its top left corner. An anchor of 1, 1 will cause the shape to draw with its position at its bottom right corner.
Example
// this method is on every Shape
let thing = new Thing();
// center the object around its position
thing.setPosition({vertical: 0.5, horizontal: 0.5});
Parameters:
Name Type Description
anchor Object

setBorder(hasBorder)

Source:
Overrides:
Sets a Thing object to filled. Throws an error if an argument is not passed.
Example
// this method is on every Shape
let thing = new Thing();
thing.setBorder(true);
Parameters:
Name Type Description
hasBorder bool A boolean of whether or not Thing has a border.

setBorderColor(color)

Source:
Overrides:
Sets the border color of a Thing. Throws an error if there are fewer than 1 params or if the param is undefined. This will automatically give the Thing a border, as if you had called thing.setBorder(true);
Example
// this method is on every Shape
let thing = new Thing();
thing.setBorderColor('orange');
Parameters:
Name Type Description
color Color The resulting color of the Thing's border.

setBorderWidth(width)

Source:
Overrides:
Sets the width of a Thing's border. Throws an error if there is not 1 argument. This will automatically set the Thing to draw with a border, as if you had called thing.setBorder(true);
Example
// this method is on every Shape
let thing = new Thing();
thing.setBorderWidth(5);
Parameters:
Name Type Description
width number The resulting width of the Thing's border.

setColor(color)

Source:
Overrides:
Sets the color of a line.
Parameters:
Name Type Description
color Color Sets the color of the line.

setEndpoint(x, y)

Source:
Sets the *ending* point of the line.
Parameters:
Name Type Description
x number The x coordinate of the resulting ending point.
y number The y coordinate of the resulting ending point.

setFilled(filled)

Source:
Overrides:
Sets a Thing object to filled. Throws an error if an argument is not passed.
Example
// this method is on every Shape
let thing = new Thing();
thing.setFilled(false);
Parameters:
Name Type Description
filled bool A boolean of whether or not Thing is filled.

setLineWidth(width)

Source:
Sets the width of the line.
Parameters:
Name Type Description
width number The resulting width of the line.

setOpacity(opacity)

Source:
Overrides:
Set the opacity of the Thing.
Example
// this method is on every Shape
let thing = new Thing();
thing.setOpacity(0.5);
Parameters:
Name Type Description
opacity number

setPosition(x, y)

Source:
Overrides:
Sets the *starting* point of the line.
Parameters:
Name Type Description
x number The x coordinate of the resulting starting point.
y number The y coordinate of the resulting starting point.

setRotation(degrees, angleUnit)

Source:
Overrides:
Sets the rotation of a Thing in degrees. Throws an error if there are fewer than 1 params or if they are not numbers.
Example
// this method is on every Shape
let thing = new Thing();
thing.setRotation(90);
thing.setRotation(Math.PI / 2, Thing.RADIANS);
Parameters:
Name Type Description
degrees number The degrees to rotate degrees.
angleUnit number Whether it is degrees or radians. Defaults to degrees.

setStartpoint(x, y)

Source:
Sets the *starting* point of the line.
Parameters:
Name Type Description
x number The x coordinate of the resulting ending point.
y number The y coordinate of the resulting ending point.

setType(type)

Source:
Overrides:
Set the .type of the Thing
Parameters:
Name Type Description
type string new type

unfocus()

Source:
Overrides:
Unfocuses the element for use with screen readers. This isn't something you should need to call manually, but you can if you'd like to unfocus to an element even if it wasn't navigated from with the keyboard.