Skip to content

Commit

Permalink
Merge branch '3.1.5'
Browse files Browse the repository at this point in the history
  • Loading branch information
mbostock committed Apr 7, 2013
2 parents ea284eb + 80a1dd6 commit 43d09af
Show file tree
Hide file tree
Showing 23 changed files with 243 additions and 144 deletions.
2 changes: 1 addition & 1 deletion component.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "d3",
"version": "3.1.4",
"version": "3.1.5",
"main": "index-browserify.js",
"scripts": [
"index-browserify.js",
Expand Down
42 changes: 20 additions & 22 deletions d3.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
d3 = function() {
var d3 = {
version: "3.1.4"
version: "3.1.5"
};
if (!Date.now) Date.now = function() {
return +new Date();
Expand Down Expand Up @@ -409,6 +409,16 @@ d3 = function() {
while (s = e.sourceEvent) e = s;
return e;
}
function d3_eventSuppress(target, type) {
function off() {
target.on(type, null);
}
target.on(type, function() {
d3_eventCancel();
off();
}, true);
setTimeout(off, 0);
}
function d3_eventDispatch(target) {
var dispatch = new d3_dispatch(), i = 0, n = arguments.length;
while (++i < n) dispatch[arguments[i]] = d3_dispatch_event(dispatch);
Expand Down Expand Up @@ -524,14 +534,10 @@ d3 = function() {
});
if (moved) {
d3_eventCancel();
if (d3.event.target === eventTarget) w.on("click.drag", click, true);
if (d3.event.target === eventTarget) d3_eventSuppress(w, "click");
}
w.on(touchId != null ? "touchmove.drag-" + touchId : "mousemove.drag", null).on(touchId != null ? "touchend.drag-" + touchId : "mouseup.drag", null);
}
function click() {
d3_eventCancel();
w.on("click.drag", null);
}
}
drag.origin = function(x) {
if (!arguments.length) return origin;
Expand Down Expand Up @@ -1171,11 +1177,7 @@ d3 = function() {
function mouseup() {
if (moved) d3_eventCancel();
w.on("mousemove.zoom", null).on("mouseup.zoom", null);
if (moved && d3.event.target === eventTarget) w.on("click.zoom", click, true);
}
function click() {
d3_eventCancel();
w.on("click.zoom", null);
if (moved && d3.event.target === eventTarget) d3_eventSuppress(w, "click.zoom");
}
}
function mousewheel() {
Expand Down Expand Up @@ -2002,14 +2004,14 @@ d3 = function() {
}
d3.geo = {};
d3.geo.stream = function(object, listener) {
if (d3_geo_streamObjectType.hasOwnProperty(object.type)) {
if (object && d3_geo_streamObjectType.hasOwnProperty(object.type)) {
d3_geo_streamObjectType[object.type](object, listener);
} else {
d3_geo_streamGeometry(object, listener);
}
};
function d3_geo_streamGeometry(geometry, listener) {
if (d3_geo_streamGeometryType.hasOwnProperty(geometry.type)) {
if (geometry && d3_geo_streamGeometryType.hasOwnProperty(geometry.type)) {
d3_geo_streamGeometryType[geometry.type](geometry, listener);
}
}
Expand Down Expand Up @@ -4683,7 +4685,7 @@ d3 = function() {
};
d3.interpolateNumber = d3_interpolateNumber;
function d3_interpolateNumber(a, b) {
b -= a;
b -= a = +a;
return function(t) {
return a + b * t;
};
Expand Down Expand Up @@ -4764,6 +4766,7 @@ d3 = function() {
d3.interpolateString = d3_interpolateString;
function d3_interpolateString(a, b) {
var m, i, j, s0 = 0, s1 = 0, s = [], q = [], n, o;
a = a + "", b = b + "";
d3_interpolate_number.lastIndex = 0;
for (i = 0; m = d3_interpolate_number.exec(b); ++i) {
if (m.index) s.push(b.substring(s0, s1 = m.index));
Expand Down Expand Up @@ -4834,14 +4837,9 @@ d3 = function() {
function d3_interpolateByName(name) {
return name == "transform" ? d3_interpolateTransform : d3_interpolate;
}
d3.interpolators = [ d3_interpolateObject, function(a, b) {
return Array.isArray(b) && d3_interpolateArray(a, b);
}, function(a, b) {
return (typeof a === "string" || typeof b === "string") && d3_interpolateString(a + "", b + "");
}, function(a, b) {
return (typeof b === "string" ? d3_rgb_names.has(b) || /^(#|rgb\(|hsl\()/.test(b) : b instanceof d3_Color) && d3_interpolateRgb(a, b);
}, function(a, b) {
return !isNaN(a = +a) && !isNaN(b = +b) && d3_interpolateNumber(a, b);
d3.interpolators = [ function(a, b) {
var t = typeof b;
return (t === "string" || t !== typeof a ? d3_rgb_names.has(b) || /^(#|rgb\(|hsl\()/.test(b) ? d3_interpolateRgb : d3_interpolateString : b instanceof d3_Color ? d3_interpolateRgb : t === "object" ? Array.isArray(b) ? d3_interpolateArray : d3_interpolateObject : d3_interpolateNumber)(a, b);
} ];
d3.interpolateArray = d3_interpolateArray;
function d3_interpolateArray(a, b) {
Expand Down
10 changes: 5 additions & 5 deletions d3.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "d3",
"version": "3.1.4",
"version": "3.1.5",
"description": "A small, free JavaScript library for manipulating documents based on data.",
"keywords": [
"dom",
Expand Down
8 changes: 1 addition & 7 deletions src/behavior/drag.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,18 +65,12 @@ d3.behavior.drag = function() {
// if moved, prevent the mouseup (and possibly click) from propagating
if (moved) {
d3_eventCancel();
if (d3.event.target === eventTarget) w.on("click.drag", click, true);
if (d3.event.target === eventTarget) d3_eventSuppress(w, "click");
}

w .on(touchId != null ? "touchmove.drag-" + touchId : "mousemove.drag", null)
.on(touchId != null ? "touchend.drag-" + touchId : "mouseup.drag", null);
}

// prevent the subsequent click from propagating (e.g., for anchors)
function click() {
d3_eventCancel();
w.on("click.drag", null);
}
}

drag.origin = function(x) {
Expand Down
7 changes: 1 addition & 6 deletions src/behavior/zoom.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,12 +116,7 @@ d3.behavior.zoom = function() {
function mouseup() {
if (moved) d3_eventCancel();
w.on("mousemove.zoom", null).on("mouseup.zoom", null);
if (moved && d3.event.target === eventTarget) w.on("click.zoom", click, true);
}

function click() {
d3_eventCancel();
w.on("click.zoom", null);
if (moved && d3.event.target === eventTarget) d3_eventSuppress(w, "click.zoom");
}
}

Expand Down
9 changes: 9 additions & 0 deletions src/event/event.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,15 @@ function d3_eventSource() {
return e;
}

// Registers an event listener for the specified target that cancels the next
// event for the specified type, but only if it occurs immediately. This is
// useful to disambiguate dragging from clicking.
function d3_eventSuppress(target, type) {
function off() { target.on(type, null); }
target.on(type, function() { d3_eventCancel(); off(); }, true);
setTimeout(off, 0); // clear the handler if it doesn't fire
}

// Like d3.dispatch, but for custom events abstracting native UI events. These
// events have a target component (such as a brush), a target element (such as
// the svg:g element containing the brush) and the standard arguments `d` (the
Expand Down
4 changes: 2 additions & 2 deletions src/geo/stream.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import "geo";

d3.geo.stream = function(object, listener) {
if (d3_geo_streamObjectType.hasOwnProperty(object.type)) {
if (object && d3_geo_streamObjectType.hasOwnProperty(object.type)) {
d3_geo_streamObjectType[object.type](object, listener);
} else {
d3_geo_streamGeometry(object, listener);
}
};

function d3_geo_streamGeometry(geometry, listener) {
if (d3_geo_streamGeometryType.hasOwnProperty(geometry.type)) {
if (geometry && d3_geo_streamGeometryType.hasOwnProperty(geometry.type)) {
d3_geo_streamGeometryType[geometry.type](geometry, listener);
}
}
Expand Down
12 changes: 7 additions & 5 deletions src/interpolate/interpolate.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,11 @@ function d3_interpolateByName(name) {
}

d3.interpolators = [
d3_interpolateObject,
function(a, b) { return Array.isArray(b) && d3_interpolateArray(a, b); },
function(a, b) { return (typeof a === "string" || typeof b === "string") && d3_interpolateString(a + "", b + ""); },
function(a, b) { return (typeof b === "string" ? d3_rgb_names.has(b) || /^(#|rgb\(|hsl\()/.test(b) : b instanceof d3_Color) && d3_interpolateRgb(a, b); },
function(a, b) { return !isNaN(a = +a) && !isNaN(b = +b) && d3_interpolateNumber(a, b); }
function(a, b) {
var t = typeof b;
return (t === "string" || t !== typeof a ? (d3_rgb_names.has(b) || /^(#|rgb\(|hsl\()/.test(b) ? d3_interpolateRgb : d3_interpolateString)
: b instanceof d3_Color ? d3_interpolateRgb
: t === "object" ? (Array.isArray(b) ? d3_interpolateArray : d3_interpolateObject)
: d3_interpolateNumber)(a, b);
}
];
2 changes: 1 addition & 1 deletion src/interpolate/number.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
d3.interpolateNumber = d3_interpolateNumber;

function d3_interpolateNumber(a, b) {
b -= a;
b -= a = +a;
return function(t) { return a + b * t; };
}
3 changes: 3 additions & 0 deletions src/interpolate/string.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ function d3_interpolateString(a, b) {
n, // q.length
o;

// Coerce inputs to strings.
a = a + "", b = b + "";

// Reset our regular expression!
d3_interpolate_number.lastIndex = 0;

Expand Down
2 changes: 1 addition & 1 deletion src/start.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
d3 = (function(){
var d3 = {version: "3.1.4"}; // semver
var d3 = {version: "3.1.5"}; // semver
6 changes: 6 additions & 0 deletions test/assert.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@ var assert = require("assert");

assert = module.exports = Object.create(assert);

assert.isArray = function(actual, message) {
if (!Array.isArray(actual)) {
assert.fail(actual, null, message || "expected {actual} to be an Array", null, assert.isArray);
}
};

assert.inDelta = function(actual, expected, delta, message) {
if (!inDelta(actual, expected, delta)) {
assert.fail(actual, expected, message || "expected {actual} to be in within *" + delta + "* of {expected}", null, assert.inDelta);
Expand Down
6 changes: 6 additions & 0 deletions test/geo/stream-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ suite.addBatch({
stream({type: "FeatureCollection", features: [{type: "Feature", geometry: {type: "Unknown"}}]}, {});
stream({type: "GeometryCollection", geometries: [{type: "Unknown"}]}, {});
},
"ignores null geometries": function(stream) {
stream(null, {});
stream({type: "Feature", geometry: null}, {});
stream({type: "FeatureCollection", features: [{type: "Feature", geometry: null}]}, {});
stream({type: "GeometryCollection", geometries: [null]}, {});
},
"returns void": function(stream) {
assert.isUndefined(stream({type: "Point", coordinates: [1, 2]}, {point: function() { return true; }}));
},
Expand Down
52 changes: 26 additions & 26 deletions test/interpolate/ease-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,37 +49,37 @@ suite.addBatch({
},
"invalid eases and modes default to linear-in": function(ease) {
var e = ease("__proto__-__proto__");
assert.equal(e(0), 0);
assert.equal(e(.5), .5);
assert.equal(e(1), 1);
assert.strictEqual(e(0), 0);
assert.strictEqual(e(.5), .5);
assert.strictEqual(e(1), 1);
var e = ease("hasOwnProperty-constructor");
assert.equal(e(0), 0);
assert.equal(e(.5), .5);
assert.equal(e(1), 1);
assert.strictEqual(e(0), 0);
assert.strictEqual(e(.5), .5);
assert.strictEqual(e(1), 1);
},
"all easing functions return exactly 0 for t = 0": function(ease) {
assert.equal(ease("linear")(0), 0);
assert.equal(ease("poly", 2)(0), 0);
assert.equal(ease("quad")(0), 0);
assert.equal(ease("cubic")(0), 0);
assert.equal(ease("sin")(0), 0);
assert.equal(ease("exp")(0), 0);
assert.equal(ease("circle")(0), 0);
assert.equal(ease("elastic")(0), 0);
assert.equal(ease("back")(0), 0);
assert.equal(ease("bounce")(0), 0);
assert.strictEqual(ease("linear")(0), 0);
assert.strictEqual(ease("poly", 2)(0), 0);
assert.strictEqual(ease("quad")(0), 0);
assert.strictEqual(ease("cubic")(0), 0);
assert.strictEqual(ease("sin")(0), 0);
assert.strictEqual(ease("exp")(0), 0);
assert.strictEqual(ease("circle")(0), 0);
assert.strictEqual(ease("elastic")(0), 0);
assert.strictEqual(ease("back")(0), 0);
assert.strictEqual(ease("bounce")(0), 0);
},
"all easing functions return exactly 1 for t = 1": function(ease) {
assert.equal(ease("linear")(1), 1);
assert.equal(ease("poly", 2)(1), 1);
assert.equal(ease("quad")(1), 1);
assert.equal(ease("cubic")(1), 1);
assert.equal(ease("sin")(1), 1);
assert.equal(ease("exp")(1), 1);
assert.equal(ease("circle")(1), 1);
assert.equal(ease("elastic")(1), 1);
assert.equal(ease("back")(1), 1);
assert.equal(ease("bounce")(1), 1);
assert.strictEqual(ease("linear")(1), 1);
assert.strictEqual(ease("poly", 2)(1), 1);
assert.strictEqual(ease("quad")(1), 1);
assert.strictEqual(ease("cubic")(1), 1);
assert.strictEqual(ease("sin")(1), 1);
assert.strictEqual(ease("exp")(1), 1);
assert.strictEqual(ease("circle")(1), 1);
assert.strictEqual(ease("elastic")(1), 1);
assert.strictEqual(ease("back")(1), 1);
assert.strictEqual(ease("bounce")(1), 1);
},
"the -in suffix returns the identity": function(ease) {
assert.inDelta(ease("linear-in")(.25), ease("linear")(.25), 1e-6);
Expand Down
16 changes: 8 additions & 8 deletions test/interpolate/hsl-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,22 @@ suite.addBatch({
"interpolateHsl": {
topic: load("interpolate/hsl"), // beware instanceof d3_Color
"parses string input": function(d3) {
assert.equal(d3.interpolateHsl("steelblue", "#f00")(.2), "#383dc3");
assert.equal(d3.interpolateHsl("steelblue", "#f00")(.6), "#dd1ce1");
assert.strictEqual(d3.interpolateHsl("steelblue", "#f00")(.2), "#383dc3");
assert.strictEqual(d3.interpolateHsl("steelblue", "#f00")(.6), "#dd1ce1");
},
"parses d3.hsl input": function(d3) {
assert.equal(d3.interpolateHsl(d3.hsl("steelblue"), "#f00")(.2), "#383dc3");
assert.equal(d3.interpolateHsl("steelblue", d3.hsl(0, 1, .5))(.6), "#dd1ce1");
assert.strictEqual(d3.interpolateHsl(d3.hsl("steelblue"), "#f00")(.2), "#383dc3");
assert.strictEqual(d3.interpolateHsl("steelblue", d3.hsl(0, 1, .5))(.6), "#dd1ce1");
},
"parses d3.rgb input": function(d3) {
assert.equal(d3.interpolateHsl(d3.rgb("steelblue"), "#f00")(.2), "#383dc3");
assert.equal(d3.interpolateHsl("steelblue", d3.rgb(255, 0, 0))(.6), "#dd1ce1");
assert.strictEqual(d3.interpolateHsl(d3.rgb("steelblue"), "#f00")(.2), "#383dc3");
assert.strictEqual(d3.interpolateHsl("steelblue", d3.rgb(255, 0, 0))(.6), "#dd1ce1");
},
"interpolates in HSL color space": function(d3) {
assert.equal(d3.interpolateHsl("steelblue", "#f00")(.2), "#383dc3");
assert.strictEqual(d3.interpolateHsl("steelblue", "#f00")(.2), "#383dc3");
},
"outputs a hexadecimal string": function(d3) {
assert.equal(d3.interpolateHsl("steelblue", "#f00")(.2), "#383dc3");
assert.strictEqual(d3.interpolateHsl("steelblue", "#f00")(.2), "#383dc3");
}
}
});
Expand Down
Loading

0 comments on commit 43d09af

Please sign in to comment.