-
Notifications
You must be signed in to change notification settings - Fork 4
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
Add map legend #115
Add map legend #115
Changes from all commits
bb98daa
2d53f3b
3342378
cd0e864
fe890c8
9879edf
3dbdb82
10e261f
a77c461
bb5dc66
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,3 +12,4 @@ python-multipart | |
requests | ||
pandas | ||
jenkspy | ||
sigfig |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,6 @@ pre-commit install -f | |
|
||
# lift & update containers | ||
docker-compose build | ||
docker-compose up db | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ty so much |
||
docker-compose run --rm api pip install -r requirements.txt | ||
docker-compose run --rm api pip install -r requirements.dev.txt | ||
docker-compose run --rm api python init_db.py | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,6 +24,7 @@ export default function Map({ draggable = true }) { | |
lng: -119.6, | ||
lat: 36.7, | ||
}); | ||
const [legendRanges, setLegendRanges] = useState([]); | ||
|
||
useEffect(() => { | ||
getUserLocation(); | ||
|
@@ -51,6 +52,19 @@ export default function Map({ draggable = true }) { | |
}); | ||
}, [location, map]); | ||
|
||
const addLegend = (data) => { | ||
const clusters = data.clusters; | ||
const colorGroups = data.groups; | ||
const newRanges = | ||
clusters && | ||
clusters.map((range, i) => { | ||
return { | ||
label: `${range[0].toLocaleString()} - ${range[1].toLocaleString()}`, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See, here's were we could be doing the native rounding I was speaking about before with either this native JS thing I mentioned before, or actually, passing some options like |
||
color: getColor(colorGroups[i]), | ||
}; | ||
}); | ||
newRanges && setLegendRanges(newRanges); | ||
}; | ||
const getUserLocation = async () => { | ||
const userLocation = await fetchUserLocation(); | ||
if (userLocation) { | ||
|
@@ -64,8 +78,10 @@ export default function Map({ draggable = true }) { | |
|
||
const addLayers = async (map) => { | ||
const data = await fetchCovidData(dataScope.ALL); | ||
const worldData = data["adm0"]; | ||
const usStatesData = data["adm1"]["US"]; | ||
const worldData = data["data"]["adm0"]; | ||
const usStatesData = data["data"]["adm1"]["US"]; | ||
|
||
addLegend(data); | ||
|
||
map.on("load", function () { | ||
addWorldLayer(map, worldData); | ||
|
@@ -85,7 +101,7 @@ export default function Map({ draggable = true }) { | |
const body = await api(`data/${scope}`, { | ||
method: "GET", | ||
}); | ||
return body["data"]; | ||
return body; | ||
}; | ||
|
||
const getColor = (group) => { | ||
|
@@ -214,10 +230,28 @@ export default function Map({ draggable = true }) { | |
); | ||
}; | ||
|
||
const legend = ( | ||
<div className={classNames(styles.legend)} id="legend"> | ||
<h4>Active cases</h4> | ||
{legendRanges.map((range, i) => ( | ||
<div className={classNames(styles.legendItem)} key={i}> | ||
<span style={{ backgroundColor: range.color }}></span> | ||
{range.label} | ||
</div> | ||
))} | ||
</div> | ||
); | ||
|
||
const draggableDependantFeatures = () => { | ||
if (draggable) { | ||
return legendRanges.length !== 0 ? legend : null; | ||
} | ||
return <div className={classNames(styles.fill, styles.mask)} />; | ||
}; | ||
return ( | ||
<div className={styles.root}> | ||
<div className={classNames(styles.fill)} id="map"></div> | ||
{!draggable && <div className={classNames(styles.fill, styles.mask)} />} | ||
{draggableDependantFeatures()} | ||
</div> | ||
); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
100% open to discussion, but, do you really think it's worth it to add another lib to the backend when the front can do this out of the box?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I add it in the back since
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and I don't feel like rounding the data is just format ..