Author: scooter
Date: 2011-11-22 14:44:52 -0800 (Tue, 22 Nov 2011)
New Revision: 27561
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/PieChart.java
csplugins/trunk/ucsf/scooter/nodeCharts/src/main/java/nodeCharts/view/ViewUtils.java
Log:
Some further refinement on contrasting color algorithm and label placement for
pies
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-11-22 21:56:13 UTC (rev 27560)
+++
csplugins/trunk/ucsf/scooter/nodeCharts/src/main/java/nodeCharts/command/NodeChartCommandHandler.java
2011-11-22 22:44:52 UTC (rev 27561)
@@ -315,7 +315,7 @@
* are assigned to parent network
(i.e., expanded) or to nested
* networks, making former chart
commands invalid.
*/
- if (!((String)
args.get("network")).equals(view.getNetwork().getTitle())){
+ if (args.containsKey("network") &&
!((String) args.get("network")).equals(view.getNetwork().getTitle())){
continue;
}
// Execute it
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-11-22 21:56:13 UTC (rev 27560)
+++
csplugins/trunk/ucsf/scooter/nodeCharts/src/main/java/nodeCharts/command/ValueUtils.java
2011-11-22 22:44:52 UTC (rev 27561)
@@ -483,18 +483,28 @@
// This is like rainbow, but we alternate sides of the color wheel
private static List<Color> generateContrastingColors(int nColors) {
- System.out.println("Generating contrasting colors");
List<Color> values = new ArrayList<Color>();
- float divs = (float)nColors+((float)nColors)*0.2f; // Add
fuzz to avoid cycles
- for (float i = 0.0f; i < (float)nColors; i += 1.0f) {
-
System.out.println("Color("+(i/divs)+","+1.0f+","+1.0f+")");
- values.add(new Color(Color.HSBtoRGB(i/divs, 1.0f,
1.0f)));
+ // We need to special-case the situation where we only have two
colors
+ if (nColors == 2) {
+ values.add(new Color(Color.HSBtoRGB(0.0f, 1.0f, 1.0f)));
+ values.add(new Color(Color.HSBtoRGB(0.5f, 1.0f, 1.0f)));
+ return values;
+ }
+
+ float divs = (float)nColors;
+ for (float i = 0.0f; i < divs; i += 1.0f) {
+ //
System.out.println("HSBColor("+(i/divs)+","+1.0f+","+1.0f+")");
+ Color rgbColor = new Color(Color.HSBtoRGB(i/divs, 1.0f,
1.0f));
+ // System.out.println("RGBColor = "+rgbColor);
+ values.add(rgbColor);
i += 1.0f;
- if (i >= (float)nColors) break;
- float hue = (i/divs)+0.25f;
+ if (i >= divs) break;
+ float hue = (i/divs)+0.5f; // This moves to the
opposite side of the color wheel
if (hue >= 1.0f) hue = hue - 1.0f;
- System.out.println("Color("+hue+","+1.0f+","+1.0f+")");
- values.add(new Color(Color.HSBtoRGB(hue, 1.0f, 1.0f)));
+ //
System.out.println("HSBColor("+hue+","+1.0f+","+1.0f+")");
+ rgbColor = new Color(Color.HSBtoRGB(hue, 1.0f, 1.0f));
+ // System.out.println("RGBColor = "+rgbColor);
+ values.add(rgbColor);
}
return values;
}
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-11-22 21:56:13 UTC (rev 27560)
+++
csplugins/trunk/ucsf/scooter/nodeCharts/src/main/java/nodeCharts/view/PieChart.java
2011-11-22 22:44:52 UTC (rev 27561)
@@ -179,7 +179,10 @@
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);
+ Point2D labelPosition = getLabelPosition(bbox,
midpointAngle, 1.7);
+
+ // System.out.println("label position =
"+labelPosition);
+
// 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) {
@@ -201,12 +204,21 @@
// Return a point on the midpoint of the arc
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 +
(bbox.getX()+bbox.getWidth()/2);
- double y = Math.sin(midpoint)*length*scale +
(bbox.getY()+bbox.getHeight()/2);
+ double w = bbox.getWidth()/2*scale;
+ double h = bbox.getHeight()/2*scale;
+ double x, y;
+ // Special case 90 and 270
+ if (angle == 270.0) {
+ x = 0.0;
+ y = h;
+ } else if (angle == 90.0) {
+ x = 0.0;
+ y = -h;
+ } else {
+ x = Math.cos(midpoint)*w;
+ y = Math.sin(midpoint)*h;
+ }
- // System.out.println("getLabelPosition: bbox = "+bbox+",
midpoint = "+angle+" arcpoint = ("+x+","+y+")");
-
return new Point2D.Double(x, y);
}
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-11-22 21:56:13 UTC (rev 27560)
+++
csplugins/trunk/ucsf/scooter/nodeCharts/src/main/java/nodeCharts/view/ViewUtils.java
2011-11-22 22:44:52 UTC (rev 27561)
@@ -241,13 +241,13 @@
switch (tAlign) {
case ALIGN_CENTER_TOP:
// System.out.println(" Align = CENTER_TOP");
- textStartX = pointX + textWidth/2;
- textStartY = pointY + textHeight;
+ textStartX = pointX - textWidth/2;
+ textStartY = pointY - textHeight/2;
break;
case ALIGN_CENTER_BOTTOM:
// System.out.println(" Align = CENTER_BOTTOM");
- textStartX = pointX + textWidth/2;
- textStartY = pointY - textHeight;
+ textStartX = pointX - textWidth/2;
+ textStartY = pointY + textHeight;
break;
case ALIGN_RIGHT:
// System.out.println(" Align = RIGHT");
--
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.