Published
Edited
Jun 14, 2019
Importers
Insert cell
Insert cell
Insert cell
constraintGraph = ({
"domains": [
{"id": "d1", "value": [0,1]}
],
"constraints": [
{"id": "c1", "value": [[1,2],[2,0]]}
],
"nodes": [
{"id": "x1", "domain": "d1"},
{"id": "x2", "domain": "d1"},
{"id": "x3", "domain": "d1"},
{"id": "x4", "domain": "d1"}
],
"edges": [
{"source": "x1", "target": "x2", "constraint": "c1"},
{"source": "x2", "target": "x3", "constraint": "c1"},
{"source": "x1", "target": "x3", "constraint": "c1"},
{"source": "x2", "target": "x4", "constraint": "c1"}
]
})
Insert cell
data = {
return{
"nodes": constraintGraph.nodes, "links": constraintGraph.edges
}
}
Insert cell
height = 150
Insert cell
width = 200
Insert cell
color = {
const scale = d3.scaleOrdinal(d3.schemeCategory10);
return d => scale(d.group);
}
Insert cell
drag = simulation => {
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;
}
return d3.drag()
.on("start", dragstarted)
.on("drag", dragged)
.on("end", dragended);
}
Insert cell
d3 = require("d3@5")
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more