Skip to content

Commit

Permalink
Fixed missing flag for Norway
Browse files Browse the repository at this point in the history
  • Loading branch information
tanmaylaud committed Aug 7, 2020
1 parent 06521cc commit 5fc3643
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 24 deletions.
19 changes: 15 additions & 4 deletions src/Globe.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Globe, { GlobeInstance } from "globe.gl";
import { request, getCoordinates, getPolygonLabel } from "./utils";
import { request, getCoordinates } from "./utils";
import {
GLOBE_IMAGE_URL,
BACKGROUND_IMAGE_URL,
Expand All @@ -9,6 +9,7 @@ import {
import { interpolateReds, scaleSequential } from "d3";
import { Countries, Country } from "./Country";
import { GlobalCounts } from "./GlobalCounts";
import { getPolygonLabel } from "./PolygonLabel";

const getVal = (feat: any) => {
return Math.pow(feat.covidData.active / feat.properties.POP_EST, 1 / 4);
Expand Down Expand Up @@ -38,8 +39,7 @@ export function initGlobe() {
.polygonSideColor(() => "rgba(100, 100, 100, 0.05)")
.polygonStrokeColor(() => "#ffff")
.polygonLabel(({ properties: d, covidData: c }: any) => {
const flagName = d.ADMIN === "France" ? "fr" : d.ISO_A2.toLowerCase();

const flagName = getFlagName(d);
return getPolygonLabel(flagName, d, c);
})
.onPolygonHover((hoverD: any) =>
Expand All @@ -56,6 +56,17 @@ export function initGlobe() {
world.width(window.innerWidth);
world.height(window.innerHeight);
});

function getFlagName(d: any) {
switch (d.ADMIN) {
case "France":
return "fr";
case "Norway":
return "no";
default:
return d.ISO_A2.toLowerCase();
}
}
}

let dates: string[] = [];
Expand All @@ -66,7 +77,7 @@ async function getCases() {
countries = await request(CASES_API);
featureCollection = (await request(GEOJSON_URL)).features;

dates = Object.keys(countries.China);
dates = Object.keys(countries.India);

updateCounters();
updatePolygonsData();
Expand Down
20 changes: 0 additions & 20 deletions src/utils/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import dayjs from "dayjs";
import { format } from "d3";
import { FLAG_ENDPOINT } from "../Constants";

export async function request(url: string) {
try {
Expand Down Expand Up @@ -46,21 +44,3 @@ export const isMobile = (function (a) {
);
// @ts-ignore
})(navigator.userAgent || navigator.vendor || window.opera);

export function getPolygonLabel(flagName: any, d: any, c: any): string {
return `
<div class="card">
<img class="card-img" src="${FLAG_ENDPOINT}/${flagName}.png" alt="flag" />
<div class="container">
<span class="card-title"><b>${d.NAME}</b></span> <br />
<div class="card-spacer"></div>
<hr />
<div class="card-spacer"></div>
<span>Cases: ${numberWithCommas(c.confirmed)}</span> <br />
<span>Deaths: ${numberWithCommas(c.deaths)}</span> <br />
<span>Recovered: ${numberWithCommas(c.recoveries)}</span> <br />
<span>Population: ${format(".3s")(d.POP_EST)}</span>
</div>
</div>
`;
}

0 comments on commit 5fc3643

Please sign in to comment.