diff popoto/src/js/popoto.js @ 1:db013b2f3e10

added displayAttribute to show on individual nodes. pull all labels and add getLabelFilter to ignore labels (currently with underscore). added ismi-specific app-template and html file.
author Robert Casties <casties@mpiwg-berlin.mpg.de>
date Tue, 01 Sep 2015 16:56:31 +0200
parents 3b8b5aa8ab65
children aea1b2097f4f
line wrap: on
line diff
--- a/popoto/src/js/popoto.js	Mon Aug 31 17:09:18 2015 +0200
+++ b/popoto/src/js/popoto.js	Tue Sep 01 16:56:31 2015 +0200
@@ -2012,13 +2012,16 @@
                                 ny = clickedNode.y + (100 * Math.sin((angleDeg * (Math.PI / 180)) - parentAngle));
 
                             var isGroupNode = popoto.provider.getIsGroup(d);
+                            // filter multiple labels
+                            var nodeLabel = popoto.provider.getLabelFilter(d.label);
+
                             var node = {
                                 "id": "" + (++popoto.graph.node.idgen),
                                 "parent": clickedNode,
                                 "type": (isGroupNode) ? popoto.graph.node.NodeTypes.GROUP : popoto.graph.node.NodeTypes.CHOOSE,
-                                "label": d.label,
+                                "label": nodeLabel,
                                 "fixed": false,
-                                "internalLabel": popoto.graph.node.generateInternalLabel(d.label),
+                                "internalLabel": popoto.graph.node.generateInternalLabel(nodeLabel),
                                 "x": nx,
                                 "y": ny
                             };
@@ -2651,7 +2654,8 @@
         if (popoto.query.USE_PARENT_RELATION) {
             returnElements.push("head(labels(x)) AS label");
         } else {
-            returnElements.push("last(labels(x)) AS label");
+            //returnElements.push("last(labels(x)) AS label");
+            returnElements.push("labels(x) AS label");
         }
         returnElements.push("count(r) AS count");
         endElements.push("ORDER BY count(r) DESC");
@@ -3438,6 +3442,25 @@
     };
 
     /**
+     * Select the label if there is more than one.
+     * 
+     * Discards the label with an underscore.
+     */
+    popoto.provider.getLabelFilter = function (nodeLabel) {
+        if (Array.isArray(nodeLabel)) {
+            // use last label
+            var label = nodeLabel[nodeLabel.length - 1];
+            if (label.indexOf('_') == -1 && nodeLabel.length > 1) {
+                // skip if wrong label
+                label = nodeLabel[nodeLabel.length - 2];
+            }
+            // replace array with string
+            nodeLabel = label;
+        }
+        return nodeLabel;
+    }
+    
+    /**
      * Label provider used by default if none have been defined for a label.
      * This provider can be changed if needed to customize default behavior.
      * If some properties are not found in user customized providers, default values will be extracted from this provider.
@@ -3507,6 +3530,13 @@
             "constraintAttribute": popoto.query.NEO4J_INTERNAL_ID,
 
             /**
+             * Defines the attribute of the node to display as a text identifying the node.
+             * 
+             * The default value is the Neo4j internal id.
+             */
+            "displayAttribute": popoto.query.NEO4J_INTERNAL_ID,
+            
+            /**
              * Return the list of predefined constraints to add for the given label.
              * These constraints will be added in every generated Cypher query.
              *
@@ -3591,21 +3621,21 @@
              */
             "getTextValue": function (node) {
                 var text;
-                var constraintAttr = popoto.provider.getProperty(node.label, "constraintAttribute");
+                var textAttr = popoto.provider.getProperty(node.label, "displayAttribute");
                 if (node.type === popoto.graph.node.NodeTypes.VALUE) {
-                    if (constraintAttr === popoto.query.NEO4J_INTERNAL_ID) {
+                    if (textAttr === popoto.query.NEO4J_INTERNAL_ID) {
                         text = "" + node.internalID;
                     } else {
-                        text = "" + node.attributes[constraintAttr];
+                        text = "" + node.attributes[textAttr];
                     }
                 } else {
                     if (node.value === undefined) {
                         text = node.label;
                     } else {
-                        if (constraintAttr === popoto.query.NEO4J_INTERNAL_ID) {
+                        if (textAttr === popoto.query.NEO4J_INTERNAL_ID) {
                             text = "" + node.value.internalID;
                         } else {
-                            text = "" + node.value.attributes[constraintAttr];
+                            text = "" + node.value.attributes[textAttr];
                         }
                     }
                 }
@@ -3625,21 +3655,21 @@
              */
             "getSemanticValue": function (node) {
                 var text;
-                var constraintAttr = popoto.provider.getProperty(node.label, "constraintAttribute");
+                var textAttr = popoto.provider.getProperty(node.label, "displayAttribute");
                 if (node.type === popoto.graph.node.NodeTypes.VALUE) {
-                    if (constraintAttr === popoto.query.NEO4J_INTERNAL_ID) {
+                    if (textAttr === popoto.query.NEO4J_INTERNAL_ID) {
                         text = "" + node.internalID;
                     } else {
-                        text = "" + node.attributes[constraintAttr];
+                        text = "" + node.attributes[textAttr];
                     }
                 } else {
                     if (node.value === undefined) {
                         text = node.label;
                     } else {
-                        if (constraintAttr === popoto.query.NEO4J_INTERNAL_ID) {
+                        if (textAttr === popoto.query.NEO4J_INTERNAL_ID) {
                             text = "" + node.value.internalID;
                         } else {
-                            text = "" + node.value.attributes[constraintAttr];
+                            text = "" + node.value.attributes[textAttr];
                         }
                     }
                 }