How is the getBBox() SVGRect calculated?

后端 未结 7 1639
再見小時候
再見小時候 2020-12-04 15:29

I have a g element that contains one or more path elements. As I mentioned in another question, I scale and translate the g element by

7条回答
  •  无人及你
    2020-12-04 16:09

    SVG groups have nasty practice - not to accumulate all transformations made. I have my way to cope with this issue. I'm using my own attributes to store current transformation data which I include in any further transformation. Use XML compatible attributes like alttext, value, name....or just x and y for storing accumulated value as atribute.

    Example:

    
    
    

    Therefore when I'm making transformations I'm taking those handmade attribute values, and when writing it back, I'm writing both transform and same value with attributes I made just for keeping all accumulated values.

    Example for rotation:

    function symbRot(evt) {
    
      evt.target.ondblclick = function () {
    
        stopBlur();
        var ptx=symbG.parentNode.lastChild.getAttribute("cx");
        var pty=symbG.parentNode.lastChild.getAttribute("cy");
        var currRot=symbG.getAttributeNS(null, "alttext");
    
        var rotAng;
        if (currRot == 0) {
          rotAng = 90
        } else if (currRot == 90) {
          rotAng = 180
        } else if (currRot == 180) {
          rotAng = 270
        } else if (currRot == 270) {
          rotAng = 0
        };
        symbG.setAttributeNS(null, "transform", "rotate(" + rotAng + "," + ptx + ", " + pty + ")");
        symbG.setAttributeNS(null, "alttext", rotAng );
      };
    }
    

提交回复
热议问题