Blockly.utils. svgMath
Utility methods realted to figuring out positions of SVG elements.
Methods
getDocumentScroll
getDocumentScroll() returns Blockly.utils.Coordinate
Gets the document scroll distance as a coordinate object. Copied from Closure's goog.dom.getDocumentScroll.
- Returns
-
non-null Blockly.utils.Coordinate
Object with values 'x' and 'y'.
getInjectionDivXY
getInjectionDivXY(element) returns Blockly.utils.Coordinate
Return the coordinates of the top-left corner of this element relative to the div Blockly was injected into.
Parameter |
|
---|---|
element |
Element SVG element to find the coordinates of. If this is not a child of the div Blockly was injected into, the behaviour is undefined. Value must not be null. |
- Returns
-
non-null Blockly.utils.Coordinate
Object with .x and .y properties.
getRelativeXY
getRelativeXY(element) returns Blockly.utils.Coordinate
Return the coordinates of the top-left corner of this element relative to its parent. Only for SVG elements and children (e.g. rect, g, path).
Parameter |
|
---|---|
element |
Element SVG element to find the coordinates of. Value must not be null. |
- Returns
-
non-null Blockly.utils.Coordinate
Object with .x and .y properties.
getViewportBBox
getViewportBBox() returns Blockly.utils.Rect
Get the position of the current viewport in window coordinates. This takes scroll into account.
- Returns
-
non-null Blockly.utils.Rect
An object containing window width, height, and scroll position in window coordinates.
is3dSupported
is3dSupported() returns boolean
Check if 3D transforms are supported by adding an element and attempting to set the property.
- Returns
-
boolean
True if 3D transforms are supported.
screenToWsCoordinates
screenToWsCoordinates(ws, screenCoordinates) returns Blockly.utils.Coordinate
Converts screen coordinates to workspace coordinates.
Parameter |
|
---|---|
ws |
The workspace to find the coordinates on. Value must not be null. |
screenCoordinates |
The screen coordinates to be converted to workspace coordinates Value must not be null. |
- Returns
-
non-null Blockly.utils.Coordinate
The workspace coordinates.
svgSize
svgSize(svg) returns Blockly.utils.Size
Returns the dimensions of the specified SVG image.
Parameter |
|
---|---|
svg |
SVGElement SVG image. Value must not be null. |
- Deprecated
- Use workspace.getCachedParentSvgSize. (2021 March 5)
- Returns
-
non-null Blockly.utils.Size
Contains width and height properties.