Skip to content

Commit

Permalink
fix: read ecogram data from locate result
Browse files Browse the repository at this point in the history
  • Loading branch information
friedjoff committed Mar 10, 2020
1 parent 2c3ef95 commit e1c9c8f
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 100 deletions.
65 changes: 31 additions & 34 deletions src/components/Ecogram.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import propTypes from 'prop-types';
import React from 'react';
import { useTranslation } from 'react-i18next';
import { useSelector } from 'react-redux';

function Ecogram({ data }) {
function Ecogram() {
const { locateResult } = useSelector(state => ({
locateResult: state.locateResult,
}));
const { t } = useTranslation();
const { ecogram } = locateResult;
return (
<svg x="0px" y="0px" viewBox="0 0 1200 1200">
<g transform="translate(100,100)">
Expand All @@ -22,34 +26,31 @@ function Ecogram({ data }) {
stroke="black"
strokeWidth="2"
/>
{data.forestTypes.map(({ x: [x1, x2], y: [y1, y2], forestTypes }) => {
const x = x1 * 1000;
const width = x2 * 1000 - x;
const height = 1000 - y1 * 1000 - (1000 - y2 * 1000);
const y = 1000 - y1 * 1000 - height;
return (
<>
<rect
x={x}
y={y}
width={width}
height={height}
fill="#b0cdeb"
stroke="#365bb7"
strokeWidth="2"
onClick={() => console.log(forestTypes)}
/>
<text
x={x + width / 2}
y={y + height / 2 + 10}
fontSize="2em"
textAnchor="middle"
>
{forestTypes.join(' ')}
</text>
</>
);
})}
{ecogram &&
ecogram.map(({ x, y, w, h, m }) => {
return (
<>
<rect
x={x}
y={y}
width={w}
height={h}
fill="#b0cdeb"
stroke="#365bb7"
strokeWidth="2"
onClick={() => console.log(m)}
/>
<text
x={x + w / 2}
y={y + h / 2 + 10}
fontSize="2em"
textAnchor="middle"
>
{m.join(' ')}
</text>
</>
);
})}
</g>
<text
x="0"
Expand Down Expand Up @@ -79,8 +80,4 @@ function Ecogram({ data }) {
);
}

Ecogram.propTypes = {
data: propTypes.objectOf.isRequired,
};

export default Ecogram;
7 changes: 3 additions & 4 deletions src/components/LocationPage.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import React from 'react';

import Ecogram from './Ecogram';
import ecogramData from './ecogram.json';

function LocationPage() {
return (
<div>
<Ecogram data={ecogramData} />
</div>
<>
<Ecogram />
</>
);
}

Expand Down
62 changes: 0 additions & 62 deletions src/components/ecogram.json

This file was deleted.

0 comments on commit e1c9c8f

Please sign in to comment.