Top
You are looking at an outdated 7.14.0 version of this document. Switch to the 7.14.3 version to see the up to date information.

class anychart.graphics.vector.Shape Improve this Doc

Extends: anychart.graphics.vector.Element

Base class for all vector elements.
Never invoke constructor directly!

Methods Overview

Coloring
fill()Fill settings.
stroke()Stroke settings.
Events
listen()Adds an event listener.
listenOnce()Adds an event listener that is removed automatically after the listener fired once.
removeAllListeners()Removes all listeners from this listenable.
unlisten()Removes an event listener which was added with listen() or listenOnce().
Interactive
drag()Dragging setting.
Interactivity
visible()Visibility flag
Size and Position
appendTransformationMatrix()Combines the current transformation with the given transformation matrix.
getAbsoluteBounds()Gets element bounds in absolute coordinates (root element coordinate system).
getAbsoluteHeight()Returns height within root bounds.
getAbsoluteWidth()Returns width within root bounds.
getAbsoluteX()Returns an absolute X (root element coordinate system).
getAbsoluteY()Returns an absolute Y (root element coordinate system).
getBounds()Returns the bounds.
getHeight()Returns the height.
getRotationAngle()Returns the current rotation angle in degrees.
getTransformationMatrix()Returns the current transformation matrix.
getWidth()Returns the width.
getX()Returns X in the coordinate system of the parent.
getY()Returns Y in the coordinate system of the parent.
rotate()Rotates a shape around the given rotation point.
rotateByAnchor()Rotates a shape around the given anchor.
scale()Scales a shape. Scaling center is set in the coordinate system of the parent.
scaleByAnchor()Scales a shape by anchor. Scaling center is set as an anchor.
setPosition()Sets top left corner of a shape (transformation taken into account) in the coordinate system of the parent.
setRotation()Rotates a shape around the given point.
setRotationByAnchor()Rotates a shape around the given anchor.
setTransformationMatrix()Sets the transformation matrix.
translate()Moves a shape taking an account the current transformation.
zIndex()Z-index setting.
Miscellaneous
attr()Attribute setting
clip()Clipping setting.
cursor()Cursor type.
desc()Description setting
disablePointerEvents()Pointer events setting.
disableStrokeScaling()Vector effect property
dispose()Disposes element completely.
domElement()Returns DOM element if element is rendered.
getStage()Stage object (to which the given element is bound).
hasParent()Whether parent element is set.
id()Element identifier
parent()Parent layer.
remove()Current element removes itself from the parent layer.
strokeThickness()Stroke thickness setting.
title()Title setting

Methods Description

appendTransformationMatrix

Combines the current transformation with the given transformation matrix.

Params:

Name Type Description
m00 number Scale X.
m10 number Shear Y.
m01 number Shear X.
m11 number Scale Y.
m02 number Translate X.
m12 number Translate Y.

Returns:

anychart.graphics.vector.Element - Self instance for method chaining.

Try it:

attr

Getter for the attribute.

Params:

Name Type Description
key string Name of attribute.

Returns:

* - Attribute value.

Try it:

Setter for the attribute.

Params:

Name Type Description
key string Name of attribute.
value * Value of attribute.

Returns:

anychart.graphics.vector.Element - Self instance for method chaining.

Try it:

clip

Gets the current clipping rectangle.

Returns:

anychart.graphics.math.Rect - An instance of the class for method chaining.
Sets the clipping rectangle.

Params:

Name Type Description
value anychart.graphics.math.Rect | string Clipping rectangle.

Returns:

anychart.graphics.vector.Element - Self instance for method chaining.

Try it:

cursor

Getter for the current cursor type.

Returns:

anychart.graphics.vector.Cursor - Current cursor type.

Try it:

Setter for the cursor type.

Params:

Name Type Default Description
value anychart.graphics.vector.Cursor
null
Cursor type.

Returns:

anychart.graphics.vector.Element - Self instance for method chaining.

Try it:

desc

Getter for the element description value.

Returns:

string null undefined - The element description value.

Try it:

Setter for the element description value.

Params:

Name Type Description
value string | null Value to set.

Returns:

anychart.graphics.vector.Element - Self instance for method chaining.

Try it:

disablePointerEvents

Gets the current value of the pointer events.

Returns:

boolean - Returns property value.

Try it:

Disables the pointer events.

Params:

Name Type Default Description
value boolean
false
Pointer events property value.

Returns:

anychart.graphics.vector.Element - Self instance for method chaining.

Try it:

disableStrokeScaling

Getter for the current element's vector effect property.

Returns:

boolean - The current vector effect property.
See listing
var element = stage.rect(10, 10, 100, 40);
element.disableStrokeScaling();
Setter for the element's vector effect property.
Learn more by link.

Params:

Name Type Default Description
value boolean
false
Vector effect property to set.

Returns:

anychart.graphics.vector.Element - Self instance for method chaining.

Try it:

dispose

Disposes element completely. Removes it from the parent layer, sets links to null, removes it from DOM.

Try it:

domElement

Returns DOM element if element is rendered.
In case of Stage in Suspended state or unbound element – null is returned.

Returns:

Element - DOM element.

drag

Returns the current state flag.

Returns:

boolean anychart.graphics.math.Rect - Absolute element bounds or flag.

Try it:

Turns off/on dragging (moving) of an element.

Params:

Name Type Default Description
value boolean | anychart.graphics.math.Rect
false
Flag or a dragging area.

Returns:

anychart.graphics.vector.Element - Self instance for method chaining.

Try it:

fill

Gets the current fill.

Returns:

anychart.graphics.vector.Fill - The current fill (empty fill is 'none").

Try it:

Sets a fill as an object or a string.

Params:

Name Type Description
value anychart.graphics.vector.Fill Fill as object or string.

Returns:

anychart.graphics.vector.Shape - Self instance for method chaining.
Sets a fill with opacity.

Params:

Name Type Description
color string Color as string.
opacity number Opacity.

Returns:

anychart.graphics.vector.Shape - Self instance for method chaining.

Try it:

Linear gradient fill.

Params:

Name Type Description
keys Array.<(anychart.graphics.vector.GradientKey|string)> Gradient keys.
angle number Gradient angle.
mode boolean | anychart.graphics.vector.Rect | Object Gradient mode.
opacity number Gradient opacity.

Returns:

anychart.graphics.vector.Shape - Self instance for method chaining.

Try it:

Radial gradient fill.

Params:

Name Type Description
keys Array.<(anychart.graphics.vector.GradientKey|string)> Color-stop gradient keys.
cx number X ratio of center radial gradient.
cy number Y ratio of center radial gradient.
mode anychart.graphics.math.Rect If defined then userSpaceOnUse mode else objectBoundingBox.
opacity number Opacity of the gradient.
fx number X ratio of focal point.
fy number Y ratio of focal point.

Returns:

anychart.graphics.vector.Shape - Self instance for method chaining.

Try it:

getAbsoluteBounds

Gets element bounds in absolute coordinates (root element coordinate system).

Returns:

anychart.graphics.math.Rect - Absolute element bounds.

Try it:

getAbsoluteHeight

Returns height within root bounds.
See illustrations at anychart.graphics.vector.Element#getAbsoluteWidth

Returns:

number - Height.

Try it:

getAbsoluteWidth

Returns width within root bounds.

Returns:

number - Width.

Try it:

getAbsoluteX

Returns an absolute X (root element coordinate system).

Returns:

number - Absolute X.

Try it:

getAbsoluteY

Returns an absolute Y (root element coordinate system).

Returns:

number - Absolute Y.

Try it:

getBounds

Returns the bounds.

Returns:

anychart.graphics.math.Rect - Bounds.

Try it:

getHeight

Returns the height.

Returns:

number - Height.

Try it:

getRotationAngle

Returns the current rotation angle in degrees.

Returns:

number - Rotation angle.

Try it:

getStage

Stage object (to which the given element is bound).

Returns:

anychart.graphics.vector.Stage - Stage object.

Try it:

getTransformationMatrix

Returns the current transformation matrix.

Returns:

Array.<number> - Transformation matrix array.

Try it:

getWidth

Returns the width.

Returns:

number - Width.

Try it:

getX

Returns X in the coordinate system of the parent.

Returns:

number - X in the coordinate system of the parent.

Try it:

getY

Returns Y in the coordinate system of the parent.

Returns:

number - Y in the coordinate system of the parent.

Try it:

hasParent

Whether parent element is set.

Returns:

boolean - Whether parent element is set.

Try it:

id

Gets the current element identifier.

Returns:

string - Returns element identifier.

Try it:

Sets the element identifier.

Params:

Name Type Description
value string Custom identifier.

Returns:

anychart.graphics.vector.Element - Self instance for method chaining.

Try it:

listen

Adds an event listener.

Params:

Name Type Default Description
type string
The event type id.
listener function
Callback method.
useCapture boolean
false
Whether to fire in capture phase. Learn more about capturing https://javascript.info/bubbling-and-capturing
listenerScope Object
Object in whose scope to call the listener.

Returns:

Object - Unique key for the listener.

Try it:

listenOnce

Adds an event listener that is removed automatically after the listener fired once.

Params:

Name Type Default Description
type string
The event type id.
listener function
Callback method.
useCapture boolean
false
Whether to fire in capture phase. Learn more about capturing https://javascript.info/bubbling-and-capturing
listenerScope Object
Object in whose scope to call the listener.

Returns:

Object - Unique key for the listener.

Try it:

parent

Returns the parent layer.

Returns:

anychart.graphics.vector.Layer anychart.graphics.vector.Stage - Instance of element current layer.

Try it:

Adds element to the given layer.

Params:

Name Type Description
value anychart.graphics.vector.Layer | anychart.graphics.vector.Stage Parent layer.

Returns:

anychart.graphics.vector.Element - Self instance for method chaining.

Try it:

remove

Current element removes itself from the parent layer.

Returns:

anychart.graphics.vector.Element - Self instance for method chaining.

Try it:

removeAllListeners

Removes all listeners from this listenable.

Params:

Name Type Description
type string Type of event to remove, default is to remove all types.

Returns:

number - Number of listeners removed.

Try it:

rotate

Rotates a shape around the given rotation point.

Params:

Name Type Description
degrees number Rotation angle in degrees.
cx number Rotation point X.
cy number Rotation point Y.

Returns:

anychart.graphics.vector.Element - Self instance for method chaining.

Try it:

rotateByAnchor

Rotates a shape around the given anchor.

Params:

Name Type Description
degrees number Rotation angle in degrees.
anchor anychart.graphics.vector.Anchor | string Rotation anchor.

Returns:

anychart.graphics.vector.Element - Self instance for method chaining.

Try it:

scale

Scales a shape. Scaling center is set in the coordinate system of the parent.

Params:

Name Type Description
sx number X scaling factor.
sy number Y scaling factor.
cx number Scaling point X.
cy number Scaling point Y.

Returns:

anychart.graphics.vector.Element - Self instance for method chaining.

Try it:

scaleByAnchor

Scales a shape by anchor. Scaling center is set as an anchor.

Params:

Name Type Description
sx number X scaling factor.
sy number Y scaling factor.
anchor anychart.graphics.vector.Anchor | string Scaling anchor point.

Returns:

anychart.graphics.vector.Element - Self instance for method chaining.

Try it:

setPosition

Sets top left corner of a shape (transformation taken into account) in the coordinate system of the parent.

Params:

Name Type Description
x number X coordinate.
y number Y coordinate.

Returns:

anychart.graphics.vector.Element - Self instance for method chaining.

Try it:

setRotation

Rotates a shape around the given point.

Params:

Name Type Description
degrees number Rotation angle in degrees.
cx number Rotation point X.
cy number Rotation point Y.

Returns:

anychart.graphics.vector.Element - Self instance for method chaining.

Try it:

setRotationByAnchor

Rotates a shape around the given anchor.

Params:

Name Type Description
degrees number Rotation angle in degrees.
anchor anychart.graphics.vector.Anchor | string Rotation anchor.

Returns:

anychart.graphics.vector.Element - Self instance for method chaining.

Try it:

setTransformationMatrix

Sets the transformation matrix.

Params:

Name Type Description
m00 number Scale X.
m10 number Shear Y.
m01 number Shear X.
m11 number Scale Y.
m02 number Translate X.
m12 number Translate Y.

Returns:

anychart.graphics.vector.Element - Self instance for method chaining.

Try it:

stroke

Gets the current stroke.

Returns:

anychart.graphics.vector.Stroke - The current stroke.

Try it:

Sets a stroke using one parameter.

Params:

Name Type Description
value anychart.graphics.vector.Stroke | anychart.graphics.vector.ColoredFill | string | null Stroke as '[thickness ]color[ opacity]'. return {anychart.graphics.vector.Shape} Self instance for method chaining.
Sets stroke settings using several parameter.

Params:

Name Type Description
value anychart.graphics.vector.Stroke | anychart.graphics.vector.ColoredFill | string Stroke style, as described above.
thickness number Line thickness. Defaults to 1.
dashpattern string Controls the pattern of dashes and gaps used to stroke paths. Dash array contains a list of white space separated lengths and percentages that specify the lengths of alternating dashes and gaps. If an odd number of values is provided, then the list of values is repeated to yield an even number of values. Thus, stroke dashpattern: "5 3 2" is equivalent to dashpattern: "5 3 2 5 3 2".
lineJoin anychart.graphics.vector.StrokeLineJoin Line join style.
lineCap anychart.graphics.vector.StrokeLineCap Line cap style.

Returns:

anychart.graphics.vector.Shape - Self instance for method chaining.

Try it:

strokeThickness

Gets the current stroke thickness.

Returns:

number - Thickness value.

Try it:

Sets a stroke thickness.

Params:

Name Type Description
value number Thickness value.

Returns:

anychart.graphics.vector.Shape - Self instance for method chaining.

Try it:

title

Getter for the element title value.

Returns:

string null undefined - The element title value.

Try it:

Setter for the element title value.

Params:

Name Type Description
value string | null Value to set.

Returns:

anychart.graphics.vector.Element - Self instance for method chaining.

Try it:

translate

Moves a shape taking an account the current transformation.

Params:

Name Type Description
tx number X movement amount.
ty number Y movement amount.

Returns:

anychart.graphics.vector.Element - Self instance for method chaining.

Try it:

unlisten

Removes an event listener which was added with listen() or listenOnce().

Params:

Name Type Default Description
type string
The event type id.
listener function
Callback method.
useCapture boolean
false
Whether to fire in capture phase. Learn more about capturing https://javascript.info/bubbling-and-capturing
listenerScope Object
Object in whose scope to call the listener.

Returns:

boolean - Whether any listener was removed.

Try it:

visible

Gets the current visibility flag.

Returns:

boolean - Returns the current visibility flag.

Try it:

Hides or shows an element.

Params:

Name Type Default Description
isVisible boolean
true
Visibility flag.

Returns:

anychart.graphics.vector.Element - Self instance for method chaining.

Try it:

zIndex

Gets the current element's zIndex.

Returns:

number - Z-index.

Try it:

Sets the element's zIndex.

Params:

Name Type Description
value number Z-index to set.

Returns:

anychart.graphics.vector.Element - Self instance for method chaining.

Try it: