Skip to content

Instantly share code, notes, and snippets.

@kwltrs
Forked from mbostock/.block
Last active March 22, 2018 14:21
Show Gist options
  • Save kwltrs/9daa1fefec1fefa0cf60d8d7ba24f0da to your computer and use it in GitHub Desktop.
Save kwltrs/9daa1fefec1fefa0cf60d8d7ba24f0da to your computer and use it in GitHub Desktop.
FFE Dependency Graph
license: mit
height: 800
[
{
"id": "@sb1/ffe-accordion-react",
"group": 3
},
{
"id": "@sb1/ffe-accordion",
"group": 2
},
{
"id": "@sb1/ffe-account-selector-react",
"group": 3
},
{
"id": "@sb1/ffe-buttons-react",
"group": 3
},
{
"id": "@sb1/ffe-buttons",
"group": 2
},
{
"id": "@sb1/ffe-cards-react",
"group": 3
},
{
"id": "@sb1/ffe-cards",
"group": 2
},
{
"id": "@sb1/ffe-chart-donut-react",
"group": 3
},
{
"id": "@sb1/ffe-checkbox-react",
"group": 3
},
{
"id": "@sb1/ffe-context-message-react",
"group": 3
},
{
"id": "@sb1/ffe-context-message",
"group": 2
},
{
"id": "@sb1/ffe-core-react",
"group": 3
},
{
"id": "@sb1/ffe-core",
"group": 2
},
{
"id": "@sb1/ffe-datepicker-react",
"group": 3
},
{
"id": "@sb1/ffe-datepicker",
"group": 2
},
{
"id": "@sb1/ffe-decorators-react",
"group": 3
},
{
"id": "@sb1/ffe-details-list-react",
"group": 3
},
{
"id": "@sb1/ffe-details-list",
"group": 2
},
{
"id": "@sb1/ffe-dropdown-react",
"group": 3
},
{
"id": "@sb1/ffe-file-upload-react",
"group": 3
},
{
"id": "@sb1/ffe-form-react",
"group": 3
},
{
"id": "@sb1/ffe-form",
"group": 2
},
{
"id": "@sb1/ffe-formatters",
"group": 2
},
{
"id": "@sb1/ffe-grid-react",
"group": 3
},
{
"id": "@sb1/ffe-grid",
"group": 2
},
{
"id": "@sb1/ffe-header",
"group": 2
},
{
"id": "@sb1/ffe-icons-react",
"group": 3
},
{
"id": "@sb1/ffe-icons",
"group": 2
},
{
"id": "@sb1/ffe-lists-react",
"group": 3
},
{
"id": "@sb1/ffe-lists",
"group": 2
},
{
"id": "@sb1/ffe-message-box-react",
"group": 3
},
{
"id": "@sb1/ffe-message-box",
"group": 2
},
{
"id": "@sb1/ffe-radio-button-react",
"group": 3
},
{
"id": "@sb1/ffe-searchable-dropdown-react",
"group": 3
},
{
"id": "@sb1/ffe-spinner-react",
"group": 3
},
{
"id": "@sb1/ffe-spinner",
"group": 2
},
{
"id": "@sb1/ffe-system-message-react",
"group": 3
},
{
"id": "@sb1/ffe-system-message",
"group": 2
},
{
"id": "@sb1/ffe-tables-react",
"group": 3
},
{
"id": "@sb1/ffe-tables",
"group": 2
},
{
"id": "@sb1/ffe-tabs-react",
"group": 3
},
{
"id": "@sb1/ffe-tabs",
"group": 2
},
{
"id": "@sb1/ffe-webfonts",
"group": 2
},
{
"id": "@sb1/eslint-config-ffe-base",
"group": 1
},
{
"id": "@sb1/eslint-config-ffe",
"group": 1
},
{
"id": "@sb1/stylelint-config-ffe",
"group": 1
}
]
<!DOCTYPE html>
<meta charset="utf-8">
<style>
.links line {
stroke: #999;
stroke-opacity: 0.6;
}
.nodes circle {
stroke: #fff;
stroke-width: 1.5px;
}
</style>
<svg width="960" height="600"></svg>
<script src="https://d3js.org/d3.v4.min.js"></script>
<script>
var svg = d3.select("svg"),
width = +svg.attr("width"),
height = +svg.attr("height");
var color = d3.scaleOrdinal(d3.schemeCategory20);
var simulation = d3.forceSimulation()
.force("link", d3.forceLink().id(function(d) { return d.id; }))
.force("charge", d3.forceManyBody())
.force("center", d3.forceCenter(width / 2, height / 2));
d3.json("data.json", function(error, graph) {
if (error) throw error;
var link = svg.append("g")
.attr("class", "links")
.selectAll("line")
.data(graph.links)
.enter().append("line")
.attr("stroke-width", function(d) { return Math.sqrt(d.value); });
var node = svg.append("g")
.attr("class", "nodes")
.selectAll("circle")
.data(graph.nodes)
.enter().append("circle")
.attr("r", 5)
.attr("fill", function(d) { return color(d.group); })
.call(d3.drag()
.on("start", dragstarted)
.on("drag", dragged)
.on("end", dragended));
node.append("title")
.text(function(d) { return d.id; });
simulation
.nodes(graph.nodes)
.on("tick", ticked);
simulation.force("link")
.links(graph.links);
function ticked() {
link
.attr("x1", function(d) { return d.source.x; })
.attr("y1", function(d) { return d.source.y; })
.attr("x2", function(d) { return d.target.x; })
.attr("y2", function(d) { return d.target.y; });
node
.attr("cx", function(d) { return d.x; })
.attr("cy", function(d) { return d.y; });
}
});
function dragstarted(d) {
if (!d3.event.active) simulation.alphaTarget(0.3).restart();
d.fx = d.x;
d.fy = d.y;
}
function dragged(d) {
d.fx = d3.event.x;
d.fy = d3.event.y;
}
function dragended(d) {
if (!d3.event.active) simulation.alphaTarget(0);
d.fx = null;
d.fy = null;
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment