~ubuntu-branches/ubuntu/precise/whoopsie-daisy/precise-proposed

« back to all changes in this revision

Viewing changes to backend/stats/static/js/d3/src/core/transform.js

  • Committer: Package Import Robot
  • Author(s): Evan Dandrea
  • Date: 2012-04-10 14:28:58 UTC
  • Revision ID: package-import@ubuntu.com-20120410142858-nk453o1z7t7py3bs
Tags: 0.1.26
* Take ownership of the NetworkManager state variant on setup and
  unref it, plugging a memory leak.
* Log the reason the server rejected the submitted crash report.
* Send the Whoopsie version with each crash submission.
* Delete both .upload and .uploaded files after 14 days. Thanks
  Marc Deslauriers (LP: #973687).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
d3.transform = function(string) {
 
2
  var g = document.createElementNS(d3.ns.prefix.svg, "g"),
 
3
      identity = {a: 1, b: 0, c: 0, d: 1, e: 0, f: 0};
 
4
  return (d3.transform = function(string) {
 
5
    g.setAttribute("transform", string);
 
6
    var t = g.transform.baseVal.consolidate();
 
7
    return new d3_transform(t ? t.matrix : identity);
 
8
  })(string);
 
9
};
 
10
 
 
11
// Compute x-scale and normalize the first row.
 
12
// Compute shear and make second row orthogonal to first.
 
13
// Compute y-scale and normalize the second row.
 
14
// Finally, compute the rotation.
 
15
function d3_transform(m) {
 
16
  var r0 = [m.a, m.b],
 
17
      r1 = [m.c, m.d],
 
18
      kx = d3_transformNormalize(r0),
 
19
      kz = d3_transformDot(r0, r1),
 
20
      ky = d3_transformNormalize(d3_transformCombine(r1, r0, -kz)) || 0;
 
21
  if (r0[0] * r1[1] < r1[0] * r0[1]) {
 
22
    r0[0] *= -1;
 
23
    r0[1] *= -1;
 
24
    kx *= -1;
 
25
    kz *= -1;
 
26
  }
 
27
  this.rotate = (kx ? Math.atan2(r0[1], r0[0]) : Math.atan2(-r1[0], r1[1])) * d3_transformDegrees;
 
28
  this.translate = [m.e, m.f];
 
29
  this.scale = [kx, ky];
 
30
  this.skew = ky ? Math.atan2(kz, ky) * d3_transformDegrees : 0;
 
31
};
 
32
 
 
33
d3_transform.prototype.toString = function() {
 
34
  return "translate(" + this.translate
 
35
      + ")rotate(" + this.rotate
 
36
      + ")skewX(" + this.skew
 
37
      + ")scale(" + this.scale
 
38
      + ")";
 
39
};
 
40
 
 
41
function d3_transformDot(a, b) {
 
42
  return a[0] * b[0] + a[1] * b[1];
 
43
}
 
44
 
 
45
function d3_transformNormalize(a) {
 
46
  var k = Math.sqrt(d3_transformDot(a, a));
 
47
  if (k) {
 
48
    a[0] /= k;
 
49
    a[1] /= k;
 
50
  }
 
51
  return k;
 
52
}
 
53
 
 
54
function d3_transformCombine(a, b, k) {
 
55
  a[0] += k * b[0];
 
56
  a[1] += k * b[1];
 
57
  return a;
 
58
}
 
59
 
 
60
var d3_transformDegrees = 180 / Math.PI;