cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

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.

Quick-add: + add another resource

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.

Quick-add: + add another resource

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.

            
              <body>
   <svg></svg>
   <script src="https://d3js.org/d3.v3.min.js"></script> 
   <script src="https://d3js.org/topojson.v1.min.js"></script>
   <script src="https://polyshrink.s3.amazonaws.com/texas.js"></script>
</body>
            
          
!
            
              svg,body {
   background-color: black;
   margin:0px;
   position:absolute;
   height:100%;
   width:100%;
   overflow:hidden;
}
path.state {
   stroke: #ffffff;
   stroke-width: 2px;
   fill: #ffffff;
   fill-opacity: 0.2;
}

circle.centroid {
  fill: blue;
}
circle.node {
  fill: blue;
}
circle.new-node {
  fill: red;
}
path.spline {
  stroke: white;
  stroke-width: 0.3px;
}
            
          
!
            
              var pageHeight = window.innerHeight; // Grab the page height.
var pageWidth = window.innerWidth; // Grab the page width.

/*
 * The projection
 */
var proj = new d3.geo.mercator().
   center([-100.084,30.8885]).  // Centre over Prince George
   translate([(pageWidth/2),pageHeight/2]). // Centre in window.
   scale(1 << 11); // zoom level ten shows the whole province

/*
 * The path generator. Insert the projection
 */
var path = d3.geo.path().
   projection(proj);

var svg = d3.select("svg"); 

/*
 * Convert the topojson object to geojson
 */
var texasData = topojson.
  feature(texasBnd,texasBnd.objects.texas_exploded).
  features;

/*
 * Insert the path 
 */
var texas = svg.selectAll("path.state").
   data(texasData).
   enter().append("path").
   attr("id","texas").
   attr("class","state").
   attr("d",path);

var state = path(texasData[0]);
var centroid = path.centroid(texasData[0]);

/*
 * Create array of nodes
 */
var nodes = path(texasData[0]).
   slice(1,-1). // Remove start and end marks
   split(/L/). // Split the nodes
   map(function(d,i) {
      return d.split(/,/). // split x and y
         map(function(d) { // Convert to integers.
            return parseInt(d,10);
         });
   });

/*
 * Add nodes just so we can see them
 */
svg.selectAll("circle.node1").
   data(nodes).
   enter().append("circle").
   attr("class","node").
   attr("cx",function(d) {
      return d[0];
   }).
   attr("cy",function(d) {
      return d[1];
   }).
   attr("r",2);

/*
 * The lines connecting the nodes to the centroid
 */
var splines = svg.selectAll("path.spline").
   data(nodes).
   enter().append("path").
   attr("class","spline").
   attr("d",function(d) {
      return "M "+centroid[0]+" "+centroid[1]+" L "+d[0]+" "+d[1];
   });

/*
 * Here's the centroid
 */
svg.append("circle").
   attr("class","centroid").
   attr("cx",centroid[0]).
   attr("cy",centroid[1]).
   attr("r",2);
/*
 * Now draw the nodes at a radius from the centroid
 */
svg.selectAll(".spline")[0].forEach(function(d,i){
   var point = d.getPointAtLength(10);
   svg.
      append("circle").
      attr("class","new-node").
      attr("cx", point.x).
      attr("cy", point.y).
      attr("r",2);
});
            
          
!
999px
Loading ..................

Console