Skip to content

Commit

Permalink
Use d3_identity instead of Object.
Browse files Browse the repository at this point in the history
  • Loading branch information
mbostock committed Mar 17, 2012
1 parent d3c3324 commit 7f38862
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 34 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ d3.core.js: \
src/core/class.js \
src/core/array.js \
src/core/map.js \
src/core/identity.js \
src/core/this.js \
src/core/functor.js \
src/core/rebind.js \
Expand Down
33 changes: 18 additions & 15 deletions d3.v2.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@ d3_class(d3_Map, {

var d3_map_prefix = "\0", // prevent collision with built-ins
d3_map_prefixCode = d3_map_prefix.charCodeAt(0);
function d3_identity(d) {
return d;
}
function d3_this() {
return this;
}
Expand Down Expand Up @@ -3247,36 +3250,36 @@ function d3_svg_line(projection) {
return d.length < 1 ? null : "M" + interpolator(projection(d3_svg_linePoints(this, d, x, y)), tension);
}

line.x = function(v) {
line.x = function(_) {
if (!arguments.length) return x;
x = v;
x = _;
return line;
};

line.y = function(v) {
line.y = function(_) {
if (!arguments.length) return y;
y = v;
y = _;
return line;
};

line.interpolate = function(v) {
line.interpolate = function(_) {
if (!arguments.length) return interpolate;
if (!d3_svg_lineInterpolators.has(v += "")) v = d3_svg_lineInterpolatorDefault;
interpolator = d3_svg_lineInterpolators.get(interpolate = v);
if (!d3_svg_lineInterpolators.has(_ += "")) _ = d3_svg_lineInterpolatorDefault;
interpolator = d3_svg_lineInterpolators.get(interpolate = _);
return line;
};

line.tension = function(v) {
line.tension = function(_) {
if (!arguments.length) return tension;
tension = v;
tension = _;
return line;
};

return line;
}

d3.svg.line = function() {
return d3_svg_line(Object);
return d3_svg_line(d3_identity);
};

// Converts the specified array of data into an array of points
Expand Down Expand Up @@ -5366,7 +5369,7 @@ d3.layout.force = function() {
// use `node.call(force.drag)` to make nodes draggable
force.drag = function() {
if (!drag) drag = d3.behavior.drag()
.origin(Object)
.origin(d3_identity)
.on("dragstart", dragstart)
.on("drag", d3_layout_forceDrag)
.on("dragend", d3_layout_forceDragEnd);
Expand Down Expand Up @@ -5589,7 +5592,7 @@ d3.layout.pie = function() {
var d3_layout_pieSortByValue = {};
// data is two-dimensional array of x,y; we populate y0
d3.layout.stack = function() {
var values = Object,
var values = d3_identity,
order = d3_layout_stackOrderDefault,
offset = d3_layout_stackOffsetZero,
out = d3_layout_stackOut,
Expand Down Expand Up @@ -7585,7 +7588,7 @@ d3.geo.circle = function() {
var origin = [0, 0],
degrees = 90 - 1e-2,
radians = degrees * d3_geo_radians,
arc = d3.geo.greatArc().target(Object);
arc = d3.geo.greatArc().target(d3_identity);

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

FeatureCollection: function(o) {
var features = o.features.map(clipType).filter(Object);
var features = o.features.map(clipType).filter(d3_identity);
return features && (o = Object.create(o), o.features = features, o);
},

Expand Down Expand Up @@ -7645,7 +7648,7 @@ d3.geo.circle = function() {
},

GeometryCollection: function(o) {
var geometries = o.geometries.map(clipType).filter(Object);
var geometries = o.geometries.map(clipType).filter(d3_identity);
return geometries.length && (o = Object.create(o), o.geometries = geometries, o);
}

Expand Down
8 changes: 4 additions & 4 deletions d3.v2.min.js

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions src/core/identity.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
function d3_identity(d) {
return d;
}
6 changes: 3 additions & 3 deletions src/geo/circle.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ d3.geo.circle = function() {
var origin = [0, 0],
degrees = 90 - 1e-2,
radians = degrees * d3_geo_radians,
arc = d3.geo.greatArc().target(Object);
arc = d3.geo.greatArc().target(d3_identity);

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

FeatureCollection: function(o) {
var features = o.features.map(clipType).filter(Object);
var features = o.features.map(clipType).filter(d3_identity);
return features && (o = Object.create(o), o.features = features, o);
},

Expand Down Expand Up @@ -64,7 +64,7 @@ d3.geo.circle = function() {
},

GeometryCollection: function(o) {
var geometries = o.geometries.map(clipType).filter(Object);
var geometries = o.geometries.map(clipType).filter(d3_identity);
return geometries.length && (o = Object.create(o), o.geometries = geometries, o);
}

Expand Down
2 changes: 1 addition & 1 deletion src/layout/force.js
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ d3.layout.force = function() {
// use `node.call(force.drag)` to make nodes draggable
force.drag = function() {
if (!drag) drag = d3.behavior.drag()
.origin(Object)
.origin(d3_identity)
.on("dragstart", dragstart)
.on("drag", d3_layout_forceDrag)
.on("dragend", d3_layout_forceDragEnd);
Expand Down
2 changes: 1 addition & 1 deletion src/layout/stack.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// data is two-dimensional array of x,y; we populate y0
d3.layout.stack = function() {
var values = Object,
var values = d3_identity,
order = d3_layout_stackOrderDefault,
offset = d3_layout_stackOffsetZero,
out = d3_layout_stackOut,
Expand Down
20 changes: 10 additions & 10 deletions src/svg/line.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,36 +9,36 @@ function d3_svg_line(projection) {
return d.length < 1 ? null : "M" + interpolator(projection(d3_svg_linePoints(this, d, x, y)), tension);
}

line.x = function(v) {
line.x = function(_) {
if (!arguments.length) return x;
x = v;
x = _;
return line;
};

line.y = function(v) {
line.y = function(_) {
if (!arguments.length) return y;
y = v;
y = _;
return line;
};

line.interpolate = function(v) {
line.interpolate = function(_) {
if (!arguments.length) return interpolate;
if (!d3_svg_lineInterpolators.has(v += "")) v = d3_svg_lineInterpolatorDefault;
interpolator = d3_svg_lineInterpolators.get(interpolate = v);
if (!d3_svg_lineInterpolators.has(_ += "")) _ = d3_svg_lineInterpolatorDefault;
interpolator = d3_svg_lineInterpolators.get(interpolate = _);
return line;
};

line.tension = function(v) {
line.tension = function(_) {
if (!arguments.length) return tension;
tension = v;
tension = _;
return line;
};

return line;
}

d3.svg.line = function() {
return d3_svg_line(Object);
return d3_svg_line(d3_identity);
};

// Converts the specified array of data into an array of points
Expand Down

0 comments on commit 7f38862

Please sign in to comment.