Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

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

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

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.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <div id='container'></div>
              
            
!

CSS

              
                @import url(https://fonts.googleapis.com/css?family=Lato);

html,body {
  margin: 0;
}

.tooltip {   
  font-family: 'Lato', 'Arial', sans-serif;
  position: absolute;           
  text-align: left;           
  width: auto;                  
  height: auto;                 
  padding: 20px;             
  font: 1em;
  background: hsla(0, 0%, 100%, .8);
  pointer-events: none;         
  box-shadow: 0 5px 10px hsla(0, 0%, 0%, .2);
  line-height: 1.5em;
}

.def {
  font-weight: 700;
}
              
            
!

JS

              
                // Initialization 
var width = '100%',
    height = '100%',
    sizeModifier = 50,
    hue = 0, colors = {},
    meteorites;

var projection = d3.geo.mercator()
  .translate([780,360])
  .scale(300);

var zoom = d3.behavior.zoom()
  .translate([0, 0])
  .scale(1)
  .scaleExtent([.5, 18])
  .on("zoom", zoomed);

var path = d3.geo.path()
  .projection(projection);

var svg = d3.select('#container')
  .append('svg')
  .attr('width', '100%')

// Set background color
svg.append('rect')
  .attr('width', width)
  .attr('height', height)
  .attr('fill', '#266D98')
  .call(zoom)


d3.select(window).on("resize", sizeChange);

// Tooltip
var div = d3.select('body').append('div')
  .attr('class', 'tooltip')
  .style('opacity', 0);

var map = svg.append('g');

// Map of earth
d3.json('https://d3js.org/world-50m.v1.json', function(json) {
  map.selectAll('path')
    .data(topojson.feature(json, json.objects.countries).features)
    .enter()
    .append('path')
    .attr('fill', '#95E1D3')
    .attr('stroke', '#266D98')
    .attr('d', path)
    //.call(zoom) // This is super jittery for some reason
});

// Data points
d3.json('https://data.nasa.gov/resource/y77d-th95.geojson', function(json) {

  json.features.sort(function(a,b) {
    return new Date(a.properties.year) - new Date(b.properties.year);
  })
  json.features.map(function(e) {
    hue+=.35;
    colors[e.properties.year] = hue;
    e.color = 'hsl(' + hue + ',100%, 50%)';
  })

  json.features.sort(function(a,b) {
    return b.properties.mass - a.properties.mass
  })

  meteorites = svg.append('g')
  .selectAll('path')
    .data(json.features)
    .enter()
      .append('circle')
      .attr('cx', function(d) { return projection([d.properties.reclong,d.properties.reclat])[0] })
      .attr('cy', function(d) { return projection([d.properties.reclong,d.properties.reclat])[1] })
      .attr('r', function(d) { 
        var range = 718750/2/2;
    
        if (d.properties.mass <= range) return 2;
        else if (d.properties.mass <= range*2) return 10;
        else if (d.properties.mass <= range*3) return 20;
        else if (d.properties.mass <= range*20) return 30;
        else if (d.properties.mass <= range*100) return 40;
        return 50;
      })
      .attr('fill-opacity', function(d) {
        var range = 718750/2/2;
        if (d.properties.mass <= range) return 1;
        return .5;
      })
      .attr('stroke-width', 1)
      .attr('stroke', '#EAFFD0')
      .attr('fill', function(d) { return d.color })
      .on('mouseover', function(d) {
        d3.select(this).attr('d', path).style('fill', 'black');
        // Show tooltip
        div.transition()
          .duration(200)
          .style('opacity', .9);
        div.html( '<span class="def">fall:</span> ' + d.properties.fall + '<br>' + 
                  '<span class="def">mass:</span> ' + d.properties.mass + '<br>' + 
                  '<span class="def">name:</span> ' + d.properties.name + '<br>' + 
                  '<span class="def">nametype:</span> ' + d.properties.nametype + '<br>' +
                  '<span class="def">recclass:</span> ' + d.properties.recclass + '<br>' + 
                  '<span class="def">reclat:</span> ' + d.properties.reclat + '<br>' + 
                  '<span class="def">year:</span> ' + d.properties.year + '<br>')
          .style('left', (d3.event.pageX+30) + 'px')
          .style('top', (d3.event.pageY/1.5) + 'px')
      })
      .on('mouseout', function(d) {
        // Reset color of dot
        d3.select(this).attr('d', path).style('fill', function(d) { return d.properties.hsl });

        // Fade out tooltip
        div.transition()
          .duration(500)
          .style('opacity', 0);
      });
  
  // Initialize map sizes
  sizeChange();
});

// Move and scale map and meteorites on interaction
function zoomed() {
  map.attr("transform", "translate(" + d3.event.translate + ")scale(" + d3.event.scale + ")");
  meteorites.attr('transform', 'translate(' + d3.event.translate + ')scale(' + d3.event.scale + ')');
}


// Resize map on window resize
function sizeChange() {
  d3.selectAll("g").attr("transform", "scale(" + $("#container").width()/1900 + ")");
  $("svg").height($("#container").width()/2);
}
              
            
!
999px

Console