Pen Settings

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation


Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

  <div id='map'></div>
  <script src='' charset="utf-8"></script>
  <script src="" charset="utf-8"></script>
  <script src='' charset='utf-8'></script>
  <script src=""></script>
              body,html,svg,div#map {
  width: 100%;
  height: 100%;
  padding: 0px;
  margin: 0px;
  overflow: hidden;
body {
  background-color: #2D2F30;

              pageWidth = window.innerWidth
pageHeight = window.innerHeight
proj = new d3.geo.mercator!
  .center [-105,51] 
  .rotate [0,0,0]
  .translate [(pageWidth/2),pageHeight/2] 
  .scale 1 .<<. 8  

zoomed = ->
  transform = "translate(#{zoom.translate!}) scale(#{zoom.scale!})" 'svg#map-canvas g'
    .attr 'transform', transform
    .selectAll 'path'
    .style 'stroke-width', -> 3 / zoom.scale!

zoom = new d3.behavior.zoom!on 'zoom', zoomed

g = 'div#map'
  .append 'svg'
  .attr 'id', 'map-canvas'
  .call zoom
  .append 'g'

path = d3.geo.path().projection(proj) # Path generating function

# Transpose a shape onto a circle
circleIt = (it,x,y,r) ->
  from = path it # The coastline boundary
  # A simple circle path of two arcs
  circle = "m #{x - r} #y 
    a #r #r 0 1 0 #{2*r} 0 
    a #r #r 0 1 0 #{-2*r} 0"
  polymorph.transpose from, circle

randomCircle = ->
    p = 20 # padding
    w = pageWidth - (2 * p)
    h = pageHeight - (2 * p)
    x = (Math.random! * w) + p
    y = (Math.random! * h) + p
    r = (Math.log * 3
    circleIt it, x, y, r
colours =
  Canada: '#CACACA'
  Mexico: '#8C8787'
  'United States': '#4E4E4E'
cstGeoJson = topojson.feature countries,countries.objects.countries

g.selectAll 'path'
  .data cstGeoJson.features.filter -> # Let's be selective
    name =
    area = # Filter out small island
    reg = /(Canada|Mexico|United States)/ # Only NA for now
    if name.match reg and area > 1 then yes else no
  .append 'path'
  .attr 'd', randomCircle
  .style 'fill', -> colours[]

toDots = ->
  l = d3.selectAll('path')[0].length
  i = 1
  d3.selectAll 'path'
    .delay -> Math.random! * 1000
    .duration 5000
    .attr 'd', randomCircle
    .each 'end', -> toCountries! if l is i++
toCountries = ->
  l = d3.selectAll('path')[0].length
  i = 1
  d3.selectAll 'path'
    .delay -> Math.random! * 1000
    .duration 5000
    .attr 'd', path
    .each 'end', -> toDots! if l is i++


🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.