Author: scooter
Date: 2011-03-09 11:07:41 -0800 (Wed, 09 Mar 2011)
New Revision: 24348
Modified:
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/HeatStrip.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
Log:
Updates to HeatStrips and Bars. Also added size parameter to allow user to fix
the size of the
chart.
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
2011-03-09 02:08:04 UTC (rev 24347)
+++
csplugins/trunk/ucsf/scooter/nodeCharts/src/main/java/nodeCharts/command/NodeChartCommandHandler.java
2011-03-09 19:07:41 UTC (rev 24348)
@@ -33,6 +33,7 @@
package nodeCharts.command;
// System imports
+import java.awt.geom.Rectangle2D;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
@@ -85,6 +86,7 @@
public static final String POSITION = "position";
public static final String SCALE = "scale";
public static final String SELECTED = "selected";
+ public static final String SIZE = "size";
public static final String SHOWLABELS = "showlabels";
public static final String VALUES = "valuelist";
@@ -224,6 +226,15 @@
throw new CyCommandException("unknown position
keyword or illegal position expression: "+position);
}
+ // Get our size (if we have one)
+ Rectangle2D size = null;
+ if (args.containsKey(SIZE)) {
+ String sizeString = (String) args.get(SIZE);
+ size = ValueUtils.getSize(sizeString);
+ if (size == null)
+ throw new CyCommandException("unknown size
expression: "+sizeString);
+ }
+
if (!showLabels)
labels = null;
@@ -237,7 +248,8 @@
ValueUtils.normalize(values, maxValues);
}
- List<CustomGraphic> cgList =
viewer.getCustomGraphics(args, values, labels, node, view, pos, scale);
+ Rectangle2D bbox = ViewUtils.getNodeBoundingBox(node,
size, view, pos, scale);
+ List<CustomGraphic> cgList =
viewer.getCustomGraphics(args, values, labels, bbox, view);
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
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
2011-03-09 02:08:04 UTC (rev 24347)
+++
csplugins/trunk/ucsf/scooter/nodeCharts/src/main/java/nodeCharts/command/ValueUtils.java
2011-03-09 19:07:41 UTC (rev 24348)
@@ -33,6 +33,7 @@
package nodeCharts.command;
// System imports
+import java.awt.geom.Rectangle2D;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
@@ -219,6 +220,38 @@
throw new NumberFormatException("input can not be converted to
double");
}
+ /**
+ * Return the size specified by the user in the width and height fields
of the Rectangle
+ * The size can be either "sss" where "sss" will be both the height and
the width or
+ * "hhhxwww" where hhh is the height and www is the width.
+ *
+ * @param input the input size
+ * @return a rectangle to get the width and height from
+ */
+ public static Rectangle2D getSize(Object input) throws
CyCommandException {
+ if (input instanceof Rectangle2D)
+ return (Rectangle2D) input;
+ else if (input instanceof Double) {
+ double v = ((Double)input).doubleValue();
+ return new Rectangle2D.Double(0.0,0.0,v,v);
+ } else if (input instanceof Integer) {
+ double v = ((Integer)input).doubleValue();
+ return new Rectangle2D.Double(0.0,0.0,v,v);
+ } else if (input instanceof String) {
+ String inputString = (String)input;
+ String[] sizes = inputString.split("[xX]");
+ if (sizes.length == 1) {
+ double v = Double.parseDouble(sizes[0]);
+ return new Rectangle2D.Double(0.0,0.0,v,v);
+ } else if (sizes.length == 2) {
+ double h = Double.parseDouble(sizes[0]);
+ double w = Double.parseDouble(sizes[1]);
+ return new Rectangle2D.Double(0.0,0.0,w,h);
+ }
+ }
+ throw new CyCommandException("unable to convert
"+input.toString()+" to a size");
+ }
+
public static List<Double> arrayMax(List<Double> maxValues,
List<Double> values) {
// Initialize, if necessary
if (maxValues == null) {
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
2011-03-09 02:08:04 UTC (rev 24347)
+++
csplugins/trunk/ucsf/scooter/nodeCharts/src/main/java/nodeCharts/view/BarChart.java
2011-03-09 19:07:41 UTC (rev 24348)
@@ -41,7 +41,7 @@
}
public String getDescription() {
- return "Display the values passed as arguments as a line chart
on the node";
+ return "Display the values passed as arguments as a bar chart
on the node";
}
public Map<String, String> getOptions() {
@@ -52,8 +52,8 @@
}
public List<CustomGraphic> getCustomGraphics(Map<String, Object> args,
- List<Double> values, List<String> labels, CyNode node,
- CyNetworkView view, Object position, double scale)
throws CyCommandException {
+ List<Double> values, List<String> labels, Rectangle2D
bbox,
+ CyNetworkView view) throws CyCommandException {
// Get our colors
List<Color> colors =
ValueUtils.convertInputToColor(args.get(COLORS), values);
@@ -80,7 +80,6 @@
// We need to get our bounding box in order to scale our graphic
// properly
- Rectangle2D bbox = ViewUtils.getNodeBoundingBox(node, view,
position, scale);
double height = bbox.getHeight();
double width = bbox.getWidth();
@@ -118,18 +117,22 @@
double px1 = x + (i * slice);
double w = slice;
PaintFactory pf = new
DefaultPaintFactory(colors.get(i));
- double val = values.get(i);
- double py1 = y + (0.5 * height);
- if (val > 0.0) // positive, work down to midpoint
- {
- py1 = py1 - ((0.5 * height) * (val / max));
- }
- else // negative, work down from midpoint
- {
- val = -val;
- }
-
- double h = (0.5 * height) * (val / max);
+ double val = values.get(i);
+ double py1 = y + (0.5 * height);
+ if (val > 0.0) // positive, work down to midpoint
+ {
+ py1 = py1 - ((0.5 * height) * (val / max));
+ }
+ else // negative, work down from midpoint
+ {
+ val = -val;
+ }
+
+ double h = (0.5 * height) * (val / max);
+
+ // Outline the bars for clarity
+ Rectangle2D outline = new Rectangle2D.Double(px1, py1,
w, h);
+ cgList.add(new CustomGraphic(outline, new
DefaultPaintFactory(Color.BLACK)));
barArray[i] = new Rectangle2D.Double(px1, py1, w, h);
// System.out.println ("Got rectangle from: " + px1 +
"," + py1 + " of width " + w + " and height " + h);
@@ -161,6 +164,8 @@
cgList.add(c1);
}
}
+ CustomGraphic cLine = new CustomGraphic(new
Rectangle2D.Double(x, yMid, width, .5), new DefaultPaintFactory(Color.BLACK));
+ cgList.add(cLine);
return cgList;
}
Modified:
csplugins/trunk/ucsf/scooter/nodeCharts/src/main/java/nodeCharts/view/HeatStrip.java
===================================================================
---
csplugins/trunk/ucsf/scooter/nodeCharts/src/main/java/nodeCharts/view/HeatStrip.java
2011-03-09 02:08:04 UTC (rev 24347)
+++
csplugins/trunk/ucsf/scooter/nodeCharts/src/main/java/nodeCharts/view/HeatStrip.java
2011-03-09 19:07:41 UTC (rev 24348)
@@ -40,8 +40,8 @@
private static final String YELLOWCYAN = "yellowcyan";
float[] dist = {0.0f, 0.5f, 1.0f};
- Color[] redGreen = {Color.GREEN, Color.BLACK, Color.RED};
- Color[] yellowCyan = {Color.CYAN, Color.BLACK, Color.YELLOW};
+ Color[] redGreen = {Color.GREEN, Color.WHITE, Color.RED};
+ Color[] yellowCyan = {Color.CYAN, Color.WHITE, Color.YELLOW};
public String getName() {
@@ -60,8 +60,8 @@
}
public List<CustomGraphic> getCustomGraphics(Map<String, Object> args,
- List<Double> values, List<String> labels, CyNode node,
- CyNetworkView view, Object position, double scale)
throws CyCommandException {
+ List<Double> values, List<String> labels, Rectangle2D
bbox,
+ CyNetworkView view) throws CyCommandException {
Color[] colorScale = null;
@@ -94,7 +94,6 @@
// We need to get our bounding box in order to scale our graphic
// properly
- Rectangle2D bbox = ViewUtils.getNodeBoundingBox(node, view,
position, scale);
double height = bbox.getHeight();
double width = bbox.getWidth();
@@ -146,7 +145,11 @@
double h = (0.5 * height) * (val / max);
- barArray[i] = new Rectangle2D.Double(px1, py1, w, h);
+ // Outline the bars for clarity
+ Rectangle2D outline = new Rectangle2D.Double(px1, py1,
w, h);
+ cgList.add(new CustomGraphic(outline, new
DefaultPaintFactory(Color.BLACK)));
+
+ barArray[i] = new Rectangle2D.Double(px1+0.2, py1+0.2,
w-0.2, h-0.2);
// System.out.println ("Got rectangle from: " + px1 +
"," + py1 + " of width " + w + " and height " + h);
maxY = Math.max(maxY, barArray[i].getMaxY());
@@ -176,6 +179,8 @@
cgList.add(c1);
}
}
+ CustomGraphic cLine = new CustomGraphic(new
Rectangle2D.Double(x, yMid, width, .5), new DefaultPaintFactory(Color.BLACK));
+ cgList.add(cLine);
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
2011-03-09 02:08:04 UTC (rev 24347)
+++
csplugins/trunk/ucsf/scooter/nodeCharts/src/main/java/nodeCharts/view/LineChart.java
2011-03-09 19:07:41 UTC (rev 24348)
@@ -41,8 +41,8 @@
}
public List<CustomGraphic> getCustomGraphics(Map<String, Object> args,
- List<Double> values, List<String> labels, CyNode node,
- CyNetworkView view, Object position, double scale)
throws CyCommandException {
+ List<Double> values, List<String> labels, Rectangle2D
bbox,
+ CyNetworkView view) throws CyCommandException {
// Get our color
// Get our colors
List<Color> colors =
ValueUtils.convertInputToColor(args.get(COLORS), values);
@@ -60,7 +60,6 @@
// We need to get our bounding box in order to scale our graphic
// properly
- 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
2011-03-09 02:08:04 UTC (rev 24347)
+++
csplugins/trunk/ucsf/scooter/nodeCharts/src/main/java/nodeCharts/view/NodeChartViewer.java
2011-03-09 19:07:41 UTC (rev 24348)
@@ -33,6 +33,7 @@
package nodeCharts.view;
// System imports
+import java.awt.geom.Rectangle2D;
import java.util.List;
import java.util.Map;
@@ -55,7 +56,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, double scale)
+ Rectangle2D bbox,
CyNetworkView view)
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
2011-03-09 02:08:04 UTC (rev 24347)
+++
csplugins/trunk/ucsf/scooter/nodeCharts/src/main/java/nodeCharts/view/PieChart.java
2011-03-09 19:07:41 UTC (rev 24348)
@@ -89,7 +89,7 @@
}
public List<CustomGraphic> getCustomGraphics(Map<String, Object>args,
List<Double> values, List<String> labels,
- CyNode node, CyNetworkView
view, Object position, double scale)
+ Rectangle2D bbox,
CyNetworkView view)
throws CyCommandException {
// Get our colors
List<Color> colors =
ValueUtils.convertInputToColor(args.get(COLORS), values);
@@ -119,11 +119,6 @@
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, scale);
-
- // System.out.println("Node: "+node);
-
for (int slice = 0; slice < nSlices; slice++) {
String label = null;
if (labels != null && labels.size() > 0)
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
2011-03-09 02:08:04 UTC (rev 24347)
+++
csplugins/trunk/ucsf/scooter/nodeCharts/src/main/java/nodeCharts/view/StripeChart.java
2011-03-09 19:07:41 UTC (rev 24348)
@@ -80,8 +80,8 @@
return options;
}
- public List<CustomGraphic> getCustomGraphics(Map<String, Object> args,
List<Double> values, List<String> labels, CyNode node,
- CyNetworkView view, Object position, double scale)
throws CyCommandException {
+ public List<CustomGraphic> getCustomGraphics(Map<String, Object> args,
List<Double> values, List<String> labels, Rectangle2D bbox,
+ CyNetworkView view) throws CyCommandException {
// Get our colors
List<Color> colors =
ValueUtils.convertInputToColor(args.get(COLORS), values);
@@ -89,10 +89,6 @@
List<CustomGraphic> cgList = new ArrayList<CustomGraphic>();
- // We need to get our bounding box in order to scale our graphic
- // properly
- Rectangle2D bbox = ViewUtils.getNodeBoundingBox(node, view,
position, scale);
-
// System.out.println("Node: "+node);
for (int stripe = 0; stripe < nStripes; stripe++) {
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
2011-03-09 02:08:04 UTC (rev 24347)
+++
csplugins/trunk/ucsf/scooter/nodeCharts/src/main/java/nodeCharts/view/ViewUtils.java
2011-03-09 19:07:41 UTC (rev 24348)
@@ -135,16 +135,21 @@
}
}
- public static Rectangle2D getNodeBoundingBox(CyNode node, CyNetworkView
view, Object position, double nodePortion) {
+ public static Rectangle2D getNodeBoundingBox(CyNode node, Rectangle2D
size, CyNetworkView view, Object position, double nodePortion) {
DNodeView nView = (DNodeView)view.getNodeView(node);
+ double height, width;
- // Get the affine transform
- double height =
(nView.getHeight()-nView.getBorderWidth())*nodePortion;
- double width =
(nView.getWidth()-nView.getBorderWidth())*nodePortion;
+ if (size == null) {
+ height =
(nView.getHeight()-nView.getBorderWidth())*nodePortion;
+ width =
(nView.getWidth()-nView.getBorderWidth())*nodePortion;
+ } else {
+ height = size.getHeight()*nodePortion;
+ width = size.getWidth()*nodePortion;
+ }
// Create the bounding box.
Rectangle2D.Double bbox = new Rectangle2D.Double(-width/2,
-height/2, width, height);
- return positionAdjust(bbox, position);
+ return positionAdjust(bbox, nView.getHeight(),
nView.getWidth(), position);
}
/**
@@ -308,7 +313,7 @@
return stroke.createStrokedShape(new Line2D.Double(lineStartX,
lineStartY, labelPosition.getX(), labelPosition.getY()));
}
- private static Rectangle2D positionAdjust(Rectangle2D.Double bbox,
Object pos) {
+ private static Rectangle2D positionAdjust(Rectangle2D bbox, double
nodeHeight, double nodeWidth, Object pos) {
if (pos == null)
return bbox;
@@ -322,32 +327,32 @@
switch (p) {
case EAST:
- x = width/2;
+ x = nodeWidth/2;
break;
case WEST:
- x = -width*1.5;
+ x = -nodeWidth*1.5;
break;
case NORTH:
- y = -height*1.5;
+ y = -nodeHeight*1.5;
break;
case SOUTH:
- y = height/2;
+ y = nodeHeight/2;
break;
case NORTHEAST:
- x = width/2;
- y = -height*1.5;
+ x = nodeWidth/2;
+ y = -nodeHeight*1.5;
break;
case NORTHWEST:
- x = -width*1.5;
- y = -height*1.5;
+ x = -nodeWidth*1.5;
+ y = -nodeHeight*1.5;
break;
case SOUTHEAST:
- x = width/2;
- y = height/2;
+ x = nodeWidth/2;
+ y = nodeHeight/2;
break;
case SOUTHWEST:
- x = -width*1.5;
- y = height/2;
+ x = -nodeWidth*1.5;
+ y = nodeHeight/2;
break;
case CENTER:
default:
--
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.