Skip to content

Commit

Permalink
Merge branch '2.10.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
mbostock committed Sep 4, 2012
2 parents 38a6c30 + 8000976 commit 39347b4
Show file tree
Hide file tree
Showing 21 changed files with 6,118 additions and 6,103 deletions.
12,073 changes: 6,036 additions & 6,037 deletions d3.v2.js

Large diffs are not rendered by default.

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

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions examples/bundle/bundle-radial.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,9 @@ d3.json("../data/flare-imports.json", function(classes) {
.attr("class", "node")
.attr("transform", function(d) { return "rotate(" + (d.x - 90) + ")translate(" + d.y + ")"; })
.append("text")
.attr("dx", function(d) { return d.x < 180 ? 8 : -8; })
.attr("dy", ".31em")
.attr("text-anchor", function(d) { return d.x < 180 ? "start" : "end"; })
.attr("transform", function(d) { return d.x < 180 ? null : "rotate(180)"; })
.attr("transform", function(d) { return d.x < 180 ? "translate(8)" : "rotate(180)translate(-8)"; })
.text(function(d) { return d.key; });
});

Expand Down
3 changes: 1 addition & 2 deletions examples/cluster/cluster-radial.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,8 @@ d3.json("../data/flare.json", function(json) {
.attr("r", 4.5);

node.append("text")
.attr("dx", function(d) { return d.x < 180 ? 8 : -8; })
.attr("dy", ".31em")
.attr("text-anchor", function(d) { return d.x < 180 ? "start" : "end"; })
.attr("transform", function(d) { return d.x < 180 ? null : "rotate(180)"; })
.attr("transform", function(d) { return d.x < 180 ? "translate(8)" : "rotate(180)translate(-8)"; })
.text(function(d) { return d.name; });
});
22 changes: 17 additions & 5 deletions examples/drag/drag.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,26 +19,38 @@
radius = 120;

var drag = d3.behavior.drag()
.origin(Object)
.on("drag", dragmove);
.origin(function(d) { return d; })
.on("dragstart", dragstart)
.on("drag", dragmove)
.on("dragend", dragend);

var svg = d3.select("body").append("svg")
.attr("width", width)
.attr("height", height)

var circle = svg.append("circle")
.data([{x: width / 2, y: height / 2}])
var circle = svg.selectAll("circle")
.data([1 / 3, 2 / 3])
.enter().append("circle")
.datum(function(d) { return {x: width * d, y: height / 2}; })
.attr("r", radius)
.attr("cx", function(d) { return d.x; })
.attr("cy", function(d) { return d.y; })
.call(drag);

function dragstart() {
d3.select(this).style("fill", "red");
}

function dragmove(d) {
circle
d3.select(this)
.attr("cx", d.x = Math.max(radius, Math.min(width - radius, d3.event.x)))
.attr("cy", d.y = Math.max(radius, Math.min(height - radius, d3.event.y)));
}

function dragend() {
d3.select(this).style("fill", null);
}

</script>
</body>
</html>
3 changes: 1 addition & 2 deletions examples/tree/tree-radial.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,8 @@ d3.json("../data/flare.json", function(json) {
.attr("r", 4.5);

node.append("text")
.attr("dx", function(d) { return d.x < 180 ? 8 : -8; })
.attr("dy", ".31em")
.attr("text-anchor", function(d) { return d.x < 180 ? "start" : "end"; })
.attr("transform", function(d) { return d.x < 180 ? null : "rotate(180)"; })
.attr("transform", function(d) { return d.x < 180 ? "translate(8)" : "rotate(180)translate(-8)"; })
.text(function(d) { return d.name; });
});
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "d3",
"version": "2.10.0",
"version": "2.10.1",
"description": "A small, free JavaScript library for manipulating documents based on data.",
"keywords": [
"dom",
Expand All @@ -26,9 +26,9 @@
"sizzle": "1.1.x"
},
"devDependencies": {
"uglify-js": "1.2.3",
"uglify-js": "1.3.3",
"vows": "0.6.x",
"canvas": "0.12.1"
"canvas": "0.13.0"
},
"scripts": {
"test": "./node_modules/vows/bin/vows"
Expand Down
25 changes: 11 additions & 14 deletions src/behavior/drag.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// TODO Track touch points by identifier.

d3.behavior.drag = function() {
var event = d3_eventDispatch(drag, "drag", "dragstart", "dragend"),
origin = null;
Expand All @@ -13,15 +11,14 @@ d3.behavior.drag = function() {
var target = this,
event_ = event.of(target, arguments),
eventTarget = d3.event.target,
touchId = d3.event.touches && d3.event.changedTouches[0].identifier,
offset,
origin_ = point(),
moved = 0;

var w = d3.select(window)
.on("mousemove.drag", dragmove)
.on("touchmove.drag", dragmove)
.on("mouseup.drag", dragend, true)
.on("touchend.drag", dragend, true);
.on(touchId ? "touchmove.drag-" + touchId : "mousemove.drag", dragmove)
.on(touchId ? "touchend.drag-" + touchId : "mouseup.drag", dragend, true);

if (origin) {
offset = origin.apply(target, arguments);
Expand All @@ -30,13 +27,15 @@ d3.behavior.drag = function() {
offset = [0, 0];
}

d3_eventCancel();
// Only cancel mousedown; touchstart is needed for draggable links.
if (!touchId) d3_eventCancel();
event_({type: "dragstart"});

function point() {
var p = target.parentNode,
t = d3.event.changedTouches;
return t ? d3.touches(p, t)[0] : d3.mouse(p);
var p = target.parentNode;
return touchId
? d3.touches(p).filter(function(p) { return p.identifier === touchId; })[0]
: d3.mouse(p);
}

function dragmove() {
Expand All @@ -62,10 +61,8 @@ d3.behavior.drag = function() {
if (d3.event.target === eventTarget) w.on("click.drag", click, true);
}

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

// prevent the subsequent click from propagating (e.g., for anchors)
Expand Down
2 changes: 1 addition & 1 deletion src/core/core.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
d3 = {version: "2.10.0"}; // semver
d3 = {version: "2.10.1"}; // semver
2 changes: 1 addition & 1 deletion src/core/format.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ d3.format = function(specifier) {
if (integer && (value % 1)) return "";

// Convert negative to positive, and record the sign prefix.
var negative = (value < 0) && (value = -value) ? "-" : sign;
var negative = value < 0 && (value = -value) ? "-" : sign;

// Apply the scale, computing it from the value's exponent for si format.
if (scale < 0) {
Expand Down
2 changes: 1 addition & 1 deletion src/core/interpolate.js
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ function d3_interpolateByName(name) {

d3.interpolators = [
d3.interpolateObject,
function(a, b) { return (b instanceof Array) && d3.interpolateArray(a, b); },
function(a, b) { return b instanceof Array && 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_Rgb || b instanceof d3_Hsl) && d3.interpolateRgb(a, b); },
function(a, b) { return !isNaN(a = +a) && !isNaN(b = +b) && d3.interpolateNumber(a, b); }
Expand Down
2 changes: 1 addition & 1 deletion src/core/mouse.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ function d3_mousePoint(container, e) {
var svg = container.ownerSVGElement || container;
if (svg.createSVGPoint) {
var point = svg.createSVGPoint();
if ((d3_mouse_bug44083 < 0) && (window.scrollX || window.scrollY)) {
if (d3_mouse_bug44083 < 0 && (window.scrollX || window.scrollY)) {
svg = d3.select(document.body)
.append("svg")
.style("position", "absolute")
Expand Down
4 changes: 2 additions & 2 deletions src/core/nest.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ d3.nest = function() {
}
}

valuesByKey.forEach(function(keyValue) {
o[keyValue] = map(valuesByKey.get(keyValue), depth);
valuesByKey.forEach(function(keyValue, values) {
o[keyValue] = map(values, depth);
});

return o;
Expand Down
2 changes: 1 addition & 1 deletion src/dsv/dsv.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ function d3_dsv(delimiter, mimeType) {

while ((t = token()) !== EOF) {
var a = [];
while ((t !== EOL) && (t !== EOF)) {
while (t !== EOL && t !== EOF) {
a.push(t);
t = token();
}
Expand Down
43 changes: 22 additions & 21 deletions src/layout/force.js
Original file line number Diff line number Diff line change
Expand Up @@ -274,43 +274,44 @@ d3.layout.force = function() {
force.drag = function() {
if (!drag) drag = d3.behavior.drag()
.origin(d3_identity)
.on("dragstart", dragstart)
.on("drag", d3_layout_forceDrag)
.on("dragend", d3_layout_forceDragEnd);
.on("dragstart", d3_layout_forceDragstart)
.on("drag", dragmove)
.on("dragend", d3_layout_forceDragend);

this.on("mouseover.force", d3_layout_forceDragOver)
.on("mouseout.force", d3_layout_forceDragOut)
this.on("mouseover.force", d3_layout_forceMouseover)
.on("mouseout.force", d3_layout_forceMouseout)
.call(drag);
};

function dragstart(d) {
d3_layout_forceDragOver(d3_layout_forceDragNode = d);
d3_layout_forceDragForce = force;
function dragmove(d) {
d.px = d3.event.x;
d.py = d3.event.y;
force.resume(); // restart annealing
}

return d3.rebind(force, event, "on");
};

var d3_layout_forceDragForce,
d3_layout_forceDragNode;
// The fixed property has three bits:
// Bit 1 can be set externally (e.g., d.fixed = true) and show persist.
// Bit 2 stores the dragging state, from mousedown to mouseup.
// Bit 3 stores the hover state, from mouseover to mouseout.
// Dragend is a special case: it also clears the hover state.

function d3_layout_forceDragOver(d) {
d.fixed |= 2;
function d3_layout_forceDragstart(d) {
d.fixed |= 2; // set bit 2
}

function d3_layout_forceDragOut(d) {
if (d !== d3_layout_forceDragNode) d.fixed &= 1;
function d3_layout_forceDragend(d) {
d.fixed &= 1; // unset bits 2 and 3
}

function d3_layout_forceDragEnd() {
d3_layout_forceDragNode.fixed &= 1;
d3_layout_forceDragForce = d3_layout_forceDragNode = null;
function d3_layout_forceMouseover(d) {
d.fixed |= 4; // set bit 3
}

function d3_layout_forceDrag() {
d3_layout_forceDragNode.px = d3.event.x;
d3_layout_forceDragNode.py = d3.event.y;
d3_layout_forceDragForce.resume(); // restart annealing
function d3_layout_forceMouseout(d) {
d.fixed &= 3; // unset bit 3
}

function d3_layout_forceAccumulate(quad, alpha, charges) {
Expand Down
2 changes: 1 addition & 1 deletion src/layout/histogram.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ d3.layout.histogram = function() {
if (m > 0) {
i = -1; while(++i < n) {
x = values[i];
if ((x >= range[0]) && (x <= range[1])) {
if (x >= range[0] && x <= range[1]) {
bin = bins[d3.bisect(thresholds, x, 1, m) - 1];
bin.y += k;
bin.push(data[i]);
Expand Down
4 changes: 2 additions & 2 deletions src/package.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ require("util").puts(JSON.stringify({
"sizzle": "1.1.x"
},
"devDependencies": {
"uglify-js": "1.2.3",
"uglify-js": "1.3.3",
"vows": "0.6.x",
"canvas": "0.12.1" // for node-canvas example
"canvas": "0.13.0" // for node-canvas example
},
"scripts": {"test": "./node_modules/vows/bin/vows"}
}, null, 2));
2 changes: 1 addition & 1 deletion src/scale/ordinal.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ function d3_scale_ordinal(domain, ranger) {
if (arguments.length < 2) padding = 0;
var start = x[0],
stop = x[1],
step = (stop - start) / (domain.length - 1 + padding);
step = (stop - start) / (Math.max(1, domain.length - 1) + padding);
range = steps(domain.length < 2 ? (start + stop) / 2 : start + step * padding / 2, step);
rangeBand = 0;
ranger = {t: "rangePoints", a: arguments};
Expand Down
4 changes: 2 additions & 2 deletions src/time/day.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
d3.time.day = d3_time_interval(function(date) {
var day = new d3_time(0, date.getMonth(), date.getDate());
day.setFullYear(date.getFullYear());
var day = new d3_time(1970, 0);
day.setFullYear(date.getFullYear(), date.getMonth(), date.getDate());
return day;
}, function(date, offset) {
date.setDate(date.getDate() + offset);
Expand Down
5 changes: 5 additions & 0 deletions test/scale/ordinal-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,11 @@ suite.addBatch({
assert.deepEqual(x.range(), [30, 60, 90]);
assert.equal(x.rangeBand(), 0);
},
"correctly handles singleton domains": function(ordinal) {
var x = ordinal().domain(["a"]).rangePoints([0, 120]);
assert.deepEqual(x.range(), [60]);
assert.equal(x.rangeBand(), 0);
},
"can be set to a descending range": function(ordinal) {
var x = ordinal().domain(["a", "b", "c"]).rangePoints([120, 0]);
assert.deepEqual(x.range(), [120, 60,0]);
Expand Down
4 changes: 4 additions & 0 deletions test/time/day-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ suite.addBatch({
assert.deepEqual(ceil(utc(2011, 10, 06, 08)), local(2011, 10, 07));
assert.deepEqual(ceil(utc(2011, 10, 06, 09)), local(2011, 10, 07));
assert.deepEqual(ceil(utc(2011, 10, 06, 10)), local(2011, 10, 07));
},
"handles midnight for leap years": function(ceil) {
assert.deepEqual(ceil(utc(2012, 02, 01, 00)), local(2012, 02, 01));
assert.deepEqual(ceil(utc(2012, 02, 01, 00)), local(2012, 02, 01));
}
},
"offset": {
Expand Down

0 comments on commit 39347b4

Please sign in to comment.