Newer
Older
import * as Helpers from "../helpers";
import jQuery from "jquery";
import * as Config from "../../config";
export { NodeNeighborOverlay };
/**
* 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.activeTabNav = null; // The currently selected tab handle
this.activeTabContent = null; // The currently selected tab content

Matthias Konitzny
committed
this.tabNavHandles = {};
/**
* 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",
coll.className = "collapsible";
coll.innerText = "Nachbarn";
var contentTabs = Helpers.createDiv(
"content",
coll.addEventListener("click", function() {
if(contentTabs.style.display === "flex") {
contentTabs.style.display = "none";
} else {
contentTabs.style.display = "flex";
}
});

Matthias Konitzny
committed
const colors =
this.type === "link"
? this.graph.edgeColors
: this.graph.nodeColors;
for (const [cls, color] of Object.entries(colors)) {
const collTab = Helpers.createDiv(
"button",
contentTabs
collTab.className = "collapsible";
collTab.innerText = cls;
collTab.style.backgroundColor = color;
collTab.type = cls;
const collTabContent = Helpers.createDiv(
"content",
contentTabs
collTabContent.innerText = "Example Text";
collTab.addEventListener("click", function() {
if(collTabContent.style.display === "flex") {
collTabContent.style.display = "none";
} else {
collTabContent.style.display = "flex";

Matthias Konitzny
committed
}

Matthias Konitzny
committed
}
}
/**
* Clears the images from all tab content pages.
*/
//TODO: Clear all content of content containers
/*for (const page of Object.values(this.tabContentPages)) {
/**
* Creates a new image (with link) for the given target node.
* @param target
* @returns {HTMLDivElement}
*/
createReference(target) {
const linkDiv = document.createElement("div");
linkDiv.className = "link-img";
if ("image" in target) {
const linkImage = document.createElement("img");
linkImage.src =
Config.PLUGIN_PATH + "datasets/images/" + target.image;
linkDiv.appendChild(linkImage);
}
if ("name" in target) {
Helpers.createHTMLElement("p", linkDiv, {
className: "bottom-container-link-text",
innerText: target.name,
});
}
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
*/
//TODO: Write update function to update content container
/*this.clearTabContentPages();
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].appendChild(reference);
} else {
this.tabContentPages[target.type].appendChild(reference);
}