Skip to content

Commit

Permalink
v0.6.37
Browse files Browse the repository at this point in the history
  • Loading branch information
mbloch committed Jul 19, 2023
1 parent 4b85e2a commit a6ca9a8
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 19 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
v0.6.37
* Support for simple line symbols using `type-arrow head-length=0`.

v0.6.36
* Improved `fill-effect=sphere` gradient.
* Sphere effect can be previewed in the web UI.
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mapshaper",
"version": "0.6.36",
"version": "0.6.37",
"description": "A tool for editing vector datasets for mapping and GIS.",
"keywords": [
"shapefile",
Expand Down
38 changes: 22 additions & 16 deletions src/symbols/mapshaper-arrow-symbols.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export function getArrowCoords(d, style) {
headDx = size.headWidth / 2,
stemDx = size.stemWidth / 2,
baseDx = stemDx * (1 - stemTaper),
head, stem, coords, dx, dy;
coords, dx, dy;

if (curvature) {
// make curved stem
Expand All @@ -36,35 +36,38 @@ export function getArrowCoords(d, style) {
dy = stemLen * Math.cos(theta / 2);

if (stickArrow) {
stem = getCurvedStemCoords(-ax, -ay, dx, dy);
coords = getCurvedStemCoords(-ax, -ay, dx, dy);
} else {
var leftStem = getCurvedStemCoords(-ax, -ay, -stemDx + dx, dy);
var rightStem = getCurvedStemCoords(ax, ay, stemDx + dx, dy);
stem = leftStem.concat(rightStem.reverse());
coords = leftStem.concat(rightStem.reverse());
}

} else {
// make straight stem
dx = 0;
dy = stemLen;
if (stickArrow) {
stem = [[0, 0], [0, stemLen]];
coords = [[0, 0], [0, stemLen]];
} else {
stem = [[-baseDx, 0], [baseDx, 0]];
coords = [[-baseDx, 0], [baseDx, 0]];
}
}

if (stickArrow) {
// make stick arrow
head = [[-headDx + dx, stemLen - headLen], [dx, stemLen], [headDx + dx, stemLen - headLen]];
coords = [stem, head]; // MultiLineString coords
coords = [coords]; // MultiLineString coords
if (headLen > 0) {
coords.push([[-headDx + dx, stemLen - headLen], [dx, stemLen], [headDx + dx, stemLen - headLen]]);
}
} else {
// make filled arrow
// coordinates go counter clockwise, starting from the leftmost head coordinate
head = [[stemDx + dx, dy], [headDx + dx, dy],
[dx, headLen + dy], [-headDx + dx, dy], [-stemDx + dx, dy]];
coords = stem.concat(head);
coords.push(stem[0].concat()); // closed path
coords.push([stemDx + dx, dy]);
if (headLen > 0) {
coords.push([headDx + dx, dy], [dx, headLen + dy], [-headDx + dx, dy]);
}
coords.push([-stemDx + dx, dy], coords[0].concat()); // close path
coords = [coords]; // Polygon coords
}

Expand Down Expand Up @@ -93,7 +96,6 @@ function calcArrowSize(d, stickArrow) {
var totalLen = Math.max(d.radius || d.length || d.r || 0, 0),
scale = 1,
o = initArrowSize(d); // calc several parameters

if (totalLen >= 0) {
scale = calcScale(totalLen, o.headLen, d);
o.stemWidth *= scale;
Expand All @@ -102,7 +104,7 @@ function calcArrowSize(d, stickArrow) {
o.stemLen = stickArrow ? totalLen : totalLen - o.headLen;
}

if (o.headWidth < o.stemWidth) {
if (o.headWidth < o.stemWidth && o.headWidth > 0) {
stop('Arrow head must be at least as wide as the stem.');
}
return o;
Expand Down Expand Up @@ -131,14 +133,18 @@ export function initArrowSize(d) {
headWidth: d['head-width'],
headLen: d['head-length']
};
if (!o.headWidth) {
if (o.headLen) {
if (o.headWidth === 0) {
o.headLen = 0;
} else if (o.headWidth > 0 === false) {
if (o.headLen > 0) {
o.headWidth = o.headLen / sizeRatio;
} else if (o.headLen === 0) {
o.headWidth = 0;
} else {
o.headWidth = o.stemWidth * 3; // assumes stemWidth has been set
}
}
if (!o.headLen) {
if (o.headLen >= 0 === false) {
o.headLen = o.headWidth * sizeRatio;
}
return o;
Expand Down

0 comments on commit a6ca9a8

Please sign in to comment.