Sha256: 66357a6d4fd6902b01d0b9718e5664c46fa662d586de10cf6377f339f00cf6b1

Contents?: true

Size: 1.59 KB

Versions: 25

Compression:

Stored size: 1.59 KB

Contents

d3.transform = function(string) {
  d3_transformG.setAttribute("transform", string);
  var t = d3_transformG.transform.baseVal.consolidate();
  return new d3_transform(t ? t.matrix : d3_transformIdentity);
};

// Compute x-scale and normalize the first row.
// Compute shear and make second row orthogonal to first.
// Compute y-scale and normalize the second row.
// Finally, compute the rotation.
function d3_transform(m) {
  var r0 = [m.a, m.b],
      r1 = [m.c, m.d],
      kx = d3_transformNormalize(r0),
      kz = d3_transformDot(r0, r1),
      ky = d3_transformNormalize(d3_transformCombine(r1, r0, -kz)) || 0;
  if (r0[0] * r1[1] < r1[0] * r0[1]) {
    r0[0] *= -1;
    r0[1] *= -1;
    kx *= -1;
    kz *= -1;
  }
  this.rotate = (kx ? Math.atan2(r0[1], r0[0]) : Math.atan2(-r1[0], r1[1])) * d3_transformDegrees;
  this.translate = [m.e, m.f];
  this.scale = [kx, ky];
  this.skew = ky ? Math.atan2(kz, ky) * d3_transformDegrees : 0;
};

d3_transform.prototype.toString = function() {
  return "translate(" + this.translate
      + ")rotate(" + this.rotate
      + ")skewX(" + this.skew
      + ")scale(" + this.scale
      + ")";
};

function d3_transformDot(a, b) {
  return a[0] * b[0] + a[1] * b[1];
}

function d3_transformNormalize(a) {
  var k = Math.sqrt(d3_transformDot(a, a));
  if (k) {
    a[0] /= k;
    a[1] /= k;
  }
  return k;
}

function d3_transformCombine(a, b, k) {
  a[0] += k * b[0];
  a[1] += k * b[1];
  return a;
}

var d3_transformG = document.createElementNS(d3.ns.prefix.svg, "g"),
    d3_transformIdentity = {a: 1, b: 0, c: 0, d: 1, e: 0, f: 0},
    d3_transformDegrees = 180 / Math.PI;

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
picky-statistics-4.5.0 lib/picky-statistics/application/javascripts/d3/src/core/transform.js
picky-statistics-4.4.2 lib/picky-statistics/application/javascripts/d3/src/core/transform.js
picky-statistics-4.4.1 lib/picky-statistics/application/javascripts/d3/src/core/transform.js
picky-statistics-4.4.0 lib/picky-statistics/application/javascripts/d3/src/core/transform.js
picky-statistics-4.3.2 lib/picky-statistics/application/javascripts/d3/src/core/transform.js
picky-statistics-4.3.1 lib/picky-statistics/application/javascripts/d3/src/core/transform.js
picky-statistics-4.3.0 lib/picky-statistics/application/javascripts/d3/src/core/transform.js
picky-statistics-4.2.4 lib/picky-statistics/application/javascripts/d3/src/core/transform.js
picky-statistics-4.2.3 lib/picky-statistics/application/javascripts/d3/src/core/transform.js
picky-statistics-4.2.2 lib/picky-statistics/application/javascripts/d3/src/core/transform.js
picky-statistics-4.2.1 lib/picky-statistics/application/javascripts/d3/src/core/transform.js
picky-statistics-4.2.0 lib/picky-statistics/application/javascripts/d3/src/core/transform.js
picky-statistics-4.1.0 lib/picky-statistics/application/javascripts/d3/src/core/transform.js
picky-statistics-4.0.9 lib/picky-statistics/application/javascripts/d3/src/core/transform.js
picky-statistics-4.0.8 lib/picky-statistics/application/javascripts/d3/src/core/transform.js
picky-statistics-4.0.7 lib/picky-statistics/application/javascripts/d3/src/core/transform.js
picky-statistics-4.0.6 lib/picky-statistics/application/javascripts/d3/src/core/transform.js
picky-statistics-4.0.5 lib/picky-statistics/application/javascripts/d3/src/core/transform.js
picky-statistics-4.0.4 lib/picky-statistics/application/javascripts/d3/src/core/transform.js
picky-statistics-4.0.3 lib/picky-statistics/application/javascripts/d3/src/core/transform.js