xxxxxxxxxx
67
var url;
var cultures = [];
function preload() {
// Loading data from the API.
// *** Insert your API key here: ***
var API_KEY = 'ba7fed2a-e5cb-4ccd-9281-2065b6527037';
var query = 'culture';
var params = '&size=100';
url = 'https://api.harvardartmuseums.org/'+query+'?apikey='+API_KEY+params;
loadJSON(url, gotResponse);
}
function setup() {
createCanvas(1000, 1000);
title = createElement('h2', 'Most Popular Cultures:');
title.position(10, 20);
// ---------------------------------------------
// Using the data from the cultures[] array, make a histogram
// showing the number of objects in Harvard's collection for each culture.
// ---------------------------------------------
// Hint: You might want to start by just displaying a list of all cultures' name
// and number of associated objects. Remember to use the dot notation for
// key/value pairs. You can look at the whole cultures array in the console
// below with this line:
console.log(cultures);
console.log(cultures[0].name);
var cultureList = [];
var cultureDict = [];
var culture;
var objectcount;
// *** Your code here: ***
for (var i = 0; i<=255; i++) {
var name = cultures[i].name;
objectcount = cultures[i].objectcount;
culture = name + ' ' + objectcount;
cultureList += name[objectcount];
if(objectcount>=5000){
createElement('span', culture).style('text-indent', '20px').style('font-size', '10pt').position(10, 20 * i);
}
}
}
function gotResponse(response) {
// This API is limited to 100 items per page. This code determines how many
// pages there are, calls up each page, and loads each page's JSON into memory.
var totalPages = response.info.pages;
for (var currentPage = 1; currentPage <= totalPages; currentPage += 1) {
url = url+'&page='+currentPage;
loadJSON(url, gotPages);
}
}
function gotPages(response) {
// For each page of results, this code adds the results to cultures[] array.
cultures = cultures.concat(response.records);
}