1

In d3 4.9.1 if I make call to get transform of element that has style like this:

<g style="transform: translateX(3.84559px);"></g>

Operation:

d3.select(this).style("transform")

Output in d3v4.9.1 :

translateX(3.84559px)

But in d3v4.8.0 it has different output:

matrix(1, 0, 0, 1, 3.84559, 0)

Is there any change in this new version that is causing this issue?

I was having function to find different parameters of transform property, which is now broken:

contents.getTransformation = function (transform) {
    // console.log(transform);
    var g = document.createElementNS("http://www.w3.org/2000/svg", "g");
    g.setAttributeNS(null, "transform", transform);
    var matrix = g.transform.baseVal.consolidate().matrix;
    var a = matrix.a;
    var b = matrix.b;
    var c = matrix.c;
    var d = matrix.d;
    var e = matrix.e;
    var f = matrix.f;
    var scaleX = Math.sqrt(a * a + b * b);
    var scaleY = Math.sqrt(c * c + d * d);
    var skewX = a * c + b * d;
    if (scaleX) {
        a /= scaleX;
        b /= scaleX;
    }
    if (skewX) {
        c -= a * skewX;
        d -= b * skewX;
    }
    if (scaleY) {
        c /= scaleY;
        d /= scaleY;
        skewX /= scaleY;
    }
    if (a * d < b * c) {
        a = -a;
        b = -b;
        skewX = -skewX;
        scaleX = -scaleX;
    }
    return {
        translateX: e,
        translateY: f,
        rotate: Math.atan2(b, a) * Math.PI / 180,
        skewX: Math.atan(skewX) * Math.PI / 180,
        scaleX: scaleX,
        scaleY: scaleY
    };
};

Ref: Replacing d3.transform in D3 v4

Shashwat Tripathi
  • 572
  • 1
  • 5
  • 19

1 Answers1

3

The release notes of v4.9.0 have it:

Change selection.style to return the inline style, if present.

Since you specified an inline style on your <g> this value will be returned when using version v4.9.1. Prior versions always returned the computed style.

altocumulus
  • 21,179
  • 13
  • 61
  • 84