Constructor
new Rectangle(strokeopt, backgroundopt, opacityopt, xopt, yopt, widthopt, heightopt)
Creates an instance of Rectangle shape.
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
stroke | Stroke | <optional> | A border of the shape. | |
background | string | <optional> | Color, gradient, or image background, similar to CSS. Use an empty string to remove the background. | |
opacity | number | <optional> | 1 | Opacity of the shape (0 to 1). |
x | number | <optional> | 0 | Horizontal position from the left edge. |
y | number | <optional> | 0 | Vertical position from the top edge. |
width | number | <optional> | 100 | Width of the ellipse (horizontal diameter). |
height | number | <optional> | Height of the ellipse (vertical diameter). If omitted, height will be same as width. |
- See
Classes
Methods
cornerArc(width, heightopt) → {Object|Rectangle}
Sets corner radius if only one argument passed, or arc width and height if two arguments or size object supplied. The arc size is applied to all corners.
This a way to create all rounded corners with arc of same or different width and height. If you want to specify corner radius for specific corners, use Rectangle#cornerRadius method: cornerRadius(...).
| Name | Type | Attributes | Description |
|---|---|---|---|
width | number | | Width of the corner arc, or a size object (e.g., {width:300,height:300}). | |
height | number | <optional> | Height of the corner arc. |
If called without parameters, current arc size is returned; otherwise this Rectangle object is returned.
- Type:
- Object |
Rectangle
<h2>Valid ways to set arc size:</h2>
rectangle.cornerArc(radius);
rectangle.cornerArc(width,height);
rectangle.cornerArc({width:5,height:10});cornerRadius(topLeft_or_all, topRight, bottomRight, bottomLeft) → {Object|Rectangle}
Sets or gets a corner radius for each corner separately or for all corners at once.
This method sets same width and height of the arc. If you need to set arc with different width and height, you can use Rectangle#cornerArc method: cornerArc(...).
| Name | Type | Description |
|---|---|---|
topLeft_or_all | number | | Radius for top-left corner, a |
topRight | number | | Radius for top-right corner. If omitted, it defaults to topLeft corner. |
bottomRight | number | | Radius for bottom-right corner. If omitted, it defaults to topRight corner. |
bottomLeft | number | | Radius for bottom-left corner. If omitted, it defaults to bottomRight corner. |
If called without parameters or topLeft is undefined, current corner radius object is returned. If called with arguments, this Rectangle shape is returned for chaining.
- Type:
- Object |
Rectangle
<h2>3 ways to set radius for each corner separately:</h2>
rectangle.cornerRadius(10, 10, 0, 0); // as separate parameters
rectangle.cornerRadius("10 10 0 0"); // in a string (CSS style)
rectangle.cornerRadius({tl:10, tr:10, br:0, bl:0}); // In same object format as this method returns<h2>Setting radius for all corners at once:</h2>
rectangle.cornerRadius(10);size(width, heightopt) → {Object|Rectangle}
Sets or gets the size of the Rectangle.
| Name | Type | Attributes | Description |
|---|---|---|---|
width | number | | Width of the Rectangle, or a size object (e.g., {width:300,height:300}). | |
height | number | <optional> | Height of the Rectangle. |
If called without parameters, current size is returned; otherwise this Rectangle object is returned.
- Type:
- Object |
Rectangle
toObject(includeopt) → {object}
Returns a JSON object that contains this shape properties. It may be converted back to this shape.
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
include | string | <optional> | "all" | Specified what to include. "all" is default. Valid values are: "all", "stroke", "background", "points", "basic". |
Returns an object containing this shape's properties.
- Type:
- object