Author: scooter
Date: 2011-11-21 16:59:13 -0800 (Mon, 21 Nov 2011)
New Revision: 27546

Modified:
   
csplugins/trunk/ucsf/scooter/metaNodePlugin2/src/metaNodePlugin2/model/MetaNode.java
   
csplugins/trunk/ucsf/scooter/metaNodePlugin2/src/metaNodePlugin2/model/MetaNodeManager.java
   
csplugins/trunk/ucsf/scooter/metaNodePlugin2/src/metaNodePlugin2/ui/MetanodeSettingsDialog.java
   
csplugins/trunk/ucsf/scooter/metaNodePlugin2/src/metaNodePlugin2/view/NodeCharts.java
Log:
Added a little more support for nodecharts


Modified: 
csplugins/trunk/ucsf/scooter/metaNodePlugin2/src/metaNodePlugin2/model/MetaNode.java
===================================================================
--- 
csplugins/trunk/ucsf/scooter/metaNodePlugin2/src/metaNodePlugin2/model/MetaNode.java
        2011-11-22 00:16:28 UTC (rev 27545)
+++ 
csplugins/trunk/ucsf/scooter/metaNodePlugin2/src/metaNodePlugin2/model/MetaNode.java
        2011-11-22 00:59:13 UTC (rev 27546)
@@ -90,6 +90,7 @@
        private boolean useNestedNetworks = false;
        private String nodeChartAttribute = null;
        private String chartType = null;
+       private String chartColorType = "contrasting";
 
        private Map<CyEdge,CyEdge> metaEdges = new HashMap<CyEdge,CyEdge>();
        private Map<CyNode,CyEdge> membershipEdges = null;
@@ -458,6 +459,24 @@
        }
 
        /**
+        * Sets the node chart color type
+        *
+        * @param chartColorType the chart color type
+        */
+       public void setChartColorType(String chartColorType) {
+               this.chartColorType = chartColorType;
+       }
+
+       /**
+        * Get the chart color type we're using
+        *
+        * @return chart color type
+        */
+       public String getChartColorType() {
+               return this.chartColorType;
+       }
+
+       /**
         * Sets whether or not we hide the metnode when we expand the
         * network.
         *

Modified: 
csplugins/trunk/ucsf/scooter/metaNodePlugin2/src/metaNodePlugin2/model/MetaNodeManager.java
===================================================================
--- 
csplugins/trunk/ucsf/scooter/metaNodePlugin2/src/metaNodePlugin2/model/MetaNodeManager.java
 2011-11-22 00:16:28 UTC (rev 27545)
+++ 
csplugins/trunk/ucsf/scooter/metaNodePlugin2/src/metaNodePlugin2/model/MetaNodeManager.java
 2011-11-22 00:59:13 UTC (rev 27546)
@@ -62,6 +62,7 @@
        protected static boolean useNestedNetworksDefault = false;
        protected static boolean dontExpandEmptyDefault = true;
        protected static String chartTypeDefault = null;
+       protected static String chartColorTypeDefault = "contrasting";
        protected static String nodeChartAttributeDefault = null;
        protected static AttributeManager defaultAttributeManager = new 
AttributeManager();
 
@@ -136,6 +137,7 @@
                mn.setHideMetaNode(hideMetanodeDefault);
                mn.setMetaNodeOpacity(metanodeOpacityDefault);
                mn.setChartType(chartTypeDefault);
+               mn.setChartColorType(chartColorTypeDefault);
                mn.setNodeChartAttribute(nodeChartAttributeDefault);
                mn.setAttributeManager(new 
AttributeManager(defaultAttributeManager));
                
mn.getAttributeManager().loadHandlerMappings(metaGroup.getNetwork(), mn);
@@ -348,6 +350,24 @@
        }
 
        /**
+        * Sets the chart color type to use for node charting.
+        *
+        * @param chartColorType the chart color type to use for node charts
+        */
+       static public void setChartColorTypeDefault(String chartColorType) {
+               MetaNodeManager.chartColorTypeDefault = chartColorType;
+       }
+
+       /**
+        * Gets the node chart color type.
+        *
+        * @return the node chart color type
+        */
+       static public String getChartColorTypeDefault() {
+               return MetaNodeManager.chartColorTypeDefault;
+       }
+
+       /**
         * Gets the default attribute manager
         *
         * @return the default attribute manager object

Modified: 
csplugins/trunk/ucsf/scooter/metaNodePlugin2/src/metaNodePlugin2/ui/MetanodeSettingsDialog.java
===================================================================
--- 
csplugins/trunk/ucsf/scooter/metaNodePlugin2/src/metaNodePlugin2/ui/MetanodeSettingsDialog.java
     2011-11-22 00:16:28 UTC (rev 27545)
+++ 
csplugins/trunk/ucsf/scooter/metaNodePlugin2/src/metaNodePlugin2/ui/MetanodeSettingsDialog.java
     2011-11-22 00:59:13 UTC (rev 27546)
@@ -39,12 +39,13 @@
 package metaNodePlugin2.ui;
 
 import metaNodePlugin2.MetaNodeGroupViewer;
+import metaNodePlugin2.data.AttributeHandler;
+import metaNodePlugin2.data.AttributeHandlingType;
+import metaNodePlugin2.data.AttributeManager;
 import metaNodePlugin2.model.MetaNode;
 import metaNodePlugin2.model.MetaNodeManager;
 import metaNodePlugin2.model.MetanodeProperties;
-import metaNodePlugin2.data.AttributeHandler;
-import metaNodePlugin2.data.AttributeHandlingType;
-import metaNodePlugin2.data.AttributeManager;
+import metaNodePlugin2.view.NodeCharts;
 
 import cytoscape.CyNetwork;
 import cytoscape.CyNode;
@@ -91,12 +92,14 @@
 public class MetanodeSettingsDialog extends JDialog 
                                     implements ActionListener, 
TunableListener, ComponentListener {
 
+       private static String[] colorTypes = {"contrasting", "rainbow", 
"modulated", "random"};
        private MetanodeProperties metanodeProperties;
        private Tunable typeString = null;
        private Tunable typeList = null;
        private Tunable attrList = null;
        private Tunable nodeChartAttrList = null;
        private Tunable nodeChartTypeList = null;
+       private Tunable nodeChartColorList = null;
        private String[] attributeArray = null;
        private List<Tunable>tunableEnablers = null;
        private List<Tunable>nodeChartEnablers = null;
@@ -106,6 +109,7 @@
   private boolean useNestedNetworks = false;
        private double metanodeOpacity = 100.0;
        private String chartType = null;
+       private String chartColorType = null;
        private String nodeChartAttribute = null;
        public MetaNodeGroupViewer groupViewer = null;
        private AttributeManager defaultAttributeManager = null;
@@ -284,6 +288,8 @@
                        }
                }
 
+               // System.out.println("------------------------------------ 
enableHandling = "+enableHandling);
+
                {
                        Tunable t = new Tunable("enableHandling",
                                                "Enable Attribute Aggregation",
@@ -334,7 +340,7 @@
                // If we have nodeCharts, provide chart options for aggregated 
attributes
                {
                        Tunable t = new Tunable("nodeChartsGroup", "Node Chart 
Options",
-                                               Tunable.GROUP, new Integer(2),
+                                               Tunable.GROUP, new Integer(4),
                                          new Boolean(true), null, 
Tunable.COLLAPSABLE);
                        metanodeProperties.add(t);
                        t.setImmutable(true);
@@ -358,6 +364,23 @@
                                metanodeProperties.add(nodeChartTypeList);
                                nodeChartTypeList.addTunableValueListener(this);
                                nodeChartTypeList.setImmutable(true);
+
+                               // Get the color types
+                               nodeChartColorList = new 
Tunable("chartColorType", "How to color chart",
+                                                                Tunable.LIST, 
new Integer(0),
+                                                                colorTypes, 
null, 0);
+                               nodeChartEnablers.add(nodeChartColorList);
+                               metanodeProperties.add(nodeChartColorList);
+                               
nodeChartColorList.addTunableValueListener(this);
+                               nodeChartColorList.setImmutable(true);
+
+                               // Allow the user to reset the label-color 
memory
+                               t = new Tunable("resetColors", "Reset colors 
for this attribute",
+                                               Tunable.BUTTON, "Reset colors",
+                                               this, null, 0);
+                               metanodeProperties.add(t);
+                               t.setImmutable(true);
+                               nodeChartEnablers.add(t);
                        }
                }
                updateSettings(true);
@@ -411,6 +434,12 @@
                        metanodeProperties.setProperty(t.getName(), chartType);
                }
 
+               t = metanodeProperties.get("chartColorType");
+               if ((t != null) && (t.valueChanged() || force)) {
+                       chartColorType = (String)getListValue(t);
+                       metanodeProperties.setProperty(t.getName(), 
chartColorType);
+               }
+
                // For each default value, get the default and set it
                t = metanodeProperties.get("stringDefaults");
                if ((t != null) && (t.valueChanged() || force)) {
@@ -582,6 +611,7 @@
         */
        public void actionPerformed(ActionEvent e) {
                String command = e.getActionCommand();
+               System.out.println("actionPerformed("+e+")");
 
                if (command.equals("done")) {
                        updateSettings(true);
@@ -644,6 +674,11 @@
                        // Update defaults
                        updateDefaultSettings();
                        setVisible(false);
+               } else if (command.equals("resetColors")) {
+                       if (nodeChartAttribute != null)
+                               
NodeCharts.resetNodeChartLabels(nodeChartAttribute);
+                       else
+                               NodeCharts.resetNodeChartLabels();
                }
        }
 
@@ -656,6 +691,7 @@
        this.useNestedNetworks = MetaNodeManager.getUseNestedNetworksDefault();
                this.metanodeOpacity = 
MetaNodeManager.getExpandedOpacityDefault();
                this.chartType = MetaNodeManager.getChartTypeDefault();
+               this.chartColorType = 
MetaNodeManager.getChartColorTypeDefault();
                this.nodeChartAttribute = 
MetaNodeManager.getNodeChartAttributeDefault();
                this.myAttributeManager = new 
AttributeManager(defaultAttributeManager);
        this.enableHandling = myAttributeManager.getEnable();
@@ -669,7 +705,7 @@
                this.dontExpandEmpty = context.getDontExpandEmpty();
        this.useNestedNetworks = context.getUseNestedNetworks();
                this.metanodeOpacity = context.getMetaNodeOpacity();
-               this.chartType = context.getChartType();
+               this.chartColorType = context.getChartColorType();
                this.nodeChartAttribute = context.getNodeChartAttribute();
                this.myAttributeManager = new 
AttributeManager(context.getAttributeManager());
                
myAttributeManager.loadHandlerMappings(Cytoscape.getCurrentNetwork(), context);
@@ -682,6 +718,7 @@
                mn.setHideMetaNode(hideMetaNode);
                mn.setMetaNodeOpacity(metanodeOpacity);
                mn.setChartType(chartType);
+               mn.setChartColorType(chartColorType);
                mn.setNodeChartAttribute(nodeChartAttribute);
                mn.setAttributeManager(myAttributeManager);
                myAttributeManager.updateAttributes(mn);
@@ -695,6 +732,7 @@
                MetaNodeManager.setExpandedOpacityDefault(metanodeOpacity);
                
MetaNodeManager.setNodeChartAttributeDefault(nodeChartAttribute);
                MetaNodeManager.setChartTypeDefault(chartType);
+               MetaNodeManager.setChartColorTypeDefault(chartColorType);
        }
 
        private void updateTunableSettings() {
@@ -713,6 +751,8 @@
                t.setValue(nodeChartAttribute);
                t = metanodeProperties.get("chartType");
                t.setValue(chartType);
+               t = metanodeProperties.get("chartColorType");
+               t.setValue(chartColorType);
 
                // Clear the tunables for overrides
        }
@@ -734,6 +774,8 @@
                        nodeChartAttribute = (String)getListValue(t);
                } else if (t.getName().equals("chartType")) {
                        chartType = (String)getListValue(t);
+               } else if (t.getName().equals("chartColorType")) {
+                       chartColorType = (String)getListValue(t);
                } else if (t.getName().equals("attributeList")) {
                        String attributeWP = (String)getListValue(t);
                        if (attributeWP == null)

Modified: 
csplugins/trunk/ucsf/scooter/metaNodePlugin2/src/metaNodePlugin2/view/NodeCharts.java
===================================================================
--- 
csplugins/trunk/ucsf/scooter/metaNodePlugin2/src/metaNodePlugin2/view/NodeCharts.java
       2011-11-22 00:16:28 UTC (rev 27545)
+++ 
csplugins/trunk/ucsf/scooter/metaNodePlugin2/src/metaNodePlugin2/view/NodeCharts.java
       2011-11-22 00:59:13 UTC (rev 27546)
@@ -81,6 +81,8 @@
 
        private static String VALUELIST = "valuelist";
        private static String LABELLIST = "labellist";
+
+       private static Map<String, List<String>> attrLabelListMap = null;
        
        /**
         * This method calculates the values and labels and draws the 
@@ -98,6 +100,12 @@
 
                if (nodeChartAttribute == null || chartType == null || 
chartType.equals(MetaNodeGroupViewer.NONODECHART)) return;
 
+               if (attrLabelListMap == null)
+                       attrLabelListMap = new HashMap<String, List<String>>();
+
+               if (!attrLabelListMap.containsKey(nodeChartAttribute))
+                       attrLabelListMap.put(nodeChartAttribute, new 
ArrayList<String>());
+
                // Get the values from all of our children
                CyGroup group = mn.getCyGroup();
                List<CyNode> nodeList = group.getNodes();
@@ -114,7 +122,7 @@
                // Create our argument map
                Map<String, Object> args = new HashMap<String, Object>();
                args.put("node", group.getGroupNode().getIdentifier());
-               args.put("colorlist", "contrasting");
+               args.put("colorlist", mn.getChartColorType());
 
                // Depending on the attribute type -- do the right thing
                switch (attributeType) {
@@ -132,6 +140,10 @@
                        default:
                }
 
+               // System.out.println("Nodechart args: ");
+               // for (String arg: args.keySet()) {
+               //      System.out.println("   "+arg+"="+args.get(arg));
+               // }
                try {
                        // First, make sure we don't have any nodechart on the 
node
                        CyCommandResult result = 
CyCommandManager.execute("nodecharts", "clear", args);
@@ -142,6 +154,15 @@
                }
        }
 
+       public static void resetNodeChartLabels() {
+               attrLabelListMap = new HashMap<String, List<String>>();
+       }
+
+       public static void resetNodeChartLabels(String attr) {
+               if (attrLabelListMap != null)
+                       attrLabelListMap.put(attr, new ArrayList<String>());
+       }
+
        /**
         * This method is used to handle numeric attribute types
         */
@@ -162,49 +183,64 @@
        /**
         * This method is used to handle string attribute types
         */
-       private static void getStringLabelsAndValues(Map<String,Object>args, 
CyGroup group, CyAttributes nodeAttributes,
-                                                     String 
nodeChartAttribute, String chartType) {
-               Map<String, Integer> valueMap = new HashMap<String, Integer>();
+       private static void getStringLabelsAndValues(Map<String,Object>args, 
CyGroup group, 
+                                                    CyAttributes 
nodeAttributes,
+                                                    String nodeChartAttribute, 
String chartType) {
+               Map<String, Integer> valueMap = 
initializeHistogram(nodeChartAttribute);
                for (CyNode node: group.getNodes()) {
                        if (nodeAttributes.hasAttribute(node.getIdentifier(), 
nodeChartAttribute)) {
                                String v = 
nodeAttributes.getAttribute(node.getIdentifier(), 
nodeChartAttribute).toString();
-                               incrementHistogram(valueMap, v);
+                               incrementHistogram(nodeChartAttribute, 
valueMap, v);
                        }
                }
 
-               addHistoArgs(valueMap, args);
+               addHistoArgs(nodeChartAttribute, valueMap, args);
        }
 
        /**
         * This method is used to handle list attribute types
         */
-       private static void getHistogramLabelsAndValues(Map<String,Object>args, 
CyGroup group, CyAttributes nodeAttributes,
-                                                     String 
nodeChartAttribute, String chartType) {
-               Map<String, Integer> valueMap = new HashMap<String, Integer>();
+       private static void getHistogramLabelsAndValues(Map<String,Object>args, 
+                                                       CyGroup group, 
CyAttributes nodeAttributes,
+                                                       String 
nodeChartAttribute, String chartType) {
+               Map<String, Integer> valueMap = 
initializeHistogram(nodeChartAttribute);
                for (CyNode node: group.getNodes()) {
                        if (nodeAttributes.hasAttribute(node.getIdentifier(), 
nodeChartAttribute)) {
                                List l = 
nodeAttributes.getListAttribute(node.getIdentifier(), nodeChartAttribute);
                                for (Object v: l) {
                                        String label = v.toString();
-                                       incrementHistogram(valueMap, label);
+                                       incrementHistogram(nodeChartAttribute, 
valueMap, label);
                                }
                        }
                }
-               addHistoArgs(valueMap, args);
+               addHistoArgs(nodeChartAttribute, valueMap, args);
        }
 
-       private static void incrementHistogram(Map<String, Integer> map, String 
value) {
-               if (!map.containsKey(value))
+       private static Map<String, Integer> initializeHistogram(String 
nodeChartAttribute) {
+               Map<String, Integer> histo = new HashMap<String, Integer>();
+               for (String s: attrLabelListMap.get(nodeChartAttribute)) {
+                       // System.out.println("Initializing value for "+s+" to 
0");
+                       histo.put(s, 0);
+               }
+               return histo;
+       }
+
+       private static void incrementHistogram(String nodeChartAttribute, 
+                                              Map<String, Integer> map, String 
value) {
+               if (!map.containsKey(value)) {
                        map.put(value, new Integer(1));
-               else {
+                       // System.out.println("Adding "+value+" to value map");
+                       attrLabelListMap.get(nodeChartAttribute).add(value);
+               } else {
                        Integer count = map.get(value);
                        map.put(value, count+1);
                }
        }
 
-       private static void addHistoArgs(Map<String, Integer> map, Map<String, 
Object> args) {
+       private static void addHistoArgs(String nodeChartAttribute,
+                                        Map<String, Integer> map, Map<String, 
Object> args) {
                // Now, we've got the histogram, create the appropriate arrays
-               List<String>labels = new ArrayList<String>(map.keySet());
+               List<String>labels = attrLabelListMap.get(nodeChartAttribute);
                List<Integer>values = new ArrayList<Integer>();
                for (String label: labels) {
                        values.add(map.get(label));

-- 
You received this message because you are subscribed to the Google Groups 
"cytoscape-cvs" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/cytoscape-cvs?hl=en.

Reply via email to