More stream examples.
This commit is contained in:
Родитель
c0b5b08af9
Коммит
8f5fe826c7
|
@ -1,43 +1,38 @@
|
|||
function d3_geo_streamBuffer() {
|
||||
this._buffer = [];
|
||||
this._point = d3_geo_pathCircle(4.5);
|
||||
}
|
||||
|
||||
d3_geo_streamBuffer.prototype = {
|
||||
point: d3_geo_streamBufferPoint,
|
||||
function d3_geo_streamBuffer(buffer, pointRadius) {
|
||||
var stream = {
|
||||
point: point,
|
||||
|
||||
// While inside a line, override point to moveTo then lineTo.
|
||||
lineStart: function() { this.point = d3_geo_streamBufferPointLineStart; },
|
||||
lineEnd: d3_geo_streamBufferLineEnd,
|
||||
lineStart: function() { stream.point = pointLineStart; },
|
||||
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;
|
||||
}
|
||||
polygonStart: function() { stream.lineEnd = lineEndPolygon; },
|
||||
polygonEnd: function() { stream.lineEnd = lineEnd; }
|
||||
};
|
||||
|
||||
function d3_geo_streamBufferPoint(x, y) {
|
||||
this._buffer.push("M", x, ",", y, this._point);
|
||||
function point(x, y) {
|
||||
buffer.push("M", x, ",", y, pointRadius);
|
||||
}
|
||||
|
||||
function d3_geo_streamBufferPointLineStart(x, y) {
|
||||
this._buffer.push("M", x, ",", y);
|
||||
this.point = d3_geo_streamBufferPointLine;
|
||||
function pointLineStart(x, y) {
|
||||
buffer.push("M", x, ",", y);
|
||||
stream.point = pointLine;
|
||||
}
|
||||
|
||||
function d3_geo_streamBufferPointLine(x, y) {
|
||||
this._buffer.push("L", x, ",", y);
|
||||
function pointLine(x, y) {
|
||||
buffer.push("L", x, ",", y);
|
||||
}
|
||||
|
||||
function d3_geo_streamBufferLineEnd() {
|
||||
this.point = d3_geo_streamBufferPoint;
|
||||
function lineEnd() {
|
||||
stream.point = point;
|
||||
}
|
||||
|
||||
function d3_geo_streamBufferLineEndPolygon() {
|
||||
this._buffer.push("Z");
|
||||
function lineEndPolygon() {
|
||||
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,
|
||||
function d3_geo_streamContext(context, pointRadius) {
|
||||
var stream = {
|
||||
point: point,
|
||||
|
||||
// While inside a line, override point to moveTo then lineTo.
|
||||
lineStart: function() { this.point = d3_geo_streamContextPointLineStart; },
|
||||
lineEnd: d3_geo_streamContextLineEnd,
|
||||
lineStart: function() { stream.point = pointLineStart; },
|
||||
lineEnd: lineEnd,
|
||||
|
||||
// While inside a polygon, override lineEnd to closePath.
|
||||
polygonStart: function() { this.lineEnd = d3_geo_streamContextLineEndPolygon; },
|
||||
polygonEnd: function() { this.lineEnd = d3_geo_streamContextLineEnd; }
|
||||
polygonStart: function() { stream.lineEnd = lineEndPolygon; },
|
||||
polygonEnd: function() { stream.lineEnd = lineEnd; }
|
||||
};
|
||||
|
||||
function d3_geo_streamContextPoint(x, y) {
|
||||
this._context.moveTo(x, y);
|
||||
this._context.arc(x, y, this._pointRadius, 0, 2 * π);
|
||||
function point(x, y) {
|
||||
context.moveTo(x, y);
|
||||
context.arc(x, y, pointRadius, 0, 2 * π);
|
||||
}
|
||||
|
||||
function d3_geo_streamContextPointLineStart(x, y) {
|
||||
this._context.moveTo(x, y);
|
||||
this.point = d3_geo_streamContextPointLine;
|
||||
function pointLineStart(x, y) {
|
||||
context.moveTo(x, y);
|
||||
stream.point = pointLine;
|
||||
}
|
||||
|
||||
function d3_geo_streamContextPointLine(x, y) {
|
||||
this._context.lineTo(x, y);
|
||||
function pointLine(x, y) {
|
||||
context.lineTo(x, y);
|
||||
}
|
||||
|
||||
function d3_geo_streamContextLineEnd() {
|
||||
this.point = d3_geo_streamContextPoint;
|
||||
function lineEnd() {
|
||||
stream.point = point;
|
||||
}
|
||||
|
||||
function d3_geo_streamContextLineEndPolygon() {
|
||||
this._context.closePath();
|
||||
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);
|
||||
});
|
||||
}
|
|
@ -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
|
||||
};
|
||||
}
|
Загрузка…
Ссылка в новой задаче