Skip to content

Commit e71de33

Browse files
committed
Merge branch '2.9.5'
2 parents ad43a2e + a3ab896 commit e71de33

13 files changed

Lines changed: 194 additions & 75 deletions

d3.v2.js

Lines changed: 31 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ try {
1010
d3_style_setProperty.call(this, name, value + "", priority);
1111
};
1212
}
13-
d3 = {version: "2.9.4"}; // semver
13+
d3 = {version: "2.9.5"}; // semver
1414
function d3_class(ctor, properties) {
1515
try {
1616
for (var key in properties) {
@@ -449,7 +449,7 @@ function d3_splitter(d) {
449449
return d == null;
450450
}
451451
function d3_collapse(s) {
452-
return s.replace(/(^\s+)|(\s+$)/g, "").replace(/\s+/g, " ");
452+
return s.replace(/^\s+|\s+$/g, "").replace(/\s+/g, " ");
453453
}
454454
d3.range = function(start, stop, step) {
455455
if (arguments.length < 3) {
@@ -1035,6 +1035,7 @@ d3.interpolateTransform = function(a, b) {
10351035
}
10361036

10371037
if (ra != rb) {
1038+
if (ra - rb > 180) rb += 360; else if (rb - ra > 180) ra += 360; // shortest path
10381039
q.push({i: s.push(s.pop() + "rotate(", null, ")") - 2, x: d3.interpolateNumber(ra, rb)});
10391040
} else if (rb) {
10401041
s.push(s.pop() + "rotate(" + rb + ")");
@@ -1626,7 +1627,7 @@ d3_selectionPrototype.attr = function(name, value) {
16261627
: (name.local ? attrConstantNS : attrConstant)));
16271628
};
16281629
d3_selectionPrototype.classed = function(name, value) {
1629-
var names = name.split(d3_selection_classedWhitespace),
1630+
var names = d3_collapse(name).split(" "),
16301631
n = names.length,
16311632
i = -1;
16321633
if (arguments.length > 1) {
@@ -1638,8 +1639,6 @@ d3_selectionPrototype.classed = function(name, value) {
16381639
}
16391640
};
16401641

1641-
var d3_selection_classedWhitespace = /\s+/g;
1642-
16431642
function d3_selection_classed(name, value) {
16441643
var re = new RegExp("(^|\\s+)" + d3.requote(name) + "(\\s+|$)", "g");
16451644

@@ -2011,14 +2010,19 @@ d3_selectionPrototype.on = function(type, listener, capture) {
20112010
});
20122011
};
20132012
d3_selectionPrototype.each = function(callback) {
2014-
for (var j = -1, m = this.length; ++j < m;) {
2015-
for (var group = this[j], i = -1, n = group.length; ++i < n;) {
2016-
var node = group[i];
2017-
if (node) callback.call(node, node.__data__, i, j);
2013+
return d3_selection_each(this, function(node, i, j) {
2014+
callback.call(node, node.__data__, i, j);
2015+
});
2016+
};
2017+
2018+
function d3_selection_each(groups, callback) {
2019+
for (var j = 0, m = groups.length; j < m; j++) {
2020+
for (var group = groups[j], i = 0, n = group.length, node; i < n; i++) {
2021+
if (node = group[i]) callback(node, i, j);
20182022
}
20192023
}
2020-
return this;
2021-
};
2024+
return groups;
2025+
}
20222026
//
20232027
// Note: assigning to the arguments array simultaneously changes the value of
20242028
// the corresponding argument!
@@ -2145,12 +2149,12 @@ function d3_transition(groups, id, time) {
21452149
};
21462150

21472151
d3.timer(function(elapsed) {
2148-
groups.each(function(d, i, j) {
2152+
return d3_selection_each(groups, function(node, i, j) {
21492153
var tweened = [],
2150-
node = this,
2151-
delay = groups[j][i].delay,
2152-
duration = groups[j][i].duration,
2153-
lock = node.__transition__ || (node.__transition__ = {active: 0, count: 0});
2154+
delay = node.delay,
2155+
duration = node.duration,
2156+
lock = (node = node.node).__transition__ || (node.__transition__ = {active: 0, count: 0}),
2157+
d = node.__data__;
21542158

21552159
++lock.count;
21562160

@@ -2196,7 +2200,6 @@ function d3_transition(groups, id, time) {
21962200
return 1;
21972201
}
21982202
});
2199-
return 1;
22002203
}, 0, time);
22012204

22022205
return groups;
@@ -2341,16 +2344,14 @@ d3_transitionPrototype.remove = function() {
23412344
});
23422345
};
23432346
d3_transitionPrototype.delay = function(value) {
2344-
var groups = this;
2345-
return groups.each(typeof value === "function"
2346-
? function(d, i, j) { groups[j][i].delay = value.apply(this, arguments) | 0; }
2347-
: (value = value | 0, function(d, i, j) { groups[j][i].delay = value; }));
2347+
return d3_selection_each(this, typeof value === "function"
2348+
? function(node, i, j) { node.delay = value.call(node = node.node, node.__data__, i, j) | 0; }
2349+
: (value = value | 0, function(node) { node.delay = value; }));
23482350
};
23492351
d3_transitionPrototype.duration = function(value) {
2350-
var groups = this;
2351-
return groups.each(typeof value === "function"
2352-
? function(d, i, j) { groups[j][i].duration = Math.max(1, value.apply(this, arguments) | 0); }
2353-
: (value = Math.max(1, value | 0), function(d, i, j) { groups[j][i].duration = value; }));
2352+
return d3_selection_each(this, typeof value === "function"
2353+
? function(node, i, j) { node.duration = Math.max(1, value.call(node = node.node, node.__data__, i, j) | 0); }
2354+
: (value = Math.max(1, value | 0), function(node) { node.duration = value; }));
23542355
};
23552356
function d3_transition_each(callback) {
23562357
var id = d3_transitionId,
@@ -2360,16 +2361,11 @@ function d3_transition_each(callback) {
23602361

23612362
d3_transitionId = this.id;
23622363
d3_transitionEase = this.ease();
2363-
for (var j = 0, m = this.length; j < m; j++) {
2364-
for (var group = this[j], i = 0, n = group.length; i < n; i++) {
2365-
var node = group[i];
2366-
if (node) {
2367-
d3_transitionDelay = this[j][i].delay;
2368-
d3_transitionDuration = this[j][i].duration;
2369-
callback.call(node = node.node, node.__data__, i, j);
2370-
}
2371-
}
2372-
}
2364+
d3_selection_each(this, function(node, i, j) {
2365+
d3_transitionDelay = node.delay;
2366+
d3_transitionDuration = node.duration;
2367+
callback.call(node = node.node, node.__data__, i, j);
2368+
});
23732369

23742370
d3_transitionId = id;
23752371
d3_transitionEase = ease;

d3.v2.min.js

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
<!DOCTYPE html>
2+
<meta charset="utf-8">
3+
<style>
4+
5+
table {
6+
width: 960px;
7+
border-spacing: 0;
8+
border-collapse: collapse;
9+
}
10+
11+
th, td {
12+
padding: 4px;
13+
}
14+
15+
th {
16+
text-align: left;
17+
}
18+
19+
td {
20+
border: solid 1px #ccc;
21+
text-align: right;
22+
}
23+
24+
td.fail {
25+
background: lightcoral;
26+
}
27+
28+
td.success {
29+
background: lightgreen;
30+
}
31+
32+
</style>
33+
<table>
34+
<thead>
35+
<th>start</th>
36+
<th>end</th>
37+
<th colspan=5>actual intermediate values</th>
38+
<th>exp.</th>
39+
<th>act.</th>
40+
</thead>
41+
<tbody>
42+
</tbody>
43+
</table>
44+
<script src="../../d3.v2.js"></script>
45+
<script>
46+
47+
var format = d3.format(",.2f");
48+
49+
var tests = [
50+
{start: 170, end: 225, expected: [ 170.00, -176.25, -162.50, -148.75, -135.00]},
51+
{start: 225, end: 170, expected: [-135.00, -148.75, -162.50, -176.25, 170.00]},
52+
{start: -170, end: -225, expected: [-170.00, 176.25, 162.50, 148.75, 135.00]},
53+
{start: -225, end: -170, expected: [ 135.00, 148.75, 162.50, 176.25, -170.00]},
54+
{start: -170, end: 170, expected: [-170.00, -175.00, 180.00, 175.00, 170.00]},
55+
{start: -170, end: 0, expected: [-170.00, -127.50, -85.00, -42.50, 0.00]},
56+
{start: 170, end: 0, expected: [ 170.00, 127.50, 85.00, 42.50, 0.00]},
57+
{start: -180, end: 90, expected: [ 180.00, 157.50, 135.00, 112.50, 90.00]},
58+
{start: 180, end: 90, expected: [ 180.00, 157.50, 135.00, 112.50, 90.00]},
59+
{start: -180, end: -90, expected: [-180.00, -157.50, -135.00, -112.50, -90.00]},
60+
{start: 180, end: -90, expected: [ 180.00, -157.50, -135.00, -112.50, -90.00]}
61+
];
62+
63+
var tr = d3.select("tbody").selectAll("tr")
64+
.data(tests)
65+
.enter().append("tr");
66+
67+
tr.append("td")
68+
.text(function(d) { return format(d.start); });
69+
70+
tr.append("td")
71+
.text(function(d) { return format(d.end); });
72+
73+
tr.selectAll(".actual")
74+
.data(function(d) {
75+
var interpolate = d3.interpolateTransform("rotate(" + d.start + ")", "rotate(" + d.end + ")");
76+
return d.expected.map(function(expected, i) {
77+
return {
78+
expected: expected,
79+
actual: d3.transform(interpolate(i / 4)).rotate
80+
};
81+
});
82+
})
83+
.enter().append("td")
84+
.text(function(d, i) { return format(d.actual); })
85+
.attr("class", function(d) { return Math.abs(d.actual - d.expected) < .01 ? "success" : "fail"; });
86+
87+
tr.append("td").attr("width", 40).append("svg")
88+
.attr("width", 40)
89+
.attr("height", 20)
90+
.append("g")
91+
.attr("transform", "translate(20,10)")
92+
.append("path")
93+
.attr("d", d3.svg.symbol().type("cross").size(120))
94+
.each(animateExpected);
95+
96+
tr.append("td").attr("width", 40).append("svg")
97+
.attr("width", 40)
98+
.attr("height", 20)
99+
.append("g")
100+
.attr("transform", "translate(20,10)")
101+
.append("path")
102+
.attr("d", d3.svg.symbol().type("cross").size(120))
103+
.each(animateActual);
104+
105+
function animateExpected(d) {
106+
d3.select(this).transition()
107+
.duration(2500)
108+
.attrTween("transform", rotateTween)
109+
.each("end", animateExpected);
110+
111+
function rotateTween(d) {
112+
if (d.start - d.end > 180) d.end += 360;
113+
else if (d.end - d.start > 180) d.start += 360;
114+
return d3.interpolateString("rotate(" + d.start + ")", "rotate(" + d.end + ")");
115+
}
116+
}
117+
118+
function animateActual(d) {
119+
d3.select(this)
120+
.attr("transform", "rotate(" + d.start + ")")
121+
.transition()
122+
.duration(2500)
123+
.attr("transform", "rotate(" + d.end + ")")
124+
.each("end", animateActual);
125+
}
126+
127+
</script>

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "d3",
3-
"version": "2.9.4",
3+
"version": "2.9.5",
44
"description": "A small, free JavaScript library for manipulating documents based on data.",
55
"keywords": [
66
"dom",

src/core/collapse.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
function d3_collapse(s) {
2-
return s.replace(/(^\s+)|(\s+$)/g, "").replace(/\s+/g, " ");
2+
return s.replace(/^\s+|\s+$/g, "").replace(/\s+/g, " ");
33
}

src/core/core.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
d3 = {version: "2.9.4"}; // semver
1+
d3 = {version: "2.9.5"}; // semver

src/core/interpolate.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ d3.interpolateTransform = function(a, b) {
117117
}
118118

119119
if (ra != rb) {
120+
if (ra - rb > 180) rb += 360; else if (rb - ra > 180) ra += 360; // shortest path
120121
q.push({i: s.push(s.pop() + "rotate(", null, ")") - 2, x: d3.interpolateNumber(ra, rb)});
121122
} else if (rb) {
122123
s.push(s.pop() + "rotate(" + rb + ")");

src/core/selection-classed.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
d3_selectionPrototype.classed = function(name, value) {
2-
var names = name.split(d3_selection_classedWhitespace),
2+
var names = d3_collapse(name).split(" "),
33
n = names.length,
44
i = -1;
55
if (arguments.length > 1) {
@@ -11,8 +11,6 @@ d3_selectionPrototype.classed = function(name, value) {
1111
}
1212
};
1313

14-
var d3_selection_classedWhitespace = /\s+/g;
15-
1614
function d3_selection_classed(name, value) {
1715
var re = new RegExp("(^|\\s+)" + d3.requote(name) + "(\\s+|$)", "g");
1816

src/core/selection-each.js

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
d3_selectionPrototype.each = function(callback) {
2-
for (var j = -1, m = this.length; ++j < m;) {
3-
for (var group = this[j], i = -1, n = group.length; ++i < n;) {
4-
var node = group[i];
5-
if (node) callback.call(node, node.__data__, i, j);
2+
return d3_selection_each(this, function(node, i, j) {
3+
callback.call(node, node.__data__, i, j);
4+
});
5+
};
6+
7+
function d3_selection_each(groups, callback) {
8+
for (var j = 0, m = groups.length; j < m; j++) {
9+
for (var group = groups[j], i = 0, n = group.length, node; i < n; i++) {
10+
if (node = group[i]) callback(node, i, j);
611
}
712
}
8-
return this;
9-
};
13+
return groups;
14+
}

src/core/transition-delay.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
d3_transitionPrototype.delay = function(value) {
2-
var groups = this;
3-
return groups.each(typeof value === "function"
4-
? function(d, i, j) { groups[j][i].delay = value.apply(this, arguments) | 0; }
5-
: (value = value | 0, function(d, i, j) { groups[j][i].delay = value; }));
2+
return d3_selection_each(this, typeof value === "function"
3+
? function(node, i, j) { node.delay = value.call(node = node.node, node.__data__, i, j) | 0; }
4+
: (value = value | 0, function(node) { node.delay = value; }));
65
};

0 commit comments

Comments
 (0)