Pen Settings

HTML

CSS

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. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ 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

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.

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

              
                
<!-- <svg width="960" height="960"></svg> -->

<div class="worldmap" align="center"></div>
              
            
!

CSS

              
                .stroke {
  fill: none;
  stroke: #000;
  stroke-width: 3px;
}

.fill {
  fill: #fff;
}

.graticule {
  fill: none;
  stroke: #777;
  stroke-width: 0.5px;
  stroke-opacity: 0.5;
}

.land {
  fill: #222;                   /* Set colors for land - default #222 */
}

.boundary {
  fill: none;
  stroke: #fff;
  stroke-width: 0.5px;
}

.tooltip {
  position: absolute;
  padding: 2px;	
  pointer-events: none;
}

div.tooltip {	
    width: 250px;					
    padding: 10px;				
    font: 12px sans-serif;		
    background: lightsteelblue;	
    border: 0px;		
    border-radius: 8px;			
    pointer-events: none;			
}

.m_circle:hover {
    fill:	#181818;
}
              
            
!

JS

              
                var dataUrl = 'https://raw.githubusercontent.com/FreeCodeCamp/ProjectReferenceData/master/meteorite-strike-data.json';

var margin = {top: 20, right: 20, bottom: 40, left: 80},
    // width = 1200 - margin.left - margin.right,
    // height = 900 - margin.top - margin.bottom;
    width = 1400,
    height = 1200 - margin.top - margin.bottom;

// var fisheye = d3.fisheye.circular()
//     .radius(200)
//     .distortion(2);
var fisheye = d3.fisheye();

d3.json(dataUrl, function(error, data) {
  // var nodeArr = data['features'].map(function(d) {
  //   // console.log(d)
  //   return {x: d.geometry?projection(d.geometry.coordinates)[0]:null, y: d.geometry?projection(d.geometry.coordinates)[1]:null};
  // })
  // console.log(nodeArr)
  
  // Sort removing largest paths like Sikhote-Alin, 
  // var massSorted = data.features.sort(function(a,b) {
  //   // if (b.properties.mass != null && a.properties.mass != null) {
  //     return b.properties.mass - a.properties.mass
  //   // }
  // })
  
 // Returns meteor sizes
  // var meteorMass = data.features.map(function(item) {
  var meteorMass = data.features.map(function(item) {
      // console.log(item.properties)
      if (item.properties.mass != null)
        return parseFloat(item.properties.mass);
        // return item.properties.mass;
      else
        return 0
    });
    
    console.log(meteorMass)
  
  // console.log(meteorMass)
  var maxSize = d3.max(meteorMass, function (d) { return d; });
  var minSize = d3.min(meteorMass, function (d) { return d; });
  
  // console.log(maxSize)
  var colors = ["#5e4fa2","#3288bd","#66c2a5","#abdda4","#e6f598","#ffffbf","#fee08b","#fdae61","#f46d43", "#d53e4f", "#9e0142"];
  var sizeScale = d3.scaleSqrt().domain([minSize, maxSize]).range([2, 30]);
  var colorScale = d3.scaleOrdinal().domain([minSize, maxSize]).range(colors);

// var svg = d3.select("svg"),
//     width = +svg.attr("width"),
//     height = +svg.attr("height");
  
  var svg = d3.select(".worldmap")
        .append("svg")
        .attr("width", width + margin.left + margin.right + (width / 4))
        .attr("height", height + margin.top + margin.bottom + (height / 2))
        .append("g")
          .attr("transform", "translate(" + margin.left * 2 + "," + (margin.top * 10) + ")");
  
  // svg.on("mousemove", function() {
  //     console.log('fishy')
  //     fisheye.focus(d3.mouse(this));
  //   });
  
var tooltip = d3.select(".worldmap").append("div")
    .attr("class", "tooltip")
    .style("opacity", 0);
// console.log((width * 1.25) / (2 * Math.PI))
var projection = d3.geoMercator()
    // .scale((width - 3) / (2 * Math.PI))
    .scale((width * 1.20) / (2 * Math.PI))
    .translate([width / 2, height / 2]);
  
  var path = d3.geoPath()
    .projection(projection);
  
  var meteorPath = d3.geoPath()
    .projection(projection)
    .pointRadius(d => { 
      return sizeScale(d.properties.mass) })

var graticule = d3.geoGraticule();
  
  // Boundary around map - comment to remove
  // svg.append("defs").append("path")
  //     .datum({type: "Sphere"})
  //     .attr("id", "sphere")
  //     .attr("d", path);

  svg.append("use")
      .attr("class", "stroke")
      .attr("xlink:href", "#sphere");

  svg.append("use")
      .attr("class", "fill")
      .attr("xlink:href", "#sphere");

  // Grid over the map - comment to remove
  // svg.append("path")
  //     .datum(graticule)
  //     .attr("class", "graticule")
  //     .attr("d", path);

  d3.json("https://unpkg.com/world-atlas@1/world/50m.json", function(error, world) {
    if (error) throw error;

    svg.insert("path", ".graticule")
        .datum(topojson.feature(world, world.objects.land))
        .attr("class", "land")
        .attr("d", path)

    // Displays country lines
    svg.insert("path", ".graticule")
        .datum(topojson.mesh(world, world.objects.countries, function(a, b) { return a !== b; }))
        .attr("class", "boundary")
        .attr("d", path)

    // Displays meteor landings
    // var meteors = svg.append('g');
    
    // var node = svg.append("g")
    //   // .selectAll('path')
    //   .attr("class", "nodes")
    //   // .selectAll("circle")
    //   .data(data.features)
    //   .attr("d", path)
    //   .enter().append("circle")
    //   .attr("r", 5)

    // meteors.selectAll('path')
      // .data(data.features)
      // // .data(data.features, function(d) {
      // //     // console.log(d)  
      // // })
      // .enter()
      // .append('path')
      // .attr('fill', '#900')
      // .attr("cursor", "pointer")
      // .attr('stroke', '#999')
      // .attr('d', meteorPath)
      // .style("opacity", 0.7)      
      // .attr("fill", d => { 
      //   return colorScale(d.properties.mass) })
    
      var meteors = svg.selectAll('path')
        .data(data.features)
        .enter()
        .append('g')
      
      meteors.append('path')
        .attr('d', meteorPath)
        .attr('vector-effect', 'non-scaling-stroke')
        .attr('pointer-events', 'stroke')
        .attr('stroke-width', 1)
        .attr("fill", d => { 
          return colorScale(d.properties.mass) })
        .style("opacity", 0.1) 
        // .attr("r", 1)
        .attr('r', d => { 
          // console.log(sizeScale(d.properties.mass))
          if (d.properties.mass != null) {      
            return sizeScale(d.properties.mass) 
          }
          else {
            return sizeScale(minSize)
          }
          })
    
      meteors.append('circle')
        .attr("class", "m_circle")
        .style("opacity", 0.7)  
        .attr('stroke', '#999')
        .attr('stroke-width', 1)
        .attr('pointer-events', 'stroke')
        .attr("cursor", "pointer")
        // .attr('cx', function(d) { 
        //   if (d.geometry != null) {
        //     return projection(d.geometry.coordinates)[0];
        //   }
        //   else {
        //     return 0;
        //   }
        // })
        // .attr('cy', function(d) { 
        //   if (d.geometry != null) {
        //       return projection(d.geometry.coordinates)[1];
        //     }
        //     else {
        //       return 0;
        //     }
        // })
        .attr("id", function(d){ 
          return d.properties.id; 
        })
        .attr("transform", function(d) { 
          if (d.geometry != null) {
            // console.log(projection(d.geometry.coordinates))
            return "translate(" + projection(d.geometry.coordinates) + ")";
          }
          else {
            return "translate(0, 0)"
          }
        })
        .attr('r', d => { 
          // console.log(sizeScale(d.properties.mass))
          if (d.properties.mass != null) {      
            return sizeScale(d.properties.mass) 
          }
          else {
            return sizeScale(minSize)
          }
          })
          // return 1 })
        .attr("fill", d => { 
          return colorScale(d.properties.mass) })
    
      .on("mouseover", function(d) {
                tooltip.transition()
                  .duration(200)
                  .style("opacity", 1);
                tooltip.html("Meteor Name: <b>" + d.properties.name + "</b><br/>Status: <b>" + d.properties.fall + "</b><br/>Mass: <b>" + d.properties.mass + "</b><br/>Date: <b>" + d.properties.year.slice(0, 10) + "</b><br/>Class: <b>" + d.properties.recclass + "</b>")
                  .style("stroke", "#000")
                  .style("left", (d3.event.pageX + 10) + "px")
                 .style("top", (d3.event.pageY + 10) + "px")
              })
        .on("mouseout", function(d) {
          tooltip.transition()
            .duration(500)
            .style("opacity", 0);
        });
    // Start: Code to add fisheye behavior
     var line = d3.line(); 
    svg.on("mousemove", function() {
      // Custom implementation v1
      // fisheye.center(d3.mouse(this));
      // var xy_coords = {"x": d3.event.x, "y": d3.event.y}
      // console.log({"x": d3.event.x, "y": d3.event.y});
      // fisheye.focus(d3.mouse(this)); 
      // graticule.each(function(d) { 
      // d.fisheye = fisheye(d); })
      //   .attr("cx", function(d) { return d.fisheye.x; })
      //   .attr("cy", function(d) { return d.fisheye.y; })
      //   .attr("r", function(d) { return d.fisheye.z * 4.5; });
      // meteors.attr("d", function(d) { 
      //   console.log(d)
      // return meteorPath(d.map(fisheye)); });
      
      // Custom implementation v2
      // fisheye.focus(d3.mouse(this));
      // // console.log(node)
      // node.each(function(d) { 
      //   // console.log(d);
      //   d.fisheye = fisheye(d);
      // })
      //   .attr("cx", function(d) { 
      //     console.log(d.fisheye.x + ' and ' + d.fisheye.y)
      //     return d.fisheye.x; })
      //   .attr("cy", function(d) { return d.fisheye.y; })
      //   .attr("r", function(d) { return d.fisheye.z * 4.5; });
      
      // Custom implementation v3
      // // fisheye.focus(d3.mouse(this));
      // fisheye.focus(d3.mouse(this));
      // // console.log(meteors)
      // // console.log(nodeArr)
      // node.each(function(d) {
      //   // if (d.geometry != null) {
      //   //   console.log(projection(d.geometry.coordinates))
      //   //   d.fisheye = fisheye(projection(d.geometry.coordinates));
      //   //   console.log(d.fisheye)
      //   // }
      //   console.log(d)
      //   d.fisheye = fisheye(d)
      //   // console.log(d.fisheye)
      // })
      //   // .attr("cx", function(d) { return d.fisheye.x; })
      //   .attr('cx', function(d) { 
      //     if (d.geometry != null) {
      //       // console.log(d.fisheye[projection(d.geometry.coordinates)[0]])
      //       return d.fisheye[projection(d.geometry.coordinates)[0]];
      //     }
      //     else {
      //       return 0;
      //     }
      //   })
      //   // .attr("cy", function(d) { return d.fisheye.y; })
      //   .attr('cy', function(d) { 
      //     // console.log(d.geometry.coordinates[0])
      //     // return d.x; })
      //     if (d.geometry != null) {
      //       return d.fisheye[projection(d.geometry.coordinates)[1]];
      //     }
      //     else {
      //       return 0;
      //     }
      //   })
      //   // .attr("r", function(d) { return d.fisheye.z * 4.5; });
      //   .attr("r", function(d) { return 4.5; });
      
      // Custom Implementation v4
      // fisheye.center(d3.mouse(this));
      // meteors.attr("d", function(d) { 
      //   // console.log(d)
      //   // console.log(projection(d.geometry.coordinates))
      //   // console.log(line(projection(d.geometry.coordinates).map(fisheye)))
      //   return d.geometry?line(d.geometry.coordinates.map(fisheye)):null });
    });
    // End: Code to add fisheye behavior
    
    // Start: Code for zoom
    
    // Zoom implementation from: http://bl.ocks.org/shimizu/bf7f84066d10c71bd61d716500b26a31
    var zoomed = function() {
      svg.attr("transform", d3.event.transform);
    }
    
    svg.call(d3.zoom()
      .scaleExtent([1 / 2, 12])
      .on("zoom", zoomed));	
    
    // End: Code for zoom
  });
  
});


              
            
!
999px

Console