Built population sort.

master
Ben Burlingham 9 years ago
parent 84ec845e8b
commit b352040a9a
  1. 6
      Worldcup/Countries.hs
  2. 62
      js/diagram.js
  3. 2
      worldcup.json

@ -14,20 +14,22 @@ type Countries = HashMap Int Country
data Country = Country {
countryId :: Int,
countryContinentId :: Int,
countryPop :: Int,
countryName :: String } deriving (Show)
instance ToJSON Country where
toJSON Country{..} = object [ "cId" .= countryContinentId, "n" .= countryName ]
toJSON Country{..} = object [ "cId" .= countryContinentId, "n" .= countryName, "p" .= countryPop ]
instance FromJSON Country where
parseJSON = withObject "country" $ \o -> do
countryId <- o .: "id"
countryContinentId <- o .: "continent_id"
countryPop <- o .: "pop"
countryName <- o .: "name"
return Country{..}
lookupCountry :: Int -> Countries -> Country
lookupCountry _id hm = M.fromMaybe (Country 999 999 "DNE") (HM.lookup _id hm)
lookupCountry _id hm = M.fromMaybe (Country 999 999 999 "DNE") (HM.lookup _id hm)
parseCountries :: Either String [Value] -> Countries
parseCountries (Left x) = error x

@ -4,52 +4,6 @@ const goalsAgainst = {};
const Diagram = {
clear: () => d3.select('svg').selectAll("*").remove(),
// // json.tourneys[eventKey].teams.sort()
//
// sortKey = "goalsFor"
//
// switch (sortKey) {
// case 'goalsFor':
// // console.info(json.tourneys[eventKey].teams)/
// // return json.tourneys[eventKey].teams;
//
// const teams = json.tourneys[eventKey].teams
// .slice()
// .sort((a, b) => {
// const n1 = json.countries[json.teams[a]].n;
// const n2 = json.countries[json.teams[b]].n;
//
// if (n1 < n2) {
// return -1;
// }
// else if (n1 > n2) {
// return 1;
// }
//
// return 0;
// });
//
// console.warn(teams.map(v => {
// return json.countries[json.teams[v]].n
// }))
//
// // console.warn(teams.map(a => json.countries[json.teams[a]].n))
//
// return teams;
// break;
//
// case 'goalsAgainst':
// break;
//
// case 'countryName':
// break;
//
// case 'countryPopulation':
// break;
// }
swapGroupArcs: (chords, i, j) => {
if (i < 0 || j < 0 || i === j) {
return chords;
@ -101,6 +55,11 @@ const Diagram = {
return data.countries[countryId].n;
},
getPopulation: (data, eventIndex, n) => {
const teamId = data.tourneys[eventIndex].teams[n];
return data.countries[data.teams[teamId]].p;
},
getGoalsFor: (data, eventIndex, n) => {
const teamId = data.tourneys[eventIndex].teams[n];
@ -156,9 +115,10 @@ const Diagram = {
.call(null, chordMatrix);
const sortedChords = Sorter.sort(chords, 0, chords.groups.length - 1,
Diagram.getCountryName.bind(null, data, eventIndex),
// Diagram.getCountryName.bind(null, data, eventIndex),
// Diagram.getGoalsFor.bind(null, data, eventIndex),
// Diagram.getGoalsAgainst.bind(null, data, eventIndex),
Diagram.getPopulation.bind(null, data, eventIndex),
Diagram.swapGroups.bind(null, data, eventIndex));
const arc = d3.arc()
@ -234,15 +194,11 @@ const Diagram = {
})
.style("text-anchor", function(d) { return d.angle > Math.PI ? "end" : null; })
.text(function(d) {
// SORT BY GOALS SCORED
// SORT BY ALPHABETICAL
// SORT BY COUNTRY SIZE
// COLOR BY CONTINENT
// STRANGE EXTENDED TIME CHILE-BRAZIL - FIX BY HAND? IS BECAUE se1 IS SCORE __GOING INTO__ EXTENDED TIME
// console.info(metaMatrix[d.index])
const teamId = data.tourneys[eventIndex].teams[d.index];
return data.countries[data.teams[teamId]].n + ' ' + goalsAgainst[teamId];
const country = data.countries[data.teams[teamId]];
return data.countries[data.teams[teamId]].n + ' ' + country.p;
});
},
};

File diff suppressed because one or more lines are too long
Loading…
Cancel
Save