This commit is contained in:
Mike Bostock 2012-12-12 11:32:08 -08:00
Родитель c0b5b08af9
Коммит 8f5fe826c7
5 изменённых файлов: 85 добавлений и 69 удалений

Просмотреть файл

@ -1,43 +1,38 @@
function d3_geo_streamBuffer() {
this._buffer = [];
this._point = d3_geo_pathCircle(4.5);
}
function d3_geo_streamBuffer(buffer, pointRadius) {
var stream = {
point: point,
d3_geo_streamBuffer.prototype = {
point: d3_geo_streamBufferPoint,
// While inside a line, override point to moveTo then lineTo.
lineStart: function() { stream.point = pointLineStart; },
lineEnd: lineEnd,
// While inside a line, override point to moveTo then lineTo.
lineStart: function() { this.point = d3_geo_streamBufferPointLineStart; },
lineEnd: d3_geo_streamBufferLineEnd,
// While inside a polygon, override lineEnd to closePath.
polygonStart: function() { stream.lineEnd = lineEndPolygon; },
polygonEnd: function() { stream.lineEnd = lineEnd; }
};
// While inside a polygon, override lineEnd to closePath.
polygonStart: function() { this.lineEnd = d3_geo_streamBufferLineEndPolygon; },
polygonEnd: function() { this.lineEnd = d3_geo_streamBufferLineEnd; },
toString: function() {
var s = this._buffer.join("");
this._buffer = [];
return s;
function point(x, y) {
buffer.push("M", x, ",", y, pointRadius);
}
};
function d3_geo_streamBufferPoint(x, y) {
this._buffer.push("M", x, ",", y, this._point);
}
function pointLineStart(x, y) {
buffer.push("M", x, ",", y);
stream.point = pointLine;
}
function d3_geo_streamBufferPointLineStart(x, y) {
this._buffer.push("M", x, ",", y);
this.point = d3_geo_streamBufferPointLine;
}
function pointLine(x, y) {
buffer.push("L", x, ",", y);
}
function d3_geo_streamBufferPointLine(x, y) {
this._buffer.push("L", x, ",", y);
}
function lineEnd() {
stream.point = point;
}
function d3_geo_streamBufferLineEnd() {
this.point = d3_geo_streamBufferPoint;
}
function lineEndPolygon() {
buffer.push("Z");
}
function d3_geo_streamBufferLineEndPolygon() {
this._buffer.push("Z");
pointRadius = d3_geo_pathCircle(4.5);
return stream;
}

Просмотреть файл

@ -1,37 +1,37 @@
function d3_geo_streamContext() {
this._pointRadius = 4.5;
}
d3_geo_streamContext.prototype = {
point: d3_geo_streamContextPoint,
// While inside a line, override point to moveTo then lineTo.
lineStart: function() { this.point = d3_geo_streamContextPointLineStart; },
lineEnd: d3_geo_streamContextLineEnd,
// While inside a polygon, override lineEnd to closePath.
polygonStart: function() { this.lineEnd = d3_geo_streamContextLineEndPolygon; },
polygonEnd: function() { this.lineEnd = d3_geo_streamContextLineEnd; }
};
function d3_geo_streamContextPoint(x, y) {
this._context.moveTo(x, y);
this._context.arc(x, y, this._pointRadius, 0, 2 * π);
}
function d3_geo_streamContextPointLineStart(x, y) {
this._context.moveTo(x, y);
this.point = d3_geo_streamContextPointLine;
}
function d3_geo_streamContextPointLine(x, y) {
this._context.lineTo(x, y);
}
function d3_geo_streamContextLineEnd() {
this.point = d3_geo_streamContextPoint;
}
function d3_geo_streamContextLineEndPolygon() {
this._context.closePath();
function d3_geo_streamContext(context, pointRadius) {
var stream = {
point: point,
// While inside a line, override point to moveTo then lineTo.
lineStart: function() { stream.point = pointLineStart; },
lineEnd: lineEnd,
// While inside a polygon, override lineEnd to closePath.
polygonStart: function() { stream.lineEnd = lineEndPolygon; },
polygonEnd: function() { stream.lineEnd = lineEnd; }
};
function point(x, y) {
context.moveTo(x, y);
context.arc(x, y, pointRadius, 0, 2 * π);
}
function pointLineStart(x, y) {
context.moveTo(x, y);
stream.point = pointLine;
}
function pointLine(x, y) {
context.lineTo(x, y);
}
function lineEnd() {
stream.point = point;
}
function lineEndPolygon() {
context.closePath();
}
return stream;
}

Просмотреть файл

@ -0,0 +1,5 @@
function d3_geo_streamRadians(stream) {
return d3_geo_streamTransform(stream, function(x, y) {
stream.point(x * d3_radians, y * d3_radians);
});
}

6
src/geo/stream-rotate.js Normal file
Просмотреть файл

@ -0,0 +1,6 @@
function d3_geo_streamRotate(rotate, stream) {
return d3_geo_streamTransform(stream, function(x, y) {
x = rotate(x, y);
stream.point(x[0], x[1]);
});
}

Просмотреть файл

@ -0,0 +1,10 @@
function d3_geo_streamTransform(stream, point) {
return {
point: point,
sphere: stream.sphere,
lineStart: stream.lineStart,
lineEnd: stream.lineEnd,
polygonStart: stream.polygonStart,
polygonEnd: stream.polygonEnd
};
}