Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>There is a method for retrieving the bounding box of an element with and without transformation.</p> <p>With transformation:</p> <pre><code>var bbox = image.getBBox(), width = bbox.width, height = bbox.height; </code></pre> <p>Without transformation:</p> <pre><code>var bbox = image.getBBoxWOTransform(), width = bbox.width, height = bbox.height; </code></pre> <hr> <p>You can extend Raphael.el with helper methods (if you are careful) that provide the width and height directly if this helps you. You could just use the bounding box method and return the portion that you're interested in, but to be a bit more efficient I have calculated only the requested property using the matrix property on the elements and the position/width/height from attributes.</p> <pre><code>(function (r) { function getX() { var posX = this.attr("x") || 0, posY = this.attr("y") || 0; return this.matrix.x(posX, posY); } function getY() { var posX = this.attr("x") || 0, posY = this.attr("y") || 0; return this.matrix.y(posX, posY); } function getWidth() { var posX = this.attr("x") || 0, posY = this.attr("y") || 0, maxX = posX + (this.attr("width") || 0), maxY = posY + (this.attr("height") || 0), m = this.matrix, x = [ m.x(posX, posY), m.x(maxX, posY), m.x(maxX, maxY), m.x(posX, maxY) ]; return Math.max.apply(Math, x) - Math.min.apply(Math, x); } function getHeight() { var posX = this.attr("x") || 0, posY = this.attr("y") || 0, maxX = posX + (this.attr("width") || 0), maxY = posY + (this.attr("height") || 0), m = this.matrix, y = [ m.y(posX, posY), m.y(maxX, posY), m.y(maxX, maxY), m.y(posX, maxY) ]; return Math.max.apply(Math, y) - Math.min.apply(Math, y); } r.getX = getX; r.getY = getY; r.getWidth = getWidth; r.getHeight = getHeight; }(Raphael.el)) </code></pre> <p>With usage:</p> <pre><code>var x = image.getX(); var y = image.getY(); var width = image.getWidth(); var height = image.getHeight(); </code></pre> <p>Just include the script after you include Raphael. Note that it only works for elements with a width, height, x and y attributes, which is suitable for images. Raphael actually computes the bounding box from the path data, which transforms all of the points in the path and gets the min/max x/y values after transforming them.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload