Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disregard shapes outside projection space #35

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions src/cartogram.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ export default function() {
topology = copy(topology);

// objects are projected into screen coordinates


var anyDiscarded = false;
// project the arcs into screen space
var tf = transformer(topology.transform),x,y,len1,i1,out1,len2=topology.arcs.length,i2=0,
projectedArcs = new Array(len2);
Expand All @@ -64,11 +65,22 @@ export default function() {
topology.arcs[i2][i1][0] = (x += topology.arcs[i2][i1][0]);
topology.arcs[i2][i1][1] = (y += topology.arcs[i2][i1][1]);
out1[i1] = projection === null ? tf(topology.arcs[i2][i1]) : projection(tf(topology.arcs[i2][i1]));
if (out1[i1] === null) {
// shape has points outside projection (projection() returned null)
// so we'd better disregard it completely
out1 = [];
anyDiscarded = true;
break;
}
i1++;
}
projectedArcs[i2++]=out1;

}

if (anyDiscarded && typeof console !== "undefined" && console.warn) {
console.warn("Some shapes were discarded due to being outside the projection");
}

// path with identity projection
var path = geoPath()
Expand Down Expand Up @@ -325,4 +337,4 @@ export default function() {
};

return cartogram;
};
};