Author: scooter
Date: 2010-12-21 13:04:24 -0800 (Tue, 21 Dec 2010)
New Revision: 23259

Modified:
   csplugins/trunk/ucsf/scooter/nodeCharts/pom.xml
   
csplugins/trunk/ucsf/scooter/nodeCharts/src/main/java/nodeCharts/command/NodeChartCommandHandler.java
   
csplugins/trunk/ucsf/scooter/nodeCharts/src/main/java/nodeCharts/command/ValueUtils.java
   
csplugins/trunk/ucsf/scooter/nodeCharts/src/main/java/nodeCharts/view/BarChart.java
   
csplugins/trunk/ucsf/scooter/nodeCharts/src/main/java/nodeCharts/view/LineChart.java
   
csplugins/trunk/ucsf/scooter/nodeCharts/src/main/java/nodeCharts/view/NodeChartViewer.java
   
csplugins/trunk/ucsf/scooter/nodeCharts/src/main/java/nodeCharts/view/PieChart.java
   
csplugins/trunk/ucsf/scooter/nodeCharts/src/main/java/nodeCharts/view/StripeChart.java
   
csplugins/trunk/ucsf/scooter/nodeCharts/src/main/java/nodeCharts/view/ViewUtils.java
   
csplugins/trunk/ucsf/scooter/nodeCharts/src/main/resources/nodeCharts/plugin.props
Log:
0.93: added ability to skip labels and a scale argument to allow for the
graphics to be larger or smaller than the default 90% of the node size


Modified: csplugins/trunk/ucsf/scooter/nodeCharts/pom.xml
===================================================================
--- csplugins/trunk/ucsf/scooter/nodeCharts/pom.xml     2010-12-21 20:38:00 UTC 
(rev 23258)
+++ csplugins/trunk/ucsf/scooter/nodeCharts/pom.xml     2010-12-21 21:04:24 UTC 
(rev 23259)
@@ -14,7 +14,7 @@
   <groupId>cytoscape.csplugins</groupId>
   <artifactId>nodeCharts</artifactId>
   <packaging>jar</packaging>
-  <version>0.91</version>
+  <version>0.93</version>
 
   <name>Node Charts Plugin</name>
 

Modified: 
csplugins/trunk/ucsf/scooter/nodeCharts/src/main/java/nodeCharts/command/NodeChartCommandHandler.java
===================================================================
--- 
csplugins/trunk/ucsf/scooter/nodeCharts/src/main/java/nodeCharts/command/NodeChartCommandHandler.java
       2010-12-21 20:38:00 UTC (rev 23258)
+++ 
csplugins/trunk/ucsf/scooter/nodeCharts/src/main/java/nodeCharts/command/NodeChartCommandHandler.java
       2010-12-21 21:04:24 UTC (rev 23259)
@@ -81,6 +81,7 @@
        public static final String NODE = "node";
        public static final String NODELIST = "nodelist";
        public static final String POSITION = "position";
+       public static final String SCALE = "scale";
        public static final String SELECTED = "selected";
        public static final String VALUES = "valuelist";
 
@@ -168,9 +169,6 @@
                if (args.containsKey(VALUES) && args.containsKey(ATTRIBUTELIST))
                        throw new CyCommandException("nodecharts can't handle 
both attributeslist and valuelist");
 
-               if (!args.containsKey(LABELS) && 
!args.containsKey(ATTRIBUTELIST))
-                       throw new CyCommandException("nodecharts requires 
either a labels list or an attribute list");
-
                // Now get our actual viewer
                NodeChartViewer viewer = viewerMap.get(command);
 
@@ -187,6 +185,15 @@
                        labels = ValueUtils.getStringList(args.get(LABELS));
                }
 
+               double scale = 0.90;
+               if (args.containsKey(SCALE)) {
+                       try {
+                               scale = 
ValueUtils.getDoubleValue(args.get(SCALE));
+                       } catch (NumberFormatException e) {
+                               throw new CyCommandException("Can't convert 
"+args.get(SCALE).toString()+" to double");
+                       }
+               }
+
                // Get our position
                Object pos = null;
                if (args.containsKey(POSITION)) {
@@ -203,7 +210,7 @@
                        if (args.containsKey(ATTRIBUTELIST))
                                values = ValueUtils.getDataFromAttributes 
(node, args.get(ATTRIBUTELIST), labels);
 
-                       List<CustomGraphic> cgList = 
viewer.getCustomGraphics(args, values, labels, node, view, pos);
+                       List<CustomGraphic> cgList = 
viewer.getCustomGraphics(args, values, labels, node, view, pos, scale);
                        ViewUtils.addCustomGraphics(cgList, node, view);
                        result.addMessage("Created "+viewer.getName()+" chart 
for node "+node.getIdentifier());
                        // If we succeeded, serialize the command and save it 
in the appropriate nodeAttribute
@@ -223,6 +230,7 @@
                addArgument(viewer.getName(), NODELIST);
                addArgument(viewer.getName(), POSITION);
                addArgument(viewer.getName(), VALUES);
+               addArgument(viewer.getName(), SCALE, "0.90");
 
                // Get the specific commands handled by the viewer
                Map<String,String> args = viewer.getOptions();

Modified: 
csplugins/trunk/ucsf/scooter/nodeCharts/src/main/java/nodeCharts/command/ValueUtils.java
===================================================================
--- 
csplugins/trunk/ucsf/scooter/nodeCharts/src/main/java/nodeCharts/command/ValueUtils.java
    2010-12-21 20:38:00 UTC (rev 23258)
+++ 
csplugins/trunk/ucsf/scooter/nodeCharts/src/main/java/nodeCharts/command/ValueUtils.java
    2010-12-21 21:04:24 UTC (rev 23259)
@@ -190,6 +190,16 @@
                return new ArrayList<String>();
        }
 
+       public static double getDoubleValue(Object input) throws 
NumberFormatException {
+               if (input instanceof Double)
+                       return ((Double)input).doubleValue();
+               else if (input instanceof Integer)
+                       return ((Integer)input).doubleValue();
+               else if (input instanceof String)
+                       return Double.parseDouble((String)input);
+               throw new NumberFormatException("input can not be converted to 
double");
+       }
+
        /**
         * Takes a map of objects indexed by a string keyword and returns
         * a map of strings indexed by that keyword.  This involves figuring

Modified: 
csplugins/trunk/ucsf/scooter/nodeCharts/src/main/java/nodeCharts/view/BarChart.java
===================================================================
--- 
csplugins/trunk/ucsf/scooter/nodeCharts/src/main/java/nodeCharts/view/BarChart.java
 2010-12-21 20:38:00 UTC (rev 23258)
+++ 
csplugins/trunk/ucsf/scooter/nodeCharts/src/main/java/nodeCharts/view/BarChart.java
 2010-12-21 21:04:24 UTC (rev 23259)
@@ -53,7 +53,7 @@
 
        public List<CustomGraphic> getCustomGraphics(Map<String, Object> args,
                        List<Double> values, List<String> labels, CyNode node,
-                       CyNetworkView view, Object position) throws 
CyCommandException {
+                       CyNetworkView view, Object position, double scale) 
throws CyCommandException {
        
                // Get our colors
                List<Color> colors = 
ValueUtils.convertInputToColor(args.get(COLORS), values);
@@ -68,7 +68,9 @@
                }
 
                // Sanity check
-               if (labels.size() != values.size() || labels.size() != 
colors.size())
+               if (labels != null && labels.size() > 0 && 
+                   (labels.size() != values.size() ||
+                    labels.size() != colors.size()))
                        throw new CyCommandException("number of labels (" + 
labels.size()
                                        + "), values (" + values.size() + "), 
and colors ("
                                        + colors.size() + ") don't match");
@@ -78,7 +80,7 @@
 
                // We need to get our bounding box in order to scale our graphic
                // properly
-               Rectangle2D bbox = ViewUtils.getNodeBoundingBox(node, view, 
position);
+               Rectangle2D bbox = ViewUtils.getNodeBoundingBox(node, view, 
position, scale);
                double height = bbox.getHeight();
                double width = bbox.getWidth();
                
@@ -138,25 +140,26 @@
                        cgList.add(c);
                }
 
-               // Now, create the labels.  We want to do this here so we can 
adjust the label for the slice
-               for (int i = 0; i < values.size(); i++) {
-                       
-                       // add labels
-                       TextAlignment tAlign = TextAlignment.ALIGN_LEFT;
-                       
-                       // Now, create the label.  Put the label on the outer 
edge of the circle.
-                       Point2D labelPosition = new 
Point2D.Double(barArray[i].getCenterX(), maxY);
-                       // vals[1] = ViewUtils.getLabelCustomGraphic(label, 
null, 0, 0, labelPosition, tAlign, view);
-                       Shape textShape = 
ViewUtils.getLabelShape(labels.get(i), null, 0, 0, view);
-
-                       double maxHeight = barArray[i].getWidth();
-                       textShape = ViewUtils.positionLabel(textShape, 
labelPosition, tAlign, maxHeight, 0.0, 70.0);
-                       if (textShape == null) continue;
-
-//                     vals[1] = new CustomGraphic(textArea, new 
DefaultPaintFactory(Color.BLACK));
-                       CustomGraphic c1  = new CustomGraphic(textShape, new 
DefaultPaintFactory(Color.BLACK));
-                       cgList.add(c1);
-
+               if (labels != null && labels.size() > 0) {
+                       // Now, create the labels.  We want to do this here so 
we can adjust the label for the slice
+                       for (int i = 0; i < values.size(); i++) {
+                               
+                               // add labels
+                               TextAlignment tAlign = TextAlignment.ALIGN_LEFT;
+                               
+                               // Now, create the label.  Put the label on the 
outer edge of the circle.
+                               Point2D labelPosition = new 
Point2D.Double(barArray[i].getCenterX(), maxY);
+                               // vals[1] = 
ViewUtils.getLabelCustomGraphic(label, null, 0, 0, labelPosition, tAlign, view);
+                               Shape textShape = 
ViewUtils.getLabelShape(labels.get(i), null, 0, 0, view);
+       
+                               double maxHeight = barArray[i].getWidth();
+                               textShape = ViewUtils.positionLabel(textShape, 
labelPosition, tAlign, maxHeight, 0.0, 70.0);
+                               if (textShape == null) continue;
+       
+       //                      vals[1] = new CustomGraphic(textArea, new 
DefaultPaintFactory(Color.BLACK));
+                               CustomGraphic c1  = new 
CustomGraphic(textShape, new DefaultPaintFactory(Color.BLACK));
+                               cgList.add(c1);
+                       }
                }
                return cgList;
        }

Modified: 
csplugins/trunk/ucsf/scooter/nodeCharts/src/main/java/nodeCharts/view/LineChart.java
===================================================================
--- 
csplugins/trunk/ucsf/scooter/nodeCharts/src/main/java/nodeCharts/view/LineChart.java
        2010-12-21 20:38:00 UTC (rev 23258)
+++ 
csplugins/trunk/ucsf/scooter/nodeCharts/src/main/java/nodeCharts/view/LineChart.java
        2010-12-21 21:04:24 UTC (rev 23259)
@@ -42,13 +42,15 @@
 
        public List<CustomGraphic> getCustomGraphics(Map<String, Object> args,
                        List<Double> values, List<String> labels, CyNode node,
-                       CyNetworkView view, Object position) throws 
CyCommandException {
+                       CyNetworkView view, Object position, double scale) 
throws CyCommandException {
                // Get our color
                // Get our colors
                List<Color> colors = 
ValueUtils.convertInputToColor(args.get(COLORS), values);
 
                // Sanity check
-               if (labels.size() != values.size() || labels.size() != 
colors.size())
+               if (labels != null && labels.size() > 0 && 
+                   (labels.size() != values.size() ||
+                    labels.size() != colors.size()))
                        throw new CyCommandException("number of labels (" + 
labels.size()
                                        + "), values (" + values.size() + "), 
and colors ("
                                        + colors.size() + ") don't match");
@@ -58,7 +60,7 @@
 
                // We need to get our bounding box in order to scale our graphic
                // properly
-               Rectangle2D bbox = ViewUtils.getNodeBoundingBox(node, view, 
position);
+               Rectangle2D bbox = ViewUtils.getNodeBoundingBox(node, view, 
position, scale);
                double height = bbox.getHeight();
                double width = bbox.getWidth();
                double x = bbox.getX();

Modified: 
csplugins/trunk/ucsf/scooter/nodeCharts/src/main/java/nodeCharts/view/NodeChartViewer.java
===================================================================
--- 
csplugins/trunk/ucsf/scooter/nodeCharts/src/main/java/nodeCharts/view/NodeChartViewer.java
  2010-12-21 20:38:00 UTC (rev 23258)
+++ 
csplugins/trunk/ucsf/scooter/nodeCharts/src/main/java/nodeCharts/view/NodeChartViewer.java
  2010-12-21 21:04:24 UTC (rev 23259)
@@ -55,7 +55,7 @@
        public Map<String,String> getOptions();
 
        public List<CustomGraphic> getCustomGraphics(Map<String,Object>args, 
List<Double> values, List<String> labels,
-                                                    CyNode node, CyNetworkView 
view, Object position) 
+                                                    CyNode node, CyNetworkView 
view, Object position, double scale) 
                                                                                
     throws CyCommandException;
 
 }

Modified: 
csplugins/trunk/ucsf/scooter/nodeCharts/src/main/java/nodeCharts/view/PieChart.java
===================================================================
--- 
csplugins/trunk/ucsf/scooter/nodeCharts/src/main/java/nodeCharts/view/PieChart.java
 2010-12-21 20:38:00 UTC (rev 23258)
+++ 
csplugins/trunk/ucsf/scooter/nodeCharts/src/main/java/nodeCharts/view/PieChart.java
 2010-12-21 21:04:24 UTC (rev 23259)
@@ -89,7 +89,7 @@
        }
 
        public List<CustomGraphic> getCustomGraphics(Map<String, Object>args, 
List<Double> values, List<String> labels,
-                                                    CyNode node, CyNetworkView 
view, Object position) 
+                                                    CyNode node, CyNetworkView 
view, Object position, double scale) 
                                                                                
       throws CyCommandException {
                // Get our colors
                List<Color> colors = 
ValueUtils.convertInputToColor(args.get(COLORS), values);
@@ -98,16 +98,10 @@
                double arcStart = 0.0;
                Object startObj = args.get(ARCSTART);
                if (startObj != null) {
-                       if (startObj instanceof Double)
-                               arcStart = ((Double)startObj).doubleValue();
-                       else if (startObj instanceof Integer)
-                               arcStart = ((Integer)startObj).doubleValue();
-                       else if (startObj instanceof String) {
-                               try {
-                                       arcStart = 
Double.parseDouble((String)startObj);
-                               } catch (NumberFormatException e) {
-                                       throw new CyCommandException("arcstart 
must be a number: "+e.getMessage());
-                               }
+                       try {
+                               arcStart = ValueUtils.getDoubleValue(startObj);
+                       } catch (NumberFormatException e) {
+                               throw new CyCommandException("arcstart must be 
a number: "+e.getMessage());
                        }
                }
 
@@ -115,29 +109,34 @@
                values= convertData(values);
 
                // Sanity check
-               if (labels.size() != values.size() ||
-                   labels.size() != colors.size())
+               if (labels != null && labels.size() > 0 && 
+                   (labels.size() != values.size() ||
+                    labels.size() != colors.size()))
                        throw new CyCommandException("number of labels 
("+labels.size()+"), values ("+
                                                     values.size()+"), and 
colors ("+colors.size()+") don't match");
 
-               int nSlices = labels.size();
+               int nSlices = values.size();
                List<CustomGraphic> cgList = new ArrayList<CustomGraphic>();
                List<CustomGraphic> labelList = new ArrayList<CustomGraphic>();
 
                // We need to get our bounding box in order to scale our 
graphic properly
-               Rectangle2D bbox = ViewUtils.getNodeBoundingBox(node, view, 
position);
+               Rectangle2D bbox = ViewUtils.getNodeBoundingBox(node, view, 
position, scale);
 
                // System.out.println("Node: "+node);
 
                for (int slice = 0; slice < nSlices; slice++) {
-                       CustomGraphic[] cg = createSlice(bbox, arcStart, 
values.get(slice), labels.get(slice), colors.get(slice), view);
+                       String label = null;
+                       if (labels != null && labels.size() > 0)
+                               label = labels.get(slice);
+                       CustomGraphic[] cg = createSlice(bbox, arcStart, 
values.get(slice), label, colors.get(slice), view);
                        cgList.add(cg[0]);
                        if (cg[1] != null)
                                labelList.add(cg[1]);
                        arcStart += values.get(slice).doubleValue();
                }
 
-               cgList.addAll(labelList);
+               if (labelList != null && labelList.size() > 0)
+                       cgList.addAll(labelList);
                return cgList;
        }
 
@@ -177,29 +176,28 @@
 
                TextAlignment tAlign = getLabelAlignment(midpointAngle);
                
-               // create the label
-               Shape textShape = ViewUtils.getLabelShape(label, null, 0, 0, 
view);
+               vals[1] = null;
+               if (label != null) {
+                       // create the label
+                       Shape textShape = ViewUtils.getLabelShape(label, null, 
0, 0, view);
 
-               // Now, position the label.  Put the label on the outer edge of 
the circle.
-               Point2D labelPosition = getLabelPosition(bbox, midpointAngle, 
1.4);
-               // vals[1] = ViewUtils.getLabelCustomGraphic(label, null, 0, 0, 
labelPosition, tAlign, view);
-               textShape = ViewUtils.positionLabel(textShape, labelPosition, 
tAlign, 0.0, 0.0, 0.0);
-               if (textShape == null) {
-                       vals[1] = null;
-                       return vals;
-               }
+                       // Now, position the label.  Put the label on the outer 
edge of the circle.
+                       Point2D labelPosition = getLabelPosition(bbox, 
midpointAngle, 1.4);
+                       // vals[1] = ViewUtils.getLabelCustomGraphic(label, 
null, 0, 0, labelPosition, tAlign, view);
+                       textShape = ViewUtils.positionLabel(textShape, 
labelPosition, tAlign, 0.0, 0.0, 0.0);
+                       if (textShape != null) {
+                               // Draw a line between our label and the slice
+                               labelPosition = getLabelPosition(bbox, 
midpointAngle, 1.0);
+                               Shape labelLine = 
ViewUtils.getLabelLine(textShape.getBounds2D(), labelPosition, tAlign);
 
-               // Draw a line between our label and the slice
-               labelPosition = getLabelPosition(bbox, midpointAngle, 1.0);
-               Shape labelLine = 
ViewUtils.getLabelLine(textShape.getBounds2D(), labelPosition, tAlign);
+                               // Combine the shapes
+                               Area textArea = new Area(textShape);
+                               textArea.add(new Area(labelLine));
 
-               // Combine the shapes
-               Area textArea = new Area(textShape);
-               textArea.add(new Area(labelLine));
+                               vals[1] = new CustomGraphic(textArea, new 
DefaultPaintFactory(Color.BLACK));
+                       }
+               }
 
-
-               vals[1] = new CustomGraphic(textArea, new 
DefaultPaintFactory(Color.BLACK));
-
                return vals;
        }
 

Modified: 
csplugins/trunk/ucsf/scooter/nodeCharts/src/main/java/nodeCharts/view/StripeChart.java
===================================================================
--- 
csplugins/trunk/ucsf/scooter/nodeCharts/src/main/java/nodeCharts/view/StripeChart.java
      2010-12-21 20:38:00 UTC (rev 23258)
+++ 
csplugins/trunk/ucsf/scooter/nodeCharts/src/main/java/nodeCharts/view/StripeChart.java
      2010-12-21 21:04:24 UTC (rev 23259)
@@ -81,7 +81,7 @@
        }
 
        public List<CustomGraphic> getCustomGraphics(Map<String, Object> args, 
List<Double> values, List<String> labels, CyNode node,
-                       CyNetworkView view, Object position) throws 
CyCommandException {
+                       CyNetworkView view, Object position, double scale) 
throws CyCommandException {
                // Get our colors
                List<Color> colors = 
ValueUtils.convertInputToColor(args.get(COLORS), values);
 
@@ -91,7 +91,7 @@
 
                // We need to get our bounding box in order to scale our graphic
                // properly
-               Rectangle2D bbox = ViewUtils.getNodeBoundingBox(node, view, 
position);
+               Rectangle2D bbox = ViewUtils.getNodeBoundingBox(node, view, 
position, scale);
 
                // System.out.println("Node: "+node);
 

Modified: 
csplugins/trunk/ucsf/scooter/nodeCharts/src/main/java/nodeCharts/view/ViewUtils.java
===================================================================
--- 
csplugins/trunk/ucsf/scooter/nodeCharts/src/main/java/nodeCharts/view/ViewUtils.java
        2010-12-21 20:38:00 UTC (rev 23258)
+++ 
csplugins/trunk/ucsf/scooter/nodeCharts/src/main/java/nodeCharts/view/ViewUtils.java
        2010-12-21 21:04:24 UTC (rev 23259)
@@ -135,12 +135,12 @@
                }
        }
 
-       public static Rectangle2D getNodeBoundingBox(CyNode node, CyNetworkView 
view, Object position) {
+       public static Rectangle2D getNodeBoundingBox(CyNode node, CyNetworkView 
view, Object position, double nodePortion) {
                DNodeView nView = (DNodeView)view.getNodeView(node);
 
                // Get the affine transform 
-               double height = (nView.getHeight()-nView.getBorderWidth())*0.90;
-               double width = (nView.getWidth()-nView.getBorderWidth())*0.90;
+               double height = 
(nView.getHeight()-nView.getBorderWidth())*nodePortion;
+               double width = 
(nView.getWidth()-nView.getBorderWidth())*nodePortion;
 
                // Create the bounding box.
                Rectangle2D.Double bbox = new Rectangle2D.Double(-width/2, 
-height/2, width, height);

Modified: 
csplugins/trunk/ucsf/scooter/nodeCharts/src/main/resources/nodeCharts/plugin.props
===================================================================
--- 
csplugins/trunk/ucsf/scooter/nodeCharts/src/main/resources/nodeCharts/plugin.props
  2010-12-21 20:38:00 UTC (rev 23258)
+++ 
csplugins/trunk/ucsf/scooter/nodeCharts/src/main/resources/nodeCharts/plugin.props
  2010-12-21 21:04:24 UTC (rev 23259)
@@ -11,7 +11,7 @@
 pluginDescription=Paint a chart on a node
 
 # Plugin version number, this must be two numbers separated by a decimlal.  
Ex. 0.2, 14.03
-pluginVersion=0.91
+pluginVersion=0.93
 
 # Compatible Cytoscape version
 cytoscapeVersion=2.8
@@ -29,6 +29,6 @@
 projectURL=http://www.rbvi.ucsf.edu/Research/cytoscape/
 
 # Date this plugin/plugin version was released
-releaseDate=December 17, 2010
+releaseDate=December 21, 2010
 
 # -- The following properties should be set ONLY BY CORE PLUGINS -- #

-- 
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