Skip to content

Commit

Permalink
fix: improve label placement for ecograms
Browse files Browse the repository at this point in the history
  • Loading branch information
friedjoff committed Jul 6, 2020
1 parent 13c0dcc commit 0201350
Show file tree
Hide file tree
Showing 15 changed files with 973 additions and 496 deletions.
1,424 changes: 949 additions & 475 deletions lib/data/ecograms.json

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion lib/data/nais/ecogram.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ const aggregateEcograms = () => {
w: Math.round(x2 * 1000 - x1 * 1000), // width
h: Math.round(height),
r: parseInt(f.properties.rows, 10),
o: parseFloat(f.properties.offset),
ox: parseFloat(f.properties.offsetX),
oy: parseFloat(f.properties.offsetY),
z: parseInt(f.properties.z, 10), // z-index
f: ft,
});
Expand Down
2 changes: 1 addition & 1 deletion lib/data/nais/ecogram/11.geojson
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@
"properties": {
"id": 12,
"z": "1",
"offset": "1",
"offsetY": "1",
"forestTypes": "20",
"otherForestTypes": "20Fe,20G"
},
Expand Down
2 changes: 1 addition & 1 deletion lib/data/nais/ecogram/12.geojson
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@
"properties": {
"id": 10,
"z": "1",
"offset": "1",
"offsetY": "1",
"forestTypes": "20",
"otherForestTypes": "20Fe,20G"
},
Expand Down
5 changes: 3 additions & 2 deletions lib/data/nais/ecogram/13.geojson
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@
"id": 5,
"z": "1",
"rows": "2",
"offset": "-1",
"offsetY": "-1",
"forestTypes": "4",
"otherForestTypes": "4G"
},
Expand Down Expand Up @@ -157,7 +157,8 @@
"id": 7,
"z": "1",
"rows": "2",
"offset": "1",
"offsetX": "1",
"offsetY": "1",
"forestTypes": "3",
"otherForestTypes": "3G"
},
Expand Down
2 changes: 1 addition & 1 deletion lib/data/nais/ecogram/15.geojson
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@
"properties": {
"id": 7,
"z": "2",
"offset": "-0.1",
"offsetY": "-0.1",
"forestTypes": "47",
"otherForestTypes": null
},
Expand Down
6 changes: 3 additions & 3 deletions lib/data/nais/ecogram/16.geojson
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@
"properties": {
"id": 13,
"z": "3",
"offset": "-0.1",
"offsetY": "-0.1",
"forestTypes": "47",
"otherForestTypes": null
},
Expand Down Expand Up @@ -413,7 +413,7 @@
"properties": {
"id": 18,
"z": "1",
"offset": "1",
"offsetY": "1.3",
"forestTypes": "68",
"otherForestTypes": null
},
Expand Down Expand Up @@ -508,7 +508,7 @@
"properties": {
"id": 22,
"z": "1",
"offset": "1",
"offsetY": "1",
"forestTypes": "65*",
"otherForestTypes": null
},
Expand Down
4 changes: 2 additions & 2 deletions lib/data/nais/ecogram/17.geojson
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@
"properties": {
"id": 17,
"z": "1",
"offset": "1",
"offsetY": "1",
"forestTypes": "65*",
"otherForestTypes": null
},
Expand Down Expand Up @@ -550,7 +550,7 @@
"properties": {
"id": 24,
"z": "1",
"offset": "1",
"offsetY": "1.3",
"forestTypes": "68",
"otherForestTypes": null
},
Expand Down
2 changes: 1 addition & 1 deletion lib/data/nais/ecogram/18.geojson
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@
"properties": {
"id": 10,
"z": "1",
"offset": "1",
"offsetY": "1",
"forestTypes": "46MRe",
"otherForestTypes": null
},
Expand Down
2 changes: 1 addition & 1 deletion lib/data/nais/ecogram/21.geojson
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@
"properties": {
"id": 15,
"z": "1",
"offset": "1",
"offsetY": "1",
"forestTypes": "68",
"otherForestTypes": null
},
Expand Down
2 changes: 1 addition & 1 deletion lib/data/nais/ecogram/23.geojson
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@
"id": 10,
"z": "1",
"rows": "3",
"offset": "0.2",
"offsetY": "0.2",
"forestTypes": "60A",
"otherForestTypes": "60ALä,60AG"
},
Expand Down
1 change: 1 addition & 0 deletions lib/data/nais/ecogram/6.geojson
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@
"properties": {
"id": 10,
"z": "1",
"rows": "2",
"forestTypes": "93",
"otherForestTypes": null
},
Expand Down
2 changes: 1 addition & 1 deletion lib/data/sql/V3__create_types.sql
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ VALUES ('obermontan',


INSERT INTO altitudinal_zone_meta (projection, nais, code)
VALUES ('ober- und untermontan',
VALUES ('ober- & untermontan',
'UMOM',
'70');

Expand Down
2 changes: 1 addition & 1 deletion lib/data/types.json
Original file line number Diff line number Diff line change
Expand Up @@ -39637,7 +39637,7 @@
{ "de": "submontan", "id": 5, "code": "40" },
{ "de": "untermontan", "id": 6, "code": "50" },
{ "de": "obermontan", "id": 7, "code": "60" },
{ "de": "ober- und untermontan", "id": 8, "code": "70" },
{ "de": "ober- & untermontan", "id": 8, "code": "70" },
{ "de": "hochmontan", "id": 9, "code": "80" },
{ "de": "subalpin", "id": 10, "code": "90" },
{ "de": "obersubalpin", "id": 11, "code": "100" }
Expand Down
10 changes: 5 additions & 5 deletions src/components/Ecogram.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ function Ecogram({ data, selectForestType }) {
<line x1="500" y1="0" x2="500" y2="1000" className={styles.grid} />
<line x1="800" y1="0" x2="800" y2="1000" className={styles.grid} />
<line x1="0" y1="200" x2="1000" y2="200" className={styles.grid} />
<line x1="0" y1="500" x2="1000" y2="500" className={styles.grid} />
<line x1="0" y1="492" x2="1000" y2="492" className={styles.grid} />
<line x1="0" y1="800" x2="1000" y2="800" className={styles.grid} />
{data
.sort((a, b) => a.z - b.z)
.map(({ a, x, y, w, h, f, r, o }) => (
.map(({ a, x, y, w, h, f, r, ox, oy }) => (
<>
<rect
x={x}
Expand All @@ -38,11 +38,11 @@ function Ecogram({ data, selectForestType }) {
className={`${styles.box} ${a && styles.active}`}
onClick={({ target }) => setPopup({ target, forestTypes: f })}
/>
{r || o ? (
{r || ox || oy ? (
[...new Array(r)].map((_, i) => (
<text
x={x + w / 2}
y={y + h / 2 - (20 * r || 0) + 35 * (i + 1) - 35 * o}
x={x + w / 2 + ox * 10}
y={y + h / 2 - (20 * r || 0) + 35 * (i + 1) - 35 * oy}
className={styles.boxText}
>
{f
Expand Down

0 comments on commit 0201350

Please sign in to comment.