Author: scooter
Date: 2010-09-07 13:51:32 -0700 (Tue, 07 Sep 2010)
New Revision: 21729
Modified:
csplugins/trunk/ucsf/scooter/nodeCharts/src/main/java/nodeCharts/view/BarChart.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:
Updated to split label handling into getting the initial shape
and transforming the shape
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 20:41:01 UTC (rev 21728)
+++
csplugins/trunk/ucsf/scooter/nodeCharts/src/main/java/nodeCharts/view/BarChart.java
2010-09-07 20:51:32 UTC (rev 21729)
@@ -109,6 +109,9 @@
max = -1.0 * min;
}
+ Rectangle2D [] barArray = new Rectangle2D[values.size()];
+ double maxY = 0.0;
+
for (int i = 0; i < values.size(); i++) {
double px1 = x + (i * slice);
double w = slice;
@@ -126,30 +129,32 @@
double h = (0.5 * height) * (val / max);
- Rectangle2D drect = new Rectangle2D.Double(px1, py1, w,
h);
+ barArray[i] = new Rectangle2D.Double(px1, py1, w, h);
// System.out.println ("Got rectangle from: " + px1 +
"," + py1 + " of width " + w + " and height " + h);
+ maxY = Math.max(maxY, barArray[i].getMaxY());
- CustomGraphic c = new CustomGraphic(drect, pf);
+ CustomGraphic c = new CustomGraphic(barArray[i], pf);
// System.out.println("added custome graphic for line from
" + drect.getP1() + " to " + .getP2());
cgList.add(c);
- // Now, create the label. We want to do this here so
we can adjust the label for the slice
+ }
+
+ // 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(drect.getCenterX(), drect.getMaxY());
+ 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, labelPosition, tAlign, 70.0,
view);
+ Shape textShape =
ViewUtils.getLabelShape(labels.get(i), null, 0, 0, view);
- // Combine the shapes
- Area textArea = new Area(textShape);
-// textArea.add(new Area(labelLine));
+ 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(textArea, new
DefaultPaintFactory(Color.BLACK));
+ CustomGraphic c1 = new CustomGraphic(textShape, new
DefaultPaintFactory(Color.BLACK));
cgList.add(c1);
}
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 20:41:01 UTC (rev 21728)
+++
csplugins/trunk/ucsf/scooter/nodeCharts/src/main/java/nodeCharts/view/PieChart.java
2010-09-07 20:51:32 UTC (rev 21729)
@@ -114,7 +114,8 @@
for (int slice = 0; slice < nSlices; slice++) {
CustomGraphic[] cg = createSlice(bbox, arcStart,
values.get(slice), labels.get(slice), colors.get(slice), view);
cgList.add(cg[0]);
- labelList.add(cg[1]);
+ if (cg[1] != null)
+ labelList.add(cg[1]);
arcStart += values.get(slice).doubleValue();
}
@@ -141,6 +142,7 @@
private CustomGraphic[] createSlice(Rectangle2D bbox, double arcStart,
Double arc, String label, Color color,
CyNetworkView view) {
CustomGraphic[] vals = new CustomGraphic[2];
+
// System.out.println("Creating arc from "+arcStart+" to
"+(arc.doubleValue()+arcStart)+" with color: "+color);
double x = bbox.getX();
double y = bbox.getY();
@@ -157,10 +159,17 @@
TextAlignment tAlign = getLabelAlignment(midpointAngle);
- // Now, create the label. Put the label on the outer edge of
the circle.
+ // 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);
- Shape textShape = ViewUtils.getLabelShape(label, null, 0, 0,
labelPosition, tAlign, 0.0, view);
+ textShape = ViewUtils.positionLabel(textShape, labelPosition,
tAlign, 0.0, 0.0, 0.0);
+ if (textShape == null) {
+ vals[1] = null;
+ return vals;
+ }
// Draw a line between our label and the slice
labelPosition = getLabelPosition(bbox, midpointAngle, 1.0);
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 20:41:01 UTC (rev 21728)
+++
csplugins/trunk/ucsf/scooter/nodeCharts/src/main/java/nodeCharts/view/ViewUtils.java
2010-09-07 20:51:32 UTC (rev 21729)
@@ -182,10 +182,7 @@
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, double rotation, CyNetworkView view) {
-
-
+ public static Shape getLabelShape(String label, String fontName, int
fontStyle, int fontSize, CyNetworkView view) {
if (fontName == null) fontName = DEFAULT_FONT;
if (fontStyle == 0) fontStyle = DEFAULT_STYLE;
if (fontSize == 0) fontSize = DEFAULT_SIZE;
@@ -196,14 +193,38 @@
Graphics2D g2d = (Graphics2D)canvas.getGraphics();
FontRenderContext frc = g2d.getFontRenderContext();
TextLayout tl = new TextLayout(label, font, frc);
- Shape lShape = tl.getOutline(null);
+ return tl.getOutline(null);
+ }
+ public static Shape positionLabel(Shape lShape, Point2D position,
TextAlignment tAlign,
+ double maxHeight, double maxWidth,
double rotation) {
+
// System.out.println(" Label = "+label);
// Figure out how to move the text to center it on the bbox
- double textWidth = lShape.getBounds2D().getMaxX() -
lShape.getBounds2D().getMinX();
- double textHeight = lShape.getBounds2D().getMaxY() -
lShape.getBounds2D().getMinY();
+ double textWidth = lShape.getBounds2D().getWidth();
+ double textHeight = lShape.getBounds2D().getHeight();
+ // Before we go any further, scale the text, if necessary
+ if (maxHeight > 0.0 || maxWidth > 0.0) {
+ double scaleWidth = 1.0;
+ double scaleHeight = 1.0;
+ if (maxWidth > 0.0 && textWidth > maxWidth)
+ scaleWidth = maxWidth/textWidth * 0.9;
+ if (maxHeight > 0.0 && textHeight > maxHeight)
+ scaleHeight = maxHeight/textHeight * 0.9;
+
+ double scale = Math.min(scaleWidth, scaleHeight);
+
+ // We don't want to scale down too far. If scale < 20%
of the font size, skip the label
+ if (scale < 0.20)
+ return null;
+ System.out.println("scale = "+scale);
+ AffineTransform sTransform = new AffineTransform();
+ sTransform.scale(scale, scale);
+ lShape = sTransform.createTransformedShape(lShape);
+ }
+
// System.out.println(" Text size =
("+textWidth+","+textHeight+")");
double pointX = position.getX();
--
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.