Skip to content

Commit 0dce022

Browse files
committed
Add two stream implementations.
1 parent 6994640 commit 0dce022

2 files changed

Lines changed: 80 additions & 0 deletions

File tree

src/geo/stream-buffer.js

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
function d3_geo_streamBuffer() {
2+
this._buffer = [];
3+
this._point = d3_geo_pathCircle(4.5);
4+
}
5+
6+
var d3_geo_streamBufferPrototype = {
7+
point: d3_geo_streamBufferPoint,
8+
9+
// While inside a line, override point to moveTo then lineTo.
10+
lineStart: function() { this.point = d3_geo_streamBufferPointLineStart; },
11+
lineEnd: d3_geo_streamBufferLineEnd,
12+
13+
// While inside a polygon, override lineEnd to closePath.
14+
polygonStart: function() { this.lineEnd = d3_geo_streamBufferLineEndPolygon; },
15+
polygonEnd: function() { this.lineEnd = d3_geo_streamBufferLineEnd; },
16+
17+
toString: function() {
18+
var s = this._buffer.join("");
19+
this._buffer = [];
20+
return s;
21+
}
22+
}
23+
24+
function d3_geo_streamBufferPoint(x, y) {
25+
this._buffer.push("M", x, ",", y, this._point);
26+
}
27+
28+
function d3_geo_streamBufferPointLineStart(x, y) {
29+
this._buffer.push("M", x, ",", y);
30+
this.point = d3_geo_streamBufferPointLine;
31+
}
32+
33+
function d3_geo_streamBufferPointLine(x, y) {
34+
this._buffer.push("L", x, ",", y);
35+
}
36+
37+
function d3_geo_streamBufferLineEnd() {
38+
this.point = d3_geo_streamBufferPoint;
39+
}
40+
41+
function d3_geo_streamBufferLineEndPolygon() {
42+
this._buffer.push("Z");
43+
}

src/geo/stream-context.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
function d3_geo_streamContext() {
2+
this._pointRadius = 4.5;
3+
}
4+
5+
var d3_geo_streamContextPrototype = {
6+
point: d3_geo_streamContextPoint,
7+
8+
// While inside a line, override point to moveTo then lineTo.
9+
lineStart: function() { this.point = d3_geo_streamContextPointLineStart; },
10+
lineEnd: d3_geo_streamContextLineEnd,
11+
12+
// While inside a polygon, override lineEnd to closePath.
13+
polygonStart: function() { this.lineEnd = d3_geo_streamContextLineEndPolygon; },
14+
polygonEnd: function() { this.lineEnd = d3_geo_streamContextLineEnd; }
15+
}
16+
17+
function d3_geo_streamContextPoint(x, y) {
18+
this._context.moveTo(x, y);
19+
this._context.arc(x, y, this._pointRadius, 0, 2 * π);
20+
}
21+
22+
function d3_geo_streamContextPointLineStart(x, y) {
23+
this._context.moveTo(x, y);
24+
this.point = d3_geo_streamContextPointLine;
25+
}
26+
27+
function d3_geo_streamContextPointLine(x, y) {
28+
this._context.lineTo(x, y);
29+
}
30+
31+
function d3_geo_streamContextLineEnd() {
32+
this.point = d3_geo_streamContextPoint;
33+
}
34+
35+
function d3_geo_streamContextLineEndPolygon() {
36+
this._context.closePath();
37+
}

0 commit comments

Comments
 (0)