Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge branch 'release'

  • Loading branch information...
commit b04112af83ece9c50af43bee81580d73be3f0833 2 parents 4090261 + b4c6b00
Mike Bostock authored
32 d3.js
View
@@ -10,7 +10,7 @@ try {
d3_style_setProperty.call(this, name, value + "", priority);
};
}
-d3 = {version: "2.5.0"}; // semver
+d3 = {version: "2.5.1"}; // semver
var d3_array = d3_arraySlice; // conversion for NodeLists
function d3_arrayCopy(pseudoarray) {
@@ -2250,7 +2250,8 @@ var d3_timer_frame = window.requestAnimationFrame
|| function(callback) { setTimeout(callback, 17); };
d3.transform = function(string) {
d3_transformG.setAttribute("transform", string);
- return new d3_transform(d3_transformG.transform.baseVal.consolidate().matrix);
+ var t = d3_transformG.transform.baseVal.consolidate();
+ return new d3_transform(t ? t.matrix : d3_transformIdentity);
};
// Compute x-scale and normalize the first row.
@@ -2262,11 +2263,17 @@ function d3_transform(m) {
r1 = [m.c, m.d],
kx = d3_transformNormalize(r0),
kz = d3_transformDot(r0, r1),
- ky = d3_transformNormalize(d3_transformCombine(r1, r0, -kz));
+ 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.rotate = Math.atan2(m.b, m.a) * d3_transformDegrees;
- this.scale = [kx, ky || 0];
- this.skew = ky ? kz / ky * d3_transformDegrees : 0;
+ this.scale = [kx, ky];
+ this.skew = ky ? Math.atan2(kz, ky) * d3_transformDegrees : 0;
};
d3_transform.prototype.toString = function() {
@@ -2283,8 +2290,10 @@ function d3_transformDot(a, b) {
function d3_transformNormalize(a) {
var k = Math.sqrt(d3_transformDot(a, a));
- a[0] /= k;
- a[1] /= k;
+ if (k) {
+ a[0] /= k;
+ a[1] /= k;
+ }
return k;
}
@@ -2295,6 +2304,7 @@ function d3_transformCombine(a, b, k) {
}
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;
function d3_noop() {}
d3.scale = {};
@@ -2499,8 +2509,8 @@ function d3_scale_log(linear, log) {
if (extent.every(isFinite)) {
var i = Math.floor(extent[0]),
j = Math.ceil(extent[1]),
- u = Math.round(pow(extent[0])),
- v = Math.round(pow(extent[1]));
+ u = pow(extent[0]),
+ v = pow(extent[1]);
if (log === d3_scale_logn) {
ticks.push(pow(i));
for (; i++ < j;) for (var k = 9; k > 0; k--) ticks.push(pow(i) * k);
@@ -2533,7 +2543,7 @@ function d3_scale_log(linear, log) {
return d3_scale_linearRebind(scale, linear);
};
-var d3_scale_logFormat = d3.format("e");
+var d3_scale_logFormat = d3.format(".0e");
function d3_scale_logp(x) {
return Math.log(x) / Math.LN10;
4 d3.min.js
View
2 additions, 2 deletions not shown
85 examples/transform/test.html
View
@@ -0,0 +1,85 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
+ <title>Transform Test</title>
+ <script type="text/javascript" src="../../d3.js"></script>
+ <style type="text/css">
+ th, td { border: solid #ccc 1px; }
+ </style>
+ </head>
+ <body>
+ <script type="text/javascript">
+
+var outcome = d3.select("body").append("p");
+
+var g = d3.select("body").append("svg:svg")
+ .attr("width", 10)
+ .attr("height", 10)
+ .append("svg:g");
+
+var results = d3.select("body").append("table")
+ .style("display", "none");
+results.append("tr").selectAll("th")
+ .data(["Expected", "Actual", "Expected matrix", "Actual matrix"])
+ .enter().append("th").text(String);
+
+var el = g[0][0],
+ v,
+ m,
+ a,
+ b,
+ failures = 0;
+
+for (var tx = -10; tx <= 10; tx += 5) {
+ for (var ty = -10; ty <= 10; ty += 5) {
+ for (var r = -180; r <= 180; r += 15) {
+ for (var skx = -45; skx <= 45; skx += 45) {
+ for (var sx = -2; sx <= 2; sx++) {
+ for (var sy = -2; sy <= 2; sy++) {
+ v = "translate(" + tx + "," + ty + ")rotate(" + r + ")skewX(" + skx + ")scale(" + sx + "," + sy + ")";
+ g.attr("transform", v);
+ a = matrix(el);
+ g.attr("transform", d3.transform(v));
+ b = matrix(el);
+ if (!deepEqual(a, b, 1e-6)) {
+ failures++;
+ results
+ .style("display", null)
+ .append("tr").selectAll("td")
+ .data([v, d3.transform(v), a, b])
+ .enter().append("td").text(String);
+ }
+ }
+ }
+ }
+ }
+ }
+}
+
+outcome.text(failures ? failures + " failures" : "Success!");
+
+function matrix(el) {
+ var t = el.transform.baseVal.consolidate();
+ if (t) {
+ var m = t.matrix;
+ return [m.a, m.b, m.c, m.d, m.e, m.f];
+ }
+ return null;
+}
+
+function deepEqual(actual, expected, epsilon) {
+ epsilon = epsilon || 0;
+ if (actual === expected) return true;
+ if (actual == null || expected == null) return false;
+ if (actual.length !== expected.length) return false;
+
+ for (var i = 0; i < actual.length; i++) {
+ if (Math.abs(actual[i] - expected[i]) > epsilon) return false;
+ }
+ return true;
+}
+
+ </script>
+ </body>
+</html>
2  package.json
View
@@ -1,6 +1,6 @@
{
"name": "d3",
- "version": "2.5.0",
+ "version": "2.5.1",
"description": "A small, free JavaScript library for manipulating documents based on data.",
"keywords": [
"dom",
2  src/core/core.js
View
@@ -1 +1 @@
-d3 = {version: "2.5.0"}; // semver
+d3 = {version: "2.5.1"}; // semver
24 src/core/transform.js
View
@@ -1,6 +1,7 @@
d3.transform = function(string) {
d3_transformG.setAttribute("transform", string);
- return new d3_transform(d3_transformG.transform.baseVal.consolidate().matrix);
+ var t = d3_transformG.transform.baseVal.consolidate();
+ return new d3_transform(t ? t.matrix : d3_transformIdentity);
};
// Compute x-scale and normalize the first row.
@@ -12,11 +13,17 @@ function d3_transform(m) {
r1 = [m.c, m.d],
kx = d3_transformNormalize(r0),
kz = d3_transformDot(r0, r1),
- ky = d3_transformNormalize(d3_transformCombine(r1, r0, -kz));
+ 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.rotate = Math.atan2(m.b, m.a) * d3_transformDegrees;
- this.scale = [kx, ky || 0];
- this.skew = ky ? kz / ky * d3_transformDegrees : 0;
+ this.scale = [kx, ky];
+ this.skew = ky ? Math.atan2(kz, ky) * d3_transformDegrees : 0;
};
d3_transform.prototype.toString = function() {
@@ -33,8 +40,10 @@ function d3_transformDot(a, b) {
function d3_transformNormalize(a) {
var k = Math.sqrt(d3_transformDot(a, a));
- a[0] /= k;
- a[1] /= k;
+ if (k) {
+ a[0] /= k;
+ a[1] /= k;
+ }
return k;
}
@@ -45,4 +54,5 @@ function d3_transformCombine(a, b, k) {
}
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;
6 src/scale/log.js
View
@@ -32,8 +32,8 @@ function d3_scale_log(linear, log) {
if (extent.every(isFinite)) {
var i = Math.floor(extent[0]),
j = Math.ceil(extent[1]),
- u = Math.round(pow(extent[0])),
- v = Math.round(pow(extent[1]));
+ u = pow(extent[0]),
+ v = pow(extent[1]);
if (log === d3_scale_logn) {
ticks.push(pow(i));
for (; i++ < j;) for (var k = 9; k > 0; k--) ticks.push(pow(i) * k);
@@ -66,7 +66,7 @@ function d3_scale_log(linear, log) {
return d3_scale_linearRebind(scale, linear);
};
-var d3_scale_logFormat = d3.format("e");
+var d3_scale_logFormat = d3.format(".0e");
function d3_scale_logp(x) {
return Math.log(x) / Math.LN10;
7 test/scale/log-test.js
View
@@ -157,6 +157,11 @@ suite.addBatch({
"1e+1", "2e+1", "3e+1", "4e+1", "5e+1", "6e+1", "7e+1", "8e+1", "9e+1",
"1e+2"
]);
+ var x = log().domain([0.49999, 0.006029505943610648]);
+ assert.deepEqual(x.ticks().map(x.tickFormat()), [
+ "7e-3", "8e-3", "9e-3", "1e-2", "2e-2", "3e-2", "4e-2", "5e-2",
+ "6e-2", "7e-2", "8e-2", "9e-2", "1e-1", "2e-1", "3e-1", "4e-1"
+ ]);
},
"can generate fewer ticks, if desired": function(log) {
var x = log();
@@ -172,7 +177,7 @@ suite.addBatch({
]);
},
"can override the tick format": function(log) {
- var x = log().domain([1000, 1]);
+ var x = log().domain([1000.1, 1]);
assert.deepEqual(x.ticks().map(x.tickFormat(10, d3.format("+,d"))), [
"+1", "+2", "+3", "", "", "", "", "", "",
"+10", "+20", "+30", "", "", "", "", "", "",
Please sign in to comment.
Something went wrong with that request. Please try again.