Newer
Older
import * as Helpers from "../helpers";
import jQuery from "jquery";
import { createHTMLElement } from "../helpers";
/**
* Displays an overlay showing the neighbors of a node divided by the link type
* that connects them.
*/

Matthias Konitzny
committed
constructor(graph, parentNode, infoOverlay, type = "link") {
this.graph = graph;
this.parentNode = parentNode;
this.infoOverlay = infoOverlay;

Matthias Konitzny
committed
this.type = type;
this.tabContentPages = {}; // Page content - links to other nodes
this.tabNavHandles = {}; // Top-level handles of the content pages
/**
* Creates the visible elements of the overlay.
* Must be called after the graph has been initialized.
*/
create() {
const bottomContainerDiv = Helpers.createDiv(
"bottom-container",
this.parentNode
);
const coll = Helpers.createDiv("button", bottomContainerDiv);
coll.className = "neighbor-collapsible-title";
// Div that displays the information about all the chapters
coll.addEventListener("click", function () {
if (contentTabs.style.display === "flex") {
jQuery(contentTabs).slideDown({
start: function () {
jQuery(this).css({

Matthias Konitzny
committed
const colors =
this.type === "link"
? this.graph.edgeColors
: this.graph.nodeColors;
for (const [cls, color] of Object.entries(colors)) {
this.createCollapsibleTab(contentTabs, cls, color);

Matthias Konitzny
committed
}
}
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
/**
* Creates a new collapsible tab for a node with type name and a given color.
* @param {HTMLElement} parent Parent of the new tab.
* @param {string} name Name of the node type class
* @param {string} color Color of the node type class
*/
createCollapsibleTab(parent, name, color) {
// Creating the collapsible tabs for the different chapters
const collTab = Helpers.createDiv("button", parent);
collTab.className = "neighbor-collapsible-section";
collTab.innerText = name;
collTab.type = name;
this.tabNavHandles[name] = collTab;
const collTabMarker = Helpers.createDiv(
"neighbor-collapsible-marker-div",
collTab
);
collTabMarker.style.borderColor = color;
collTabMarker.style.backgroundColor = color;
const openMarkerTabs = Helpers.createDiv(
"neighbor-tab-open-status-marker",
collTab
);
openMarkerTabs.innerText = "+";
collTab.marker = openMarkerTabs;
// Content of the different tabs
const collTabContent = Helpers.createDiv(
"neighbor-content-linksection",
parent
);
collTabContent.type = name;
const list = createHTMLElement("ul", collTabContent);
list.style.margin = 0;
collTabContent.list = list;
this.tabContentPages[name] = collTabContent;
collTabContent.marker = openMarkerTabs;
collTab.addEventListener("click", function () {
if (collTabContent.style.display === "flex") {
jQuery(collTabContent).slideUp("fast");
openMarkerTabs.innerText = "+";
} else {
jQuery(collTabContent).slideDown({
start: function () {
jQuery(this).css({ display: "flex" });
},
});
openMarkerTabs.innerText = "-";
}
});
}
* Clears the images from all tab content pages and makes the object
* invisible.
for (const page of Object.values(this.tabContentPages)) {
/*if(page.style.display === "flex") {
/**
* Creates a new image (with link) for the given target node.
* @param target
* @returns {HTMLDivElement}
*/
const linkDiv = document.createElement("li");
var linkText = document.createTextNode(target.name);
linkDiv.className = "neighbor-content-link";
jQuery(linkDiv).on("click", () => {
this.graph.focusOnNode(target);
this.infoOverlay.updateInfoOverlay(target);
});
return linkDiv;
}
/**
* Updates all tabs to have content matching the given node.
* @param node
*/
for (const link of node.links) {
const target = link.source == node ? link.target : link.source;
const reference = this.createReference(target);

Matthias Konitzny
committed
if (this.type === "link") {
this.tabContentPages[link.type].list.appendChild(reference);

Matthias Konitzny
committed
} else {
this.tabContentPages[target.type].list.appendChild(reference);

Matthias Konitzny
committed
}
/**
* Hides all the categories of a node that are not represented by a link
* to another neighbor.
*/
for (const page of Object.values(this.tabContentPages)) {
this.tabNavHandles[page.type].style.display = "none";
} else {
this.tabNavHandles[page.type].style.display = "flex";
if (this.tabContentPages[page.type].style.display === "flex") {
this.tabNavHandles[page.type].marker.innerText = "-";
this.tabNavHandles[page.type].marker.innerText = "+";
/**
* Toggle the visibility for a node type
* @param {string} type The name of the type that should be toggled
*/
toggleCategory(type) {
const page = this.tabContentPages[type];
if (this.tabNavHandles[page.type].style.display === "flex") {
this.tabNavHandles[page.type].style.display = "none";
const collTabContent = this.tabContentPages[page.type];
jQuery(collTabContent).slideUp("fast");
} else {
if (page.list.hasChildNodes()) {
this.tabNavHandles[page.type].style.display = "flex";
if (this.tabContentPages[page.type].style.display === "flex") {
this.tabNavHandles[page.type].marker.innerText = "-";
this.tabNavHandles[page.type].marker.innerText = "+";