[ Launch: World Map With Cities ] 5a36f4baaa4247c6e330 by jkeohan
[ Launch: Projections (merc,orth,stero) ] 311df900bc33ce754dd4 by jkeohan
[ Launch: Tributary inlet ] eae9e630e544c02b8433 by jkeohan
-
-
Save jkeohan/5a36f4baaa4247c6e330 to your computer and use it in GitHub Desktop.
World Map With Cities - Demo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
code | city | country | lat | lon | |
---|---|---|---|---|---|
ZNZ | ZANZIBAR | TANZANIA | -6.13 | 39.31 | |
TYO | TOKYO | JAPAN | 35.68 | 139.76 | |
AKL | AUCKLAND | NEW ZEALAND | -36.85 | 174.78 | |
BKK | BANGKOK | THAILAND | 13.75 | 100.48 | |
DEL | DELHI | INDIA | 29.01 | 77.38 | |
SIN | SINGAPORE | SINGAPOR | 1.36 | 103.75 | |
BSB | BRASILIA | BRAZIL | -15.67 | -47.43 | |
RIO | RIO DE JANEIRO | BRAZIL | -22.90 | -43.24 | |
YTO | TORONTO | CANADA | 43.64 | -79.40 | |
IPC | EASTER ISLAND | CHILE | -27.11 | -109.36 | |
SEA | SEATTLE | USA | 47.61 | -122.33 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{"description":"World Map With Cities - Demo","endpoint":"","display":"svg","public":true,"require":[{"name":"tooltip","url":"http://labratrevenge.com/d3-tip/javascripts/d3.tip.v0.6.3.js"}],"fileconfigs":{"inlet.js":{"default":true,"vim":false,"emacs":false,"fontSize":12},"countries.json":{"default":true,"vim":false,"emacs":false,"fontSize":12},"_.md":{"default":true,"vim":false,"emacs":false,"fontSize":12},"config.json":{"default":true,"vim":false,"emacs":false,"fontSize":12},"cities.csv":{"default":true,"vim":false,"emacs":false,"fontSize":12},"styles.css":{"default":true,"vim":false,"emacs":false,"fontSize":12}},"fullscreen":false,"play":false,"loop":false,"restart":false,"autoinit":true,"pause":true,"loop_type":"pingpong","bv":false,"nclones":15,"clone_opacity":0.4,"duration":3000,"ease":"linear","dt":0.01,"ajax-caching":true,"thumbnail":"http://i.imgur.com/Bq1hClk.png"} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//https://quizlet.com/ | |
var countries = tributary.countries | |
var cities = tributary.cities | |
//console.log(cities) | |
//console.log(countries.features) | |
var svg = d3.select('svg').style("background-color","#000000") | |
var canvas = canvasSize('svg') | |
//console.log(canvas) | |
w = canvas[0] | |
h = canvas[1] | |
//Define map projection | |
var projection = d3.geo.mercator() | |
.center([ 0, 0 ]) | |
.translate([ w/2, h/1.74026575872 ]) | |
.scale([ w/6.5 ]) | |
//Define path generator | |
var path = d3.geo.path() | |
.projection(projection); | |
svg.selectAll("path") | |
.data(countries.features) | |
.enter() | |
.append("path") | |
.style("fill","#054bff") | |
.attr("d", path); | |
var elem = svg.selectAll('g').data(cities) | |
var elemEnter = elem.enter().append('g') | |
.attr("transform", function(d,i) { | |
return "translate(" + projection([d.lon, d.lat])[0] + "," + projection([d.lon, d.lat])[1]+ ")" } ) | |
var circle = elemEnter.append('circle') | |
.attr("fill-opacity",0) | |
.style("stroke-width",0) | |
.attr("fill","#d4ee80") | |
.transition().delay(function(d,i) { | |
console.log(i % 3) | |
if(i % 2 === 0) { text(this) } | |
return i / cities.length * 12000}) | |
.attr("r",15) | |
.transition().duration(500) | |
.attr("stroke", "rgba(230,230,230, .5)") | |
.attr("fill-opacity",1) | |
.attr("fill","#59b318") | |
.attr("r",5) | |
.style("stroke-width",10) | |
.attr("stroke-opacity",.8) | |
.transition() | |
.duration(1000) | |
.ease(Math.sqrt) | |
.attr("r",6) | |
//.style("fill-opacity", 1e-6) | |
.style("stroke-width",40) | |
.attr("stroke-opacity", 1e-6) | |
//transition will allow the stroke-width to be fully expanded and then | |
//reset to 0 before growing in diam | |
//if the first trans() is removed then s-w trans to 0 and then back out | |
//I believe that transition() is aware of the previous trans\duration | |
//even though they aren't chained | |
circle.transition().duration(500).style("stroke-width",0).attr("stroke-opacity",0) | |
.transition().style("stroke-width",10).attr("stroke-opacity",.8) | |
// | |
function text () { | |
// console.log(this) | |
var text = elemEnter.append("text") | |
.attr("fill","white") | |
.transition().duration(1000).delay(500) | |
.transition().delay(function(d,i) { return i / cities.length * 11000}) | |
.transition().duration(1000) | |
.attr("dx", function(d){return -33}) | |
.attr("dy", function(d) { return 20 } ) | |
.text(function(d){return d.city}) | |
.attr("fill","white") | |
.style("font-size",10).style("font-weight","bold") | |
.attr("text-anchor","start") | |
} | |
//Load in GeoJSON data | |
function canvasSize(target) { | |
var height = parseFloat(d3.select(target).node().clientHeight) | |
var width = parseFloat(d3.select(target).node().clientWidth) | |
console.log(d3.select(target).node().clientWidth) | |
return [width,height] | |
}//canvasSize | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.d3-tip { | |
line-height: 1; | |
font-weight: bold; | |
padding: 5px; | |
background: rgba(255, 255, 255, 0.8); | |
color: #fff; | |
border-radius: 2px; | |
font-size:12px; | |
} | |
/* Creates a small triangle extender for the tooltip */ | |
.d3-tip:after { | |
box-sizing: border-box; | |
display: inline; | |
font-size: 12px; | |
width: 100%; | |
line-height: 1; | |
color: rgba(255, 255, 255, 0.8); | |
content: "\25BC"; | |
position: absolute; | |
text-align: center; | |
} | |
/* Style northward tooltips differently */ | |
.d3-tip.n:after { | |
margin: -1px 0 0 0; | |
top: 100%; | |
left: 0; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment