2011-09-10 18:37:39 +04:00
|
|
|
require("../env");
|
|
|
|
|
|
|
|
var vows = require("vows"),
|
|
|
|
assert = require("assert");
|
|
|
|
|
|
|
|
var suite = vows.describe("d3.geo.path");
|
|
|
|
|
|
|
|
suite.addBatch({
|
|
|
|
"path": {
|
2012-10-02 09:39:17 +04:00
|
|
|
topic: function() {
|
|
|
|
return d3.geo.path()
|
|
|
|
.context(testContext)
|
|
|
|
.projection(d3.geo.equirectangular()
|
|
|
|
.scale(900 / Math.PI)
|
|
|
|
.precision(0));
|
2012-09-27 08:01:42 +04:00
|
|
|
},
|
2012-10-02 09:39:17 +04:00
|
|
|
|
|
|
|
"LineString": function(path) {
|
|
|
|
path({
|
|
|
|
type: "Feature",
|
|
|
|
geometry: {
|
|
|
|
type: "LineString",
|
|
|
|
coordinates: [[-63, 18], [-62, 18], [-62, 17]]
|
|
|
|
},
|
|
|
|
});
|
|
|
|
assert.deepEqual(testContext.buffer(), [
|
|
|
|
{type: "moveTo", x: 165, y: 160},
|
|
|
|
{type: "lineTo", x: 170, y: 160},
|
|
|
|
{type: "lineTo", x: 170, y: 165}
|
|
|
|
]);
|
2012-09-23 03:08:27 +04:00
|
|
|
},
|
2012-10-02 09:39:17 +04:00
|
|
|
|
2011-09-10 18:37:39 +04:00
|
|
|
"Polygon": function(path) {
|
2012-10-02 09:39:17 +04:00
|
|
|
path({
|
2011-09-10 18:37:39 +04:00
|
|
|
type: "Feature",
|
|
|
|
geometry: {
|
|
|
|
type: "Polygon",
|
2012-10-02 09:39:17 +04:00
|
|
|
coordinates: [[[-63, 18], [-62, 18], [-62, 17], [-63, 18]]]
|
2011-09-10 18:37:39 +04:00
|
|
|
},
|
2012-10-02 09:39:17 +04:00
|
|
|
});
|
|
|
|
assert.deepEqual(testContext.buffer(), [
|
|
|
|
{type: "moveTo", x: 165, y: 160},
|
|
|
|
{type: "lineTo", x: 170, y: 160},
|
|
|
|
{type: "lineTo", x: 170, y: 165},
|
|
|
|
{type: "closePath"}
|
|
|
|
]);
|
|
|
|
},
|
|
|
|
|
|
|
|
"returns null when passed null or undefined": function(path) {
|
|
|
|
assert.isNull(path(null));
|
|
|
|
assert.isNull(path(undefined));
|
|
|
|
assert.isNull(path());
|
2012-02-21 20:42:37 +04:00
|
|
|
},
|
|
|
|
"bogus type name": function(path) {
|
|
|
|
assert.isNull(path({
|
|
|
|
type: "Feature",
|
|
|
|
geometry: {
|
|
|
|
type: "__proto__",
|
|
|
|
coordinates: [[[-63.03, 18.02], [-63.14, 18.06], [-63.01, 18.07], [-63.03, 18.02]]]
|
|
|
|
},
|
|
|
|
}));
|
2012-10-02 09:39:17 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
"projection": {
|
|
|
|
"returns the current projection when called with no arguments": function() {
|
|
|
|
var path = d3.geo.path(), projection = d3.geo.albers();
|
|
|
|
path.projection(projection);
|
|
|
|
assert.strictEqual(path.projection(), projection);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
"pointRadius": {
|
|
|
|
"returns the current point radius when called with no arguments": function() {
|
|
|
|
var path = d3.geo.path(), radius = function() { return 5; };
|
|
|
|
assert.strictEqual(path.pointRadius(), 4.5);
|
|
|
|
assert.strictEqual(path.pointRadius(radius).pointRadius(), radius);
|
|
|
|
}
|
2011-09-10 18:37:39 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2012-10-02 09:39:17 +04:00
|
|
|
var testBuffer = [];
|
|
|
|
|
|
|
|
var testContext = {
|
|
|
|
point: function(x, y) { testBuffer.push({type: "point", x: Math.round(x), y: Math.round(y)}); },
|
|
|
|
moveTo: function(x, y) { testBuffer.push({type: "moveTo", x: Math.round(x), y: Math.round(y)}); },
|
|
|
|
lineTo: function(x, y) { testBuffer.push({type: "lineTo", x: Math.round(x), y: Math.round(y)}); },
|
|
|
|
closePath: function() { testBuffer.push({type: "closePath"}); },
|
|
|
|
buffer: function() { var result = testBuffer; testBuffer = []; return result; }
|
|
|
|
};
|
|
|
|
|
2011-09-10 18:37:39 +04:00
|
|
|
suite.export(module);
|