Skip to content

Instantly share code, notes, and snippets.

@martgnz
martgnz / coaches.csv
Last active April 7, 2016 20:12
Football Coach World Ranking
coach team points country
Luis Enrique Barcelona 20596 Spain
Unai Emery Sevilla 13468 Spain
Guardiola Bayern München 13350 Spain
M. Allegri Juventus 12177 Italy
D. Simeone Atlético Madrid 12092 Argentina
L. Blanc PSG 10933 France
T. Tuchel Borussia Dortmund 10651 Germany
Ernesto Valverde Athletic Club 10418 Spain
Marcelino Villarreal 9675 Spain
var StaticCanvasMap;var ZoomableCanvasMap;!function(){"use strict";function inside(pt,polygon){var polys=polygon.geometry.coordinates;if(polygon.geometry.type==="Polygon")polys=[polys];var insidePoly=false;var i=0;while(i<polys.length&&!insidePoly){if(inRing(pt,polys[i][0])){var inHole=false;var k=1;while(k<polys[i].length&&!inHole){if(inRing(pt,polys[i][k])){inHole=true}k++}if(!inHole)insidePoly=true}i++}return insidePoly}function inRing(pt,ring){var isInside=false;for(var i=0,j=ring.length-1;i<ring.length;j=i++){var xi=ring[i][0],yi=ring[i][1];var xj=ring[j][0],yj=ring[j][1];var intersect=yi>pt[1]!==yj>pt[1]&&pt[0]<(xj-xi)*(pt[1]-yi)/(yj-yi)+xi;if(intersect)isInside=!isInside}return isInside}function maxBounds(one,two){var bounds=two;if(one[0][0]<two[0][0])bounds[0][0]=one[0][0];if(one[0][1]<two[0][1])bounds[0][1]=one[0][1];if(one[1][0]>two[1][0])bounds[1][0]=one[1][0];if(one[1][1]>two[1][1])bounds[1][1]=one[1][1];return bounds}function createRTree(element,dataPath){element.lookupTree=rbush(4);var elements=
@martgnz
martgnz / 2016-word-press-freedom-index.csv
Created May 3, 2016 15:53
2016 World Press Freedom Index Data
ranking fill country
1 #fff0b3 Finland
2 #fff0b3 Netherlands
3 #fff0b3 Norway
4 #fff0b3 Denmark
5 #fff0b3 New Zealand
6 #fff0b3 Costa Rica
7 #fff0b3 Switzerland
8 #fff0b3 Sweden
9 #fff0b3 Ireland
@martgnz
martgnz / map.js
Last active May 3, 2016 17:03
Basic Spam.js map
d3.json("map.json", function(error, d) {
topojson.presimplify(d)
var map = new StaticCanvasMap({
element: "body",
data: [
{
features: topojson.feature(d, d.objects["map"]),
static: {
paintfeature: function(parameters, d) {
@martgnz
martgnz / bcn-rent.csv
Created May 4, 2016 14:59
Rent in Barcelona by neigbourhoods in 2014
id barri poblacio index ranking
01 el Raval 48.471 65.9 53
02 el Barri Gótic 15.911 98.5 21
03 la Barceloneta 15.181 84.5 32
04 Sant Pere Santa Caterina i la Ribera 22.674 92.5 24
05 el Fort Pienc 31.785 104.5 17
06 la Sagrada Família 51.562 92.4 25
07 la Dreta de l'Eixample 43.749 165.3 7
08 l'Antiga Esquerra de l'Eixample 41.975 127.8 11
09 la Nova Esquerra de l'Eixample 57.863 109.1 15
id total without_studies primary_school secondary_school high_school university unknown
11 1158 37 378 226 205 312 0
12 1358 65 485 288 242 278 0
13 2761 113 1146 581 449 472 0
14 2376 74 782 477 425 618 0
15 2193 98 815 435 352 490 3
16 1395 37 469 302 254 333 0
17 1774 33 714 383 281 363 0
18 2947 92 1505 606 352 392 0
19 1910 54 752 399 327 376 2
@martgnz
martgnz / choropleth-1.html
Last active May 4, 2016 19:25
Spam.js choropleth boilerplate
<!DOCTYPE html>
<meta charset="utf-8" />
<body>
<script src="d3.min.js"></script>
<script src="topojson.min.js"></script>
<script src="rbush.min.js"></script>
<script src="spam.min.js"></script>
<script type='text/javascript'>
d3.json("bcn.json", function(error, d) {
@martgnz
martgnz / choropleth-2.html
Last active May 4, 2016 19:31
Spam.js choropleth with colors
<!DOCTYPE html>
<meta charset="utf-8" />
<body>
<script src="d3.min.js"></script>
<script src="topojson.min.js"></script>
<script src="rbush.min.js"></script>
<script src="spam.min.js"></script>
<script type='text/javascript'>
var color = d3.scale.linear()
@martgnz
martgnz / choropleth-3.html
Last active May 4, 2016 19:37
Final code for Spam.js Choropleth
<!DOCTYPE html>
<meta charset="utf-8" />
<style>
#map {
margin: 0 auto;
text-align: center;
}
.legend {
height: 35px;
width: 250px;