Author: scooter
Date: 2010-09-07 11:30:28 -0700 (Tue, 07 Sep 2010)
New Revision: 21723

Added:
   csplugins/trunk/ucsf/scooter/nodeCharts/examples/bar2.com
Modified:
   
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/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
Log:
Added up:color,down:color handling and fixed up labels on bars.



Added: csplugins/trunk/ucsf/scooter/nodeCharts/examples/bar2.com
===================================================================
--- csplugins/trunk/ucsf/scooter/nodeCharts/examples/bar2.com                   
        (rev 0)
+++ csplugins/trunk/ucsf/scooter/nodeCharts/examples/bar2.com   2010-09-07 
18:30:28 UTC (rev 21723)
@@ -0,0 +1,3 @@
+nodecharts bar nodelist="all" attributelist="gal1RGexp,gal4RGexp,gal80Rexp" 
colorlist="up:cyan,down:yellow"
+
+network view update

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-09-07 17:29:22 UTC (rev 21722)
+++ 
csplugins/trunk/ucsf/scooter/nodeCharts/src/main/java/nodeCharts/command/ValueUtils.java
    2010-09-07 18:30:28 UTC (rev 21723)
@@ -207,12 +207,16 @@
                return result;
        }
 
-       private static final String RANDOM = "random";
        private static final String     CONTRASTING = "contrasting";
+       private static final String     DOWN = "down:";
+       private static final String     MODULATED = "modulated";
        private static final String     RAINBOW = "rainbow";
-       private static final String     MODULATED = "modulated";
+       private static final String RANDOM = "random";
+       private static final String     UP = "up:";
 
-       public static List<Color> convertInputToColor(Object input, int 
nColors) throws CyCommandException {
+       public static List<Color> convertInputToColor(Object input, 
List<Double>values) throws CyCommandException {
+               int nColors = values.size();
+
                if (input == null) {
                        // give the default: contrasting colors
                        return generateContrastingColors(nColors);
@@ -229,7 +233,13 @@
                        String inputString = (String) input;
                        // See if we have a csv
                        String [] colorArray = inputString.split(",");
-                       if (colorArray.length > 1)
+                       // Look for up/down special case
+                       if (colorArray.length == 2 &&
+                           (colorArray[0].toLowerCase().startsWith(UP) ||
+                            colorArray[1].toLowerCase().startsWith(DOWN))) {
+                               return parseUpDownColor(colorArray, values);
+                               
+                       } else if (colorArray.length > 1)
                                return parseColorList(colorArray);
                        else
                                return parseColorKeyword(inputString.trim(), 
nColors);
@@ -237,6 +247,28 @@
                        throw new CyCommandException("unknown type for color 
list");
        }
 
+       private static List<Color> parseUpDownColor(String[] colorArray, 
List<Double>values) throws CyCommandException {
+               String [] colors = new String[2];
+               if (colorArray[0].toLowerCase().startsWith(UP)) {
+                       colors[0] = colorArray[0].substring(UP.length());
+                       colors[1] = colorArray[1].substring(DOWN.length());
+               } else {
+                       colors[1] = colorArray[0].substring(DOWN.length());
+                       colors[0] = colorArray[1].substring(UP.length());
+               }
+               List<Color> upDownColors = parseColorList(colors);
+               Color up = upDownColors.get(0);
+               Color down = upDownColors.get(1);
+               List<Color> results = new ArrayList<Color>(values.size());
+               for (Double v: values) {
+                       if (v < 0.0) 
+                               results.add(down);
+                       else
+                               results.add(up);
+               }
+               return results;
+       }
+
        private static List<Color> parseColorKeyword(String input, int nColors) 
throws CyCommandException {
                if (input.equals(RANDOM))
                        return generateRandomColors(nColors);

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-09-07 17:29:22 UTC (rev 21722)
+++ 
csplugins/trunk/ucsf/scooter/nodeCharts/src/main/java/nodeCharts/view/BarChart.java
 2010-09-07 18:30:28 UTC (rev 21723)
@@ -56,8 +56,7 @@
                        CyNetworkView view, Object position) throws 
CyCommandException {
        
                // Get our colors
-               List<Color> colors = 
ValueUtils.convertInputToColor(args.get(COLORS),
-                               labels.size());
+               List<Color> colors = 
ValueUtils.convertInputToColor(args.get(COLORS), values);
                int separation = 0;
                Object separationObj = args.get(SEPARATION);
                if (separationObj instanceof String)
@@ -137,12 +136,12 @@
                        
                        
                        // add labels
-                       TextAlignment tAlign = 
TextAlignment.ALIGN_CENTER_BOTTOM;
+                       TextAlignment tAlign = TextAlignment.ALIGN_LEFT;
                        
                        // Now, create the label.  Put the label on the outer 
edge of the circle.
-                       Point2D labelPosition = new 
Point2D.Double(bbox.getMaxX(), bbox.getMaxY());
+                       Point2D labelPosition = new 
Point2D.Double(drect.getCenterX(), drect.getMaxY());
                        // vals[1] = ViewUtils.getLabelCustomGraphic(label, 
null, 0, 0, labelPosition, tAlign, view);
-                       Shape textShape = 
ViewUtils.getLabelShape(labels.get(i), null, 0, 0, labelPosition, tAlign, view);
+                       Shape textShape = 
ViewUtils.getLabelShape(labels.get(i), null, 0, 0, labelPosition, tAlign, 70.0, 
view);
 
                        // Combine the shapes
                        Area textArea = new Area(textShape);
@@ -151,7 +150,7 @@
 
 //                     vals[1] = new CustomGraphic(textArea, new 
DefaultPaintFactory(Color.BLACK));
                        CustomGraphic c1  = new CustomGraphic(textArea, new 
DefaultPaintFactory(Color.BLACK));
-                       cgList.add(c);
+                       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-09-07 17:29:22 UTC (rev 21722)
+++ 
csplugins/trunk/ucsf/scooter/nodeCharts/src/main/java/nodeCharts/view/LineChart.java
        2010-09-07 18:30:28 UTC (rev 21723)
@@ -45,8 +45,7 @@
                        CyNetworkView view, Object position) throws 
CyCommandException {
                // Get our color
                // Get our colors
-               List<Color> colors = 
ValueUtils.convertInputToColor(args.get(COLORS),
-                               labels.size());
+               List<Color> colors = 
ValueUtils.convertInputToColor(args.get(COLORS), values);
 
                // Sanity check
                if (labels.size() != values.size() || labels.size() != 
colors.size())

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-09-07 17:29:22 UTC (rev 21722)
+++ 
csplugins/trunk/ucsf/scooter/nodeCharts/src/main/java/nodeCharts/view/PieChart.java
 2010-09-07 18:30:28 UTC (rev 21723)
@@ -90,7 +90,7 @@
                                                     CyNode node, CyNetworkView 
view, Object position) 
                                                                                
       throws CyCommandException {
                // Get our colors
-               List<Color> colors = 
ValueUtils.convertInputToColor(args.get(COLORS), labels.size());
+               List<Color> colors = 
ValueUtils.convertInputToColor(args.get(COLORS), values);
 
                // Convert our data from values to increments
                values= convertData(values);
@@ -160,7 +160,7 @@
                // Now, create 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);
-               Shape textShape = ViewUtils.getLabelShape(label, null, 0, 0, 
labelPosition, tAlign, view);
+               Shape textShape = ViewUtils.getLabelShape(label, null, 0, 0, 
labelPosition, tAlign, 0.0, view);
 
                // Draw a line between our label and the slice
                labelPosition = getLabelPosition(bbox, midpointAngle, 1.0);
@@ -180,8 +180,8 @@
        private Point2D getLabelPosition(Rectangle2D bbox, double angle, double 
scale) {
                double midpoint = Math.toRadians(360.0-angle);
                double length = bbox.getWidth()/2; // Assumes width = height!
-               double x = Math.cos(midpoint)*length*scale;
-               double y = Math.sin(midpoint)*length*scale;
+               double x = Math.cos(midpoint)*length*scale + 
(bbox.getX()+bbox.getWidth()/2);
+               double y = Math.sin(midpoint)*length*scale + 
(bbox.getY()+bbox.getHeight()/2);
 
                // System.out.println("getLabelPosition: bbox = "+bbox+", 
midpoint = "+angle+" arcpoint = ("+x+","+y+")");
 

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-09-07 17:29:22 UTC (rev 21722)
+++ 
csplugins/trunk/ucsf/scooter/nodeCharts/src/main/java/nodeCharts/view/StripeChart.java
      2010-09-07 18:30:28 UTC (rev 21723)
@@ -83,10 +83,8 @@
        public List<CustomGraphic> getCustomGraphics(Map<String, Object> args, 
List<Double> values, List<String> labels, CyNode node,
                        CyNetworkView view, Object position) throws 
CyCommandException {
                // Get our colors
-               List<Color> colors = 
ValueUtils.convertInputToColor(args.get(COLORS),
-                               args.size());
+               List<Color> colors = 
ValueUtils.convertInputToColor(args.get(COLORS), values);
 
-
                int nStripes = colors.size();
                
                List<CustomGraphic> cgList = new ArrayList<CustomGraphic>();

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-09-07 17:29:22 UTC (rev 21722)
+++ 
csplugins/trunk/ucsf/scooter/nodeCharts/src/main/java/nodeCharts/view/ViewUtils.java
        2010-09-07 18:30:28 UTC (rev 21723)
@@ -180,10 +180,10 @@
        private static final int DEFAULT_STYLE=Font.PLAIN;
        private static final int DEFAULT_SIZE=8;
 
-       public static enum TextAlignment {ALIGN_LEFT, ALIGN_CENTER_TOP, 
ALIGN_RIGHT, ALIGN_CENTER_BOTTOM};
+       public static enum TextAlignment {ALIGN_LEFT, ALIGN_CENTER_TOP, 
ALIGN_RIGHT, ALIGN_CENTER_BOTTOM, ALIGN_MIDDLE};
 
        public static Shape getLabelShape(String label, String fontName, int 
fontStyle, int fontSize,
-                                         Point2D position, TextAlignment 
tAlign, CyNetworkView view) {
+                                         Point2D position, TextAlignment 
tAlign, double rotation, CyNetworkView view) {
 
 
                if (fontName == null) fontName = DEFAULT_FONT;
@@ -233,6 +233,10 @@
                        textStartX = pointX;
                        textStartY = pointY + textHeight/2;
                        break;
+               case ALIGN_MIDDLE:
+                       textStartX = pointX - textWidth/2;;
+                       textStartY = pointY + textHeight/2;
+                       break;
                default:
                        // System.out.println("  Align = "+tAlign);
                }
@@ -245,6 +249,8 @@
                // Use the bounding box to create an Affine transform.  We may 
need to scale the font
                // shape if things are too cramped, but not beneath some 
arbitrary minimum
                AffineTransform trans = new AffineTransform();
+               if (rotation != 0.0)
+                       trans.rotate(Math.toRadians(rotation), pointX, pointY);
                trans.translate(textStartX, textStartY);
 
                // System.out.println("  Transform: "+trans);

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