Skip to content
Snippets Groups Projects
filteroverlay.js 2.44 KiB
Newer Older
  • Learn to ignore specific revisions
  • import * as Helpers from "../helpers";
    
     * Represents an overlay showing the meaning of different link/node colors.
     * Offers the ability to toggle certain types.
    
         * Creates the overlay for a given graph object.
    
         * @param {Graph} graph The graph object.
    
         * @param {String} type The selection type. Can be "link" or "node".
    
            this.type = type;
            this.filterChangedCallback = (type) => void type;
    
        /**
         * Creates the overlay based on the edges and nodes of the graph object.
         * Must be called after the graph has been initialized.
         */
    
            const sceneNode = Helpers.getCanvasDivNode();
            const overlayNode = document.createElement("div");
            overlayNode.className = "link-overlay";
            sceneNode.insertBefore(overlayNode, sceneNode.childNodes[2]);
    
            const classes =
                this.type === "link"
                    ? this.graph.getLinkClasses()
                    : this.graph.getNodeClasses();
    
                const relation = Helpers.createDiv("relation", overlayNode, {
    
                    type: link, // Attach the link type to the relation div object
    
                    innerHTML: "<p>" + link + "</p>",
                });
    
                jQuery(relation).click((event) => this.toggleVisibility(event));
    
                const colorStrip = Helpers.createDiv("rel-container", relation);
    
                colorStrip.style.backgroundColor = this.graph.edgeColors[link];
                colorStrip.style.width = 10 * chars + "px";
    
        /**
         * Event handler for the click event of the link type divs.
         * Toggles the visibility of certain edge types.
         * @param {MouseEvent} event
         */
    
            const target = event.currentTarget;
    
            if (this.type === "link") {
                this.graph.toggleLinkVisibility(target.type);
            } else {
                this.graph.toggleNodeVisibility(target.type);
            }
            this.filterChangedCallback(target.type);
    
            if (getComputedStyle(target).opacity == 1.0) {
                target.style.opacity = 0.4;
            } else {
                target.style.opacity = 1.0;
            }
        }