Skip to content

Commit

Permalink
Merge branch '3.3.9'
Browse files Browse the repository at this point in the history
  • Loading branch information
mbostock committed Oct 25, 2013
2 parents ed54503 + d44de8f commit 87acef2
Show file tree
Hide file tree
Showing 15 changed files with 188 additions and 84 deletions.
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "d3",
"version": "3.3.8",
"version": "3.3.9",
"main": "d3.js",
"scripts": [
"d3.js"
Expand Down
2 changes: 1 addition & 1 deletion component.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"animation",
"canvas"
],
"version": "3.3.8",
"version": "3.3.9",
"main": "index-browserify.js",
"scripts": [
"d3.js",
Expand Down
140 changes: 90 additions & 50 deletions d3.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
d3 = function() {
var d3 = {
version: "3.3.8"
version: "3.3.9"
};
if (!Date.now) Date.now = function() {
return +new Date();
Expand Down Expand Up @@ -1059,13 +1059,16 @@ d3 = function() {
}
};
}
var d3_event_dragSelect = d3_vendorSymbol(d3_documentElement.style, "userSelect"), d3_event_dragId = 0;
var d3_event_dragSelect = "onselectstart" in d3_document ? null : d3_vendorSymbol(d3_documentElement.style, "userSelect"), d3_event_dragId = 0;
function d3_event_dragSuppress() {
var name = ".dragsuppress-" + ++d3_event_dragId, touchmove = "touchmove" + name, selectstart = "selectstart" + name, dragstart = "dragstart" + name, click = "click" + name, w = d3.select(d3_window).on(touchmove, d3_eventPreventDefault).on(selectstart, d3_eventPreventDefault).on(dragstart, d3_eventPreventDefault), style = d3_documentElement.style, select = style[d3_event_dragSelect];
style[d3_event_dragSelect] = "none";
var name = ".dragsuppress-" + ++d3_event_dragId, click = "click" + name, w = d3.select(d3_window).on("touchmove" + name, d3_eventPreventDefault).on("dragstart" + name, d3_eventPreventDefault).on("selectstart" + name, d3_eventPreventDefault);
if (d3_event_dragSelect) {
var style = d3_documentElement.style, select = style[d3_event_dragSelect];
style[d3_event_dragSelect] = "none";
}
return function(suppressClick) {
w.on(name, null);
style[d3_event_dragSelect] = select;
if (d3_event_dragSelect) style[d3_event_dragSelect] = select;
if (suppressClick) {
function off() {
w.on(click, null);
Expand Down Expand Up @@ -3511,6 +3514,15 @@ d3 = function() {
function d3_geo_resample(project) {
var δ2 = .5, cosMinDistance = Math.cos(30 * d3_radians), maxDepth = 16;
function resample(stream) {
return (maxDepth ? resampleRecursive : resampleNone)(stream);
}
function resampleNone(stream) {
return d3_geo_transformPoint(stream, function(x, y) {
x = project(x, y);
stream.point(x[0], x[1]);
});
}
function resampleRecursive(stream) {
var λ00, φ00, x00, y00, a00, b00, c00, λ0, x0, y0, a0, b0, c0;
var resample = {
point: point,
Expand Down Expand Up @@ -3577,38 +3589,6 @@ d3 = function() {
};
return resample;
}
d3.geo.transform = function(methods) {
return {
stream: function(stream) {
var transform = new d3_geo_transform(stream);
for (var k in methods) transform[k] = methods[k];
return transform;
}
};
};
function d3_geo_transform(stream) {
this.stream = stream;
}
d3_geo_transform.prototype = {
point: function(x, y) {
this.stream.point(x, y);
},
sphere: function() {
this.stream.sphere();
},
lineStart: function() {
this.stream.lineStart();
},
lineEnd: function() {
this.stream.lineEnd();
},
polygonStart: function() {
this.stream.polygonStart();
},
polygonEnd: function() {
this.stream.polygonEnd();
}
};
d3.geo.path = function() {
var pointRadius = 4.5, projection, context, projectStream, contextStream, cacheStream;
function path(object) {
Expand Down Expand Up @@ -3661,11 +3641,59 @@ d3 = function() {
return project([ x * d3_degrees, y * d3_degrees ]);
});
return function(stream) {
var transform = new d3_geo_transform(stream = resample(stream));
transform.point = function(x, y) {
stream.point(x * d3_radians, y * d3_radians);
};
return transform;
return d3_geo_projectionRadians(resample(stream));
};
}
d3.geo.transform = function(methods) {
return {
stream: function(stream) {
var transform = new d3_geo_transform(stream);
for (var k in methods) transform[k] = methods[k];
return transform;
}
};
};
function d3_geo_transform(stream) {
this.stream = stream;
}
d3_geo_transform.prototype = {
point: function(x, y) {
this.stream.point(x, y);
},
sphere: function() {
this.stream.sphere();
},
lineStart: function() {
this.stream.lineStart();
},
lineEnd: function() {
this.stream.lineEnd();
},
polygonStart: function() {
this.stream.polygonStart();
},
polygonEnd: function() {
this.stream.polygonEnd();
}
};
function d3_geo_transformPoint(stream, point) {
return {
point: point,
sphere: function() {
stream.sphere();
},
lineStart: function() {
stream.lineStart();
},
lineEnd: function() {
stream.lineEnd();
},
polygonStart: function() {
stream.polygonStart();
},
polygonEnd: function() {
stream.polygonEnd();
}
};
}
d3.geo.projection = d3_geo_projection;
Expand Down Expand Up @@ -3748,11 +3776,9 @@ d3 = function() {
};
}
function d3_geo_projectionRadians(stream) {
var transform = new d3_geo_transform(stream);
transform.point = function(λ, φ) {
stream.point(λ * d3_radians, φ * d3_radians);
};
return transform;
return d3_geo_transformPoint(stream, function(x, y) {
stream.point(x * d3_radians, y * d3_radians);
});
}
function d3_geo_equirectangular(λ, φ) {
return [ λ, φ ];
Expand Down Expand Up @@ -6955,10 +6981,24 @@ d3 = function() {
return d3.range.apply(d3, d3_scale_linearTickRange(domain, m));
}
function d3_scale_linearTickFormat(domain, m, format) {
var precision = -Math.floor(Math.log(d3_scale_linearTickRange(domain, m)[2]) / Math.LN10 + .01);
var range = d3_scale_linearTickRange(domain, m);
return d3.format(format ? format.replace(d3_format_re, function(a, b, c, d, e, f, g, h, i, j) {
return [ b, c, d, e, f, g, h, i || "." + (precision - (j === "%") * 2), j ].join("");
}) : ",." + precision + "f");
return [ b, c, d, e, f, g, h, i || "." + d3_scale_linearFormatPrecision(j, range), j ].join("");
}) : ",." + d3_scale_linearPrecision(range[2]) + "f");
}
var d3_scale_linearFormatSignificant = {
s: 1,
g: 1,
p: 1,
r: 1,
e: 1
};
function d3_scale_linearPrecision(value) {
return -Math.floor(Math.log(value) / Math.LN10 + .01);
}
function d3_scale_linearFormatPrecision(type, range) {
var p = d3_scale_linearPrecision(range[2]);
return type in d3_scale_linearFormatSignificant ? Math.abs(p - d3_scale_linearPrecision(Math.max(Math.abs(range[0]), Math.abs(range[1])))) + +(type !== "e") : p - (type === "%") * 2;
}
d3.scale.log = function() {
return d3_scale_log(d3.scale.linear().domain([ 0, 1 ]), 10, true, [ 1, 10 ]);
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.3.8",
"version": "3.3.9",
"description": "A small, free JavaScript library for manipulating documents based on data.",
"keywords": [
"dom",
Expand Down
20 changes: 11 additions & 9 deletions src/event/drag.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,24 @@ import "../core/document";
import "../core/vendor";
import "../selection/on";

var d3_event_dragSelect = d3_vendorSymbol(d3_documentElement.style, "userSelect"),
var d3_event_dragSelect = "onselectstart" in d3_document ? null : d3_vendorSymbol(d3_documentElement.style, "userSelect"),
d3_event_dragId = 0;

function d3_event_dragSuppress() {
var name = ".dragsuppress-" + ++d3_event_dragId,
touchmove = "touchmove" + name,
selectstart = "selectstart" + name,
dragstart = "dragstart" + name,
click = "click" + name,
w = d3.select(d3_window).on(touchmove, d3_eventPreventDefault).on(selectstart, d3_eventPreventDefault).on(dragstart, d3_eventPreventDefault),
style = d3_documentElement.style,
select = style[d3_event_dragSelect];
style[d3_event_dragSelect] = "none";
w = d3.select(d3_window)
.on("touchmove" + name, d3_eventPreventDefault)
.on("dragstart" + name, d3_eventPreventDefault)
.on("selectstart" + name, d3_eventPreventDefault);
if (d3_event_dragSelect) {
var style = d3_documentElement.style,
select = style[d3_event_dragSelect];
style[d3_event_dragSelect] = "none";
}
return function(suppressClick) {
w.on(name, null);
style[d3_event_dragSelect] = select;
if (d3_event_dragSelect) style[d3_event_dragSelect] = select;
if (suppressClick) { // suppress the next click, but only if it’s immediate
function off() { w.on(click, null); }
w.on(click, function() { d3_eventPreventDefault(); off(); }, true);
Expand Down
7 changes: 1 addition & 6 deletions src/geo/path.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import "path-context";
import "projection";
import "resample";
import "stream";
import "transform";

d3.geo.path = function() {
var pointRadius = 4.5,
Expand Down Expand Up @@ -84,9 +83,5 @@ d3.geo.path = function() {

function d3_geo_pathProjectStream(project) {
var resample = d3_geo_resample(function(x, y) { return project([x * d3_degrees, y * d3_degrees]); });
return function(stream) {
var transform = new d3_geo_transform(stream = resample(stream));
transform.point = function(x, y) { stream.point(x * d3_radians, y * d3_radians); };
return transform;
};
return function(stream) { return d3_geo_projectionRadians(resample(stream)); };
}
9 changes: 3 additions & 6 deletions src/geo/projection.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import "geo";
import "path";
import "resample";
import "rotation";
import "stream";
import "transform";

d3.geo.projection = d3_geo_projection;
Expand Down Expand Up @@ -116,9 +115,7 @@ function d3_geo_projectionMutator(projectAt) {
}

function d3_geo_projectionRadians(stream) {
var transform = new d3_geo_transform(stream);
transform.point = function(λ, φ) {
stream.point(λ * d3_radians, φ * d3_radians);
};
return transform;
return d3_geo_transformPoint(stream, function(x, y) {
stream.point(x * d3_radians, y * d3_radians);
});
}
12 changes: 11 additions & 1 deletion src/geo/resample.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,24 @@
import "../math/abs";
import "../math/trigonometry";
import "cartesian";
import "stream";

function d3_geo_resample(project) {
var δ2 = .5, // precision, px²
cosMinDistance = Math.cos(30 * d3_radians), // cos(minimum angular distance)
maxDepth = 16;

function resample(stream) {
return (maxDepth ? resampleRecursive : resampleNone)(stream);
}

function resampleNone(stream) {
return d3_geo_transformPoint(stream, function(x, y) {
x = project(x, y);
stream.point(x[0], x[1]);
});
}

function resampleRecursive(stream) {
var λ00, φ00, x00, y00, a00, b00, c00, // first point
λ0, x0, y0, a0, b0, c0; // previous point

Expand Down
11 changes: 11 additions & 0 deletions src/geo/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,14 @@ d3_geo_transform.prototype = {
polygonStart: function() { this.stream.polygonStart(); },
polygonEnd: function() { this.stream.polygonEnd(); }
};

function d3_geo_transformPoint(stream, point) {
return {
point: point,
sphere: function() { stream.sphere(); },
lineStart: function() { stream.lineStart(); },
lineEnd: function() { stream.lineEnd(); },
polygonStart: function() { stream.polygonStart(); },
polygonEnd: function() { stream.polygonEnd(); },
};
}
26 changes: 23 additions & 3 deletions src/scale/linear.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,28 @@ function d3_scale_linearTicks(domain, m) {
}

function d3_scale_linearTickFormat(domain, m, format) {
var precision = -Math.floor(Math.log(d3_scale_linearTickRange(domain, m)[2]) / Math.LN10 + .01);
var range = d3_scale_linearTickRange(domain, m);
return d3.format(format
? format.replace(d3_format_re, function(a, b, c, d, e, f, g, h, i, j) { return [b, c, d, e, f, g, h, i || "." + (precision - (j === "%") * 2), j].join(""); })
: ",." + precision + "f");
? format.replace(d3_format_re, function(a, b, c, d, e, f, g, h, i, j) { return [b, c, d, e, f, g, h, i || "." + d3_scale_linearFormatPrecision(j, range), j].join(""); })
: ",." + d3_scale_linearPrecision(range[2]) + "f");
}

var d3_scale_linearFormatSignificant = {s: 1, g: 1, p: 1, r: 1, e: 1};

// Returns the number of significant digits after the decimal point.
function d3_scale_linearPrecision(value) {
return -Math.floor(Math.log(value) / Math.LN10 + .01);
}

// For some format types, the precision specifies the number of significant
// digits; for others, it specifies the number of digits after the decimal
// point. For significant format types, the desired precision equals one plus
// the difference between the decimal precision of the range’s maximum absolute
// value and the tick step’s decimal precision. For format "e", the digit before
// the decimal point counts as one.
function d3_scale_linearFormatPrecision(type, range) {
var p = d3_scale_linearPrecision(range[2]);
return type in d3_scale_linearFormatSignificant
? Math.abs(p - d3_scale_linearPrecision(Math.max(Math.abs(range[0]), Math.abs(range[1])))) + +(type !== "e")
: p - (type === "%") * 2;
}
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.3.8"}; // semver
var d3 = {version: "3.3.9"}; // semver
2 changes: 2 additions & 0 deletions test/format/format-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ suite.addBatch({
assert.strictEqual(f(-42), "-4.2e+1");
assert.strictEqual(f(-4200000), "-4.2e+6");
assert.strictEqual(f(-42000000), "-4.2e+7");
assert.strictEqual(format(".0e")(42), "4e+1")
assert.strictEqual(format(".3e")(42), "4.200e+1")
},
"can output SI prefix notation": function(format) {
var f = format("s");
Expand Down
Loading

0 comments on commit 87acef2

Please sign in to comment.