atlas/web/_js/atlas.js

152 lines
3.3 KiB
JavaScript
Raw Normal View History

/*
========================================================================
The /r/place Atlas
An Atlas of Reddit's /r/place, with information to each
artwork of the canvas provided by the community.
Copyright (C) 2017 Roland Rytz <roland@draemm.li>
Licensed under the GNU Affero General Public License Version 3
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
For more information, see:
https://draemm.li/various/place-atlas/license.txt
========================================================================
*/
2017-04-10 17:57:13 +02:00
window.addEventListener("error", function(e){
console.log(e);
var errorMessage = "<p class=\"error\">An error has occurred:</p>";
errorMessage += "<p class=\"errorBody\">"+e.message+"</p>";
errorMessage += "<p class=\"errorBody\">on line "+e.lineno+"</p>";
errorMessage += "<p class=\"error\">If this keeps happening, feel free to send me a <a href=\"mailto:roland.rytz@gmail.com\">mail</a>.</p>";
document.getElementById("loadingContent").innerHTML = errorMessage;
});
var atlas = [
{
"id": 0,
"name": "r/place still has to be indexed",
"description": "To make sure this project doesn't get flooded with a million requests or changes, I wait until april 4th so I can submit all the ",
"website": "https://place-atlas.stefanocoding.me/",
"subreddit": "r/placeAtlas2",
"center": [
502.5,
513.5
],
"path": [
[
2.5,
343.5
],
[
994.5,
339.5
],
[
996.5,
690.5
],
[
2.5,
678.5
]
]
}
];
2017-04-06 12:26:49 +02:00
//console.log("There are "+atlas.length+" entries in the Atlas.");
/*
atlas.sort(function(a, b){
if (a.id < b.id) {
return -1;
}
if (a.id > b.id) {
return 1;
}
// a must be equal to b
return 0;
});
for(var i = 0; i < atlas.length; i++){
if(atlas[i-1]){
if(atlas[i-1].id == atlas[i].id){
console.log(atlas[i-1].id + ": "+ atlas[i-1].name);
console.log(atlas[i ].id + ": "+ atlas[i ].name);
}
}
}
console.log("biggest id: "+atlas[atlas.length-1].id + ", " + atlas[atlas.length-1].name);
*/
/*
for(var i = 0; i < atlas.length; i++){
if(typeof atlas[i].website == "undefined"){
console.log(atlas[i].name);
} else if(atlas[i].website.trim() != ""){
if(atlas[i].website.trim().substring(0, 4) != "http"){
console.log(atlas[i].name + ": " + atlas[i].website);
}
}
}
*/
// sort by center.y, so that lines will overlap less
atlas.sort(function(a, b){
if (a.center[1] < b.center[1]) {
return -1;
}
if (a.center[1] > b.center[1]) {
return 1;
}
// a must be equal to b
return 0;
});
2017-04-12 15:02:24 +02:00
/*
// Populate with test data
for(var i = 0; i < 10000; i++){
var x = ~~(Math.random() * 1000)+0.5;
var y = ~~(Math.random() * 1000)+0.5;
var w = ~~(Math.random()*100);
var h = ~~(Math.random()*100);
atlas.push({
"id": 5,
"name": "test"+(i+3),
"website": "",
"subreddit": "",
"center": [0, 0],
"path":[
[x, y],
[x+w, y],
[x+w, y+h],
[x, y+h]
]
});
}
*/