Skip to content

Instantly share code, notes, and snippets.

@dmann99
Created April 19, 2014 20:12
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dmann99/11096043 to your computer and use it in GitHub Desktop.
Save dmann99/11096043 to your computer and use it in GitHub Desktop.
Pop-Up Schemio 3d
{"description":"Pop-Up Schemio 3d","endpoint":"","display":"svg","public":true,"require":[],"fileconfigs":{"inlet.js":{"default":true,"vim":false,"emacs":false,"fontSize":12},"style.css":{"default":true,"vim":false,"emacs":false,"fontSize":12},"_.md":{"default":true,"vim":false,"emacs":false,"fontSize":12},"config.json":{"default":true,"vim":false,"emacs":false,"fontSize":12},"links.json":{"default":true,"vim":false,"emacs":false,"fontSize":12},"evol.json":{"default":true,"vim":false,"emacs":false,"fontSize":12}},"fullscreen":false,"play":false,"loop":false,"restart":false,"autoinit":true,"pause":true,"loop_type":"pingpong","bv":false,"nclones":15,"clone_opacity":0.4,"duration":3000,"ease":"linear","dt":0.01,"ajax-caching":true,"thumbnail":"http://i.imgur.com/OtytzLU.png"}
[
{"source": "COUNTRIES", "target": "REGIONS"},
{"source": "DEPARTMENTS", "target": "LOCATIONS"},
{"source": "EMPLOYEES", "target": "DEPARTMENTS"},
{"source": "EMPLOYEES", "target": "JOBS"},
{"source": "JOB_HISTORY", "target": "DEPARTMENTS"},
{"source": "JOB_HISTORY", "target": "EMPLOYEES"},
{"source": "JOB_HISTORY", "target": "JOBS"},
{"source": "LOCATIONS", "target": "COUNTRIES"}
]
// David Mann || @ba6dotus || http://ba6.us
// https://gist.github.com/dmann99/c4c197da8adb996323e6
// Modifying a force layout
// http://bl.ocks.org/mbostock/1095795
// v1 - Build basic force diagram
// v2 - Enhance the node graphic
// v3 - Add dynamic build-in behavior
// Todo:
// Anaglyphic 3d? : http://threejs.org/examples/#webgl_effects_anaglyph
// http://www.w3schools.com/css/tryit.asp?filename=trycss_text-shadow
// Data from http://www.oracle.com/technetwork/developer-tools/datamodeler/sample-models-scripts-224531.html
var links = tributary.evol;
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});
});
var width = 800,
height = 600;
var force = d3.layout.force()
.nodes(d3.values(nodes))
.links(links)
.size([width, height])
.linkDistance(226)
.charge(-1546)
.on("tick", tick)
.start();
var svg = d3.select("svg")
.attr("width", width)
.attr("height", height);
var link = svg.selectAll(".link")
.data(force.links())
.enter().append("line")
.attr("class", "link");
var node = svg.selectAll(".node")
.data(force.nodes())
.enter().append("g")
.attr("class", "node")
// .on("mouseover", mouseover)
// .on("mouseout", mouseout)
.call(force.drag);
node.append("rect")
.attr("x",-65)
.attr("y",-10)
.attr("width", 130)
.attr("height",20);
node.append("rect")
.attr("class","shadow")
.attr("x",-60)
.attr("y",-10)
.attr("width", 130)
.attr("height",20);
node.append("text")
.attr("class","tablename")
.attr("x", -55)
.attr("dy", "4px")
.attr("font-weight","bold")
.text(function(d) { return d.name; });
node.append("rect")
.attr("x",-65)
.attr("y",10)
.attr("width",130)
.attr("height",55);
node.append("rect")
.attr("class","shadow")
.attr("x",-60)
.attr("y",10)
.attr("width",130)
.attr("height",55);
// Field Names
// For Positioning Only - Temporary mock-up of some field names, hook this up later
node.append("text")
.attr("class","columnname")
.attr("style","color: red;")
.attr("x", -55)
.attr("y",20)
.attr("dy", "4px")
.text(function(d) { return d.name+'_ID'; });
node.append("text")
.attr("class","columnname")
.attr("x", -55)
.attr("y",35)
.attr("dy", "4px")
.text(function(d) { return d.name+'_NAME'; });
node.append("text")
.attr("class","columnname")
.attr("x", -55)
.attr("y",50)
.attr("dy", "4px")
.text(function(d) { return 'CREATED_DATE'; });
function tick() {
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("transform", function(d) { return "translate(" + d.x + "," + d.y + ")"; });
}
function mouseover() {
d3.select(this).select("circle").transition()
.duration(750)
.attr("r", 20);
}
function mouseout() {
d3.select(this).select("circle").transition()
.duration(750)
.attr("r", 8);
}
// References:
// Labeled Force Layout - http://bl.ocks.org/mbostock/950642
setTimeout(function() {
// var a = nodes[0], b = {id: "b"}, c = nodes[1];
// nodes.push(b);
// links.push({source: a, target: b}, {source: b, target: c});
// start();
console.log("test");
force.start();
}, 3000);
.link {
fill: none;
stroke: red;
stroke-width: 2.0px;
}
.node rect {
fill: white;
stroke: #ff0000;
stroke-width: 2.0px;
opacity : 1;
}
rect.shadow {
fill : white;
stroke : #00ffff;
stroke-width: 2px;
opacity : 0.5;
}
//text {
// font: 11px sans-serif;
//}
.columnname {
font: 11px sans-serif;
color: #ff0000;
}
.tablename {
font: 14px sans-serif;
font-weight: bold;
color: #00ffff;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment