JSFiddle - React, Tailwind, and code Playground

by ninachroscicka

HTML

<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.14/d3.js"></script>

CSS

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


.link {
    stroke: #E5E8E8;
    opacity: 1;
    stroke-width: 2.5px;

}
.node circle {
    stroke: #fff;
    opacity: 1;
    stroke-width: 1.5px;
}
text {
    font: 14px 'Raleway', 'Helvetica Neue, Helvetica';
    opacity: 1;
    pointer-events: none;
}

JavaScript

var links = [{"source":"so","target":"who"},{"source":"be","target":"who"},{"source":"but","target":"who"},{"source":"has","target":"who"},{"source":"up","target":"be"},{"source":"not","target":"be"},{"source":"duży","target":"firma"},{"source":"chemiczny","target":"firma"},{"source":"człowiek","target":"roślina"},{"source":"nasienie","target":"roślina"},{"source":"człowiek","target":"genetycznie"},{"source":"żywność","target":"genetycznie"},{"source":"człowiek","target":"chemiczny"},{"source":"żywność","target":"chemiczny"},{"source":"człowiek","target":"duży"},{"source":"świat","target":"duży"},{"source":"człowiek","target":"firma"}];
var nodes = {}

// Compute the distinct nodes from the links.
links.forEach(function (link) {
    link.source = nodes[link.source] || (nodes[link.source] = {
        name: link.source
    });
    link.target = nodes[link.target] || (nodes[link.target] = {
        name: link.target
    });
    link.value = +link.value;
});

var width = 880
height = 870;

var force = d3.layout.force()
    .nodes(d3.values(nodes))
    .links(links)
    .size([width, height])
    .linkDistance(140)
    .charge(-700)
    .on("tick", tick)
    .start();

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

var link = svg.selectAll(".link")
    .data(force.links())
    .enter().append("line")
    .attr("class", "link")
    .attr('stroke-width', function (d,i) {
    							return d.value;
	       });

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

node.append("circle")
    .attr("r", 38)
    .style("fill", '#4b86b4');

node.append('text')
            .text(function(d){ return d.name; })
            .attr('font-family', 'Raleway', 'Helvetica Neue, Helvetica')
            .style("fill", "#dddddd")
            .attr('text-anchor', function(d, i) {
                  return 'middle';
            })


function tick() {
   ...