forked from d3/d3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
136 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -1 +1 @@ | |||
d3 = {version: "2.5.0"}; // semver | d3 = {version: "2.5.1"}; // semver |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters