Skip to content

Commit 7f38862

Browse files
committed
Use d3_identity instead of Object.
1 parent d3c3324 commit 7f38862

8 files changed

Lines changed: 41 additions & 34 deletions

File tree

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ d3.core.js: \
3131
src/core/class.js \
3232
src/core/array.js \
3333
src/core/map.js \
34+
src/core/identity.js \
3435
src/core/this.js \
3536
src/core/functor.js \
3637
src/core/rebind.js \

d3.v2.js

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,9 @@ d3_class(d3_Map, {
100100

101101
var d3_map_prefix = "\0", // prevent collision with built-ins
102102
d3_map_prefixCode = d3_map_prefix.charCodeAt(0);
103+
function d3_identity(d) {
104+
return d;
105+
}
103106
function d3_this() {
104107
return this;
105108
}
@@ -3247,36 +3250,36 @@ function d3_svg_line(projection) {
32473250
return d.length < 1 ? null : "M" + interpolator(projection(d3_svg_linePoints(this, d, x, y)), tension);
32483251
}
32493252

3250-
line.x = function(v) {
3253+
line.x = function(_) {
32513254
if (!arguments.length) return x;
3252-
x = v;
3255+
x = _;
32533256
return line;
32543257
};
32553258

3256-
line.y = function(v) {
3259+
line.y = function(_) {
32573260
if (!arguments.length) return y;
3258-
y = v;
3261+
y = _;
32593262
return line;
32603263
};
32613264

3262-
line.interpolate = function(v) {
3265+
line.interpolate = function(_) {
32633266
if (!arguments.length) return interpolate;
3264-
if (!d3_svg_lineInterpolators.has(v += "")) v = d3_svg_lineInterpolatorDefault;
3265-
interpolator = d3_svg_lineInterpolators.get(interpolate = v);
3267+
if (!d3_svg_lineInterpolators.has(_ += "")) _ = d3_svg_lineInterpolatorDefault;
3268+
interpolator = d3_svg_lineInterpolators.get(interpolate = _);
32663269
return line;
32673270
};
32683271

3269-
line.tension = function(v) {
3272+
line.tension = function(_) {
32703273
if (!arguments.length) return tension;
3271-
tension = v;
3274+
tension = _;
32723275
return line;
32733276
};
32743277

32753278
return line;
32763279
}
32773280

32783281
d3.svg.line = function() {
3279-
return d3_svg_line(Object);
3282+
return d3_svg_line(d3_identity);
32803283
};
32813284

32823285
// Converts the specified array of data into an array of points
@@ -5366,7 +5369,7 @@ d3.layout.force = function() {
53665369
// use `node.call(force.drag)` to make nodes draggable
53675370
force.drag = function() {
53685371
if (!drag) drag = d3.behavior.drag()
5369-
.origin(Object)
5372+
.origin(d3_identity)
53705373
.on("dragstart", dragstart)
53715374
.on("drag", d3_layout_forceDrag)
53725375
.on("dragend", d3_layout_forceDragEnd);
@@ -5589,7 +5592,7 @@ d3.layout.pie = function() {
55895592
var d3_layout_pieSortByValue = {};
55905593
// data is two-dimensional array of x,y; we populate y0
55915594
d3.layout.stack = function() {
5592-
var values = Object,
5595+
var values = d3_identity,
55935596
order = d3_layout_stackOrderDefault,
55945597
offset = d3_layout_stackOffsetZero,
55955598
out = d3_layout_stackOut,
@@ -7585,7 +7588,7 @@ d3.geo.circle = function() {
75857588
var origin = [0, 0],
75867589
degrees = 90 - 1e-2,
75877590
radians = degrees * d3_geo_radians,
7588-
arc = d3.geo.greatArc().target(Object);
7591+
arc = d3.geo.greatArc().target(d3_identity);
75897592

75907593
function circle() {
75917594
// TODO render a circle as a Polygon
@@ -7603,7 +7606,7 @@ d3.geo.circle = function() {
76037606
var clipType = d3_geo_type({
76047607

76057608
FeatureCollection: function(o) {
7606-
var features = o.features.map(clipType).filter(Object);
7609+
var features = o.features.map(clipType).filter(d3_identity);
76077610
return features && (o = Object.create(o), o.features = features, o);
76087611
},
76097612

@@ -7645,7 +7648,7 @@ d3.geo.circle = function() {
76457648
},
76467649

76477650
GeometryCollection: function(o) {
7648-
var geometries = o.geometries.map(clipType).filter(Object);
7651+
var geometries = o.geometries.map(clipType).filter(d3_identity);
76497652
return geometries.length && (o = Object.create(o), o.geometries = geometries, o);
76507653
}
76517654

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.

src/core/identity.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
function d3_identity(d) {
2+
return d;
3+
}

src/geo/circle.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ d3.geo.circle = function() {
44
var origin = [0, 0],
55
degrees = 90 - 1e-2,
66
radians = degrees * d3_geo_radians,
7-
arc = d3.geo.greatArc().target(Object);
7+
arc = d3.geo.greatArc().target(d3_identity);
88

99
function circle() {
1010
// TODO render a circle as a Polygon
@@ -22,7 +22,7 @@ d3.geo.circle = function() {
2222
var clipType = d3_geo_type({
2323

2424
FeatureCollection: function(o) {
25-
var features = o.features.map(clipType).filter(Object);
25+
var features = o.features.map(clipType).filter(d3_identity);
2626
return features && (o = Object.create(o), o.features = features, o);
2727
},
2828

@@ -64,7 +64,7 @@ d3.geo.circle = function() {
6464
},
6565

6666
GeometryCollection: function(o) {
67-
var geometries = o.geometries.map(clipType).filter(Object);
67+
var geometries = o.geometries.map(clipType).filter(d3_identity);
6868
return geometries.length && (o = Object.create(o), o.geometries = geometries, o);
6969
}
7070

src/layout/force.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ d3.layout.force = function() {
273273
// use `node.call(force.drag)` to make nodes draggable
274274
force.drag = function() {
275275
if (!drag) drag = d3.behavior.drag()
276-
.origin(Object)
276+
.origin(d3_identity)
277277
.on("dragstart", dragstart)
278278
.on("drag", d3_layout_forceDrag)
279279
.on("dragend", d3_layout_forceDragEnd);

src/layout/stack.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// data is two-dimensional array of x,y; we populate y0
22
d3.layout.stack = function() {
3-
var values = Object,
3+
var values = d3_identity,
44
order = d3_layout_stackOrderDefault,
55
offset = d3_layout_stackOffsetZero,
66
out = d3_layout_stackOut,

src/svg/line.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,36 +9,36 @@ function d3_svg_line(projection) {
99
return d.length < 1 ? null : "M" + interpolator(projection(d3_svg_linePoints(this, d, x, y)), tension);
1010
}
1111

12-
line.x = function(v) {
12+
line.x = function(_) {
1313
if (!arguments.length) return x;
14-
x = v;
14+
x = _;
1515
return line;
1616
};
1717

18-
line.y = function(v) {
18+
line.y = function(_) {
1919
if (!arguments.length) return y;
20-
y = v;
20+
y = _;
2121
return line;
2222
};
2323

24-
line.interpolate = function(v) {
24+
line.interpolate = function(_) {
2525
if (!arguments.length) return interpolate;
26-
if (!d3_svg_lineInterpolators.has(v += "")) v = d3_svg_lineInterpolatorDefault;
27-
interpolator = d3_svg_lineInterpolators.get(interpolate = v);
26+
if (!d3_svg_lineInterpolators.has(_ += "")) _ = d3_svg_lineInterpolatorDefault;
27+
interpolator = d3_svg_lineInterpolators.get(interpolate = _);
2828
return line;
2929
};
3030

31-
line.tension = function(v) {
31+
line.tension = function(_) {
3232
if (!arguments.length) return tension;
33-
tension = v;
33+
tension = _;
3434
return line;
3535
};
3636

3737
return line;
3838
}
3939

4040
d3.svg.line = function() {
41-
return d3_svg_line(Object);
41+
return d3_svg_line(d3_identity);
4242
};
4343

4444
// Converts the specified array of data into an array of points

0 commit comments

Comments
 (0)