atlas/web/_js/minified.js

109 lines
674 KiB
JavaScript
Raw Normal View History

/*
This file contains compressed versions of the following files:
https://draemm.li/various/place-atlas/_js/atlas.js
https://draemm.li/various/place-atlas/_js/main.js
https://draemm.li/various/place-atlas/_js/view.js
https://draemm.li/various/place-atlas/_js/draw.js
These files are released under the AGPL v3 license (see below)
This file also contains the function pointIsInPolygon,
which was released under the MIT license by James Halliday.
The entire source code of the /r/place Atlas is available here:
https://github.com/RolandR/place-atlas
*/
/*
The MIT License (MIT)
pointIsInPolygon function
Copyright (c) 2016 James Halliday
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
function pointIsInPolygon (point, polygon) {
// ray-casting algorithm based on
// http://www.ecse.rpi.edu/Homepages/wrf/Research/Short_Notes/pnpoly.html
var x = point[0], y = point[1];
var inside = false;
for (var i = 0, j = polygon.length - 1; i < polygon.length; j = i++) {
var xi = polygon[i][0], yi = polygon[i][1];
var xj = polygon[j][0], yj = polygon[j][1];
var intersect = ((yi > y) != (yj > y))
&& (x < (xj - xi) * (y - yi) / (yj - yi) + xi);
if (intersect) inside = !inside;
}
return inside;
};
/*
========================================================================
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-06 12:26:49 +02:00
function updateLines(){linesCanvas.width=linesCanvas.clientWidth,linesCanvas.height=linesCanvas.clientHeight,linesContext.lineCap="round",linesContext.lineWidth=Math.max(Math.min(1.5*zoom,24),6),linesContext.strokeStyle="#000000";for(var a=0;a<hovered.length;a++){var b=hovered[a].element;0!=b.getBoundingClientRect().left&&(linesContext.beginPath(),linesContext.moveTo(b.getBoundingClientRect().left+document.documentElement.scrollLeft+b.clientWidth/2,b.getBoundingClientRect().top+document.documentElement.scrollTop+20),linesContext.lineTo(~~(hovered[a].center[0]*zoom)+innerContainer.offsetLeft,~~(hovered[a].center[1]*zoom)+innerContainer.offsetTop),linesContext.stroke())}linesContext.lineWidth=Math.max(Math.min(zoom,16),4),linesContext.strokeStyle="#FFFFFF";for(var a=0;a<hovered.length;a++){var b=hovered[a].element;0!=b.getBoundingClientRect().left&&(linesContext.beginPath(),linesContext.moveTo(b.getBoundingClientRect().left+document.documentElement.scrollLeft+b.clientWidth/2,b.getBoundingClientRect().top+document.documentElement.scrollTop+20),linesContext.lineTo(~~(hovered[a].center[0]*zoom)+innerContainer.offsetLeft,~~(hovered[a].center[1]*zoom)+innerContainer.offsetTop),linesContext.stroke())}}function renderBackground(a){backgroundContext.clearRect(0,0,canvas.width,canvas.height),backgroundContext.fillStyle="rgba(0, 0, 0, 0.6)",backgroundContext.fillRect(0,0,backgroundCanvas.width,backgroundCanvas.height);for(var b=0;b<a.length;b++){var c=a[b].path;backgroundContext.beginPath(),c[0]&&backgroundContext.moveTo(c[0][0],c[0][1]);for(var d=1;d<c.length;d++)backgroundContext.lineTo(c[d][0],c[d][1]);backgroundContext.closePath(),backgroundContext.strokeStyle="rgba(255, 255, 255, 0.8)",backgroundContext.stroke()}}function initView(){function p(){for(var a=h.length-1;a>0;a--){var b=Math.floor(Math.random()*(a+1)),c=h[a];h[a]=h[b],h[b]=c}}function q(a){var b=document.createElement("div");b.className="object";var c='<h2><a href="?id='+a.id+'">'+a.name+"</a></h2>";if(a.description&&(c+="<p>"+a.description+"</p>"),a.website&&(c+='<a target="_blank" href='+a.website+">Website</a>"),a.subreddit){var d=a.subreddit.split(",");for(var e in d){var f=d[e].trim();"r/"==f.substring(0,2)?f="/"+f:"/"!=f.substring(0,1)&&(f="/r/"+f),c+='<a target="_blank" href=https://reddit.com'+f+">"+f+"</a>"}}return b.innerHTML+=c,b}function r(){var a=document.getElementById("objectsList"),b=0,d=window.location.search;d&&(b=d.split("id=")[1])&&(b=parseInt(b.split("&")[0]));var e=atlas.filter(function(a){return a.id===b});if(1===e.length){e=e[0];var f=q(e);a.innerHTML="",a.appendChild(f),zoom=4,renderBackground(atlas),applyView(),zoomOrigin=[innerContainer.clientWidth/2-e.center[0]*zoom,innerContainer.clientHeight/2-e.center[1]*zoom],scaleZoomOrigin=[500-e.center[0],500-e.center[1]],applyView(),hovered=[e],u(),hovered[0].element=f,c.className="",updateLines(),n=!0}}function s(a,d){if(!dragging&&(!n||d)){var e=[(a.clientX-(container.clientWidth/2-innerContainer.clientWidth/2+zoomOrigin[0]+container.offsetLeft))/zoom,(a.clientY-(container.clientHeight/2-innerContainer.clientHeight/2+zoomOrigin[1]+container.offsetTop))/zoom];if(e[0]<=1100&&e[0]>=-100&&e[0]<=1100&&e[0]>=-100){for(var f=[],g=0;g<atlas.length;g++)pointIsInPolygon(e,atlas[g].path)&&f.push(atlas[g]);var h=!1;if(hovered.length==f.length){for(var g=0;g<hovered.length;g++)if(hovered[g].id!=f[g].id){h=!0;break}}else h=!0;if(h){hovered=f,b.innerHTML="";for(var g in hovered){var i=q(hovered[g]);b.appendChild(i),hovered[g].element=i}hovered.length>0?c.className="":c.className="hidden",u()}}}}function t(c,d){e.contains(k)&&e.removeChild(k),h||(h=atlas.concat(),document.getElementById("atlasSize").innerHTML="The Atlas contains "+h.length+" entries."),c?(h=atlas.filter(function(a){return-1!==a.name.toLowerCase().indexOf(c)||-1!==a.description.toLowerCase().indexOf(c)}),document.getElementById("atlasSize").innerHTML="Found "+h.length+" entries."):document.getElementById("atlasSize").innerHTML="The Atlas contains "+h.length+" entries.",null===d&&(d=l),renderBackground(h),u(),document.getElementById("sort").value
2017-04-10 17:57:13 +02:00
2017-04-10 15:16:34 +02:00