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

              
                
              
            
!

CSS

              
                svg {
  background-color:#EEE;
}

path.link {
  fill: none;
  stroke: #ccc;
  stroke-width: 1.5px;
}
marker#end {
  fill:#ccc;
}

circle {
  fill: #9c9;
  stroke: #fff;
  stroke-width: 1.5px;
}

text {
  fill: #222;
  font: 10px sans-serif;
  pointer-events: none;
}
text.linkLabel {
  fill:#888;
}
.node text { 
  font-size:12px;
  fill:#000;
}
              
            
!

JS

              
                // http://www.d3noob.org/2013/03/d3js-force-directed-graph-example-basic.html
var width = 900,
    height = 700;

var nodes = [{"name":"Foothills (2331)", "x":width/2, "y":height/2},{"name":"Dark cave (2341)"},{"name":"Dark cave (2346)"},{"name":"Dark cave (2351)"},{"name":"Rope bridge (2356)"},{"name":"Falling through the air! (2361)"},{"name":"Moss cavern (2366)"},{"name":"Moss cavern (2376)"},{"name":"Passage (2381)"},{"name":"Twisty passages (2391)"},{"name":"Twisty passages (2396)"},{"name":"Twisty passages (2401)"},{"name":"Twisty passages (2406)"},{"name":"Twisty passages (2421)"},{"name":"Twisty passages (2436)"},{"name":"Twisty passages (2411)"},{"name":"Twisty passages (2416)"},{"name":"Twisty passages (2426)"},{"name":"Passage (2386)"},{"name":"Dark passage (2441)"},{"name":"Dark passage (2446)"},{"name":"Dark passage (2451)"},{"name":"Dark passage (2456)"},{"name":"Ruins (2461)"},{"name":"Ruins (2466)"},{"name":"Ruins (2471)"},{"name":"Ruins (2477)"},{"name":"Ruins (2482)"},{"name":"Ruins (2487)"},{"name":"Ruins (2492)"},{"name":"Ruins (2497)"},{"name":"Moss cavern (2371)"},{"name":"Foothills (2336)"}];

var links = [{"source":0,"target":1,"name":"doorway","strength":1},{"source":0,"target":32,"name":"south","strength":1},{"source":1,"target":2,"name":"north","strength":1},{"source":1,"target":0,"name":"south","strength":1},{"source":2,"target":3,"name":"north","strength":1},{"source":2,"target":1,"name":"south","strength":1},{"source":3,"target":4,"name":"bridge","strength":1},{"source":3,"target":1,"name":"south","strength":1},{"source":4,"target":5,"name":"continue","strength":1},{"source":4,"target":3,"name":"back","strength":1},{"source":5,"target":6,"name":"down","strength":1},{"source":6,"target":7,"name":"west","strength":1},{"source":6,"target":31,"name":"east","strength":1},{"source":7,"target":6,"name":"east","strength":1},{"source":7,"target":8,"name":"passage","strength":1},{"source":8,"target":7,"name":"cavern","strength":1},{"source":8,"target":9,"name":"ladder","strength":1},{"source":8,"target":18,"name":"darkness","strength":1},{"source":9,"target":8,"name":"ladder","strength":0.1},{"source":9,"target":10,"name":"north","strength":0.1},{"source":9,"target":11,"name":"south","strength":0.1},{"source":9,"target":12,"name":"east","strength":0.1},{"source":9,"target":15,"name":"west","strength":0.1},{"source":10,"target":11,"name":"north","strength":0.1},{"source":10,"target":9,"name":"south","strength":0.1},{"source":10,"target":10,"name":"west","strength":0.1},{"source":11,"target":9,"name":"north","strength":0.1},{"source":11,"target":10,"name":"south","strength":0.1},{"source":11,"target":11,"name":"east","strength":0.1},{"source":12,"target":13,"name":"north","strength":0.1},{"source":12,"target":12,"name":"south","strength":0.1},{"source":12,"target":9,"name":"west","strength":0.1},{"source":12,"target":14,"name":"east","strength":0.1},{"source":13,"target":11,"name":"north","strength":0.1},{"source":13,"target":10,"name":"east","strength":0.1},{"source":13,"target":13,"name":"south","strength":0.1},{"source":14,"target":10,"name":"north","strength":0.1},{"source":15,"target":15,"name":"north","strength":0.1},{"source":15,"target":16,"name":"south","strength":0.1},{"source":15,"target":9,"name":"east","strength":0.1},{"source":16,"target":17,"name":"north","strength":0.1},{"source":16,"target":10,"name":"south","strength":0.1},{"source":16,"target":11,"name":"west","strength":0.1},{"source":16,"target":14,"name":"east","strength":0.1},{"source":17,"target":9,"name":"west","strength":0.1},{"source":18,"target":19,"name":"continue","strength":1},{"source":18,"target":8,"name":"back","strength":1},{"source":19,"target":20,"name":"west","strength":1},{"source":19,"target":18,"name":"east","strength":1},{"source":20,"target":19,"name":"east","strength":1},{"source":20,"target":21,"name":"west","strength":1},{"source":21,"target":20,"name":"east","strength":1},{"source":21,"target":22,"name":"west","strength":1},{"source":22,"target":21,"name":"east","strength":1},{"source":22,"target":23,"name":"west","strength":1},{"source":23,"target":22,"name":"east","strength":1},{"source":23,"target":24,"name":"north","strength":1},{"source":24,"target":25,"name":"north","strength":1},{"source":24,"target":23,"name":"south","strength":1},{"source":25,"target":26,"name":"north","strength":1},{"source":25,"target":24,"name":"south","strength":1},{"source":25,"target":27,"name":"east","strength":1},{"source":25,"target":29,"name":"west","strength":1},{"source":26,"target":25,"name":"south","strength":1},{"source":27,"target":28,"name":"down","strength":1},{"source":27,"target":25,"name":"west","strength":1},{"source":28,"target":27,"name":"up","strength":1},{"source":29,"target":30,"name":"up","strength":1},{"source":29,"target":25,"name":"east","strength":1},{"source":30,"target":29,"name":"down","strength":1},{"source":31,"target":6,"name":"west","strength":1},{"source":32,"target":0,"name":"north","strength":1}];


links = links.filter(function(el) { return el.source !== el.target;});

var force = d3.layout.force()
    .nodes(nodes)
    .links(links)
    .size([width, height])
    .linkDistance(60)
    .charge(-400)
		.linkStrength(function(d) { return d.strength; });

force.start();
for (var i = 0; i < 200; ++i) force.tick(); // Get past the initial jitters of the system
force.on('tick', tick);


var svg = d3.select("body").append("svg")
    .attr("width", width)
    .attr("height", height);

// build the arrow.
svg.append("svg:defs").selectAll("marker")
    .data(["end"])
  .enter().append("svg:marker")
    .attr("id", String)
    .attr("viewBox", "0 -5 10 10")
    .attr("refX", 16)
    .attr("refY", -0.5)
    .attr("markerWidth", 6)
    .attr("markerHeight", 6)
    .attr("orient", "auto")
  .append("svg:path")
    .attr("d", "M0,-5L10,0L0,5");

// add the links and the arrows
// define the links
var path = svg.selectAll(".link")
    .data(force.links())
  .enter().append("svg:path")
    .attr("class", "link")
    .attr("marker-end", "url(#end)")
		.attr('id', function(d, i) {
      return 'link-'+i;
    });

var linkLabel = svg.selectAll('.linkLabel')
		.data(force.links())
	.enter().append('text')
		.attr('class', 'linkLabel')
		.attr('x', 8)
  	.attr('dy', -3)
		.attr('text-anchor', 'beginning')
		.append('textPath')
			.attr('xlink:href', function(d, i) {
  	  	return '#link-'+i;
		  })
  		.text(function(d) { return d.name; });


// define the nodes
var node = svg.selectAll(".node")
    .data(force.nodes())
  .enter().append("g")
    .attr("class", "node")
    .call(force.drag);

// add the nodes
node.append("circle")
    .attr("r", 5);

// add the text 
node.append("text")
    .attr('x', 12)
    .attr('dy', '.35em')
    .text(function(d) { return d.name; });

// add the curvy lines
function tick() {
    path.attr("d", function(d) {
        var dx = d.target.x - d.source.x,
            dy = d.target.y - d.source.y,
            dr = Math.sqrt(dx * dx + dy * dy)*1.3;
        return "M" + d.source.x + "," + d.source.y +
          	"A" + dr + "," + dr + " 0 0,1 " + 
            d.target.x + "," + d.target.y;
    });

    node
        .attr("transform", function(d) { 
            return "translate(" + d.x + "," + d.y + ")"; });
}

              
            
!
999px

Console