List of usage examples for org.jfree.util ShapeUtilities rotateShape
public static Shape rotateShape(final Shape base, final double angle, final float x, final float y)
From source file:gov.nih.nci.rembrandt.web.plots.RBTPrincipalComponentAnalysisPlot.java
/** * This chart uses the XYAnnotation as a glyph to represent * a single pca data point. Glyph shape is determined by survival time. * Survival of more than 10 months is represented by a circle. 10 months or less * is represented by a square. Component1 values are represented by X * Component2 values are represented by Y *//*from w ww .jav a 2 s . co m*/ protected void createGlyphsAndAddToPlot(XYPlot plot) { //for RBT, if its non_tumor, show a diamond meaning "N/A for survival" XYShapeAnnotation glyph; Shape glyphShape; Color glyphColor; PrincipalComponentAnalysisDataPoint pcaPoint; double x, y; for (Iterator i = dataPoints.iterator(); i.hasNext();) { pcaPoint = (PrincipalComponentAnalysisDataPoint) i.next(); x = pcaPoint.getComponentValue(component1); y = pcaPoint.getComponentValue(component2); double survival = pcaPoint.getSurvivalInMonths(); String diseaseName = pcaPoint.getDiseaseName(); if (this.colorBy.equals(PCAcolorByType.NONE)) { Ellipse2D.Double circle = new Ellipse2D.Double(); circle.setFrameFromCenter(x, y, x + 2, y + 2); glyphShape = circle; } else if (diseaseName.equals(RembrandtConstants.NON_TUMOR) || diseaseName.equals("CELL_LINE")) { //glyphShape = ShapeUtilities.createDiamond(new Float(x)); Rectangle2D.Double rect = new Rectangle2D.Double(); rect.setFrameFromCenter(x, y, x + 2, y + 2); glyphShape = rect; Shape gShape = ShapeUtilities.rotateShape(glyphShape, new Double(0.785398163), new Float(x), new Float(y)); glyphShape = gShape; } else if ((survival > 0) && (survival < 10.0)) { Rectangle2D.Double rect = new Rectangle2D.Double(); rect.setFrameFromCenter(x, y, x + 2, y + 2); glyphShape = rect; } else if ((survival > 0) && (survival >= 10.0)) { Ellipse2D.Double circle = new Ellipse2D.Double(); circle.setFrameFromCenter(x, y, x + 2, y + 2); glyphShape = circle; } else { GeneralPath gp = new GeneralPath(); float xf = (float) x; float yf = (float) y; //make a triangle gp.moveTo(xf, yf); gp.lineTo(xf + 3.0f, yf - 3.0f); gp.lineTo(xf - 3.0f, yf - 3.0f); gp.closePath(); glyphShape = gp; } glyphColor = getColorForDataPoint(pcaPoint); glyph = new XYShapeAnnotation(glyphShape, new BasicStroke(1.0f), Color.BLACK, glyphColor); String tooltip = ""; if (pcaPoint.getSurvivalInMonths() <= 0.0) { tooltip = pcaPoint.getSampleId() + " " + pcaPoint.getDiseaseName(); } else { tooltip = pcaPoint.getSampleId() + " " + pcaPoint.getDiseaseName() + " survivalMonths=" + nf.format(pcaPoint.getSurvivalInMonths()); } glyph.setToolTipText(tooltip); plot.addAnnotation(glyph); } }
From source file:gov.nih.nci.caintegrator.ui.graphing.chart.plot.PrincipalComponentAnalysisPlot.java
/** * Build the legend/*from w w w . j av a2 s . c o m*/ * */ protected void buildLegend() { LegendTitle legend = pcaChart.getLegend(); LegendItemSource[] sources = new LegendItemSource[1]; PcaLegendItemSource legendSrc = new PcaLegendItemSource(); LegendItem item = null; //Rect=survival less than 10 months item = new LegendItem("Survival less than 10 months", null, null, null, new Rectangle2D.Double(0, 0, 8, 8), Color.BLACK); legendSrc.addLegendItem(item); //Circle=survival 10 months or more item = new LegendItem("Survival over 10 months", null, null, null, new Ellipse2D.Double(0, 0, 8, 8), Color.BLACK); legendSrc.addLegendItem(item); //Triangle if data if survival data is missing GeneralPath triangle = new GeneralPath(); // triangle.moveTo(1.0f,0.0f); // triangle.moveTo(0.0f,1.0f); // triangle.moveTo(1.0f,1.0f); triangle.moveTo(0.0f, -4.0f); triangle.lineTo(4.0f, 4.0f); triangle.lineTo(-4.0f, 4.0f); triangle.closePath(); //triangle.closePath(); item = new LegendItem("Survival Unknown", null, null, null, triangle, Color.BLACK); legendSrc.addLegendItem(item); //Diamond=survival N/A, for non_tumor/normal Shape r = new Rectangle2D.Double(0, 0, 8, 8); Shape d = ShapeUtilities.rotateShape(r, new Double(0.785398163), new Float(0), new Float(0)); item = new LegendItem("Survival N/A", null, null, null, d, Color.BLACK); legendSrc.addLegendItem(item); if (colorBy == PCAcolorByType.Disease) { //go through the disease color map and add legend items String diseaseName = null; Color diseaseColor = null; DiseaseType[] diseases = DiseaseType.values(); for (int i = 0; i < diseases.length; i++) { diseaseName = diseases[i].name(); if (diseases[i].equals(DiseaseType.UNCLASSIFIED)) { continue; //remove unclassified from the legend } diseaseColor = diseases[i].getColor(); item = new LegendItem(diseaseName, null, null, null, new Line2D.Double(0, 0, 6, 6), new BasicStroke(3.0f), diseaseColor); //item = new LegendItem(diseaseName, null, null, null, new Rectangle2D.Double(0,0,6,6), diseaseColor); legendSrc.addLegendItem(item); } // item = new LegendItem("Unknown", null, null, null, new Line2D.Double(0,0,6,6), new BasicStroke(3.0f), Color.GRAY); // legendSrc.addLegendItem(item); } else if (colorBy == PCAcolorByType.Gender) { String genderName = null; Color genderColor = null; GenderType[] genderTypes = GenderType.values(); for (int i = 0; i < genderTypes.length; i++) { genderName = genderTypes[i].toString(); genderColor = genderTypes[i].getColor(); item = new LegendItem(genderName, null, null, null, new Line2D.Double(0, 0, 6, 6), new BasicStroke(3.0f), genderColor); legendSrc.addLegendItem(item); } // item = new LegendItem("Male", null, null, null, new Line2D.Double(0,0,6,6), new BasicStroke(3.0f), Color.BLUE); // legendSrc.addLegendItem(item); // item = new LegendItem("Female", null, null, null, new Line2D.Double(0,0,6,6), new BasicStroke(3.0f), Color.PINK); // legendSrc.addLegendItem(item); // item = new LegendItem("Unknown", null, null, null, new Line2D.Double(0,0,6,6), new BasicStroke(3.0f),Color.GRAY); // legendSrc.addLegendItem(item); } sources[0] = legendSrc; legend.setSources(sources); }