-
Notifications
You must be signed in to change notification settings - Fork 45
DataMade: Developer Position Coding Challenge by Grant Russell #12
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
base: main
Are you sure you want to change the base?
Changes from all commits
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 |
|---|---|---|
|
|
@@ -40,39 +40,46 @@ export default function RestaurantPermitMap() { | |
| const communityAreaColors = ["#eff3ff", "#bdd7e7", "#6baed6", "#2171b5"] | ||
|
|
||
| const [currentYearData, setCurrentYearData] = useState([]) | ||
| const [areaDataMap, setAreaDataMap] = useState({}) | ||
| const [year, setYear] = useState(2026) | ||
|
|
||
| const yearlyDataEndpoint = `/map-data/?year=${year}` | ||
| const totalNumPermits = currentYearData.reduce((sum, { num_permits}) => sum + num_permits, 0) | ||
| const maxNumPermits = currentYearData.reduce((max, { num_permits }) => Math.max(max, num_permits), 0) | ||
|
|
||
| useEffect(() => { | ||
| fetch() | ||
| fetch(yearlyDataEndpoint) | ||
| .then((res) => res.json()) | ||
| .then((data) => { | ||
| /** | ||
| * TODO: Fetch the data needed to supply to map with data | ||
| */ | ||
| setCurrentYearData(data) | ||
| const map = data.reduce((acc, area) => { | ||
| acc[area.area_id] = area | ||
| return acc | ||
| }, {}) | ||
| setAreaDataMap(map) | ||
|
Comment on lines
+55
to
+59
Author
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. I veered slightly from the instructions here as well. I added a state variable to map the area data on the same fetch response as setting the current year data. I'm storing the fetched data in two shapes for convenience, as they serve two different purposes.
|
||
| }) | ||
| }, [yearlyDataEndpoint]) | ||
|
|
||
|
|
||
| function getColor(percentageOfPermits) { | ||
| /** | ||
| * TODO: Use this function in setAreaInteraction to set a community | ||
| * area's color using the communityAreaColors constant above | ||
| */ | ||
| if (percentageOfPermits > 0.75) return communityAreaColors[3] | ||
| if (percentageOfPermits > 0.5) return communityAreaColors[2] | ||
| if (percentageOfPermits > 0.25) return communityAreaColors[1] | ||
| return communityAreaColors[0] | ||
| } | ||
|
|
||
| function setAreaInteraction(feature, layer) { | ||
| /** | ||
| * TODO: Use the methods below to: | ||
| * 1) Shade each community area according to what percentage of | ||
| * permits were issued there in the selected year | ||
| * 2) On hover, display a popup with the community area's raw | ||
| * permit count for the year | ||
| */ | ||
| layer.setStyle() | ||
| layer.on("", () => { | ||
| layer.bindPopup("") | ||
| const areaId = feature.properties.area_num_1 | ||
| const areaData = areaDataMap[areaId] | ||
| const percentage = maxNumPermits > 0 ? areaData.num_permits / maxNumPermits : 0 | ||
| layer.setStyle({ | ||
| fillColor: getColor(percentage), | ||
| fillOpacity: 0.7, | ||
| color: "#808080", | ||
| weight: 1, | ||
| }) | ||
| layer.on("mouseover", () => { | ||
| layer.bindPopup(`<b>${areaData.name}</b><br/>Permits: ${areaData.num_permits}`) | ||
| layer.openPopup() | ||
| }) | ||
| } | ||
|
|
@@ -81,11 +88,11 @@ export default function RestaurantPermitMap() { | |
| <> | ||
| <YearSelect filterVal={year} setFilterVal={setYear} /> | ||
| <p className="fs-4"> | ||
| Restaurant permits issued this year: {/* TODO: display this value */} | ||
| Restaurant permits issued this year: {totalNumPermits} | ||
| </p> | ||
| <p className="fs-4"> | ||
| Maximum number of restaurant permits in a single area: | ||
| {/* TODO: display this value */} | ||
| {maxNumPermits} | ||
| </p> | ||
| <MapContainer | ||
| id="restaurant-map" | ||
|
|
||
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 veered slightly from the instructions, but I took inspiration from the TODO example object in
get_num_permits. I would prefer to include thearea_idfor use on the frontend. I checked the raw data, and while it appears clean, it's just better practice to match on anidif one is present.