Skip to content

Commit 36ee99e

Browse files
committed
Code cleanup
1 parent 7447bfd commit 36ee99e

File tree

4 files changed

+16
-37
lines changed

4 files changed

+16
-37
lines changed

content.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,8 @@ if (isIE()) {
1212
// parse data only if tree not loaded already
1313
if (getDataFromSessionStorage(repoName + "Tree") === null) {
1414
let parsedData = parseData(dataHost, dataDict, jsonDataFile);
15-
// let parsedTreeChildren = parseData(dataHost, dataDict, jsonTreeFile);
1615
if(!parsedData.length) throw new Error("index.js: Data error");
1716
keepDataInSessionStorage(repoName + "Tree", JSON.stringify(parsedData));
18-
// keepDataInSessionStorage(repoName + "TreeChildren", JSON.stringify(parsedTreeChildren));
1917
}
2018

2119
initGraph();

dag.js

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ function initGraph() {
4545
let data = structuredClone(treeData); // A clone is made to avoid any modifications in the original data
4646
for(let i=0;i<data.length;i++)
4747
{
48-
///Expand the nodes with no parents and initialize shownNodesMap with the shown nodes in the tree
48+
// Expand the nodes with no parents and initialize shownNodesMap with the shown nodes in the tree
4949
// and nodeChildrenStateMap with the state of the node children(expanded or collapsed)
5050
if(data[i]["parentIds"].length === 0)
5151
{
@@ -61,18 +61,17 @@ function initGraph() {
6161
shownNodesMap[data[i]["id"]] = 0;
6262
}
6363
}
64-
///Get nodes with no children to draw them without children expand/collapse button
64+
// Get nodes with no children to draw them without children expand/collapse button
6565
if(getNodeChildren(data[i]["id"],data).length === 0)
6666
{
6767
leavesNodesIds.push(data[i]["id"])
6868
}
6969
}
70-
///Remove hidden parents of the nodes in the currentTree
70+
// Remove hidden parents of the nodes in the currentTree
7171
for (let i = 0; i < currentTree.length; i++)
7272
{
7373
if(shownNodesMap[currentTree[i]["id"]] === 1)
7474
{
75-
// currentTree[i]["parentIds"] = removeHiddenParents(currentTree[i]["id"]);
7675
removeHiddenParents(currentTree[i]["parentIds"]);
7776
}
7877
}
@@ -124,7 +123,6 @@ function initGraph() {
124123
let node = getNodeByTitle(d.currentTarget.__data__.data.title);
125124
$("#info_box").empty();
126125
addNodeInfos(node, "preview");
127-
// document.getElementById("preview").scrollIntoView({ behavior: 'smooth' });
128126
updateGraphPlot(currentNodeId);
129127
}
130128

@@ -137,7 +135,6 @@ function initGraph() {
137135
let node = getNodeByTitle(d.currentTarget.__data__.data.title);
138136
$("#info_box").empty();
139137
addNodeInfos(node, "preview");
140-
// document.getElementById("preview").scrollIntoView({ behavior: 'smooth' });
141138
updateGraphPlot(currentNodeId);
142139
}
143140

@@ -178,7 +175,6 @@ function initGraph() {
178175
.text(word);
179176
}
180177
}
181-
// set new box height
182178
});
183179
}
184180
/**
@@ -239,7 +235,7 @@ function onNodeParentsToggle(d)
239235
* @param {String} state node to be expanded or collapsed
240236
*/
241237
function updateTree(currentNodeId,state){
242-
let data = structuredClone(treeData);// A clone is made to avoid any modifications in the original data
238+
let data = structuredClone(treeData); // A clone is made to avoid any modifications in the original data
243239
if(state === "children expand")
244240
{
245241
nodeChildrenExpand(currentNodeId,data);
@@ -262,8 +258,6 @@ function updateTree(currentNodeId,state){
262258
updateShownNodeMap(treeData)
263259
highlightSelectedNode(currentNodeId);
264260
updateTreeGraph(currentTree,currentNodeId, state);
265-
// graph
266-
// .attr('transform', zoomTransform);
267261
}
268262

269263
/**
@@ -281,7 +275,6 @@ function drawTree(drawData,state)
281275
// --------------------------------
282276
// This code only handles rendering
283277
// --------------------------------
284-
// keepTopLayersNodesUp();
285278
svgSelection = d3.select("svg");
286279
svgSelection.selectAll('*').remove();
287280
if(state === "expand tree")
@@ -372,7 +365,7 @@ function drawTree(drawData,state)
372365
.attr("x", nodeWidth - 20 - (5 / 2))
373366
.html("i");
374367

375-
///Filter nodes with no parent to add parents expand/collapse button
368+
// Filter nodes with no parent to add parents expand/collapse button
376369
let rootsNodes = nodes.filter(function(node){
377370
return !nodeParentsStateMap[node.data.id];
378371
})
@@ -391,7 +384,7 @@ function drawTree(drawData,state)
391384
.attr("y",8.5)
392385
.html("+")
393386

394-
///Filter nodes with no children to add expand/collapse button
387+
// Filter nodes with no children to add expand/collapse button
395388
let leavesNodes = nodes.filter(function(node){
396389
return !leavesNodesIds.includes(node.data.id);
397390
})
@@ -493,7 +486,7 @@ function nodeChildrenExpand(currentNodeId,data)
493486
{
494487
if(data[i]["parentIds"].includes(currentNodeId))
495488
{
496-
///If the child is already shown, add the parent to it in currentTree
489+
// If the child is already shown, add the parent to it in currentTree
497490
if(shownNodesMap[data[i]["id"]] === 1)
498491
{
499492
for(let j = 0;j<currentTree.length;j++)
@@ -515,7 +508,7 @@ function nodeChildrenExpand(currentNodeId,data)
515508
nodeChildren.push(data[i]["id"]);
516509
}
517510
}
518-
///Link new nodes (clicked node children) to their existing children
511+
// Link new nodes (clicked node children) to their existing children
519512
linkNewNodes(nodeChildren,data)
520513
}
521514
/**
@@ -621,7 +614,7 @@ function expandSearchedNodeTree(node)
621614
currentTree.push(node);
622615
}
623616
let nodeParentsQueue = node.parentIds.slice(0);
624-
//show node parents till the top layer
617+
// show node parents till the top layer
625618
while(nodeParentsQueue.length > 0)
626619
{
627620
let parentId = nodeParentsQueue.shift();
@@ -635,7 +628,7 @@ function expandSearchedNodeTree(node)
635628
nodeParentsQueue.push(elem);
636629
})
637630
}
638-
//show node children
631+
// show node children
639632
let children = getNodeChildren(node.id,data);
640633
children.forEach(function(child){
641634
if(shownNodesMap[child.id] !==1)
@@ -727,7 +720,6 @@ function updateTreeGraph(drawData,currentNodeId,state)
727720
graph.select(".paths-list").selectAll("*").remove();
728721
generateTreeLayout(drawData);
729722
layout(dag);
730-
// keepTopLayersNodesUp();
731723

732724
// Remove collapsed nodes before starting the animation
733725
let collapsedNodes = nodes.filter(function(node){
@@ -822,7 +814,7 @@ function keepTopLayersNodesUp()
822814
{
823815
let rootsNodesY = 100000;
824816
let rootsNodesX = [];
825-
//get roots nodes y-coordinate(the minimum to make it constant for all of them) and x-coordinates
817+
// get roots nodes y-coordinate(the minimum to make it constant for all of them) and x-coordinates
826818
dag.descendants().forEach(function(node){
827819
if(node.y<rootsNodesY)
828820
{
@@ -836,7 +828,7 @@ function keepTopLayersNodesUp()
836828
rootsNodesX.sort(function(a, b){return a - b});
837829
let xStep = (rootsNodesX[rootsNodesIds.length - 1] - rootsNodesX[0])/rootsNodesIds.length;//horizontal space between roots nodes
838830
let i = 0;
839-
//Set the new coordinates to the roots nodes
831+
// Set the new coordinates to the roots nodes
840832
dag.descendants().forEach(function(node){
841833
if(rootsNodesIds.includes(node.data.id))
842834
{
@@ -846,7 +838,7 @@ function keepTopLayersNodesUp()
846838
i+=1;
847839
}
848840
})
849-
//Set the new coordinates to the roots nodes links
841+
// Set the new coordinates to the roots nodes links
850842
dag.links().forEach(function(node){
851843
if(rootsNodesIds.includes(node.source.data.id))
852844
{

helper.js

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@
44
if (!HTMLCollection.prototype.forEach) {
55
HTMLCollection.prototype.forEach = Array.prototype.forEach;
66
}
7-
/*if (!Object.prototype.forEach) {
8-
Object.prototype.forEach = Array.prototype.forEach;
9-
}*/
107
if (!HTMLCollection.prototype.indexOf) {
118
HTMLCollection.prototype.indexOf = Array.prototype.indexOf;
129
}
@@ -73,10 +70,8 @@ function addNodeInfos(node, id) {
7370
value.push(["Decomposition Block", node.decomBlock.replaceAll("\\n", "<br><br>")]);
7471
break;
7572
case "number of parent nodes":
76-
//value.push([a, getNumberOfParents(node)]);
7773
break;
7874
case "number of child nodes":
79-
//value.push([a, getNumberOfChildren(node)]);
8075
break;
8176
case "references":
8277
value = prepareReferencesInfo(node.references);
@@ -212,15 +207,13 @@ function jumpToSearch() {
212207
* @returns
213208
*/
214209
function addAutoComplete(input) {
215-
// TODO switch to jQuery
216-
217210
let tree = JSON.parse(getDataFromSessionStorage(repoName + "Tree"));
218211
if (!tree) return;
219212

220213
// collect all nodes names in tree
221214
let arr = [];
222215
let tagsArr = [];
223-
let tagsTitlesMap = {};//map that links each tag to its associated titles.
216+
let tagsTitlesMap = {}; // map that links each tag to its associated titles.
224217
tree.forEach(function (n) {
225218
if (!arr.includes(n.title)) {
226219
arr.push(n.title);
@@ -250,7 +243,7 @@ function addAutoComplete(input) {
250243
let currentFocus;
251244
input.addEventListener("input", function () {
252245
let val = this.value;
253-
let titlesMap = {};//check if the title already in the search results to avoid duplicates.
246+
let titlesMap = {}; // check if the title already in the search results to avoid duplicates.
254247

255248
// close already open lists
256249
closeAllLists();
@@ -308,8 +301,7 @@ function addAutoComplete(input) {
308301

309302
});
310303

311-
function checkSearchBarValue(data,searchVal)
312-
{
304+
function checkSearchBarValue(data,searchVal) {
313305
let includes = false;
314306
if (data.toLowerCase().includes(searchVal.toLowerCase())) {
315307
includes = true;
@@ -382,7 +374,6 @@ function prepareReferencesInfo(referenceString){
382374
let preparedRefString = referenceString
383375
.replace("[", "")
384376
.replaceAll("]", "")
385-
//.replaceAll(/[\s]/g, "")
386377
.split("[")
387378
.filter(function (e) { return e != ""; });
388379

style.css

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -358,8 +358,6 @@ body {
358358
}
359359

360360
.content #info_box {
361-
/*margin-top: 20px;*/
362-
/*display: inline-block;*/
363361
overflow-y: scroll;
364362
height: 96%;
365363
}

0 commit comments

Comments
 (0)