From e6e44a757d136475db266381ad954958106a5838 Mon Sep 17 00:00:00 2001 From: Katja <bax5612@studium.uni-hamburg.de> Date: Tue, 23 Nov 2021 20:23:31 +0100 Subject: [PATCH] comments --- Output/cn.js | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/Output/cn.js b/Output/cn.js index 73bb9fb..fc0d4f6 100644 --- a/Output/cn.js +++ b/Output/cn.js @@ -56,6 +56,12 @@ d3.json("json_text.json").then(function(graph) { update(graph.links, graph.nodes); }) +/** +* display links and nodes (with circle and text) +* initialises link, node objects +* @param {object} nodes - nodes +* @param {object} links - links +*/ function update(links, nodes) { link = g.append("g") .selectAll(".link") @@ -118,10 +124,20 @@ simulation.force("link") .links(links); } +/** +* returns true if link is directly connected to node and false if it is not +* @param {object} node - node +* @param {object} link - link +*/ function isLinkForNode(node, link){ return link.source.index == node.index || link.target.index == node.index; } +/** +* sets color of link (line and arrowhead) to black if it is directly connected to node +* and to grey otherwise +* @param {object} node - node +*/ function marklink(node){ d3.selectAll(".link") .style("stroke", function(o) { @@ -130,6 +146,10 @@ function marklink(node){ return isLinkForNode(node, o) ? marker('#000000') : marker('#999');}) } +/** +* creates arrowhead and returns its url +* @param {string} color - color of arrowhead +*/ function marker(color) { svg.append('defs').append('marker')//arrowhead .attr('id',color.replace("#", "")) @@ -149,7 +169,7 @@ function marker(color) { /** * returns last name of first author -* @param {string} authors - The comma-separated string of authors +* @param {string} authors - the comma-separated string of authors */ function firstauthor(authors){ if (/,/.test(authors)==false){ @@ -161,6 +181,10 @@ function firstauthor(authors){ return firstauthor[1] } +/** +* outputs node info to textbox +* @param {object} d - data of current node +*/ function textfunc(d){ document.getElementById('textbox').innerHTML = "Title:" + '</br>' + d.name + '</br>' +'</br>'+"Author:"+ '</br>' +d.author+'</br>'+'</br>'+"Year:"+'</br>'+d.year+'</br>'+'</br>' -- GitLab