Author: scooter
Date: 2012-10-01 15:38:56 -0700 (Mon, 01 Oct 2012)
New Revision: 30567

Added:
   
csplugins/trunk/ucsf/scooter/enhancedcg/src/main/java/edu/ucsf/rbvi/internal/charts/heatstrip/
   
csplugins/trunk/ucsf/scooter/enhancedcg/src/main/java/edu/ucsf/rbvi/internal/charts/heatstrip/HeatStripChart.java
   
csplugins/trunk/ucsf/scooter/enhancedcg/src/main/java/edu/ucsf/rbvi/internal/charts/heatstrip/HeatStripFactory.java
   
csplugins/trunk/ucsf/scooter/enhancedcg/src/main/java/edu/ucsf/rbvi/internal/charts/heatstrip/HeatStripLayer.java
   
csplugins/trunk/ucsf/scooter/enhancedcg/src/main/java/edu/ucsf/rbvi/internal/charts/stripe/
   
csplugins/trunk/ucsf/scooter/enhancedcg/src/main/java/edu/ucsf/rbvi/internal/charts/stripe/StripeChart.java
   
csplugins/trunk/ucsf/scooter/enhancedcg/src/main/java/edu/ucsf/rbvi/internal/charts/stripe/StripeChartFactory.java
   
csplugins/trunk/ucsf/scooter/enhancedcg/src/main/java/edu/ucsf/rbvi/internal/charts/stripe/StripeLayer.java
Modified:
   
csplugins/trunk/ucsf/scooter/enhancedcg/src/main/java/edu/ucsf/rbvi/internal/CyActivator.java
   
csplugins/trunk/ucsf/scooter/enhancedcg/src/main/java/edu/ucsf/rbvi/internal/charts/bar/BarLayer.java
Log:
Added heatstrip and stripe charts


Modified: 
csplugins/trunk/ucsf/scooter/enhancedcg/src/main/java/edu/ucsf/rbvi/internal/CyActivator.java
===================================================================
--- 
csplugins/trunk/ucsf/scooter/enhancedcg/src/main/java/edu/ucsf/rbvi/internal/CyActivator.java
       2012-10-01 22:25:52 UTC (rev 30566)
+++ 
csplugins/trunk/ucsf/scooter/enhancedcg/src/main/java/edu/ucsf/rbvi/internal/CyActivator.java
       2012-10-01 22:38:56 UTC (rev 30567)
@@ -4,6 +4,9 @@
 
 import org.osgi.framework.BundleContext;
 
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
 import org.cytoscape.application.CyApplicationManager;
 import org.cytoscape.service.util.AbstractCyActivator;
 import org.cytoscape.view.presentation.customgraphics.CyCustomGraphicsFactory;
@@ -11,11 +14,14 @@
 import 
edu.ucsf.rbvi.enhancedcg.internal.gradients.linear.LinearGradientCGFactory;
 import 
edu.ucsf.rbvi.enhancedcg.internal.gradients.radial.RadialGradientCGFactory;
 import edu.ucsf.rbvi.enhancedcg.internal.charts.bar.BarChartFactory;
+import edu.ucsf.rbvi.enhancedcg.internal.charts.heatstrip.HeatStripFactory;
 import edu.ucsf.rbvi.enhancedcg.internal.charts.line.LineChartFactory;
 import edu.ucsf.rbvi.enhancedcg.internal.charts.pie.PieChartFactory;
+import edu.ucsf.rbvi.enhancedcg.internal.charts.stripe.StripeChartFactory;
 
 
 public class CyActivator extends AbstractCyActivator {
+       private static Logger logger = 
LoggerFactory.getLogger(edu.ucsf.rbvi.enhancedcg.internal.CyActivator.class);
        public CyActivator() {
                super();
        }
@@ -43,9 +49,17 @@
                CyCustomGraphicsFactory lineChartFactory = new 
LineChartFactory();
                Properties lineChartProps = new Properties();
                registerService(bc, lineChartFactory, 
CyCustomGraphicsFactory.class, lineChartProps);
-               // CyCustomGraphicsFactory stripeChartFactory = new 
StripeChartCustomGraphicsFactory();
+
+               CyCustomGraphicsFactory stripeChartFactory = new 
StripeChartFactory();
+               Properties stripeChartProps = new Properties();
+               registerService(bc, stripeChartFactory, 
CyCustomGraphicsFactory.class, stripeChartProps);
+
+               CyCustomGraphicsFactory heatStripChartFactory = new 
HeatStripFactory();
+               Properties heatStripChartProps = new Properties();
+               registerService(bc, heatStripChartFactory, 
CyCustomGraphicsFactory.class, heatStripChartProps);
+
                // CyCustomGraphicsFactory stripChartFactory = new 
StripChartCustomGraphicsFactory();
-               System.out.println("Enhanced Custom Graphics started");
+               logger.info("Enhanced Custom Graphics started");
        }
 }
 

Modified: 
csplugins/trunk/ucsf/scooter/enhancedcg/src/main/java/edu/ucsf/rbvi/internal/charts/bar/BarLayer.java
===================================================================
--- 
csplugins/trunk/ucsf/scooter/enhancedcg/src/main/java/edu/ucsf/rbvi/internal/charts/bar/BarLayer.java
       2012-10-01 22:25:52 UTC (rev 30566)
+++ 
csplugins/trunk/ucsf/scooter/enhancedcg/src/main/java/edu/ucsf/rbvi/internal/charts/bar/BarLayer.java
       2012-10-01 22:38:56 UTC (rev 30567)
@@ -42,6 +42,7 @@
 
 import java.awt.geom.AffineTransform;
 import java.awt.geom.Area;
+import java.awt.geom.Path2D;
 import java.awt.geom.Point2D;
 import java.awt.geom.Rectangle2D;
 
@@ -136,7 +137,16 @@
 
        private Shape barShape() {
                // System.out.println("sliceShape: bounds = "+bounds);
-               return getBar(value);
+               Shape barShape = getBar(value);
+
+               // If this is our first bar, draw our axes
+               if (bar == 0) {
+                       Area axes = getAxes();
+                       axes.add(new Area(barShape));
+                       return axes;
+               }
+               return barShape;
+
        }
 
        private Shape labelShape() {
@@ -175,7 +185,7 @@
                else
                        max = -1.0 * min;
 
-               double px1 = x + bar*sliceSize;
+               double px1 = x + bar*width/nBars;
                double py1 = y + (0.5 * height);
 
                if (val > 0.0)
@@ -187,4 +197,19 @@
                return new Rectangle2D.Double(px1, py1, sliceSize, h);
        }
 
+       private Area getAxes() {
+               // At this point, make it simple -- a line at 0.0
+               Rectangle2D firstBar = getBar(0.0);
+               int saveBar = bar;
+               bar = nBars-1;
+               Rectangle2D lastBar = getBar(0.0);
+               bar = saveBar;
+
+               Path2D xAxes = new Path2D.Double();
+               xAxes.moveTo(firstBar.getX(), firstBar.getY());
+               xAxes.lineTo(lastBar.getX()+lastBar.getWidth(), lastBar.getY());
+               BasicStroke stroke = new BasicStroke(0.5f/2.0f);
+               return new Area(stroke.createStrokedShape(xAxes));
+       }
+
 }

Added: 
csplugins/trunk/ucsf/scooter/enhancedcg/src/main/java/edu/ucsf/rbvi/internal/charts/heatstrip/HeatStripChart.java
===================================================================
--- 
csplugins/trunk/ucsf/scooter/enhancedcg/src/main/java/edu/ucsf/rbvi/internal/charts/heatstrip/HeatStripChart.java
                           (rev 0)
+++ 
csplugins/trunk/ucsf/scooter/enhancedcg/src/main/java/edu/ucsf/rbvi/internal/charts/heatstrip/HeatStripChart.java
   2012-10-01 22:38:56 UTC (rev 30567)
@@ -0,0 +1,171 @@
+/* vim: set ts=2: */
+/**
+ * Copyright (c) 2010 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *   1. Redistributions of source code must retain the above copyright
+ *      notice, this list of conditions, and the following disclaimer.
+ *   2. Redistributions in binary form must reproduce the above
+ *      copyright notice, this list of conditions, and the following
+ *      disclaimer in the documentation and/or other materials provided
+ *      with the distribution.
+ *   3. Redistributions must acknowledge that this software was
+ *      originally developed by the UCSF Computer Graphics Laboratory
+ *      under support by the NIH National Center for Research Resources,
+ *      grant P41-RR01081.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER "AS IS" AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
+ * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+ * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+ * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
+ * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+package edu.ucsf.rbvi.enhancedcg.internal.charts.heatstrip;
+
+// System imports
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Comparator;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import java.awt.Color;
+import java.awt.Image;
+import java.awt.Paint;
+import java.awt.Shape;
+import java.awt.geom.Arc2D;
+import java.awt.geom.Area;
+import java.awt.geom.Point2D;
+import java.awt.geom.Rectangle2D;
+
+// Cytoscape imports
+import org.cytoscape.model.CyIdentifiable;
+import org.cytoscape.model.CyNetwork;
+import org.cytoscape.model.CyNode;
+
+import edu.ucsf.rbvi.enhancedcg.internal.charts.AbstractChartCustomGraphics;
+
+/**
+ * The HeatStripChart creates a list of custom graphics where each custom 
graphic represents
+ * a slice of the pie.  The data for this is of the format: 
label1:value1:color1, etc.,
+ * where value is numeric and the color is optional, but if specified, it must 
be one of
+ * the named Java colors, hex RGB values, or hex RGBA values.
+ */
+public class HeatStripChart extends 
AbstractChartCustomGraphics<HeatStripLayer> {
+       private static final String COLORS = "colorlist";
+       private static final String SEPARATION = "separation";
+       private static final String REDGREEN = "redgreen";
+       private static final String YELLOWCYAN = "yellowcyan";
+
+       private List<Color> colorList = null;
+       private String colorString = null;
+       private int separation = 0;
+       private int labelSize = 4;
+
+       Color[] redGreen = {Color.GREEN, Color.BLACK, Color.RED};
+       Color[] yellowCyan = {Color.CYAN, Color.BLACK, Color.YELLOW};
+       Color[] colorScale = null;
+
+       // Parse the input string, which is always of the form:
+       // heatstripchart:      [attributelist=value]
+       //                                                      
[colorlist=value]
+       //                                                      
[labellist=value]
+       //                              [position=value]
+       //                              [scale=0.90]
+       //                              [separation=value]
+       //                              [valuelist=value]
+       public HeatStripChart(String input) {
+               Map<String, String> args = parseInput(input);
+               // This will populate the values, attributes, and labels lists
+               populateValues(args);
+
+               colorScale = yellowCyan;
+               if (args.containsKey(COLORS)) {
+                       // Get our colors
+                       String colorSpec = args.get(COLORS).toString();
+                       if (colorSpec.equalsIgnoreCase(YELLOWCYAN)) {
+                               colorScale = yellowCyan;
+                       } else if (colorSpec.equalsIgnoreCase(REDGREEN)) {
+                               colorScale = redGreen;
+                       } else {
+                               colorScale = new Color[3];
+                               String [] colorArray = colorSpec.split(",");
+                               List<Color> colors = 
parseUpDownColor(colorArray);
+                               colorScale[1] = colors.get(2);
+                               colorScale[0] = colors.get(1);
+                               colorScale[2] = colors.get(0);
+                       }
+               }
+
+               if (args.containsKey(SEPARATION)) {
+                       separation = Integer.parseInt(args.get(SEPARATION));
+               }
+       }
+
+       public String toSerializableString() { return 
this.getIdentifier().toString()+","+displayName; }
+
+       public Image getRenderedImage() { return null; }
+
+       @Override 
+       public List<HeatStripLayer> getLayers(CyNetwork network, CyIdentifiable 
node) { 
+               // Create all of our pie slices. Each slice becomes a layer
+               if (attributes != null && attributes.size() > 0) {
+                       if (!(node instanceof CyNode))
+                               return null;
+
+                       values = getDataFromAttributes (network, (CyNode)node, 
attributes, labels);
+               }
+
+               if (labels != null && labels.size() > 0 &&
+                   labels.size() != values.size()) {
+                       logger.error("number of labels (" + labels.size()
+                                    + "), values (" + values.size() + ") don't 
match");
+               }
+
+               List<HeatStripLayer> labelList = new 
ArrayList<HeatStripLayer>();
+
+               double minValue = 0.000001;
+               double maxValue = -minValue;
+               for (double val: values) {
+                       minValue = Math.min(minValue, val);
+                       maxValue = Math.max(maxValue, val);
+               }
+                       
+               int nBars = values.size();
+               for (int bar = 0; bar < nBars; bar++) {
+                       String label = null;
+                       if (labels != null && labels.size() > 0)
+                               label = labels.get(bar);
+                       if (values.get(bar) == 0.0) continue;
+
+                       // Create the slice
+                       HeatStripLayer bl = new HeatStripLayer(bar, nBars, 
separation, values.get(bar), minValue, maxValue, colorScale);
+                       if (bl == null) continue;
+                       layers.add(bl);
+
+                       if (label != null) {
+                               // Now, create the label
+                               HeatStripLayer labelLayer = new 
HeatStripLayer(bar, nBars, separation, minValue, maxValue, label, labelSize);
+                               if (labelLayer != null)
+                                       labelList.add(labelLayer);
+                       }
+               }
+
+               // Now add all of our labels so they will be on top of our 
slices
+               if (labelList != null && labelList.size() > 0)
+                       layers.addAll(labelList);
+               return layers; 
+       }
+
+}

Added: 
csplugins/trunk/ucsf/scooter/enhancedcg/src/main/java/edu/ucsf/rbvi/internal/charts/heatstrip/HeatStripFactory.java
===================================================================
--- 
csplugins/trunk/ucsf/scooter/enhancedcg/src/main/java/edu/ucsf/rbvi/internal/charts/heatstrip/HeatStripFactory.java
                         (rev 0)
+++ 
csplugins/trunk/ucsf/scooter/enhancedcg/src/main/java/edu/ucsf/rbvi/internal/charts/heatstrip/HeatStripFactory.java
 2012-10-01 22:38:56 UTC (rev 30567)
@@ -0,0 +1,28 @@
+package edu.ucsf.rbvi.enhancedcg.internal.charts.heatstrip;
+
+import java.net.URL;
+
+import org.cytoscape.view.presentation.customgraphics.CyCustomGraphics;
+import org.cytoscape.view.presentation.customgraphics.CyCustomGraphicsFactory;
+import org.cytoscape.view.presentation.customgraphics.CustomGraphicLayer;
+
+public class HeatStripFactory implements CyCustomGraphicsFactory {
+       private static final Class<? extends CyCustomGraphics> TARGET_CLASS = 
HeatStripChart.class;
+
+       public HeatStripFactory() {
+       }
+
+       public CyCustomGraphics<HeatStripLayer> getInstance(String input) {
+               return new HeatStripChart(input);
+       }
+
+       public CyCustomGraphics<HeatStripLayer> getInstance(URL input) { return 
null; }
+
+       public String getPrefix() { return "heatstripchart"; }
+
+       public Class<? extends CyCustomGraphics> getSupportedClass() { return 
TARGET_CLASS; }
+
+       public CyCustomGraphics<HeatStripLayer> parseSerializableString(String 
string) { return null; }
+
+       public boolean supportsMime(String mimeType) { return false; }
+}

Added: 
csplugins/trunk/ucsf/scooter/enhancedcg/src/main/java/edu/ucsf/rbvi/internal/charts/heatstrip/HeatStripLayer.java
===================================================================
--- 
csplugins/trunk/ucsf/scooter/enhancedcg/src/main/java/edu/ucsf/rbvi/internal/charts/heatstrip/HeatStripLayer.java
                           (rev 0)
+++ 
csplugins/trunk/ucsf/scooter/enhancedcg/src/main/java/edu/ucsf/rbvi/internal/charts/heatstrip/HeatStripLayer.java
   2012-10-01 22:38:56 UTC (rev 30567)
@@ -0,0 +1,232 @@
+/* vim: set ts=2: */
+/**
+ * Copyright (c) 2010 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *   1. Redistributions of source code must retain the above copyright
+ *      notice, this list of conditions, and the following disclaimer.
+ *   2. Redistributions in binary form must reproduce the above
+ *      copyright notice, this list of conditions, and the following
+ *      disclaimer in the documentation and/or other materials provided
+ *      with the distribution.
+ *   3. Redistributions must acknowledge that this software was
+ *      originally developed by the UCSF Computer Graphics Laboratory
+ *      under support by the NIH National Center for Research Resources,
+ *      grant P41-RR01081.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER "AS IS" AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
+ * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+ * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+ * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
+ * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+package edu.ucsf.rbvi.enhancedcg.internal.charts.heatstrip;
+
+
+import java.awt.BasicStroke;
+import java.awt.Color;
+import java.awt.LinearGradientPaint;
+import java.awt.Paint;
+import java.awt.Rectangle;
+import java.awt.Shape;
+import java.awt.Stroke;
+
+import java.awt.geom.AffineTransform;
+import java.awt.geom.Area;
+import java.awt.geom.Path2D;
+import java.awt.geom.Point2D;
+import java.awt.geom.Rectangle2D;
+
+import java.util.Arrays;
+import java.util.Comparator;
+import java.util.List;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.cytoscape.view.presentation.customgraphics.PaintedShape;
+import edu.ucsf.rbvi.enhancedcg.internal.charts.ViewUtils;
+
+public class HeatStripLayer implements PaintedShape {
+       private boolean labelLayer = false;
+       private String label;
+       private Color[] colorScale;
+       private int fontSize;
+       protected Rectangle2D bounds;
+       private double value;
+       private double maxValue;
+       private double minValue;
+       private int bar;
+       private int nBars;
+       private int separation;
+       float[] dist = {0.0f, 0.5f, 1.0f};
+       private Logger logger = LoggerFactory.getLogger(this.getClass());
+
+       public HeatStripLayer(int bar, int nbars, int separation, double value, 
+                       double minValue, double maxValue, Color[] colorScale) {
+               labelLayer = false;
+               this.colorScale = colorScale;
+               this.bar = bar;
+               this.nBars = nbars;
+               this.separation = separation;
+               this.value = value;
+               this.minValue = minValue;
+               this.maxValue = maxValue;
+               bounds = new Rectangle2D.Double(0, 0, 100, 50);
+       }
+
+       public HeatStripLayer(int bar, int nbars, int separation, double 
minValue, double maxValue,
+                       String label, int fontSize) {
+               labelLayer = true;
+               this.bar = bar;
+               this.nBars = nbars;
+               this.separation = separation;
+               this.label = label;
+               this.fontSize = fontSize;
+               this.minValue = minValue;
+               this.maxValue = maxValue;
+               bounds = new Rectangle2D.Double(0, 0, 100, 50);
+       }
+
+       public Paint getPaint() {
+               if (labelLayer)
+                       return Color.BLACK;
+               return createGradPaint();
+       }
+
+       public Paint getPaint(Rectangle2D bounds) {
+               if (labelLayer)
+                       return Color.BLACK;
+               return createGradPaint();
+       }
+
+       public Shape getShape() {
+               // create the slice or the label, as appropriate
+               if (labelLayer)
+                       return labelShape();
+               else
+                       return barShape();
+       }
+
+       public Stroke getStroke() {
+               // We only stroke the slice
+               if (!labelLayer)
+                       return new BasicStroke(0.5f);
+               return null;
+       }
+
+       public Paint getStrokePaint() {
+               return Color.BLACK;
+       }
+
+       public Rectangle2D getBounds2D() {
+               return bounds;
+       }
+
+       public HeatStripLayer transform(AffineTransform xform) {
+               Shape newBounds = xform.createTransformedShape(bounds);
+               HeatStripLayer bl;
+               if (labelLayer)
+                       bl = new HeatStripLayer(bar, nBars, separation, 
minValue, maxValue, label, fontSize);
+               else 
+                       bl = new HeatStripLayer(bar, nBars, separation, value, 
minValue, maxValue, colorScale);
+               bl.bounds = newBounds.getBounds2D();
+               return bl;
+       }
+
+       private Shape barShape() {
+               Shape strip = getHeatStrip(value);
+
+               // If this is our first bar, draw our axes
+               if (bar == 0) {
+                       Area axes = getAxes();
+                       axes.add(new Area(strip));
+                       return axes;
+               }
+
+               return strip;
+       }
+
+       private Shape labelShape() {
+               // Get a bar that's in the right position and the maximum height
+               Rectangle2D bar = getHeatStrip(minValue);
+
+               ViewUtils.TextAlignment tAlign = 
ViewUtils.TextAlignment.ALIGN_LEFT;
+               Point2D labelPosition = new Point2D.Double(bar.getCenterX(), 
bar.getMaxY()+fontSize/2);
+
+               Shape textShape = ViewUtils.getLabelShape(label, null, 0, 
fontSize);
+
+               double maxHeight = bar.getWidth();
+
+               textShape = ViewUtils.positionLabel(textShape, labelPosition, 
tAlign, maxHeight, 0.0, 70.0);
+               if (textShape == null) {
+                       return null;
+               }
+
+               return textShape;
+       }
+
+       private Rectangle2D getHeatStrip(double val) {
+               double x = bounds.getX()-bounds.getWidth()/2;
+               double y = bounds.getY()-bounds.getHeight()/2;
+               double width = bounds.getWidth();
+               double height = bounds.getHeight();
+
+               double yMid = y + (0.5 * height);
+               double sliceSize = (width / nBars) - (nBars * separation) + 
separation; // only have n-1 separators
+
+               double min = minValue;
+               double max = maxValue;
+
+               if (Math.abs(max) > Math.abs(min))
+                       min = -1.0 * max;
+               else
+                       max = -1.0 * min;
+
+               double px1 = x + bar*width/nBars;
+               double py1 = y + (0.5 * height);
+
+               if (val > 0.0)
+                       py1 = py1 - ((0.5 * height) * (val / max));
+               else
+                       val = -val;
+
+               double h = (0.5 * height) * (val/max);
+               return new Rectangle2D.Double(px1, py1, sliceSize, h);
+       }
+
+       private Paint createGradPaint() {
+               double x = bounds.getX()-bounds.getWidth()/2;
+               double y = bounds.getY()-bounds.getHeight()/2;
+               double width = bounds.getWidth();
+               double height = bounds.getHeight();
+               return new LinearGradientPaint((float)x, (float)(y+height), 
(float)x, (float)y, dist, colorScale);
+       }
+
+       private Area getAxes() {
+               // At this point, make it simple -- a line at 0.0
+               Rectangle2D firstBar = getHeatStrip(0.0);
+               int saveBar = bar;
+               bar = nBars-1;
+               Rectangle2D lastBar = getHeatStrip(0.0);
+               bar = saveBar;
+
+               Path2D xAxes = new Path2D.Double();
+               xAxes.moveTo(firstBar.getX(), firstBar.getY());
+               xAxes.lineTo(lastBar.getX()+lastBar.getWidth(), lastBar.getY());
+               BasicStroke stroke = new BasicStroke(0.5f/2.0f);
+               return new Area(stroke.createStrokedShape(xAxes));
+
+       }
+
+}

Added: 
csplugins/trunk/ucsf/scooter/enhancedcg/src/main/java/edu/ucsf/rbvi/internal/charts/stripe/StripeChart.java
===================================================================
--- 
csplugins/trunk/ucsf/scooter/enhancedcg/src/main/java/edu/ucsf/rbvi/internal/charts/stripe/StripeChart.java
                         (rev 0)
+++ 
csplugins/trunk/ucsf/scooter/enhancedcg/src/main/java/edu/ucsf/rbvi/internal/charts/stripe/StripeChart.java
 2012-10-01 22:38:56 UTC (rev 30567)
@@ -0,0 +1,109 @@
+/* vim: set ts=2: */
+/**
+ * Copyright (c) 2010 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *   1. Redistributions of source code must retain the above copyright
+ *      notice, this list of conditions, and the following disclaimer.
+ *   2. Redistributions in binary form must reproduce the above
+ *      copyright notice, this list of conditions, and the following
+ *      disclaimer in the documentation and/or other materials provided
+ *      with the distribution.
+ *   3. Redistributions must acknowledge that this software was
+ *      originally developed by the UCSF Computer Graphics Laboratory
+ *      under support by the NIH National Center for Research Resources,
+ *      grant P41-RR01081.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER "AS IS" AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
+ * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+ * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+ * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
+ * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+package edu.ucsf.rbvi.enhancedcg.internal.charts.stripe;
+
+// System imports
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Comparator;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import java.awt.Color;
+import java.awt.Image;
+import java.awt.Paint;
+import java.awt.Shape;
+import java.awt.geom.Arc2D;
+import java.awt.geom.Area;
+import java.awt.geom.Point2D;
+import java.awt.geom.Rectangle2D;
+
+// Cytoscape imports
+import org.cytoscape.model.CyIdentifiable;
+import org.cytoscape.model.CyNetwork;
+import org.cytoscape.model.CyNode;
+
+import edu.ucsf.rbvi.enhancedcg.internal.charts.AbstractChartCustomGraphics;
+
+/**
+ * The StripeChart creates a list of custom graphics where each custom graphic 
represents
+ * a slice of the pie.  The data for this is of the format: 
label1:value1:color1, etc.,
+ * where value is numeric and the color is optional, but if specified, it must 
be one of
+ * the named Java colors, hex RGB values, or hex RGBA values.
+ */
+public class StripeChart extends AbstractChartCustomGraphics<StripeLayer> {
+       private static final String COLORS = "colorlist";
+
+       private List<Color> colorList = null;
+       private int labelSize = 4;
+       private String colorString = null;
+
+       // Parse the input string, which is always of the form:
+       // linechart:   [colorlist=value]
+       //                                              [position=value]
+       //                                              [scale=0.90]
+       public StripeChart(String input) {
+               Map<String, String> args = parseInput(input);
+               // This will populate the values, attributes, and labels lists
+               // populateValues(args);
+
+               if (args.containsKey(COLORS)) {
+                       if (attributes == null) 
+                               colorList = 
convertInputToColor(args.get(COLORS), new ArrayList<Double>());
+                       else
+                               colorString = args.get(COLORS);
+               }
+       }
+
+       public String toSerializableString() { return 
this.getIdentifier().toString()+","+displayName; }
+
+       public Image getRenderedImage() { return null; }
+
+       @Override 
+       public List<StripeLayer> getLayers(CyNetwork network, CyIdentifiable 
node) { 
+               int nStripes = colorList.size();
+               for (int stripe = 0; stripe < nStripes; stripe++) {
+                       Color color = colorList.get(stripe);
+
+                       // Create the stripe
+                       StripeLayer bl = new StripeLayer(stripe, nStripes, 
color);
+                       if (bl == null) continue;
+                       layers.add(bl);
+
+               }
+
+               return layers; 
+       }
+
+}

Added: 
csplugins/trunk/ucsf/scooter/enhancedcg/src/main/java/edu/ucsf/rbvi/internal/charts/stripe/StripeChartFactory.java
===================================================================
--- 
csplugins/trunk/ucsf/scooter/enhancedcg/src/main/java/edu/ucsf/rbvi/internal/charts/stripe/StripeChartFactory.java
                          (rev 0)
+++ 
csplugins/trunk/ucsf/scooter/enhancedcg/src/main/java/edu/ucsf/rbvi/internal/charts/stripe/StripeChartFactory.java
  2012-10-01 22:38:56 UTC (rev 30567)
@@ -0,0 +1,28 @@
+package edu.ucsf.rbvi.enhancedcg.internal.charts.stripe;
+
+import java.net.URL;
+
+import org.cytoscape.view.presentation.customgraphics.CyCustomGraphics;
+import org.cytoscape.view.presentation.customgraphics.CyCustomGraphicsFactory;
+import org.cytoscape.view.presentation.customgraphics.CustomGraphicLayer;
+
+public class StripeChartFactory implements CyCustomGraphicsFactory {
+       private static final Class<? extends CyCustomGraphics> TARGET_CLASS = 
StripeChart.class;
+
+       public StripeChartFactory() {
+       }
+
+       public CyCustomGraphics<StripeLayer> getInstance(String input) {
+               return new StripeChart(input);
+       }
+
+       public CyCustomGraphics<StripeLayer> getInstance(URL input) { return 
null; }
+
+       public String getPrefix() { return "stripechart"; }
+
+       public Class<? extends CyCustomGraphics> getSupportedClass() { return 
TARGET_CLASS; }
+
+       public CyCustomGraphics<StripeLayer> parseSerializableString(String 
string) { return null; }
+
+       public boolean supportsMime(String mimeType) { return false; }
+}

Added: 
csplugins/trunk/ucsf/scooter/enhancedcg/src/main/java/edu/ucsf/rbvi/internal/charts/stripe/StripeLayer.java
===================================================================
--- 
csplugins/trunk/ucsf/scooter/enhancedcg/src/main/java/edu/ucsf/rbvi/internal/charts/stripe/StripeLayer.java
                         (rev 0)
+++ 
csplugins/trunk/ucsf/scooter/enhancedcg/src/main/java/edu/ucsf/rbvi/internal/charts/stripe/StripeLayer.java
 2012-10-01 22:38:56 UTC (rev 30567)
@@ -0,0 +1,141 @@
+/* vim: set ts=2: */
+/**
+ * Copyright (c) 2010 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *   1. Redistributions of source code must retain the above copyright
+ *      notice, this list of conditions, and the following disclaimer.
+ *   2. Redistributions in binary form must reproduce the above
+ *      copyright notice, this list of conditions, and the following
+ *      disclaimer in the documentation and/or other materials provided
+ *      with the distribution.
+ *   3. Redistributions must acknowledge that this software was
+ *      originally developed by the UCSF Computer Graphics Laboratory
+ *      under support by the NIH National Center for Research Resources,
+ *      grant P41-RR01081.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER "AS IS" AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
+ * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+ * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+ * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
+ * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+package edu.ucsf.rbvi.enhancedcg.internal.charts.stripe;
+
+
+import java.awt.BasicStroke;
+import java.awt.Color;
+import java.awt.Paint;
+import java.awt.Rectangle;
+import java.awt.Shape;
+import java.awt.Stroke;
+
+import java.awt.geom.AffineTransform;
+import java.awt.geom.Point2D;
+import java.awt.geom.Rectangle2D;
+
+import java.util.Arrays;
+import java.util.Comparator;
+import java.util.List;
+
+import org.cytoscape.view.presentation.customgraphics.PaintedShape;
+import edu.ucsf.rbvi.enhancedcg.internal.charts.ViewUtils;
+
+public class StripeLayer implements PaintedShape {
+       private boolean labelLayer = false;
+       private String label;
+       private Color color;
+       private int fontSize;
+       protected Rectangle2D bounds;
+       private int stripe;
+       private int nStripes;
+
+       public StripeLayer(int stripe, int nStripes, Color color) {
+               labelLayer = false;
+               this.color = color;
+               this.stripe = stripe;
+               this.nStripes = nStripes;
+               bounds = new Rectangle2D.Double(0, 0, 100, 50);
+       }
+
+       public StripeLayer(int stripe, int nStripes, String label, int 
fontSize) {
+               labelLayer = true;
+               this.stripe = stripe;
+               this.nStripes = nStripes;
+               this.label = label;
+               this.fontSize = fontSize;
+               this.color = Color.BLACK;
+               bounds = new Rectangle2D.Double(0, 0, 100, 50);
+       }
+
+       public Paint getPaint() {
+               return color;
+       }
+
+       public Paint getPaint(Rectangle2D bounds) {
+               return color;
+       }
+
+       public Shape getShape() {
+               // create the slice or the label, as appropriate
+               if (labelLayer)
+                       return labelShape();
+               else
+                       return stripeShape();
+       }
+
+       public Stroke getStroke() {
+               // We only stroke the slice
+               if (!labelLayer)
+                       return new BasicStroke(0.1f);
+               return null;
+       }
+
+       public Paint getStrokePaint() {
+               return Color.BLACK;
+       }
+
+       public Rectangle2D getBounds2D() {
+               return bounds;
+       }
+
+       public StripeLayer transform(AffineTransform xform) {
+               Shape newBounds = xform.createTransformedShape(bounds);
+               StripeLayer bl;
+               if (labelLayer)
+                       bl = new StripeLayer(stripe, nStripes, label, fontSize);
+               else 
+                       bl = new StripeLayer(stripe, nStripes, color);
+               bl.bounds = newBounds.getBounds2D();
+               return bl;
+       }
+
+       private Shape stripeShape() {
+               // System.out.println("sliceShape: bounds = "+bounds);
+               return getStripe(stripe, nStripes);
+       }
+
+       private Shape labelShape() {
+               return null;
+       }
+
+       private Rectangle2D getStripe(int stripe, int nStripes) {
+               double x = bounds.getX()-bounds.getWidth()/2;
+               double y = bounds.getY()-bounds.getHeight()/2;
+               double width = bounds.getWidth();
+               double height = bounds.getHeight();
+               // Create the stripe
+               return new Rectangle2D.Double((x + (stripe * width/nStripes)), 
y, width/nStripes, height);
+       }
+
+}

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