From 6421c8f4221b152b9eba9b153997e213c6b94adc Mon Sep 17 00:00:00 2001
From: Matthias Konitzny <konitzny@ibr.cs.tu-bs.de>
Date: Wed, 4 Aug 2021 16:03:01 +0200
Subject: [PATCH] Workaround to reduce errors from the plugin_path external
 variable.

---
 config.js              |  3 +++
 display/graph.js       | 12 +++++++-----
 display/infooverlay.js | 10 ++++++----
 3 files changed, 16 insertions(+), 9 deletions(-)

diff --git a/config.js b/config.js
index 9d779ce..e1c17d8 100644
--- a/config.js
+++ b/config.js
@@ -7,3 +7,6 @@ export const COLOR_PALETTE = [
     "rgb(239, 65, 35)",
     "rgb(255, 255, 255)",
 ];
+
+// Just renaming a variable which is given by the PHP script. This avoids errors in all other files.
+export const PLUGIN_PATH = plugin_path;
diff --git a/display/graph.js b/display/graph.js
index d088c4b..dfa2183 100644
--- a/display/graph.js
+++ b/display/graph.js
@@ -257,7 +257,9 @@ class Graph {
         const loader = new THREE.TextureLoader();
         //const planeMaterial = new THREE.MeshLambertMaterial({color: 0xFF0000, side: THREE.DoubleSide}); //THREE.BackSide
         const planeMaterial = new THREE.MeshBasicMaterial({
-            map: loader.load(plugin_path + "backgrounds/background_4.jpg"),
+            map: loader.load(
+                Config.PLUGIN_PATH + "backgrounds/background_4.jpg"
+            ),
             side: THREE.DoubleSide,
         }); //THREE.BackSide
         const mesh = new THREE.Mesh(sphereGeometry, planeMaterial);
@@ -294,17 +296,17 @@ class Graph {
         // Draw node circle image
         const textureLoader = new THREE.TextureLoader();
         const imageAlpha = textureLoader.load(
-            plugin_path + "datasets/images/alpha.png"
+            Config.PLUGIN_PATH + "datasets/images/alpha.png"
         );
         let imageTexture = null;
 
         if ("image" in node) {
             imageTexture = textureLoader.load(
-                plugin_path + "datasets/images/" + node.image
+                Config.PLUGIN_PATH + "datasets/images/" + node.image
             );
         } else {
             imageTexture = textureLoader.load(
-                plugin_path + "datasets/images/default.jpg"
+                Config.PLUGIN_PATH + "datasets/images/default.jpg"
             );
         }
 
@@ -353,7 +355,7 @@ function createFullScreenButton() {
     sceneNode.appendChild(overlayNode);
 }
 
-const dataUrl = plugin_path + "datasets/aud1.json";
+const dataUrl = Config.PLUGIN_PATH + "datasets/aud1.json";
 const G = new Graph(dataUrl);
 const linkoverlay = new LinkOverlay(G);
 const infooverlay = new InfoOverlay(G);
diff --git a/display/infooverlay.js b/display/infooverlay.js
index 8da19c3..a821327 100644
--- a/display/infooverlay.js
+++ b/display/infooverlay.js
@@ -1,5 +1,6 @@
 import * as Helpers from "./helpers";
 import jQuery from "jquery";
+import * as Config from "../config";
 
 export { InfoOverlay };
 
@@ -104,7 +105,7 @@ class InfoOverlay {
 
         const nodeImage = document.createElement("img");
         nodeImage.id = "infoOverlayImage";
-        nodeImage.src = plugin_path + "datasets/images/default.jpg";
+        nodeImage.src = Config.PLUGIN_PATH + "datasets/images/default.jpg";
         nodeImage.className = "detail-view-image";
         topArea.appendChild(nodeImage);
 
@@ -130,12 +131,12 @@ class InfoOverlay {
         if ("image" in node) {
             jQuery("#infoOverlayImage").attr(
                 "src",
-                plugin_path + "datasets/images/" + node.image
+                Config.PLUGIN_PATH + "datasets/images/" + node.image
             );
         } else {
             jQuery("#infoOverlayImage").attr(
                 "src",
-                plugin_path + "datasets/images/default.jpg"
+                Config.PLUGIN_PATH + "datasets/images/default.jpg"
             );
         }
 
@@ -162,7 +163,8 @@ class InfoOverlay {
 
         if ("image" in target) {
             const linkImage = document.createElement("img");
-            linkImage.src = plugin_path + "datasets/images/" + target.image;
+            linkImage.src =
+                Config.PLUGIN_PATH + "datasets/images/" + target.image;
             linkDiv.appendChild(linkImage);
         }
 
-- 
GitLab