Compare commits
2 commits
d471ab197a
...
f9dec8a947
Author | SHA1 | Date | |
---|---|---|---|
|
f9dec8a947 | ||
|
f348decd02 |
1 changed files with 79 additions and 69 deletions
18
graph.js
18
graph.js
|
@ -3,6 +3,7 @@ const CONFIG = {
|
||||||
'nodeSize': 16,
|
'nodeSize': 16,
|
||||||
'baseUrl': 'https://www.securityvision.io/wiki/index.php/',
|
'baseUrl': 'https://www.securityvision.io/wiki/index.php/',
|
||||||
'dataUrl': 'semantic_data.json',
|
'dataUrl': 'semantic_data.json',
|
||||||
|
'preSimulate': true, // run simulation before starting, so we don't start with lines jumping around
|
||||||
'labels': {
|
'labels': {
|
||||||
'rotate': true,
|
'rotate': true,
|
||||||
},
|
},
|
||||||
|
@ -84,7 +85,7 @@ function splitText(text) {
|
||||||
};
|
};
|
||||||
|
|
||||||
function getTitle(obj) {
|
function getTitle(obj) {
|
||||||
if(obj.parent) {
|
if (obj.parent) {
|
||||||
return "sub of " + obj.parent.split('#', 1)[0].replace(/_/g, " ")
|
return "sub of " + obj.parent.split('#', 1)[0].replace(/_/g, " ")
|
||||||
}
|
}
|
||||||
return obj['@id'].split('#', 1)[0].replace(/_/g, " ")
|
return obj['@id'].split('#', 1)[0].replace(/_/g, " ")
|
||||||
|
@ -129,7 +130,7 @@ function buildGraph(data) {
|
||||||
.iterations(2) // increase to make more rigid
|
.iterations(2) // increase to make more rigid
|
||||||
)
|
)
|
||||||
.force("charge", d3.forceManyBody()
|
.force("charge", d3.forceManyBody()
|
||||||
.strength(-50)
|
.strength(-40)
|
||||||
)
|
)
|
||||||
.force("center", d3.forceCenter(width / 2, height / 2))
|
.force("center", d3.forceCenter(width / 2, height / 2))
|
||||||
.force("collision", d3.forceCollide(function (d) {
|
.force("collision", d3.forceCollide(function (d) {
|
||||||
|
@ -300,6 +301,15 @@ function buildGraph(data) {
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// simulate the first bit without drawing, so we don't have the 'jumping' graph in the beginning
|
||||||
|
if (CONFIG.preSimulate) {
|
||||||
|
for (var i = 0, n = Math.ceil(Math.log(simulation.alphaMin()) / Math.log(1 - simulation.alphaDecay())); i < n; ++i) {
|
||||||
|
simulation.tick();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
return svg.node();
|
return svg.node();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -333,7 +343,7 @@ const drag = simulation => {
|
||||||
.on("end", dragended);
|
.on("end", dragended);
|
||||||
};
|
};
|
||||||
|
|
||||||
function selectNode(evt, node, d3Node){
|
function selectNode(evt, node, d3Node) {
|
||||||
console.log(evt, node, d3Node);
|
console.log(evt, node, d3Node);
|
||||||
document.querySelectorAll('svg .node').forEach(n => n.classList.remove('selected'));
|
document.querySelectorAll('svg .node').forEach(n => n.classList.remove('selected'));
|
||||||
d3Node._groups[0][node.index].classList.add('selected');
|
d3Node._groups[0][node.index].classList.add('selected');
|
||||||
|
@ -344,7 +354,7 @@ function selectNode(evt, node, d3Node){
|
||||||
const url = getUrl(node);
|
const url = getUrl(node);
|
||||||
const hrefEl = infoEl.querySelector('.nodeHref');
|
const hrefEl = infoEl.querySelector('.nodeHref');
|
||||||
hrefEl.textContent = getTitle(node);
|
hrefEl.textContent = getTitle(node);
|
||||||
hrefEl.setAttribute('href',url);
|
hrefEl.setAttribute('href', url);
|
||||||
infoEl.querySelector('.nodeContents').src = url;
|
infoEl.querySelector('.nodeContents').src = url;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue