This commit is contained in:
Mike Bostock 2012-06-24 11:03:14 -07:00
Родитель ad43a2e843 a3ab896295
Коммит e71de33e31
13 изменённых файлов: 194 добавлений и 75 удалений

66
d3.v2.js поставляемый
Просмотреть файл

@ -10,7 +10,7 @@ try {
d3_style_setProperty.call(this, name, value + "", priority);
};
}
d3 = {version: "2.9.4"}; // semver
d3 = {version: "2.9.5"}; // semver
function d3_class(ctor, properties) {
try {
for (var key in properties) {
@ -449,7 +449,7 @@ function d3_splitter(d) {
return d == null;
}
function d3_collapse(s) {
return s.replace(/(^\s+)|(\s+$)/g, "").replace(/\s+/g, " ");
return s.replace(/^\s+|\s+$/g, "").replace(/\s+/g, " ");
}
d3.range = function(start, stop, step) {
if (arguments.length < 3) {
@ -1035,6 +1035,7 @@ d3.interpolateTransform = function(a, b) {
}
if (ra != rb) {
if (ra - rb > 180) rb += 360; else if (rb - ra > 180) ra += 360; // shortest path
q.push({i: s.push(s.pop() + "rotate(", null, ")") - 2, x: d3.interpolateNumber(ra, rb)});
} else if (rb) {
s.push(s.pop() + "rotate(" + rb + ")");
@ -1626,7 +1627,7 @@ d3_selectionPrototype.attr = function(name, value) {
: (name.local ? attrConstantNS : attrConstant)));
};
d3_selectionPrototype.classed = function(name, value) {
var names = name.split(d3_selection_classedWhitespace),
var names = d3_collapse(name).split(" "),
n = names.length,
i = -1;
if (arguments.length > 1) {
@ -1638,8 +1639,6 @@ d3_selectionPrototype.classed = function(name, value) {
}
};
var d3_selection_classedWhitespace = /\s+/g;
function d3_selection_classed(name, value) {
var re = new RegExp("(^|\\s+)" + d3.requote(name) + "(\\s+|$)", "g");
@ -2011,14 +2010,19 @@ d3_selectionPrototype.on = function(type, listener, capture) {
});
};
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;
}
//
// Note: assigning to the arguments array simultaneously changes the value of
// the corresponding argument!
@ -2145,12 +2149,12 @@ function d3_transition(groups, id, time) {
};
d3.timer(function(elapsed) {
groups.each(function(d, i, j) {
return d3_selection_each(groups, function(node, i, j) {
var tweened = [],
node = this,
delay = groups[j][i].delay,
duration = groups[j][i].duration,
lock = node.__transition__ || (node.__transition__ = {active: 0, count: 0});
delay = node.delay,
duration = node.duration,
lock = (node = node.node).__transition__ || (node.__transition__ = {active: 0, count: 0}),
d = node.__data__;
++lock.count;
@ -2196,7 +2200,6 @@ function d3_transition(groups, id, time) {
return 1;
}
});
return 1;
}, 0, time);
return groups;
@ -2341,16 +2344,14 @@ d3_transitionPrototype.remove = function() {
});
};
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; }));
};
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; }));
};
function d3_transition_each(callback) {
var id = d3_transitionId,
@ -2360,16 +2361,11 @@ function d3_transition_each(callback) {
d3_transitionId = this.id;
d3_transitionEase = this.ease();
for (var j = 0, m = this.length; j < m; j++) {
for (var group = this[j], i = 0, n = group.length; i < n; i++) {
var node = group[i];
if (node) {
d3_transitionDelay = this[j][i].delay;
d3_transitionDuration = this[j][i].duration;
callback.call(node = node.node, node.__data__, i, j);
}
}
}
d3_selection_each(this, function(node, i, j) {
d3_transitionDelay = node.delay;
d3_transitionDuration = node.duration;
callback.call(node = node.node, node.__data__, i, j);
});
d3_transitionId = id;
d3_transitionEase = ease;

8
d3.v2.min.js поставляемый

Различия файлов скрыты, потому что одна или несколько строк слишком длинны

Просмотреть файл

@ -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>

Просмотреть файл

@ -1,6 +1,6 @@
{
"name": "d3",
"version": "2.9.4",
"version": "2.9.5",
"description": "A small, free JavaScript library for manipulating documents based on data.",
"keywords": [
"dom",

Просмотреть файл

@ -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, " ");
}

Просмотреть файл

@ -1 +1 @@
d3 = {version: "2.9.4"}; // semver
d3 = {version: "2.9.5"}; // semver

Просмотреть файл

@ -117,6 +117,7 @@ d3.interpolateTransform = function(a, b) {
}
if (ra != rb) {
if (ra - rb > 180) rb += 360; else if (rb - ra > 180) ra += 360; // shortest path
q.push({i: s.push(s.pop() + "rotate(", null, ")") - 2, x: d3.interpolateNumber(ra, rb)});
} else if (rb) {
s.push(s.pop() + "rotate(" + rb + ")");

Просмотреть файл

@ -1,5 +1,5 @@
d3_selectionPrototype.classed = function(name, value) {
var names = name.split(d3_selection_classedWhitespace),
var names = d3_collapse(name).split(" "),
n = names.length,
i = -1;
if (arguments.length > 1) {
@ -11,8 +11,6 @@ d3_selectionPrototype.classed = function(name, value) {
}
};
var d3_selection_classedWhitespace = /\s+/g;
function d3_selection_classed(name, value) {
var re = new RegExp("(^|\\s+)" + d3.requote(name) + "(\\s+|$)", "g");

Просмотреть файл

@ -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;
}

Просмотреть файл

@ -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; }));
};

Просмотреть файл

@ -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; }));
};

Просмотреть файл

@ -6,16 +6,11 @@ function d3_transition_each(callback) {
d3_transitionId = this.id;
d3_transitionEase = this.ease();
for (var j = 0, m = this.length; j < m; j++) {
for (var group = this[j], i = 0, n = group.length; i < n; i++) {
var node = group[i];
if (node) {
d3_transitionDelay = this[j][i].delay;
d3_transitionDuration = this[j][i].duration;
callback.call(node = node.node, node.__data__, i, j);
}
}
}
d3_selection_each(this, function(node, i, j) {
d3_transitionDelay = node.delay;
d3_transitionDuration = node.duration;
callback.call(node = node.node, node.__data__, i, j);
});
d3_transitionId = id;
d3_transitionEase = ease;

Просмотреть файл

@ -29,12 +29,12 @@ function d3_transition(groups, id, time) {
};
d3.timer(function(elapsed) {
groups.each(function(d, i, j) {
return d3_selection_each(groups, function(node, i, j) {
var tweened = [],
node = this,
delay = groups[j][i].delay,
duration = groups[j][i].duration,
lock = node.__transition__ || (node.__transition__ = {active: 0, count: 0});
delay = node.delay,
duration = node.duration,
lock = (node = node.node).__transition__ || (node.__transition__ = {active: 0, count: 0}),
d = node.__data__;
++lock.count;
@ -80,7 +80,6 @@ function d3_transition(groups, id, time) {
return 1;
}
});
return 1;
}, 0, time);
return groups;