Commit 87acef2e authored by Mike Bostock's avatar Mike Bostock
Browse files

Merge branch '3.3.9'

parents ed54503f d44de8f0
{
"name": "d3",
"version": "3.3.8",
"version": "3.3.9",
"main": "d3.js",
"scripts": [
"d3.js"
......
......@@ -10,7 +10,7 @@
"animation",
"canvas"
],
"version": "3.3.8",
"version": "3.3.9",
"main": "index-browserify.js",
"scripts": [
"d3.js",
......
d3 = function() {
var d3 = {
version: "3.3.8"
version: "3.3.9"
};
if (!Date.now) Date.now = function() {
return +new Date();
......@@ -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);
......@@ -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,
......@@ -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) {
......@@ -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;
......@@ -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 [ λ, φ ];
......@@ -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 ]);
......
This source diff could not be displayed because it is too large. You can view the blob instead.
{
"name": "d3",
"version": "3.3.8",
"version": "3.3.9",
"description": "A small, free JavaScript library for manipulating documents based on data.",
"keywords": [
"dom",
......
......@@ -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);
......
......@@ -13,7 +13,6 @@ import "path-context";
import "projection";
import "resample";
import "stream";
import "transform";
d3.geo.path = function() {
var pointRadius = 4.5,
......@@ -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,7 +9,6 @@ import "geo";
import "path";
import "resample";
import "rotation";
import "stream";
import "transform";
d3.geo.projection = d3_geo_projection;
......@@ -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);
});
}
import "../math/abs";
import "../math/trigonometry";
import "cartesian";
import "stream";
function d3_geo_resample(project) {
var δ2 = .5, // precision, px²
......@@ -9,6 +8,17 @@ function d3_geo_resample(project) {
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
......
......@@ -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(); },
};
}
......@@ -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;
}
d3 = (function(){
var d3 = {version: "3.3.8"}; // semver
var d3 = {version: "3.3.9"}; // semver
......@@ -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");
......
......@@ -6,6 +6,8 @@ var fs = require("fs"),
var formatNumber = d3.format(",.02r"),
projection = d3.geo.stereographic().clipAngle(150).clipExtent([[0, 0], [960, 500]]),
path = d3.geo.path().projection(projection),
projection0 = d3.geo.mercator().precision(0),
path0 = d3.geo.path().projection(projection0),
graticule = d3.geo.graticule().step([1, 1]),
circle = d3.geo.circle().angle(30),
n = 10,
......@@ -50,6 +52,14 @@ for (var i = 0, k = 0; i < n; i++, k++) {
console.log("World countries: " + formatNumber((Date.now() - then) / k) + "ms/op.");
then = Date.now();
for (var i = 0, k = 0; i < n; i++, k++) {
path0(o);
}
console.log("World countries precision(0): " + formatNumber((Date.now() - then) / k) + "ms/op.");
o = JSON.parse(fs.readFileSync("./test/data/ocean.json"));
then = Date.now();
......
......@@ -193,6 +193,23 @@ suite.addBatch({
assert.strictEqual(x.tickFormat(64)(x.ticks(64)[0]), "0.14");
assert.strictEqual(x.tickFormat(128)(x.ticks(128)[0]), "0.13");
assert.strictEqual(x.tickFormat(256)(x.ticks(256)[0]), "0.125");
var x = d3.scale.linear().domain([0.01, 0.09]);
assert.strictEqual(x.tickFormat(10,"g")(x.ticks(10)[0]), "0.01")
assert.strictEqual(x.tickFormat(20,"g")(x.ticks(20)[0]), "0.010")
assert.strictEqual(x.tickFormat(10,"r")(x.ticks(10)[0]), "0.01")
assert.strictEqual(x.tickFormat(20,"r")(x.ticks(20)[0]), "0.010")
assert.strictEqual(x.tickFormat(10,"e")(x.ticks(10)[0]), "1e-2")
assert.strictEqual(x.tickFormat(20,"e")(x.ticks(20)[0]), "1.0e-2")
assert.strictEqual(x.tickFormat(10,"%")(x.ticks(10)[0]), "1%")
assert.strictEqual(x.tickFormat(20,"%")(x.ticks(10)[0]), "1.0%")
assert.strictEqual(x.tickFormat(10,"p")(x.ticks(10)[0]), "1%")
assert.strictEqual(x.tickFormat(20,"p")(x.ticks(10)[0]), "1.0%")
var x = d3.scale.linear().domain([1000, 1001]);
assert.strictEqual(x.tickFormat(3)(x.ticks(3)[1]), "1,000.5");
assert.strictEqual(x.tickFormat(3,",g")(x.ticks(3)[1]), "1,000.5");
assert.strictEqual(x.tickFormat(3,"g")(x.ticks(3)[1]), "1000.5");
assert.strictEqual(x.tickFormat(3,"e")(x.ticks(3)[1]), "1.0005e+3");
assert.strictEqual(x.tickFormat(3,"s")(x.ticks(3)[1]), "1.0005k");
}
},
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment