-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #17 from ClimateCompatibleGrowth/type_and_rank
Type and rank
- Loading branch information
Showing
12 changed files
with
304 additions
and
114 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,3 +24,6 @@ build/ | |
|
||
# Ignore environment variables file | ||
.env | ||
|
||
# Ignore system files | ||
.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
const HOVER_COLOR = "#d36f80" | ||
|
||
|
||
function mouseOverHandler(d, i) { | ||
d3.select(this).attr("fill", HOVER_COLOR) | ||
} | ||
function mouseOutHandler(d, i) { | ||
d3.select(this).attr("fill", "red") | ||
} | ||
function clickHandler(d, i) { | ||
const url = "/countries/" + i.id | ||
window.location.assign(url, '_blank') | ||
} | ||
|
||
|
||
// The svg | ||
const svg = d3.select("svg"), | ||
width = +svg.attr("width"), | ||
height = +svg.attr("height"); | ||
|
||
// Map and projection | ||
const projection = d3.geoNaturalEarth1() | ||
.scale(width / 1.3 / Math.PI) | ||
.translate([width / 2, height / 2]) | ||
|
||
|
||
const countries = country_data; | ||
|
||
// Load external data and draw base map | ||
d3.json("https://raw.githubusercontent.com/holtzy/D3-graph-gallery/master/DATA/world.geojson").then( function(data) { | ||
|
||
// Draw the map | ||
svg.append("g") | ||
.selectAll("path") | ||
.data(data.features) | ||
.join("path") | ||
.attr("fill", "#69b3a2") | ||
.attr("d", d3.geoPath() | ||
.projection(projection) | ||
) | ||
.style("stroke", "#fff") | ||
}) | ||
|
||
// Load external data and highlight countries | ||
d3.json("https://raw.githubusercontent.com/holtzy/D3-graph-gallery/master/DATA/world.geojson").then( function(data){ | ||
|
||
// Filter data | ||
|
||
countries.forEach(country => { | ||
|
||
const filtered_data = data.features.filter(d => {return d.properties.name==country.c.name}) | ||
|
||
// Draw the map | ||
svg.append("g") | ||
.selectAll("path") | ||
.data(filtered_data) | ||
.join("path") | ||
.attr("fill", "red") | ||
.attr("d", d3.geoPath() | ||
.projection(projection) | ||
) | ||
.style("stroke", "#fff") | ||
.on("mouseover", mouseOverHandler) | ||
.on("mouseout", mouseOutHandler) | ||
.on("click", clickHandler) | ||
|
||
} | ||
); | ||
|
||
}) | ||
|
Oops, something went wrong.