Created
June 10, 2019 16:46
-
-
Save theordorang/35ea5564b9e786af6a89a898ffe50a56 to your computer and use it in GitHub Desktop.
Network of Ser. Sulpicius Camerinus Cornutus - Simple with Children, Spouse and Adopted Children
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<meta charset="utf-8"> | |
<style> | |
.d3-tip { | |
line-height: 1; | |
font-weight: bold; | |
padding: 12px; | |
background: rgba(0, 0, 0, 0.8); | |
color: #fff; | |
border-radius: 2px; | |
} | |
/* Creates a small triangle extender for the tooltip */ | |
.d3-tip:after { | |
box-sizing: border-box; | |
display: inline; | |
font-size: 10px; | |
width: 100%; | |
line-height: 1; | |
color: rgba(0, 0, 0, 0.8); | |
content: "\25BC"; | |
position: absolute; | |
text-align: center; | |
} | |
/* Style northward tooltips differently */ | |
.d3-tip.n:after { | |
margin: -1px 0 0 0; | |
top: 100%; | |
left: 0; | |
} | |
</style> | |
<svg width="960" height="600"></svg> | |
<script src="https://d3js.org/d3.v4.min.js"></script> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3-tip/0.7.1/d3-tip.min.js"></script> | |
<script> | |
//Data goes here (format is JSON). Nodes are people, links are relationship connections | |
var nodes = [ | |
{ id: 23, group: 0, name: "SULP0023 Ser. Sulpicius (35) P. f. - n. Camerinus Cornutus", birth: -550, death: -463}, | |
{ id: 4930, group: 0, name: "SULP4930 P. Sulpicius (not in RE)", birth: -600, death: -475}, | |
{ id: 55, group: 0, name: "SULP0055 Q. Sulpicius (33) Camerinus Cornutus", birth: -525, death: -425}, | |
{ id: 138, group: 0, name: "SULP0138 Ser. (or P.) Sulpicius (36) - f. Ser. n. Camerinus Cornutus", birth: -500, death: -375}, | |
{ id: 344, group: 0, name: "SULP0344 Q. Sulpicius (34) Ser. f. Ser. n. Camerinus Cornutus", birth: -450, death: -325}, | |
{ id: 4936, group: 0, name: "SULP4936 Ser. Sulpicius (not in RE) Camerinus Cornutus", birth: -475, death: -375}, | |
{ id: 246, group: 0, name: "SULP0246 Q. Sulpicius (37) Ser. ? f. - n. Camerinus Praetextatus", birth: -475, death: -375}, | |
{ id: 388, group: 0, name: "SULP0388 Ser. Sulpicius (31 cf. 94) Q. f. Ser. n. Camerinus Rufus", birth: -425, death: -325}, | |
{ id: 465, group: 0, name: "SULP0465 Ser. Sulpicius (88) Praetextatus Praetextatus", birth: -425, death: -300}, | |
{ id: 525, group: 0, name: "SULP0525 Ser. Sulpicius (38) Camerinus Rufus", birth: -400, death: -275}, | |
{ id: 4980, group: 0, name: "SULP4980 M. Sulpicius (not in RE)", birth: -450, death: -350}, | |
{ id: 445, group: 0, name: "SULP0445 C. Sulpicius (83) M. f. Q. n. Peticus", birth: -425, death: -300}, | |
{ id: 401, group: 0, name: "SULP0401 Q. Sulpicius (76) Longus", birth: -425, death: -325}, | |
{ id: 4965, group: 0, name: "SULP4965 Ser. Sulpicius (not in RE)", birth: -400, death: -300}, | |
{ id: 541, group: 0, name: "SULP0541 C. Sulpicius (75) Ser. f. Q. n. Longus", birth: -375, death: -250}] | |
var links = [ | |
{ target: 138, source: 4936}, | |
{ target: 246, source: 4980}, | |
{ target: 344, source: 4936}, | |
{ target: 401, source: 4965}, | |
{ target: 23, source: 138}, | |
{ target: 401, source: 541}, | |
{ target: 445, source: 4980}, | |
{ target: 246, source: 401}, | |
{ target: 388, source: 465}, | |
{ target: 55, source: 4930}, | |
{ target: 23, source: 4930}, | |
{ target: 138, source: 344}, | |
{ target: 246, source: 388}, | |
{ target: 465, source: 525}, | |
{ target: 138, source: 246}, | |
{ target: 541, source: 4965}] | |
//Tooltip code. Add birth and death info here. | |
var tip = d3.tip() | |
.attr('class', 'd3-tip') | |
.offset([-10, 0]) | |
.html(function(d) { | |
return "<span style='color:red'>" + d.name + "</span><br><strong>Group:</strong> <span style='color:red'>" + d.group + "</span><br><strong>ID:</strong> <span style='color:red'>" + d.id + "</span><br><strong>Born:</strong> <span style='color:red'>" + d.birth + "</span> <strong>Died:</strong> <span style='color:red'>" + d.death + "</span>"; | |
}) | |
var d3_category437 = [ | |
0xd3fe14, 0xfec7f8, 0x0b7b3e, 0x0bf0e9, 0xc203c8, 0xfd9b39, 0x888593, | |
0x906407, 0x98ba7f, 0xfe6794, 0x10b0ff, 0xac7bff, 0xfee7c0, 0x964c63, | |
0x1da49c, 0x0ad811, 0xbbd9fd, 0xfe6cfe, 0x297192, 0xd1a09c, 0x78579e, | |
0x81ffad, 0x739400, 0xca6949, 0xd9bf01, 0x646a58, 0xd5097e, 0xbb73a9, | |
0xccf6e9, 0x9cb4b6, 0xb6a7d4, 0x9e8c62, 0x6e83c8, 0x01af64, 0xa71afd, | |
0xcfe589, 0xd4ccd1, 0xfd4109, 0xbf8f0e, 0x2f786e, 0x4ed1a5, 0xd8bb7d, | |
0xa54509, 0x6a9276, 0xa4777a, 0xfc12c9, 0x606f15, 0x3cc4d9, 0xf31c4e, | |
0x73616f, 0xf097c6, 0xfc8772, 0x92a6fe, 0x875b44, 0x699ab3, 0x94bc19, | |
0x7d5bf0, 0xd24dfe, 0xc85b74, 0x68ff57, 0xb62347, 0x994b91, 0x646b8c, | |
0x977ab4, 0xd694fd, 0xc4d5b5, 0xfdc4bd, 0x1cae05, 0x7bd972, 0xe9700a, | |
0xd08f5d, 0x8bb9e1, 0xfde945, 0xa29d98, 0x1682fb, 0x9ad9e0, 0xd6cafe, | |
0x8d8328, 0xb091a7, 0x647579, 0x1f8d11, 0xe7eafd, 0xb9660b, 0xa4a644, | |
0xfec24c, 0xb1168c, 0x188cc1, 0x7ab297, 0x4468ae, 0xc949a6, 0xd48295, | |
0xeb6dc2, 0xd5b0cb, 0xff9ffb, 0xfdb082, 0xaf4d44, 0xa759c4, 0xa9e03a, | |
0x0d906b, 0x9ee3bd, 0x5b8846, 0x0d8995, 0xf25c58, 0x70ae4f, 0x847f74, | |
0x9094bb, 0xffe2f1, 0xa67149, 0x936c8e, 0xd04907, 0xc3b8a6, 0xcef8c4, | |
0x7a9293, 0xfda2ab, 0x2ef6c5, 0x807242, 0xcb94cc, 0xb6bdd0, 0xb5c75d, | |
0xfde189, 0xb7ff80, 0xfa2d8e, 0x839a5f, 0x28c2b5, 0xe5e9e1, 0xbc79d8, | |
0x7ed8fe, 0x9f20c3, 0x4f7a5b, 0xf511fd, 0x09c959, 0xbcd0ce, 0x8685fd, | |
0x98fcff, 0xafbff9, 0x6d69b4, 0x5f99fd, 0xaaa87e, 0xb59dfb, 0x5d809d, | |
0xd9a742, 0xac5c86, 0x9468d5, 0xa4a2b2, 0xb1376e, 0xd43f3d, 0x05a9d1, | |
0xc38375, 0x24b58e, 0x6eabaf, 0x66bf7f, 0x92cbbb, 0xddb1ee, 0x1be895, | |
0xc7ecf9, 0xa6baa6, 0x8045cd, 0x5f70f1, 0xa9d796, 0xce62cb, 0x0e954d, | |
0xa97d2f, 0xfcb8d3, 0x9bfee3, 0x4e8d84, 0xfc6d3f, 0x7b9fd4, 0x8c6165, | |
0x72805e, 0xd53762, 0xf00a1b, 0xde5c97, 0x8ea28b, 0xfccd95, 0xba9c57, | |
0xb79a82, 0x7c5a82, 0x7d7ca4, 0x958ad6, 0xcd8126, 0xbdb0b7, 0x10e0f8, | |
0xdccc69, 0xd6de0f, 0x616d3d, 0x985a25, 0x30c7fd, 0x0aeb65, 0xe3cdb4, | |
0xbd1bee, 0xad665d, 0xd77070, 0x8ea5b8, 0x5b5ad0, 0x76655e, 0x598100, | |
0x86757e, 0x5ea068, 0xa590b8, 0xc1a707, 0x85c0cd, 0xe2cde9, 0xdcd79c, | |
0xd8a882, 0xb256f9, 0xb13323, 0x519b3b, 0xdd80de, 0xf1884b, 0x74b2fe, | |
0xa0acd2, 0xd199b0, 0xf68392, 0x8ccaa0, 0x64d6cb, 0xe0f86a, 0x42707a, | |
0x75671b, 0x796e87, 0x6d8075, 0x9b8a8d, 0xf04c71, 0x61bd29, 0xbcc18f, | |
0xfecd0f, 0x1e7ac9, 0x927261, 0xdc27cf, 0x979605, 0xec9c88, | |
0x8c48a3,0x676769, 0x546e64, 0x8f63a2, 0xb35b2d, 0x7b8ca2, 0xb87188, | |
0x4a9bda, 0xeb7dab, 0xf6a602, 0xcab3fe, 0xddb8bb, 0x107959, 0x885973, | |
0x5e858e, 0xb15bad, 0xe107a7, 0x2f9dad, 0x4b9e83, 0xb992dc, 0x6bb0cb, | |
0xbdb363, 0xccd6e4, 0xa3ee94, 0x9ef718, 0xfbe1d9, 0xa428a5, 0x93514c, | |
0x487434, 0xe8f1b6, 0xd00938, 0xfb50e1, 0xfa85e1, 0x7cd40a, 0xf1ade1, | |
0xb1485d, 0x7f76d6, 0xd186b3, 0x90c25e, 0xb8c813, 0xa8c9de, 0x7d30fe, | |
0x815f2d, 0x737f3b, 0xc84486, 0x946cfe, 0xe55432, 0xa88674, 0xc17a47, | |
0xb98b91, 0xfc4bb3, 0xda7f5f, 0xdf920b, 0xb7bbba, 0x99e6d9, 0xa36170, | |
0xc742d8, 0x947f9d, 0xa37d93, 0x889072, 0x9b924c, 0x23b4bc, 0xe6a25f, | |
0x86df9c, 0xa7da6c, 0x3fee03, 0xeec9d8, 0xaafdcb, 0x7b9139, 0x92979c, | |
0x72788a, 0x994cff, 0xc85956, 0x7baa1a, 0xde72fe, 0xc7bad8, 0x85ebfe, | |
0x6e6089, 0x9b4d31, 0x297a1d, 0x9052c0, 0x5c75a5, 0x698eba, 0xd46222, | |
0x6da095, 0xb483bb, 0x04d183, 0x9bcdfe, 0x2ffe8c, 0x9d4279, 0xc909aa, | |
0x826cae, 0x77787c, 0xa96fb7, 0x858f87, 0xfd3b40, 0x7fab7b, 0x9e9edd, | |
0xbba3be, 0xf8b96c, 0x7be553, 0xc0e1ce, 0x516e88, 0xbe0e5f, 0x757c09, | |
0x4b8d5f, 0x38b448, 0xdf8780, 0xebb3a0, 0xced759, 0xf0ed7c, 0xe0eef1, | |
0x0969d2, 0x756446, 0x488ea8, 0x888450, 0x61979c, 0xa37ad6, 0xb48a54, | |
0x8193e5, 0xdd6d89, 0x8aa29d, 0xc679fe, 0xa4ac12, 0x75bbb3, 0x6ae2c1, | |
0xc4fda7, 0x606877, 0xb2409d, 0x5874c7, 0xbf492c, 0x4b88cd, 0xe14ec0, | |
0xb39da2, 0xfb8300, 0xd1b845, 0xc2d083, 0xc3caef, 0x967500, 0xc56399, | |
0xed5a05, 0xaadff6, 0x6685f4, 0x1da16f, 0xf28bff, 0xc9c9bf, 0xc7e2a9, | |
0x5bfce4, 0xe0e0bf, 0xe8e2e8, 0xddf2d8, 0x9108f8, 0x932dd2, 0xc03500, | |
0xaa3fbc, 0x547c79, 0x9f6045, 0x04897b, 0x966f32, 0xd83212, 0x039f27, | |
0xdf4280, 0xef206e, 0x0095f7, 0xa5890d, 0x9a8f7f, 0xbc839e, 0x88a23b, | |
0xe55aed, 0x51af9e, | |
0x5eaf82, 0x9e91fa, 0xf76c79, 0x99a869, 0xd2957d, 0xa2aca6, 0xe3959e, | |
0xadaefc, 0x5bd14e, 0xdf9ceb, 0xfe8fb1, 0x87ca80, 0xfc986d, 0x2ad3d9, | |
0xe8a8bb, 0xa7c79c, 0xa5c7cc, 0x7befb7, 0xb7e2e0, 0x85f57b, 0xf5d95b, | |
0xdbdbff, 0xfddcff, 0x6e56bb, 0x226fa8, 0x5b659c, 0x58a10f, 0xe46c52, | |
0x62abe2, 0xc4aa77, 0xb60e74, 0x087983, 0xa95703, 0x2a6efb, 0x427d92 | |
].map(d3_rgbString); | |
function d3_rgbString (value) { | |
return d3.rgb(value >> 16, value >> 8 & 0xff, value & 0xff); | |
} | |
//Code to make the visualization work - do not edit | |
function getNeighbors(node) { | |
return links.reduce(function (neighbors, link) { | |
if (link.target.id === node.id) { | |
neighbors.push(link.source.id) | |
} else if (link.source.id === node.id) { | |
neighbors.push(link.target.id) | |
} | |
return neighbors | |
}, | |
[node.id] | |
) | |
} | |
var linked = {}; | |
links.forEach(function (node) { | |
linked[node.source.id + "," + node.target.id] = 1; | |
}) | |
function isConnected(a, b) { | |
return linked[a.id + "," + b.id] || linked[b.id + "," + a.id] || a.id === b.id | |
} | |
function isNeighborLink(node, link) { | |
console.log(node + " " + link) | |
return link.target.id === node.id || link.source.id === node.id | |
} | |
function getNodeColor(node, neighbors) { | |
return Array.isArray(neighbors) && neighbors.indexOf(node.id) > -1 ? d3_category437[node.group] : '#E2E2E2' | |
} | |
function nodeResize(node, neighbors) { | |
return Array.isArray(neighbors) && neighbors.indexOf(node.id) > -1 ? 12 : 10 | |
} | |
function originalNodeColor (node) { | |
return d3_category437[node.group]; | |
} | |
function getLinkColor(node, link) { | |
return isNeighborLink(node, link) ? 'red' : '#E5E5E5' | |
} | |
function getTextColor(node, neighbors) { | |
return Array.isArray(neighbors) && neighbors.indexOf(node.id) > -1 ? '#195E1B' : '#A9A9A9' | |
} | |
var width = window.innerWidth | |
var height = window.innerHeight | |
var svg = d3.select('svg') | |
svg.attr('width', width).attr('height', height) | |
svg.call(tip); | |
// simulation setup with all forces | |
var linkForce = d3 | |
.forceLink() | |
.id(function (link) { return link.id }) | |
.strength(function (link) { return 0.5 }) | |
var simulation = d3 | |
.forceSimulation() | |
.force('link', linkForce) | |
.force('charge', d3.forceManyBody().strength(-120)) | |
.force('center', d3.forceCenter(width / 2, height / 2)) | |
var dragDrop = d3.drag().on('start', function (node) { | |
node.fx = node.x | |
node.fy = node.y | |
}).on('drag', function (node) { | |
simulation.alphaTarget(0.7).restart() | |
node.fx = d3.event.x | |
node.fy = d3.event.y | |
}).on('end', function (node) { | |
if (!d3.event.active) { | |
simulation.alphaTarget(0) | |
} | |
node.fx = null | |
node.fy = null | |
}) | |
function selectNode(selectedNode) { | |
var neighbors = getNeighbors(selectedNode) | |
// we modify the styles to highlight selected nodes | |
nodeElements.attr('fill', function (node) { return getNodeColor(node, neighbors) }) | |
nodeElements.attr('r', function (node) { return nodeResize(node, neighbors) }) | |
textElements.attr('fill', function (node) { return getTextColor(node, neighbors) }) | |
linkElements.attr('stroke', function (link) { return getLinkColor(selectedNode, link) }) | |
} | |
function unselectNode(selectedNode) { | |
var neighbors = getNeighbors(selectedNode) | |
// we modify the styles to highlight selected nodes | |
nodeElements.attr('fill', originalNodeColor) | |
nodeElements.attr('r', 10) | |
textElements.attr('fill', 'black') | |
linkElements.attr('stroke', '#E5E5E5') | |
} | |
//add zoom capabilities | |
var zoom_handler = d3.zoom() | |
.on("zoom", zoom_actions); | |
zoom_handler(svg); | |
function zoom_actions(){ | |
g.attr("transform", d3.event.transform) | |
} | |
function mouseoverWrapper(selectedNode) { | |
selectNode(selectedNode); | |
tip.show(selectedNode); | |
} | |
function mouseoutWrapper(selectedNode) { | |
unselectNode(selectedNode); | |
tip.hide(selectedNode); | |
} | |
//add encompassing group for the zoom | |
var g = svg.append("g") | |
.attr("class", "everything"); | |
var linkElements = g.append("g") | |
.attr("class", "links") | |
.selectAll("line") | |
.data(links) | |
.enter().append("line") | |
.attr("stroke-width", 1) | |
.attr("stroke", "rgba(50, 50, 50, 0.2)") | |
var nodeElements = g.append("g") | |
.attr("class", "nodes") | |
.selectAll("circle") | |
.data(nodes) | |
.enter().append("circle") | |
.attr("r", 10) | |
.attr("fill", originalNodeColor) | |
.call(dragDrop) | |
//.on('mouseover', "selectNode; tip.show") | |
.on('mouseover', mouseoverWrapper) | |
.on('mouseout', mouseoutWrapper) | |
.on('click', function(d) { | |
window.open( | |
'http://romanrepublic.ac.uk/person/' + d.id + '/', | |
'_blank' | |
);}); | |
var textElements = g.append("g") | |
.attr("class", "texts") | |
.selectAll("text") | |
.data(nodes) | |
.enter().append("text") | |
.text(function (node) { return node.name.substring(0,8) }) | |
.attr("font-size", 15) | |
.attr("dx", 15) | |
.attr("dy", 4) | |
simulation.nodes(nodes).on('tick', () => { | |
nodeElements | |
.attr('cx', function (node) { return node.x }) | |
.attr('cy', function (node) { return node.y }) | |
textElements | |
.attr('x', function (node) { return node.x }) | |
.attr('y', function (node) { return node.y }) | |
linkElements | |
.attr('x1', function (link) { return link.source.x }) | |
.attr('y1', function (link) { return link.source.y }) | |
.attr('x2', function (link) { return link.target.x }) | |
.attr('y2', function (link) { return link.target.y }) | |
}) | |
simulation.force("link").links(links) | |
//Title information | |
svg.append("text") | |
.attr("x", width/2) | |
.attr("y", 30) | |
.attr("text-anchor", "middle") | |
.style("font-size", "16px") | |
.text("Connections of SULP0023 Ser. Sulpicius (35) P. f. - n. Camerinus Cornutus");</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment