Skip to content

Commit

Permalink
Merge branch '3.0.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
mbostock committed Dec 28, 2012
2 parents 74582d8 + 8b0c10f commit d2ad9f7
Show file tree
Hide file tree
Showing 11 changed files with 104 additions and 41 deletions.
2 changes: 1 addition & 1 deletion component.json
@@ -1,5 +1,5 @@
{
"name": "d3",
"version": "3.0.0",
"version": "3.0.1",
"main": "./d3.js"
}
37 changes: 20 additions & 17 deletions d3.js
Expand Up @@ -12,7 +12,7 @@
};
}
d3 = {
version: "3.0.0"
version: "3.0.1"
};
var π = Math.PI, ε = 1e-6, d3_radians = π / 180, d3_degrees = 180 / π;
function d3_target(d) {
Expand Down Expand Up @@ -5092,7 +5092,7 @@
function squarify(node) {
var children = node.children;
if (children && children.length) {
var rect = pad(node), row = [], remaining = children.slice(), child, best = Infinity, score, u = mode === "slice" ? rect.dx : mode === "dice" || mode === "slice-dice" && node.depth & 1 ? rect.dy : Math.min(rect.dx, rect.dy), n;
var rect = pad(node), row = [], remaining = children.slice(), child, best = Infinity, score, u = mode === "slice" ? rect.dx : mode === "dice" ? rect.dy : mode === "slice-dice" ? node.depth & 1 ? rect.dy : rect.dx : Math.min(rect.dx, rect.dy), n;
scale(remaining, rect.dx * rect.dy / node.value);
row.area = 0;
while ((n = remaining.length) > 0) {
Expand Down Expand Up @@ -5348,10 +5348,6 @@
FeatureCollection: function(object, listener) {
var features = object.features, i = -1, n = features.length;
while (++i < n) d3_geo_streamGeometry(features[i].geometry, listener);
},
GeometryCollection: function(object, listener) {
var geometries = object.geometries, i = -1, n = geometries.length;
while (++i < n) d3_geo_streamGeometry(geometries[i], listener);
}
};
var d3_geo_streamGeometryType = {
Expand Down Expand Up @@ -5379,6 +5375,10 @@
MultiPolygon: function(object, listener) {
var coordinates = object.coordinates, i = -1, n = coordinates.length;
while (++i < n) d3_geo_streamPolygon(coordinates[i], listener);
},
GeometryCollection: function(object, listener) {
var geometries = object.geometries, i = -1, n = geometries.length;
while (++i < n) d3_geo_streamGeometry(geometries[i], listener);
}
};
function d3_geo_streamLine(coordinates, listener, closed) {
Expand Down Expand Up @@ -5597,12 +5597,20 @@
};
var d3_geo_centroidDimension, d3_geo_centroidW, d3_geo_centroidX, d3_geo_centroidY, d3_geo_centroidZ;
var d3_geo_centroid = {
sphere: d3_noop,
sphere: function() {
if (d3_geo_centroidDimension < 2) {
d3_geo_centroidDimension = 2;
d3_geo_centroidW = d3_geo_centroidX = d3_geo_centroidY = d3_geo_centroidZ = 0;
}
},
point: d3_geo_centroidPoint,
lineStart: d3_geo_centroidLineStart,
lineEnd: d3_geo_centroidLineEnd,
polygonStart: function() {
d3_geo_centroidDimension = 2;
if (d3_geo_centroidDimension < 2) {
d3_geo_centroidDimension = 2;
d3_geo_centroidW = d3_geo_centroidX = d3_geo_centroidY = d3_geo_centroidZ = 0;
}
d3_geo_centroid.lineStart = d3_geo_centroidRingStart;
},
polygonEnd: function() {
Expand All @@ -5620,10 +5628,6 @@
}
function d3_geo_centroidRingStart() {
var λ00, φ00;
if (d3_geo_centroidDimension < 2) {
d3_geo_centroidDimension = 2;
d3_geo_centroidW = d3_geo_centroidX = d3_geo_centroidY = d3_geo_centroidZ = 0;
}
d3_geo_centroidDimension = 1;
d3_geo_centroidLineStart();
d3_geo_centroidDimension = 2;
Expand All @@ -5639,11 +5643,10 @@
}
function d3_geo_centroidLineStart() {
var x0, y0, z0;
if (d3_geo_centroidDimension !== 1) {
if (d3_geo_centroidDimension < 1) {
d3_geo_centroidDimension = 1;
d3_geo_centroidW = d3_geo_centroidX = d3_geo_centroidY = d3_geo_centroidZ = 0;
} else return;
if (d3_geo_centroidDimension > 1) return;
if (d3_geo_centroidDimension < 1) {
d3_geo_centroidDimension = 1;
d3_geo_centroidW = d3_geo_centroidX = d3_geo_centroidY = d3_geo_centroidZ = 0;
}
d3_geo_centroid.point = function(λ, φ) {
λ *= d3_radians;
Expand Down
6 changes: 3 additions & 3 deletions d3.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "d3",
"version": "3.0.0",
"version": "3.0.1",
"description": "A small, free JavaScript library for manipulating documents based on data.",
"keywords": [
"dom",
Expand Down
2 changes: 1 addition & 1 deletion src/core/core.js
@@ -1,4 +1,4 @@
d3 = {version: "3.0.0"}; // semver
d3 = {version: "3.0.1"}; // semver

var π = Math.PI,
ε = 1e-6,
Expand Down
25 changes: 14 additions & 11 deletions src/geo/centroid.js
Expand Up @@ -18,12 +18,20 @@ var d3_geo_centroidDimension,
d3_geo_centroidZ;

var d3_geo_centroid = {
sphere: d3_noop,
sphere: function() {
if (d3_geo_centroidDimension < 2) {
d3_geo_centroidDimension = 2;
d3_geo_centroidW = d3_geo_centroidX = d3_geo_centroidY = d3_geo_centroidZ = 0;
}
},
point: d3_geo_centroidPoint,
lineStart: d3_geo_centroidLineStart,
lineEnd: d3_geo_centroidLineEnd,
polygonStart: function() {
d3_geo_centroidDimension = 2;
if (d3_geo_centroidDimension < 2) {
d3_geo_centroidDimension = 2;
d3_geo_centroidW = d3_geo_centroidX = d3_geo_centroidY = d3_geo_centroidZ = 0;
}
d3_geo_centroid.lineStart = d3_geo_centroidRingStart;
},
polygonEnd: function() {
Expand All @@ -45,10 +53,6 @@ function d3_geo_centroidPoint(λ, φ) {
function d3_geo_centroidRingStart() {
var λ00, φ00; // first point

if (d3_geo_centroidDimension < 2) {
d3_geo_centroidDimension = 2;
d3_geo_centroidW = d3_geo_centroidX = d3_geo_centroidY = d3_geo_centroidZ = 0;
}
d3_geo_centroidDimension = 1;
d3_geo_centroidLineStart();
d3_geo_centroidDimension = 2;
Expand All @@ -67,11 +71,10 @@ function d3_geo_centroidRingStart() {
function d3_geo_centroidLineStart() {
var x0, y0, z0; // previous point

if (d3_geo_centroidDimension !== 1) {
if (d3_geo_centroidDimension < 1) {
d3_geo_centroidDimension = 1;
d3_geo_centroidW = d3_geo_centroidX = d3_geo_centroidY = d3_geo_centroidZ = 0;
} else return;
if (d3_geo_centroidDimension > 1) return;
if (d3_geo_centroidDimension < 1) {
d3_geo_centroidDimension = 1;
d3_geo_centroidW = d3_geo_centroidX = d3_geo_centroidY = d3_geo_centroidZ = 0;
}

d3_geo_centroid.point = function(λ, φ) {
Expand Down
8 changes: 4 additions & 4 deletions src/geo/stream.js
Expand Up @@ -19,10 +19,6 @@ var d3_geo_streamObjectType = {
FeatureCollection: function(object, listener) {
var features = object.features, i = -1, n = features.length;
while (++i < n) d3_geo_streamGeometry(features[i].geometry, listener);
},
GeometryCollection: function(object, listener) {
var geometries = object.geometries, i = -1, n = geometries.length;
while (++i < n) d3_geo_streamGeometry(geometries[i], listener);
}
};

Expand Down Expand Up @@ -51,6 +47,10 @@ var d3_geo_streamGeometryType = {
MultiPolygon: function(object, listener) {
var coordinates = object.coordinates, i = -1, n = coordinates.length;
while (++i < n) d3_geo_streamPolygon(coordinates[i], listener);
},
GeometryCollection: function(object, listener) {
var geometries = object.geometries, i = -1, n = geometries.length;
while (++i < n) d3_geo_streamGeometry(geometries[i], listener);
}
};

Expand Down
3 changes: 2 additions & 1 deletion src/layout/treemap.js
Expand Up @@ -34,7 +34,8 @@ d3.layout.treemap = function() {
best = Infinity, // the best row score so far
score, // the current row score
u = mode === "slice" ? rect.dx
: mode === "dice" || mode === "slice-dice" && node.depth & 1 ? rect.dy
: mode === "dice" ? rect.dy
: mode === "slice-dice" ? node.depth & 1 ? rect.dy : rect.dx
: Math.min(rect.dx, rect.dy), // initial orientation
n;
scale(remaining, rect.dx * rect.dy / node.value);
Expand Down
23 changes: 23 additions & 0 deletions test/geo/bounds-test.js
Expand Up @@ -90,6 +90,29 @@ suite.addBatch({
type: "Polygon",
coordinates: [[[-123, 39], [-122, 39], [-122, 38], [-123, 39]], [[10, 20], [20, 20], [20, 10], [10, 10], [10, 20]]]
}), [[-123, 38], [-122, 39]])
},
"NestedCollection": function (bounds) {
assert.deepEqual(bounds({
type: "FeatureCollection",
features: [
{
type: "Feature",
geometry: {
type: "GeometryCollection",
geometries: [
{
type: "Point",
coordinates: [-120,47]
},
{
type: "Point",
coordinates: [-119,46]
}
]
}
}
]
}), [[-120,46], [-119,47]])
}
}
});
Expand Down
23 changes: 21 additions & 2 deletions test/geo/centroid-test.js
Expand Up @@ -65,18 +65,37 @@ suite.addBatch({
]}), [179.5, 0], 1e-6);
},
"GeometryCollection": {
"Point and LineString": function(centroid) {
"LineString, Point": function(centroid) {
assert.inDelta(centroid({type: "GeometryCollection", geometries: [
{type: "LineString", coordinates: [[179, 0], [180, 0]]},
{type: "Point", coordinates: [0, 0]}
]}), [179.5, 0], 1e-6);
},
"Point, LineString and Polygon": function(centroid) {
"Polygon, LineString, Point": function(centroid) {
assert.inDelta(centroid({type: "GeometryCollection", geometries: [
{type: "Polygon", coordinates: [[[-180, 0], [-180, 1], [-179, 1], [-179, 0], [-180, 0]]]},
{type: "LineString", coordinates: [[179, 0], [180, 0]]},
{type: "Point", coordinates: [0, 0]}
]}), [-179.5, 0.5], 1e-6);
},
"Point, LineString, Polygon": function(centroid) {
assert.inDelta(centroid({type: "GeometryCollection", geometries: [
{type: "Point", coordinates: [0, 0]},
{type: "LineString", coordinates: [[179, 0], [180, 0]]},
{type: "Polygon", coordinates: [[[-180, 0], [-180, 1], [-179, 1], [-179, 0], [-180, 0]]]}
]}), [-179.5, 0.5], 1e-6);
},
"Sphere, Point": function(centroid) {
assert.isUndefined(centroid({type: "GeometryCollection", geometries: [
{type: "Sphere"},
{type: "Point", coordinates: [0, 0]}
]}));
},
"Point, Sphere": function(centroid) {
assert.isUndefined(centroid({type: "GeometryCollection", geometries: [
{type: "Point", coordinates: [0, 0]},
{type: "Sphere"}
]}));
}
}
}
Expand Down
14 changes: 14 additions & 0 deletions test/layout/treemap-test.js
Expand Up @@ -154,6 +154,20 @@ suite.addBatch({
{x: 0, y: 0, dx: 0, dy: 1},
{x: 0, y: 0, dx: 1, dy: 1}
]);
},
"slice-dice": function(treemap) {
assert.deepEqual(treemap().size([100, 10]).mode("slice-dice").nodes({children: [
{children: [{value: 1}, {value: 1}]},
{children: [{value: 1}, {value: 1}]}
]}).map(layout), [
{x: 0, y: 0, dx: 100, dy: 10},
{x: 50, y: 0, dx: 50, dy: 10},
{x: 50, y: 5, dx: 50, dy: 5},
{x: 50, y: 0, dx: 50, dy: 5},
{x: 0, y: 0, dx: 50, dy: 10},
{x: 0, y: 5, dx: 50, dy: 5},
{x: 0, y: 0, dx: 50, dy: 5}
]);
}
}
});
Expand Down

0 comments on commit d2ad9f7

Please sign in to comment.