Skip to content

Commit 9a25883

Browse files
committed
Fixing turf-isolines to no longer ignore the first break passed. Where it looked like the unit tests have had a 0 break added as a work around e.g. 5 breaks but only 4 break properties, have removed the presumed workaround and reviewed test fixture output. Resolves #2129.
1 parent d7c5322 commit 9a25883

File tree

9 files changed

+91
-48
lines changed

9 files changed

+91
-48
lines changed

packages/turf-isolines/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ function createIsoLines(
104104
breaksProperties: GeoJsonProperties[]
105105
): Feature<MultiLineString>[] {
106106
const results = [];
107-
for (let i = 1; i < breaks.length; i++) {
107+
for (let i = 0; i < breaks.length; i++) {
108108
const threshold = +breaks[i]; // make sure it's a number
109109

110110
const properties = { ...commonProperties, ...breaksProperties[i] };

packages/turf-isolines/test.js

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,39 @@ test("isolines", (t) => {
5555
t.end();
5656
});
5757

58+
test("isolines - skipping first break, from issue #2129", (t) => {
59+
const points = pointGrid([0, 10, 20, 30], 100);
60+
for (var i = 0; i < points.features.length; i++) {
61+
points.features[i].properties.temperature = Math.random() * 12;
62+
}
63+
64+
const breaks = [5, 10];
65+
66+
const lines = isolines(points, breaks, {
67+
zProperty: "temperature",
68+
breaksProperties: [
69+
{ name: "break5", stroke: "#F00" },
70+
{ name: "break10", stroke: "#0F0" },
71+
],
72+
});
73+
74+
lines.features.push(
75+
lineString(getCoords(envelope(points))[0], {
76+
description: "Debug line for testing",
77+
stroke: "#F00",
78+
"stroke-width": 1,
79+
})
80+
);
81+
82+
// Make sure an isoline is created for each break, and that it's
83+
// geometry isn't empty.
84+
t.equal(lines.features[0].properties.name, "break5");
85+
t.assert(lines.features[0].geometry.coordinates[0].length > 1);
86+
t.equal(lines.features[1].properties.name, "break10");
87+
t.assert(lines.features[1].geometry.coordinates[0].length > 1);
88+
t.end();
89+
});
90+
5891
test("isolines -- throws", (t) => {
5992
const points = pointGrid([-70.823364, -33.553984, -70.473175, -33.302986], 5);
6093

@@ -92,7 +125,7 @@ test("isolines -- handling properties", (t) => {
92125
commonProperties: commonProperties,
93126
breaksProperties: breaksProperties,
94127
});
95-
t.equal(lines.features[0].properties.name, "break2");
128+
t.equal(lines.features[0].properties.name, "break1");
96129
t.equal(lines.features[0].properties.source, "foobar");
97130
t.end();
98131
});

packages/turf-isolines/test/in/bigMatrix.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"origin": [6.5, 46],
33
"cellSize": 10,
4-
"breaks": [0, 0.24, 0.5, 1.5, 2.5, 100],
4+
"breaks": [0.24, 0.5, 1.5, 2.5, 100],
55
"zProperty": "pressure",
66
"commonProperties": {
77
"stroke-width": 4,

packages/turf-isolines/test/in/matrix2.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
],
1313
"origin": [10.85, 44],
1414
"cellSize": 20,
15-
"breaks": [0, 4.5, 9, 13.5, 18],
15+
"breaks": [4.5, 9, 13.5, 18],
1616
"commonProperties": {
1717
"stroke-width": 3,
1818
"stroke": "darkred",

packages/turf-isolines/test/in/pointGrid.geojson

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"type": "FeatureCollection",
33
"properties": {
4-
"breaks": [0, 20, 40, 80, 160],
4+
"breaks": [20, 40, 80, 160],
55
"breaksProperties": [
66
{
77
"fill-opacity": 0.5

packages/turf-isolines/test/out/bigMatrix.geojson

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
"properties": {
77
"stroke-width": 4,
88
"fill-opacity": 0.4,
9-
"stroke": "blue",
10-
"fill": "blue",
9+
"stroke": "grey",
10+
"fill": "grey",
1111
"pressure": 0.24
1212
},
1313
"geometry": {
@@ -265,8 +265,8 @@
265265
"properties": {
266266
"stroke-width": 4,
267267
"fill-opacity": 0.4,
268-
"stroke": "green",
269-
"fill": "green",
268+
"stroke": "blue",
269+
"fill": "blue",
270270
"pressure": 0.5
271271
},
272272
"geometry": {
@@ -620,8 +620,8 @@
620620
"properties": {
621621
"stroke-width": 4,
622622
"fill-opacity": 0.4,
623-
"stroke": "yellow",
624-
"fill": "yellow",
623+
"stroke": "green",
624+
"fill": "green",
625625
"pressure": 1.5
626626
},
627627
"geometry": {
@@ -964,8 +964,8 @@
964964
"properties": {
965965
"stroke-width": 4,
966966
"fill-opacity": 0.4,
967-
"stroke": "red",
968-
"fill": "red",
967+
"stroke": "yellow",
968+
"fill": "yellow",
969969
"pressure": 2.5
970970
},
971971
"geometry": {
@@ -1162,12 +1162,11 @@
11621162
"properties": {
11631163
"stroke-width": 4,
11641164
"fill-opacity": 0.4,
1165+
"stroke": "red",
1166+
"fill": "red",
11651167
"pressure": 100
11661168
},
1167-
"geometry": {
1168-
"type": "MultiLineString",
1169-
"coordinates": []
1170-
}
1169+
"geometry": { "type": "MultiLineString", "coordinates": [] }
11711170
},
11721171
{
11731172
"type": "Feature",

packages/turf-isolines/test/out/matrix1.geojson

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,37 @@
33
"features": [
44
{
55
"type": "Feature",
6-
"properties": {
7-
"temperature": 4
8-
},
6+
"properties": { "temperature": 2 },
7+
"geometry": {
8+
"type": "MultiLineString",
9+
"coordinates": [
10+
[
11+
[10.863591, 44.279864],
12+
[11.054363, 44.144966],
13+
[11.308726, 44.144966],
14+
[11.56309, 44.144966],
15+
[11.817453, 44.144966],
16+
[12.071816, 44.144966],
17+
[12.262588, 44.279864],
18+
[12.262588, 44.459728],
19+
[12.262588, 44.639592],
20+
[12.262588, 44.819456],
21+
[12.071816, 44.954354],
22+
[11.817453, 44.954354],
23+
[11.56309, 44.954354],
24+
[11.308726, 44.954354],
25+
[11.054363, 44.954354],
26+
[10.863591, 44.819456],
27+
[10.863591, 44.639592],
28+
[10.863591, 44.459728],
29+
[10.863591, 44.279864]
30+
]
31+
]
32+
}
33+
},
34+
{
35+
"type": "Feature",
36+
"properties": { "temperature": 4 },
937
"geometry": {
1038
"type": "MultiLineString",
1139
"coordinates": [
@@ -35,9 +63,7 @@
3563
},
3664
{
3765
"type": "Feature",
38-
"properties": {
39-
"temperature": 8
40-
},
66+
"properties": { "temperature": 8 },
4167
"geometry": {
4268
"type": "MultiLineString",
4369
"coordinates": [
@@ -59,9 +85,7 @@
5985
},
6086
{
6187
"type": "Feature",
62-
"properties": {
63-
"temperature": 12
64-
},
88+
"properties": { "temperature": 12 },
6589
"geometry": {
6690
"type": "MultiLineString",
6791
"coordinates": [

packages/turf-isolines/test/out/matrix2.geojson

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"stroke-width": 3,
88
"stroke": "darkred",
99
"fill": "darkred",
10-
"fill-opacity": 0.5,
10+
"fill-opacity": 0.4,
1111
"elevation": 4.5
1212
},
1313
"geometry": {
@@ -56,7 +56,7 @@
5656
"stroke-width": 3,
5757
"stroke": "darkred",
5858
"fill": "darkred",
59-
"fill-opacity": 0.7,
59+
"fill-opacity": 0.5,
6060
"elevation": 9
6161
},
6262
"geometry": {
@@ -105,7 +105,7 @@
105105
"stroke-width": 3,
106106
"stroke": "darkred",
107107
"fill": "darkred",
108-
"fill-opacity": 0.8,
108+
"fill-opacity": 0.7,
109109
"elevation": 13.5
110110
},
111111
"geometry": {
@@ -136,6 +136,7 @@
136136
"stroke-width": 3,
137137
"stroke": "darkred",
138138
"fill": "darkred",
139+
"fill-opacity": 0.8,
139140
"elevation": 18
140141
},
141142
"geometry": {

packages/turf-isolines/test/out/pointGrid.geojson

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,7 @@
33
"features": [
44
{
55
"type": "Feature",
6-
"properties": {
7-
"fill-opacity": 0.6,
8-
"population": 20
9-
},
6+
"properties": { "fill-opacity": 0.5, "population": 20 },
107
"geometry": {
118
"type": "MultiLineString",
129
"coordinates": [
@@ -66,10 +63,7 @@
6663
},
6764
{
6865
"type": "Feature",
69-
"properties": {
70-
"fill-opacity": 0.7,
71-
"population": 40
72-
},
66+
"properties": { "fill-opacity": 0.6, "population": 40 },
7367
"geometry": {
7468
"type": "MultiLineString",
7569
"coordinates": [
@@ -133,10 +127,7 @@
133127
},
134128
{
135129
"type": "Feature",
136-
"properties": {
137-
"fill-opacity": 0.8,
138-
"population": 80
139-
},
130+
"properties": { "fill-opacity": 0.7, "population": 80 },
140131
"geometry": {
141132
"type": "MultiLineString",
142133
"coordinates": [
@@ -162,13 +153,8 @@
162153
},
163154
{
164155
"type": "Feature",
165-
"properties": {
166-
"population": 160
167-
},
168-
"geometry": {
169-
"type": "MultiLineString",
170-
"coordinates": []
171-
}
156+
"properties": { "fill-opacity": 0.8, "population": 160 },
157+
"geometry": { "type": "MultiLineString", "coordinates": [] }
172158
},
173159
{
174160
"type": "Feature",

0 commit comments

Comments
 (0)