-
Notifications
You must be signed in to change notification settings - Fork 0
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
13 changed files
with
194 additions
and
75 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
Large diffs are not rendered by default.
Oops, something went wrong.
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 | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
<!DOCTYPE html> | ||
<meta charset="utf-8"> | ||
<style> | ||
|
||
table { | ||
width: 960px; | ||
border-spacing: 0; | ||
border-collapse: collapse; | ||
} | ||
|
||
th, td { | ||
padding: 4px; | ||
} | ||
|
||
th { | ||
text-align: left; | ||
} | ||
|
||
td { | ||
border: solid 1px #ccc; | ||
text-align: right; | ||
} | ||
|
||
td.fail { | ||
background: lightcoral; | ||
} | ||
|
||
td.success { | ||
background: lightgreen; | ||
} | ||
|
||
</style> | ||
<table> | ||
<thead> | ||
<th>start</th> | ||
<th>end</th> | ||
<th colspan=5>actual intermediate values</th> | ||
<th>exp.</th> | ||
<th>act.</th> | ||
</thead> | ||
<tbody> | ||
</tbody> | ||
</table> | ||
<script src="../../d3.v2.js"></script> | ||
<script> | ||
|
||
var format = d3.format(",.2f"); | ||
|
||
var tests = [ | ||
{start: 170, end: 225, expected: [ 170.00, -176.25, -162.50, -148.75, -135.00]}, | ||
{start: 225, end: 170, expected: [-135.00, -148.75, -162.50, -176.25, 170.00]}, | ||
{start: -170, end: -225, expected: [-170.00, 176.25, 162.50, 148.75, 135.00]}, | ||
{start: -225, end: -170, expected: [ 135.00, 148.75, 162.50, 176.25, -170.00]}, | ||
{start: -170, end: 170, expected: [-170.00, -175.00, 180.00, 175.00, 170.00]}, | ||
{start: -170, end: 0, expected: [-170.00, -127.50, -85.00, -42.50, 0.00]}, | ||
{start: 170, end: 0, expected: [ 170.00, 127.50, 85.00, 42.50, 0.00]}, | ||
{start: -180, end: 90, expected: [ 180.00, 157.50, 135.00, 112.50, 90.00]}, | ||
{start: 180, end: 90, expected: [ 180.00, 157.50, 135.00, 112.50, 90.00]}, | ||
{start: -180, end: -90, expected: [-180.00, -157.50, -135.00, -112.50, -90.00]}, | ||
{start: 180, end: -90, expected: [ 180.00, -157.50, -135.00, -112.50, -90.00]} | ||
]; | ||
|
||
var tr = d3.select("tbody").selectAll("tr") | ||
.data(tests) | ||
.enter().append("tr"); | ||
|
||
tr.append("td") | ||
.text(function(d) { return format(d.start); }); | ||
|
||
tr.append("td") | ||
.text(function(d) { return format(d.end); }); | ||
|
||
tr.selectAll(".actual") | ||
.data(function(d) { | ||
var interpolate = d3.interpolateTransform("rotate(" + d.start + ")", "rotate(" + d.end + ")"); | ||
return d.expected.map(function(expected, i) { | ||
return { | ||
expected: expected, | ||
actual: d3.transform(interpolate(i / 4)).rotate | ||
}; | ||
}); | ||
}) | ||
.enter().append("td") | ||
.text(function(d, i) { return format(d.actual); }) | ||
.attr("class", function(d) { return Math.abs(d.actual - d.expected) < .01 ? "success" : "fail"; }); | ||
|
||
tr.append("td").attr("width", 40).append("svg") | ||
.attr("width", 40) | ||
.attr("height", 20) | ||
.append("g") | ||
.attr("transform", "translate(20,10)") | ||
.append("path") | ||
.attr("d", d3.svg.symbol().type("cross").size(120)) | ||
.each(animateExpected); | ||
|
||
tr.append("td").attr("width", 40).append("svg") | ||
.attr("width", 40) | ||
.attr("height", 20) | ||
.append("g") | ||
.attr("transform", "translate(20,10)") | ||
.append("path") | ||
.attr("d", d3.svg.symbol().type("cross").size(120)) | ||
.each(animateActual); | ||
|
||
function animateExpected(d) { | ||
d3.select(this).transition() | ||
.duration(2500) | ||
.attrTween("transform", rotateTween) | ||
.each("end", animateExpected); | ||
|
||
function rotateTween(d) { | ||
if (d.start - d.end > 180) d.end += 360; | ||
else if (d.end - d.start > 180) d.start += 360; | ||
return d3.interpolateString("rotate(" + d.start + ")", "rotate(" + d.end + ")"); | ||
} | ||
} | ||
|
||
function animateActual(d) { | ||
d3.select(this) | ||
.attr("transform", "rotate(" + d.start + ")") | ||
.transition() | ||
.duration(2500) | ||
.attr("transform", "rotate(" + d.end + ")") | ||
.each("end", animateActual); | ||
} | ||
|
||
</script> |
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 | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
function d3_collapse(s) { | ||
return s.replace(/(^\s+)|(\s+$)/g, "").replace(/\s+/g, " "); | ||
return s.replace(/^\s+|\s+$/g, "").replace(/\s+/g, " "); | ||
} |
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 | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
d3 = {version: "2.9.4"}; // semver | ||
d3 = {version: "2.9.5"}; // 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,14 @@ | ||
d3_selectionPrototype.each = function(callback) { | ||
for (var j = -1, m = this.length; ++j < m;) { | ||
for (var group = this[j], i = -1, n = group.length; ++i < n;) { | ||
var node = group[i]; | ||
if (node) callback.call(node, node.__data__, i, j); | ||
return d3_selection_each(this, function(node, i, j) { | ||
callback.call(node, node.__data__, i, j); | ||
}); | ||
}; | ||
|
||
function d3_selection_each(groups, callback) { | ||
for (var j = 0, m = groups.length; j < m; j++) { | ||
for (var group = groups[j], i = 0, n = group.length, node; i < n; i++) { | ||
if (node = group[i]) callback(node, i, j); | ||
} | ||
} | ||
return this; | ||
}; | ||
return groups; | ||
} |
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 | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
d3_transitionPrototype.delay = function(value) { | ||
var groups = this; | ||
return groups.each(typeof value === "function" | ||
? function(d, i, j) { groups[j][i].delay = value.apply(this, arguments) | 0; } | ||
: (value = value | 0, function(d, i, j) { groups[j][i].delay = value; })); | ||
return d3_selection_each(this, typeof value === "function" | ||
? function(node, i, j) { node.delay = value.call(node = node.node, node.__data__, i, j) | 0; } | ||
: (value = value | 0, function(node) { node.delay = value; })); | ||
}; |
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 | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
d3_transitionPrototype.duration = function(value) { | ||
var groups = this; | ||
return groups.each(typeof value === "function" | ||
? function(d, i, j) { groups[j][i].duration = Math.max(1, value.apply(this, arguments) | 0); } | ||
: (value = Math.max(1, value | 0), function(d, i, j) { groups[j][i].duration = value; })); | ||
return d3_selection_each(this, typeof value === "function" | ||
? function(node, i, j) { node.duration = Math.max(1, value.call(node = node.node, node.__data__, i, j) | 0); } | ||
: (value = Math.max(1, value | 0), function(node) { node.duration = value; })); | ||
}; |
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