List of usage examples for org.jfree.chart.renderer.xy XYBubbleRenderer SCALE_ON_RANGE_AXIS
int SCALE_ON_RANGE_AXIS
To view the source code for org.jfree.chart.renderer.xy XYBubbleRenderer SCALE_ON_RANGE_AXIS.
Click Source Link
From source file:com.rapidminer.gui.plotter.charts.ColorizedBubbleRenderer.java
public ColorizedBubbleRenderer(double[] colors) { super(XYBubbleRenderer.SCALE_ON_RANGE_AXIS); this.minColor = Double.POSITIVE_INFINITY; this.maxColor = Double.NEGATIVE_INFINITY; for (double c : colors) { minColor = MathFunctions.robustMin(minColor, c); maxColor = MathFunctions.robustMax(maxColor, c); }//from ww w .ja va 2s . c o m this.colors = colors; }
From source file:org.talend.dataprofiler.chart.util.TopChartFactory.java
/** * Creates a bubble chart with default settings. The chart is composed of an {@link XYPlot}, with a {@link NumberAxis} for the * domain axis, a {@link NumberAxis} for the range axis, and an {@link XYBubbleRenderer} to draw the data items. * /* w w w . j a v a2s . c om*/ * This method is copied from * {@link org.jfree.chart.ChartFactory#createBubbleChart(String, String, String, XYZDataset, PlotOrientation, boolean, boolean, boolean)} * * @param title the chart title (<code>null</code> permitted). * @param xAxisLabel a label for the X-axis (<code>null</code> permitted). * @param yAxisLabel a label for the Y-axis (<code>null</code> permitted). * @param dataset the dataset for the chart (<code>null</code> permitted). * @param orientation the orientation (horizontal or vertical) (<code>null</code> NOT permitted). * @param legend a flag specifying whether or not a legend is required. * @param tooltips configure chart to generate tool tips? * @param urls configure chart to generate URLs? * * @return A bubble chart. */ public static JFreeChart createBubbleChart(String title, String xAxisLabel, String yAxisLabel, XYZDataset dataset, PlotOrientation orientation, boolean legend, boolean tooltips, boolean urls) { if (orientation == null) { throw new IllegalArgumentException(Messages.getString("TopChartFactory.argument")); //$NON-NLS-1$ } NumberAxis xAxis = new NumberAxis(xAxisLabel); xAxis.setAutoRangeIncludesZero(false); NumberAxis yAxis = new NumberAxis(yAxisLabel); yAxis.setAutoRangeIncludesZero(false); XYPlot plot = new XYPlot(dataset, xAxis, yAxis, null); XYItemRenderer renderer = new XYBubbleRenderer(XYBubbleRenderer.SCALE_ON_RANGE_AXIS) { @Override public void drawItem(Graphics2D g2, XYItemRendererState state, Rectangle2D dataArea, PlotRenderingInfo info, XYPlot plot, ValueAxis domainAxis, ValueAxis rangeAxis, XYDataset dataset, int series, int item, CrosshairState crosshairState, int pass) { // return straight away if the item is not visible if (!getItemVisible(series, item)) { return; } PlotOrientation orientation = plot.getOrientation(); // get the data point... double x = dataset.getXValue(series, item); double y = dataset.getYValue(series, item); double z = Double.NaN; if (dataset instanceof XYZDataset) { XYZDataset xyzData = (XYZDataset) dataset; z = xyzData.getZValue(series, item); } if (!Double.isNaN(z)) { RectangleEdge domainAxisLocation = plot.getDomainAxisEdge(); RectangleEdge rangeAxisLocation = plot.getRangeAxisEdge(); double transX = domainAxis.valueToJava2D(x, dataArea, domainAxisLocation); double transY = rangeAxis.valueToJava2D(y, dataArea, rangeAxisLocation); double transDomain = 0.0; double transRange = 0.0; double zero; // MOD scorreia +2L avoid points: minimal size of circle must be 1 // z = z * transX + 1; // ADD xqliu 2009-07-06 bug 8035 double zSize = getBubbleSize(z); // calculate the multiple of bubble's default size z = 0; // use bubble's default size // ~ switch (getScaleType()) { case SCALE_ON_DOMAIN_AXIS: zero = domainAxis.valueToJava2D(0.0, dataArea, domainAxisLocation); transDomain = domainAxis.valueToJava2D(z, dataArea, domainAxisLocation) - zero; transRange = transDomain; break; case SCALE_ON_RANGE_AXIS: zero = rangeAxis.valueToJava2D(0.0, dataArea, rangeAxisLocation); transRange = zero - rangeAxis.valueToJava2D(z, dataArea, rangeAxisLocation); transDomain = transRange; break; default: double zero1 = domainAxis.valueToJava2D(0.0, dataArea, domainAxisLocation); double zero2 = rangeAxis.valueToJava2D(0.0, dataArea, rangeAxisLocation); transDomain = domainAxis.valueToJava2D(z, dataArea, domainAxisLocation) - zero1; transRange = zero2 - rangeAxis.valueToJava2D(z, dataArea, rangeAxisLocation); } transDomain = Math.abs(transDomain); transRange = Math.abs(transRange); // MODSCA 2008-11-27 enlarge ellipse by diag% of the total diagonal double diag = Math.sqrt(dataArea.getHeight() * dataArea.getHeight() + dataArea.getWidth() * dataArea.getWidth()); transDomain += diag / 100; transRange += diag / 100; Ellipse2D circle = null; // ADD xqliu 2009-07-06 bug 8035 transDomain *= zSize; transRange *= zSize; // ~ if (orientation == PlotOrientation.VERTICAL) { circle = new Ellipse2D.Double(transX - transDomain / 2.0, transY - transRange / 2.0, transDomain, transRange); } else if (orientation == PlotOrientation.HORIZONTAL) { circle = new Ellipse2D.Double(transY - transRange / 2.0, transX - transDomain / 2.0, transRange, transDomain); } g2.setPaint(getItemPaint(series, item)); g2.fill(circle); g2.setStroke(getItemOutlineStroke(series, item)); g2.setPaint(getItemOutlinePaint(series, item)); g2.draw(circle); if (isItemLabelVisible(series, item)) { if (orientation == PlotOrientation.VERTICAL) { drawItemLabel(g2, orientation, dataset, series, item, transX, transY, false); } else if (orientation == PlotOrientation.HORIZONTAL) { drawItemLabel(g2, orientation, dataset, series, item, transY, transX, false); } } // add an entity if this info is being collected EntityCollection entities = null; if (info != null) { entities = info.getOwner().getEntityCollection(); if (entities != null && circle.intersects(dataArea)) { addEntity(entities, circle, dataset, series, item, circle.getCenterX(), circle.getCenterY()); } } int domainAxisIndex = plot.getDomainAxisIndex(domainAxis); int rangeAxisIndex = plot.getRangeAxisIndex(rangeAxis); updateCrosshairValues(crosshairState, x, y, domainAxisIndex, rangeAxisIndex, transX, transY, orientation); } } /** * DOC xqliu : calculate the size of bubble. for bug 8035 2009-07-06. * * @param z multiple of bubble's default size * @return */ private double getBubbleSize(double z) { if (z > 0 && z <= 10) { return 2; } else if (z > 10 && z <= 100) { return 3; } else if (z > 100) { return 4; } return 1; } }; if (tooltips) { renderer.setBaseToolTipGenerator(new StandardXYZToolTipGenerator()); } if (urls) { renderer.setURLGenerator(new StandardXYZURLGenerator()); } plot.setRenderer(renderer); plot.setOrientation(orientation); JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend); return chart; }
From source file:org.locationtech.udig.processingtoolbox.tools.BubbleChartDialog.java
private void updateChart(SimpleFeatureCollection features, String xField, String yField, String sizeField) { // 1. Create a single plot containing both the scatter and line XYPlot plot = new XYPlot(); plot.setOrientation(PlotOrientation.VERTICAL); plot.setBackgroundPaint(java.awt.Color.WHITE); plot.setDomainPannable(false);// w w w . jav a 2 s .c o m plot.setRangePannable(false); plot.setSeriesRenderingOrder(SeriesRenderingOrder.FORWARD); plot.setDomainCrosshairVisible(false); plot.setRangeCrosshairVisible(false); plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0)); plot.setForegroundAlpha(0.75f); // 2. Setup Scatter plot // Create the bubble chart data, renderer, and axis int fontStyle = java.awt.Font.BOLD; FontData fontData = getShell().getDisplay().getSystemFont().getFontData()[0]; NumberAxis xPlotAxis = new NumberAxis(xField); // Independent variable xPlotAxis.setLabelFont(new Font(fontData.getName(), fontStyle, 12)); xPlotAxis.setTickLabelFont(new Font(fontData.getName(), fontStyle, 10)); NumberAxis yPlotAxis = new NumberAxis(yField); // Dependent variable yPlotAxis.setLabelFont(new Font(fontData.getName(), fontStyle, 12)); yPlotAxis.setTickLabelFont(new Font(fontData.getName(), fontStyle, 10)); XYItemRenderer plotRenderer = new XYBubbleRenderer(XYBubbleRenderer.SCALE_ON_RANGE_AXIS); plotRenderer.setSeriesPaint(0, java.awt.Color.ORANGE); // dot plotRenderer.setBaseItemLabelGenerator(new BubbleXYItemLabelGenerator()); plotRenderer.setBaseToolTipGenerator(new StandardXYZToolTipGenerator()); plotRenderer .setBasePositiveItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.CENTER)); // Set the bubble chart data, renderer, and axis into plot plot.setDataset(0, getBubbleChartData(features, xField, yField, sizeField)); xPlotAxis.setAutoRangeIncludesZero(false); xPlotAxis.setAutoRange(false); double differUpper = minMaxVisitor.getMaxX() - minMaxVisitor.getAverageX(); double differLower = minMaxVisitor.getAverageX() - minMaxVisitor.getMinX(); double gap = Math.abs(differUpper - differLower); if (differUpper > differLower) { xPlotAxis.setRange(minMaxVisitor.getMinX() - gap, minMaxVisitor.getMaxX()); } else { xPlotAxis.setRange(minMaxVisitor.getMinX(), minMaxVisitor.getMaxX() + gap); } yPlotAxis.setAutoRangeIncludesZero(false); yPlotAxis.setAutoRange(false); differUpper = minMaxVisitor.getMaxY() - minMaxVisitor.getAverageY(); differLower = minMaxVisitor.getAverageY() - minMaxVisitor.getMinY(); gap = Math.abs(differUpper - differLower); if (differUpper > differLower) { yPlotAxis.setRange(minMaxVisitor.getMinY() - gap, minMaxVisitor.getMaxY()); } else { yPlotAxis.setRange(minMaxVisitor.getMinY(), minMaxVisitor.getMaxY() + gap); } plot.setRenderer(0, plotRenderer); plot.setDomainAxis(0, xPlotAxis); plot.setRangeAxis(0, yPlotAxis); // Map the scatter to the first Domain and first Range plot.mapDatasetToDomainAxis(0, 0); plot.mapDatasetToRangeAxis(0, 0); // 3. Setup line // Create the line data, renderer, and axis XYItemRenderer lineRenderer = new XYLineAndShapeRenderer(true, false); // Lines only lineRenderer.setSeriesPaint(0, java.awt.Color.GRAY); lineRenderer.setSeriesPaint(1, java.awt.Color.GRAY); lineRenderer.setSeriesPaint(2, java.awt.Color.GRAY); // Set the line data, renderer, and axis into plot NumberAxis xLineAxis = new NumberAxis(EMPTY); xLineAxis.setTickMarksVisible(false); xLineAxis.setTickLabelsVisible(false); NumberAxis yLineAxis = new NumberAxis(EMPTY); yLineAxis.setTickMarksVisible(false); yLineAxis.setTickLabelsVisible(false); XYSeriesCollection lineDataset = new XYSeriesCollection(); // AverageY XYSeries horizontal = new XYSeries("AverageY"); //$NON-NLS-1$ horizontal.add(xPlotAxis.getRange().getLowerBound(), minMaxVisitor.getAverageY()); horizontal.add(xPlotAxis.getRange().getUpperBound(), minMaxVisitor.getAverageY()); lineDataset.addSeries(horizontal); // AverageX XYSeries vertical = new XYSeries("AverageX"); //$NON-NLS-1$ vertical.add(minMaxVisitor.getAverageX(), yPlotAxis.getRange().getLowerBound()); vertical.add(minMaxVisitor.getAverageX(), yPlotAxis.getRange().getUpperBound()); lineDataset.addSeries(vertical); plot.setDataset(1, lineDataset); plot.setRenderer(1, lineRenderer); plot.setDomainAxis(1, xLineAxis); plot.setRangeAxis(1, yLineAxis); // Map the line to the second Domain and second Range plot.mapDatasetToDomainAxis(1, 0); plot.mapDatasetToRangeAxis(1, 0); // 4. Setup Selection NumberAxis xSelectionAxis = new NumberAxis(EMPTY); xSelectionAxis.setTickMarksVisible(false); xSelectionAxis.setTickLabelsVisible(false); NumberAxis ySelectionAxis = new NumberAxis(EMPTY); ySelectionAxis.setTickMarksVisible(false); ySelectionAxis.setTickLabelsVisible(false); XYItemRenderer selectionRenderer = new XYBubbleRenderer(XYBubbleRenderer.SCALE_ON_RANGE_AXIS); selectionRenderer.setSeriesPaint(0, java.awt.Color.RED); // dot selectionRenderer.setSeriesOutlinePaint(0, java.awt.Color.RED); plot.setDataset(2, new DefaultXYZDataset2()); plot.setRenderer(2, selectionRenderer); plot.setDomainAxis(2, xSelectionAxis); plot.setRangeAxis(2, ySelectionAxis); // Map the scatter to the second Domain and second Range plot.mapDatasetToDomainAxis(2, 0); plot.mapDatasetToRangeAxis(2, 0); // 5. Finally, Create the chart with the plot and a legend java.awt.Font titleFont = new Font(fontData.getName(), fontStyle, 20); JFreeChart chart = new JFreeChart(EMPTY, titleFont, plot, false); chart.setBackgroundPaint(java.awt.Color.WHITE); chart.setBorderVisible(false); chartComposite.setChart(chart); chartComposite.forceRedraw(); }
From source file:org.hxzon.demo.jfreechart.OtherDatasetDemo.java
private static JFreeChart createBubbleChart(XYZDataset dataset) { NumberAxis xAxis = new NumberAxis(xAxisLabel); xAxis.setAutoRangeIncludesZero(false); NumberAxis yAxis = new NumberAxis(yAxisLabel); yAxis.setAutoRangeIncludesZero(false); XYPlot plot = new XYPlot(dataset, xAxis, yAxis, null); // A renderer that draws a circle at each data point with a diameter that is // determined by the z-value in the dataset (the renderer requires the dataset // to be an instance of {@link XYZDataset}. XYItemRenderer renderer = new XYBubbleRenderer(XYBubbleRenderer.SCALE_ON_RANGE_AXIS); if (tooltips) { renderer.setBaseToolTipGenerator(new StandardXYZToolTipGenerator()); }// ww w . ja v a 2 s . c om if (urls) { renderer.setURLGenerator(new StandardXYZURLGenerator()); } plot.setRenderer(renderer); plot.setOrientation(orientation); JFreeChart chart = new JFreeChart("Bubble Chart Demo", JFreeChart.DEFAULT_TITLE_FONT, plot, legend); chart.setBackgroundPaint(Color.white); plot.setBackgroundPaint(Color.lightGray); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinePaint(Color.white); plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0)); plot.setDomainCrosshairVisible(true); plot.setRangeCrosshairVisible(true); return chart; }
From source file:probe.com.view.core.chart4j.VennDiagramPanel.java
/** * Update the plot./* w ww . j av a 2 s. c o m*/ */ public void updatePlot() { // plotPanel.removeAll(); tooltipToDatasetMap = new HashMap<String, String>(); DefaultXYZDataset xyzDataset = new DefaultXYZDataset(); chart = ChartFactory.createBubbleChart(null, "X", "Y", xyzDataset, PlotOrientation.VERTICAL, false, true, false); XYPlot plot = chart.getXYPlot(); if (currentVennDiagramType == VennDiagramType.ONE_WAY) { plot.getRangeAxis().setRange(0.86, 1.24); plot.getDomainAxis().setRange(0.85, 1.25); } else if (currentVennDiagramType == VennDiagramType.TWO_WAY) { plot.getRangeAxis().setRange(0.86, 1.24); plot.getDomainAxis().setRange(0.85, 1.25); } else if (currentVennDiagramType == VennDiagramType.THREE_WAY) { plot.getRangeAxis().setRange(0.86, 1.24); plot.getDomainAxis().setRange(0.85, 1.25); } else { plot.getRangeAxis().setRange(-0.04, 0.6); plot.getDomainAxis().setRange(-0.08, 0.7); } plot.getRangeAxis().setVisible(false); plot.getDomainAxis().setVisible(false); double radius = 0.1; Ellipse2D ellipse = new Ellipse2D.Double(1 - radius, 1 - radius, radius + radius, radius + radius); XYShapeAnnotation xyShapeAnnotation = new XYShapeAnnotation(ellipse, new BasicStroke(2f), new Color(140, 140, 140, 150), datasetAColor); // @TODO: make it possible set the line color and width? plot.addAnnotation(xyShapeAnnotation); if (currentVennDiagramType == VennDiagramType.TWO_WAY || currentVennDiagramType == VennDiagramType.THREE_WAY) { ellipse = new Ellipse2D.Double(1 - radius + 0.1, 1 - radius, radius + radius, radius + radius); xyShapeAnnotation = new XYShapeAnnotation(ellipse, new BasicStroke(2f), new Color(140, 140, 140, 150), datasetBColor); plot.addAnnotation(xyShapeAnnotation); } if (currentVennDiagramType == VennDiagramType.THREE_WAY) { ellipse = new Ellipse2D.Double(1 - radius + 0.05, 1 - radius + 0.1, radius + radius, radius + radius); xyShapeAnnotation = new XYShapeAnnotation(ellipse, new BasicStroke(2f), new Color(140, 140, 140, 150), datasetCColor); plot.addAnnotation(xyShapeAnnotation); } XYTextAnnotation anotation; if (currentVennDiagramType == VennDiagramType.ONE_WAY) { anotation = new XYTextAnnotation("" + vennDiagramResults.get("a").size(), 1.0, 1.0); anotation.setToolTipText(groupNames.get("a")); anotation.setFont(new Font(anotation.getFont().getFontName(), Font.BOLD, fontSizeValues)); plot.addAnnotation(anotation); tooltipToDatasetMap.put(anotation.getToolTipText(), "a"); // legend if (showLegend) { anotation = new XYTextAnnotation(groupNames.get("a"), legendDatasetAThreeWay.getX(), legendDatasetAThreeWay.getY()); anotation.setTextAnchor(TextAnchor.BASELINE_LEFT); anotation.setFont(new Font(anotation.getFont().getFontName(), Font.BOLD, fontSizeLegend)); plot.addAnnotation(anotation); } } else if (currentVennDiagramType == VennDiagramType.TWO_WAY) { anotation = new XYTextAnnotation("" + vennDiagramResults.get("a").size(), 0.96, 1.0); anotation.setToolTipText(groupNames.get("a")); anotation.setFont(new Font(anotation.getFont().getFontName(), Font.BOLD, fontSizeValues)); plot.addAnnotation(anotation); tooltipToDatasetMap.put(anotation.getToolTipText(), "a"); anotation = new XYTextAnnotation("" + vennDiagramResults.get("b").size(), 1.14, 1.0); anotation.setToolTipText(groupNames.get("b")); anotation.setFont(new Font(anotation.getFont().getFontName(), Font.BOLD, fontSizeValues)); plot.addAnnotation(anotation); tooltipToDatasetMap.put(anotation.getToolTipText(), "b"); anotation = new XYTextAnnotation("" + vennDiagramResults.get("ab").size(), 1.05, 1.0); anotation .setToolTipText("<html>" + groupNames.get("a") + " ∩ " + groupNames.get("b") + "</html>"); anotation.setFont(new Font(anotation.getFont().getFontName(), Font.BOLD, fontSizeValues)); plot.addAnnotation(anotation); tooltipToDatasetMap.put(anotation.getToolTipText(), "ab"); // legend if (showLegend) { anotation = new XYTextAnnotation(groupNames.get("a"), legendDatasetAThreeWay.getX(), legendDatasetAThreeWay.getY()); anotation.setTextAnchor(TextAnchor.BASELINE_LEFT); anotation.setFont(new Font(anotation.getFont().getFontName(), Font.BOLD, fontSizeLegend)); plot.addAnnotation(anotation); anotation = new XYTextAnnotation(groupNames.get("b"), legendDatasetBThreeWay.getX(), legendDatasetBThreeWay.getY()); anotation.setTextAnchor(TextAnchor.BASELINE_LEFT); anotation.setFont(new Font(anotation.getFont().getFontName(), Font.BOLD, fontSizeLegend)); plot.addAnnotation(anotation); } } else if (currentVennDiagramType == VennDiagramType.THREE_WAY) { anotation = new XYTextAnnotation("" + vennDiagramResults.get("a").size(), 0.96, 0.97); anotation.setToolTipText(groupNames.get("a")); anotation.setFont(new Font(anotation.getFont().getFontName(), Font.BOLD, fontSizeValues)); plot.addAnnotation(anotation); tooltipToDatasetMap.put(anotation.getToolTipText(), "a"); anotation = new XYTextAnnotation("" + vennDiagramResults.get("b").size(), 1.14, 0.97); anotation.setToolTipText(groupNames.get("b")); anotation.setFont(new Font(anotation.getFont().getFontName(), Font.BOLD, fontSizeValues)); plot.addAnnotation(anotation); tooltipToDatasetMap.put(anotation.getToolTipText(), "b"); anotation = new XYTextAnnotation("" + vennDiagramResults.get("ab").size(), 1.05, 0.97); anotation .setToolTipText("<html>" + groupNames.get("a") + " ∩ " + groupNames.get("b") + "</html>"); anotation.setFont(new Font(anotation.getFont().getFontName(), Font.BOLD, fontSizeValues)); plot.addAnnotation(anotation); tooltipToDatasetMap.put(anotation.getToolTipText(), "ab"); anotation = new XYTextAnnotation("" + vennDiagramResults.get("c").size(), 1.05, 1.14); anotation.setToolTipText(groupNames.get("c")); anotation.setFont(new Font(anotation.getFont().getFontName(), Font.BOLD, fontSizeValues)); plot.addAnnotation(anotation); tooltipToDatasetMap.put(anotation.getToolTipText(), "c"); anotation = new XYTextAnnotation("" + vennDiagramResults.get("ac").size(), 0.99, 1.065); anotation.setToolTipText( "<html>" + groupNames.get("a") + " ∩ " + groupNames.get("c") + "</html>"); anotation.setFont(new Font(anotation.getFont().getFontName(), Font.BOLD, fontSizeValues)); plot.addAnnotation(anotation); tooltipToDatasetMap.put(anotation.getToolTipText(), "ac"); anotation = new XYTextAnnotation("" + vennDiagramResults.get("bc").size(), 1.11, 1.065); anotation .setToolTipText("<html>" + groupNames.get("b") + " ∩ " + groupNames.get("c") + "</html>"); anotation.setFont(new Font(anotation.getFont().getFontName(), Font.BOLD, fontSizeValues)); plot.addAnnotation(anotation); tooltipToDatasetMap.put(anotation.getToolTipText(), "bc"); anotation = new XYTextAnnotation("" + vennDiagramResults.get("abc").size(), 1.05, 1.036); anotation.setToolTipText("<html>" + groupNames.get("a") + " ∩ " + groupNames.get("b") + " ∩ " + groupNames.get("c") + "</html>"); anotation.setFont(new Font(anotation.getFont().getFontName(), Font.BOLD, fontSizeValues)); plot.addAnnotation(anotation); tooltipToDatasetMap.put(anotation.getToolTipText(), "abc"); // legend if (showLegend) { anotation = new XYTextAnnotation(groupNames.get("a"), legendDatasetAThreeWay.getX(), legendDatasetAThreeWay.getY()); anotation.setTextAnchor(TextAnchor.BASELINE_LEFT); anotation.setFont(new Font(anotation.getFont().getFontName(), Font.BOLD, fontSizeLegend)); plot.addAnnotation(anotation); anotation = new XYTextAnnotation(groupNames.get("b"), legendDatasetBThreeWay.getX(), legendDatasetBThreeWay.getY()); anotation.setTextAnchor(TextAnchor.BASELINE_LEFT); anotation.setFont(new Font(anotation.getFont().getFontName(), Font.BOLD, fontSizeLegend)); plot.addAnnotation(anotation); anotation = new XYTextAnnotation(groupNames.get("c"), legendDatasetCThreeWay.getX(), legendDatasetCThreeWay.getY()); anotation.setTextAnchor(TextAnchor.BASELINE_LEFT); anotation.setFont(new Font(anotation.getFont().getFontName(), Font.BOLD, fontSizeLegend)); plot.addAnnotation(anotation); } } else if (currentVennDiagramType == VennDiagramType.FOUR_WAY) { XYBoxAnnotation anotation2 = new XYBoxAnnotation(0, 0, 0.2, 0.5, new BasicStroke(2), Color.LIGHT_GRAY, datasetAColor); plot.addAnnotation(anotation2); anotation2 = new XYBoxAnnotation(0.1, 0, 0.3, 0.4, new BasicStroke(2), Color.LIGHT_GRAY, datasetBColor); plot.addAnnotation(anotation2); anotation2 = new XYBoxAnnotation(0, 0.1, 0.4, 0.3, new BasicStroke(2), Color.LIGHT_GRAY, datasetCColor); plot.addAnnotation(anotation2); anotation2 = new XYBoxAnnotation(0, 0, 0.5, 0.2, new BasicStroke(2), Color.LIGHT_GRAY, datasetDColor); plot.addAnnotation(anotation2); anotation = new XYTextAnnotation("" + vennDiagramResults.get("a").size(), 0.15, 0.45); anotation.setToolTipText(groupNames.get("a")); anotation.setFont(new Font(anotation.getFont().getFontName(), Font.BOLD, fontSizeValues)); plot.addAnnotation(anotation); tooltipToDatasetMap.put(anotation.getToolTipText(), "a"); anotation = new XYTextAnnotation("" + vennDiagramResults.get("ab").size(), 0.15, 0.35); anotation .setToolTipText("<html>" + groupNames.get("a") + " ∩ " + groupNames.get("b") + "</html>"); anotation.setFont(new Font(anotation.getFont().getFontName(), Font.BOLD, fontSizeValues)); plot.addAnnotation(anotation); tooltipToDatasetMap.put(anotation.getToolTipText(), "ab"); anotation = new XYTextAnnotation("" + vennDiagramResults.get("abc").size(), 0.15, 0.25); anotation.setToolTipText("<html>" + groupNames.get("a") + " ∩ " + groupNames.get("b") + " ∩ " + groupNames.get("c") + "</html>"); anotation.setFont(new Font(anotation.getFont().getFontName(), Font.BOLD, fontSizeValues)); plot.addAnnotation(anotation); tooltipToDatasetMap.put(anotation.getToolTipText(), "abc"); anotation = new XYTextAnnotation("" + vennDiagramResults.get("abcd").size(), 0.15, 0.15); anotation.setToolTipText("<html>" + groupNames.get("a") + " ∩ " + groupNames.get("b") + " ∩ " + groupNames.get("c") + " ∩ " + groupNames.get("d") + "</html>"); anotation.setFont(new Font(anotation.getFont().getFontName(), Font.BOLD, fontSizeValues)); plot.addAnnotation(anotation); tooltipToDatasetMap.put(anotation.getToolTipText(), "abcd"); anotation = new XYTextAnnotation("" + vennDiagramResults.get("abd").size(), 0.15, 0.05); anotation.setToolTipText("<html>" + groupNames.get("a") + " ∩ " + groupNames.get("b") + " ∩ " + groupNames.get("d") + "</html>"); anotation.setFont(new Font(anotation.getFont().getFontName(), Font.BOLD, fontSizeValues)); plot.addAnnotation(anotation); tooltipToDatasetMap.put(anotation.getToolTipText(), "abd"); anotation = new XYTextAnnotation("" + vennDiagramResults.get("ac").size(), 0.05, 0.25); anotation .setToolTipText("<html>" + groupNames.get("a") + " ∩ " + groupNames.get("c") + "</html>"); anotation.setFont(new Font(anotation.getFont().getFontName(), Font.BOLD, fontSizeValues)); plot.addAnnotation(anotation); tooltipToDatasetMap.put(anotation.getToolTipText(), "ac"); anotation = new XYTextAnnotation("" + vennDiagramResults.get("acd").size(), 0.05, 0.15); anotation.setToolTipText("<html>" + groupNames.get("a") + " ∩ " + groupNames.get("c") + " ∩ " + groupNames.get("d") + "</html>"); anotation.setFont(new Font(anotation.getFont().getFontName(), Font.BOLD, fontSizeValues)); plot.addAnnotation(anotation); tooltipToDatasetMap.put(anotation.getToolTipText(), "acd"); anotation = new XYTextAnnotation("" + vennDiagramResults.get("ad").size(), 0.05, 0.05); anotation .setToolTipText("<html>" + groupNames.get("a") + " ∩ " + groupNames.get("d") + "</html>"); anotation.setFont(new Font(anotation.getFont().getFontName(), Font.BOLD, fontSizeValues)); plot.addAnnotation(anotation); tooltipToDatasetMap.put(anotation.getToolTipText(), "ad"); anotation = new XYTextAnnotation("" + vennDiagramResults.get("b").size(), 0.25, 0.35); anotation.setToolTipText("<html>" + groupNames.get("b") + "</html>"); anotation.setFont(new Font(anotation.getFont().getFontName(), Font.BOLD, fontSizeValues)); plot.addAnnotation(anotation); tooltipToDatasetMap.put(anotation.getToolTipText(), "b"); anotation = new XYTextAnnotation("" + vennDiagramResults.get("bc").size(), 0.25, 0.25); anotation .setToolTipText("<html>" + groupNames.get("b") + " ∩ " + groupNames.get("c") + "</html>"); anotation.setFont(new Font(anotation.getFont().getFontName(), Font.BOLD, fontSizeValues)); plot.addAnnotation(anotation); tooltipToDatasetMap.put(anotation.getToolTipText(), "bc"); anotation = new XYTextAnnotation("" + vennDiagramResults.get("bcd").size(), 0.25, 0.15); anotation.setToolTipText("<html>" + groupNames.get("b") + " ∩ " + groupNames.get("c") + " ∩ " + groupNames.get("d") + "</html>"); anotation.setFont(new Font(anotation.getFont().getFontName(), Font.BOLD, fontSizeValues)); plot.addAnnotation(anotation); tooltipToDatasetMap.put(anotation.getToolTipText(), "bcd"); anotation = new XYTextAnnotation("" + vennDiagramResults.get("bd").size(), 0.25, 0.05); anotation .setToolTipText("<html>" + groupNames.get("b") + " ∩ " + groupNames.get("d") + "</html>"); anotation.setFont(new Font(anotation.getFont().getFontName(), Font.BOLD, fontSizeValues)); plot.addAnnotation(anotation); tooltipToDatasetMap.put(anotation.getToolTipText(), "bd"); anotation = new XYTextAnnotation("" + vennDiagramResults.get("c").size(), 0.35, 0.25); anotation.setToolTipText("<html>" + groupNames.get("c") + "</html>"); anotation.setFont(new Font(anotation.getFont().getFontName(), Font.BOLD, fontSizeValues)); plot.addAnnotation(anotation); tooltipToDatasetMap.put(anotation.getToolTipText(), "c"); anotation = new XYTextAnnotation("" + vennDiagramResults.get("cd").size(), 0.35, 0.15); anotation .setToolTipText("<html>" + groupNames.get("c") + " ∩ " + groupNames.get("d") + "</html>"); anotation.setFont(new Font(anotation.getFont().getFontName(), Font.BOLD, fontSizeValues)); plot.addAnnotation(anotation); tooltipToDatasetMap.put(anotation.getToolTipText(), "cd"); anotation = new XYTextAnnotation("" + vennDiagramResults.get("d").size(), 0.45, 0.15); anotation.setToolTipText("<html>" + groupNames.get("d") + "</html>"); anotation.setFont(new Font(anotation.getFont().getFontName(), Font.BOLD, fontSizeValues)); plot.addAnnotation(anotation); tooltipToDatasetMap.put(anotation.getToolTipText(), "d"); // legend if (showLegend) { anotation = new XYTextAnnotation(groupNames.get("a"), legendDatasetAFourWay.getX(), legendDatasetAFourWay.getY()); anotation.setTextAnchor(TextAnchor.BASELINE_LEFT); anotation.setFont(new Font(anotation.getFont().getFontName(), Font.BOLD, fontSizeLegend)); plot.addAnnotation(anotation); anotation = new XYTextAnnotation(groupNames.get("b"), legendDatasetBFourWay.getX(), legendDatasetBFourWay.getY()); anotation.setTextAnchor(TextAnchor.BASELINE_LEFT); anotation.setFont(new Font(anotation.getFont().getFontName(), Font.BOLD, fontSizeLegend)); plot.addAnnotation(anotation); anotation = new XYTextAnnotation(groupNames.get("c"), legendDatasetCFourWay.getX(), legendDatasetCFourWay.getY()); anotation.setTextAnchor(TextAnchor.BASELINE_LEFT); anotation.setFont(new Font(anotation.getFont().getFontName(), Font.BOLD, fontSizeLegend)); plot.addAnnotation(anotation); anotation = new XYTextAnnotation(groupNames.get("d"), legendDatasetDFourWay.getX(), legendDatasetDFourWay.getY()); anotation.setTextAnchor(TextAnchor.BASELINE_LEFT); anotation.setFont(new Font(anotation.getFont().getFontName(), Font.BOLD, fontSizeLegend)); plot.addAnnotation(anotation); } } // set up the renderer XYBubbleRenderer renderer = new XYBubbleRenderer(XYBubbleRenderer.SCALE_ON_RANGE_AXIS); renderer.setBaseToolTipGenerator(new StandardXYZToolTipGenerator()); plot.setRenderer(renderer); // make all datapoints semitransparent plot.setForegroundAlpha(0.5f); // remove space before/after the domain axis plot.getDomainAxis().setUpperMargin(0); plot.getDomainAxis().setLowerMargin(0); plot.setRangeGridlinePaint(Color.black); // hide unwanted chart details plot.setDomainGridlinesVisible(false); plot.setRangeGridlinesVisible(false); chart.getPlot().setOutlineVisible(false); // set background color chart.getPlot().setBackgroundPaint(Color.WHITE); chart.setBackgroundPaint(Color.WHITE); chartPanel = new ChartPanel(chart); // disable the pop up menu chartPanel.setPopupMenu(null); chartPanel.setBackground(Color.WHITE); // add the plot to the chart // plotPanel.add(chartPanel); // plotPanel.revalidate(); // plotPanel.repaint(); // // this.add(plotPanel); }
From source file:probe.com.view.body.quantdatasetsoverview.diseasegroupsfilters.ComparisonsSelectionOverviewBubbleChart.java
private JFreeChart updateBubbleChartChart(Set<QuantDiseaseGroupsComparison> selectedComparisonList) { if (userCustomizedComparison != null) { return updateBubbleChartChartWithCustUserData(selectedComparisonList); }/* w ww . j ava 2 s .com*/ tooltipsProtNumberMap.clear(); DefaultXYZDataset defaultxyzdataset = new DefaultXYZDataset(); int counter = 0; int upper = -1; boolean significantOnly = this.Quant_Central_Manager.isSignificantOnly(); for (QuantDiseaseGroupsComparison qc : selectedComparisonList) { if (significantOnly) { int upperCounter = 0; for (DiseaseGroupsComparisonsProteinLayout qp : qc.getComparProtsMap().values()) { if (qp == null) { continue; } if (qp.getSignificantTrindCategory() == 2 || qp.getSignificantTrindCategory() == 5) { continue; } upperCounter++; } if (upperCounter > upper) { upper = upperCounter; } } else { if (qc.getComparProtsMap() == null) { System.out.println("null qc " + qc.getComparisonHeader()); } if (qc.getComparProtsMap().size() > upper) { upper = qc.getComparProtsMap().size(); } } } final Map<Integer, Color[]> seriousColorMap = new HashMap<Integer, Color[]>(); Color[] dataColor = new Color[] { Color.WHITE, new Color(0, 153, 0), new Color(0, 229, 132), stableColor, new Color(247, 119, 119), new Color(204, 0, 0), Color.WHITE }; double[] yAxisValueI = new double[] { 0, 0, 0, 0, 0, 0, 0 }; double[] xAxisValueI = new double[] { 0, 0, 0, 0, 0, 0, 0 }; double[] widthValueI = new double[] { 0, 0, 0, 0, 0, 0, 0 }; double[][] seriesValuesI = { yAxisValueI, xAxisValueI, widthValueI }; seriousColorMap.put(0, new Color[] { Color.WHITE, Color.WHITE, Color.WHITE, Color.WHITE, Color.WHITE, Color.WHITE, Color.WHITE }); defaultxyzdataset.addSeries(" ", seriesValuesI); for (QuantDiseaseGroupsComparison qc : selectedComparisonList) { double[] tempWidthValue = new double[8]; if (qc.getComparProtsMap() == null) { continue; } for (String key : qc.getComparProtsMap().keySet()) { qc.getComparProtsMap().get(key).updateLabelLayout(); if (significantOnly && (qc.getComparProtsMap().get(key).getSignificantTrindCategory() == 2 || qc.getComparProtsMap().get(key).getSignificantTrindCategory() == 5)) { tempWidthValue[3] = 0; tempWidthValue[6] = 0; } else { tempWidthValue[qc.getComparProtsMap().get(key).getSignificantTrindCategory() + 1] = tempWidthValue[qc.getComparProtsMap().get(key).getSignificantTrindCategory() + 1] + 1; } } if (tempWidthValue[3] > 0 && tempWidthValue[3] >= 0) { stableColor = new Color(1, 141, 244); } else { stableColor = Color.decode("#b5babb"); } tempWidthValue[3] = tempWidthValue[3] + tempWidthValue[6]; tempWidthValue[6] = 0; dataColor[3] = stableColor; int length = 0; if (upper < 10) { upper = 10; } double[] tooltipNumbess = new double[tempWidthValue.length]; System.arraycopy(tempWidthValue, 0, tooltipNumbess, 0, tempWidthValue.length); this.tooltipsProtNumberMap.put(qc.getComparisonHeader(), tooltipNumbess); for (int x = 0; x < tempWidthValue.length; x++) { if (tempWidthValue[x] > 0) { tempWidthValue[x] = scaleValues(tempWidthValue[x], upper, 2.5, 0.05);//Math.max(tempWidthValue[x] * 1.5 / upper, 0.05); length++; } } double[] yAxisValue = new double[length]; double[] xAxisValue = new double[length]; double[] widthValue = new double[length]; Color[] serColorArr = new Color[length]; length = 0; for (int x = 0; x < tempWidthValue.length; x++) { if (tempWidthValue[x] > 0) { xAxisValue[length] = x; yAxisValue[length] = counter + 1; widthValue[length] = tempWidthValue[x]; serColorArr[length] = dataColor[x]; length++; } } if (length == 1 && selectedComparisonList.size() == 1) { widthValue[0] = 1; } seriousColorMap.put(counter + 1, serColorArr); double[][] seriesValues = { yAxisValue, xAxisValue, widthValue }; defaultxyzdataset.addSeries(qc.getComparisonHeader(), seriesValues); counter++; } double[] yAxisValueII = new double[0]; double[] xAxisValueII = new double[0]; double[] widthValueII = new double[0]; seriousColorMap.put(counter + 1, new Color[] {}); double[][] seriesValuesII = { yAxisValueII, xAxisValueII, widthValueII }; defaultxyzdataset.addSeries(" ", seriesValuesII); final Color[] labelsColor = new Color[] { Color.LIGHT_GRAY, new Color(80, 183, 71), Color.LIGHT_GRAY, new Color(1, 141, 244), Color.LIGHT_GRAY, new Color(204, 0, 0), Color.LIGHT_GRAY }; Font font = new Font("Verdana", Font.BOLD, 13); SymbolAxis yAxis = new SymbolAxis(null, new String[] { " ", "Decreased", " ", "Equal", " ", "Increased", " " }) { int i = 0; @Override public RectangleInsets getTickLabelInsets() { // System.out.println("at ---- super.getTickLabelInsets() " + super.getTickLabelInsets()); // if (i == 0) { // i++; // return new RectangleInsets(-5, -5, 0, 0); // }else // return super.getTickLabelInsets(); //To change body of generated methods, choose Tools | Templates. } int x = 0; @Override public Paint getTickLabelPaint() { if (x >= labelsColor.length) { x = 0; } return labelsColor[x++]; } }; yAxis.setAutoRangeStickyZero(true); yAxis.setFixedAutoRange(8); yAxis.setTickLabelFont(font); yAxis.setGridBandsVisible(false); yAxis.setAxisLinePaint(Color.LIGHT_GRAY); yAxis.setTickMarksVisible(false); yAxis.setUpperBound(6); String[] xAxisLabels = new String[selectedComparisonList.size() + 2]; int x = 0; xAxisLabels[x] = ""; int maxLength = -1; //init labels color final Color[] diseaseGroupslabelsColor = new Color[selectedComparisonList.size() + 2]; diseaseGroupslabelsColor[x] = Color.WHITE; x++; for (QuantDiseaseGroupsComparison comp : selectedComparisonList) { String header = comp.getComparisonHeader(); String updatedHeader = header.split(" / ")[0].split("\n")[0] + " / " + header.split(" / ")[1].split("\n")[0] + ""; xAxisLabels[x] = updatedHeader + " (" + comp.getDatasetIndexes().length + ") "; if (xAxisLabels[x].length() > maxLength) { maxLength = xAxisLabels[x].length(); } diseaseGroupslabelsColor[x] = diseaseColorMap.get(header.split(" / ")[0].split("\n")[1]); x++; } xAxisLabels[x] = ""; diseaseGroupslabelsColor[x] = Color.WHITE; SymbolAxis xAxis; final boolean finalNum; finalNum = maxLength > 30 && selectedComparisonList.size() > 4; xAxis = new SymbolAxis(null, xAxisLabels) { int x = 0; @Override public Paint getTickLabelPaint() { if (x >= diseaseGroupslabelsColor.length) { x = 0; } return diseaseGroupslabelsColor[x++]; } private final boolean localfinal = finalNum; @Override protected List refreshTicksHorizontal(Graphics2D g2, Rectangle2D dataArea, RectangleEdge edge) { if (localfinal) { setVerticalTickLabels(localfinal); return super.refreshTicksHorizontal(g2, dataArea, edge); } List ticks = new java.util.ArrayList(); Font tickLabelFont = getTickLabelFont(); g2.setFont(tickLabelFont); double size = getTickUnit().getSize(); int count = calculateVisibleTickCount(); double lowestTickValue = calculateLowestVisibleTickValue(); double previousDrawnTickLabelPos = 0.0; double previousDrawnTickLabelLength = 0.0; if (count <= ValueAxis.MAXIMUM_TICK_COUNT) { for (int i = 0; i < count; i++) { double currentTickValue = lowestTickValue + (i * size); double xx = valueToJava2D(currentTickValue, dataArea, edge); String tickLabel; NumberFormat formatter = getNumberFormatOverride(); if (formatter != null) { tickLabel = formatter.format(currentTickValue) + " "; } else { tickLabel = valueToString(currentTickValue) + " "; } // avoid to draw overlapping tick labels Rectangle2D bounds = TextUtilities.getTextBounds(tickLabel, g2, g2.getFontMetrics()); double tickLabelLength = isVerticalTickLabels() ? bounds.getHeight() : bounds.getWidth(); boolean tickLabelsOverlapping = false; if (i > 0) { double avgTickLabelLength = (previousDrawnTickLabelLength + tickLabelLength) / 2.0; if (Math.abs(xx - previousDrawnTickLabelPos) < avgTickLabelLength) { tickLabelsOverlapping = true; } } if (tickLabelsOverlapping) { setVerticalTickLabels(true); } else { // remember these values for next comparison previousDrawnTickLabelPos = xx; previousDrawnTickLabelLength = tickLabelLength; } TextAnchor anchor; TextAnchor rotationAnchor; double angle = 0.0; if (isVerticalTickLabels()) { anchor = TextAnchor.CENTER_RIGHT; rotationAnchor = TextAnchor.CENTER_RIGHT; if (edge == RectangleEdge.TOP) { angle = 76.5; } else { angle = -76.5; } } else { if (edge == RectangleEdge.TOP) { anchor = TextAnchor.BOTTOM_CENTER; rotationAnchor = TextAnchor.BOTTOM_CENTER; } else { anchor = TextAnchor.TOP_CENTER; rotationAnchor = TextAnchor.TOP_CENTER; } } Tick tick = new NumberTick(new Double(currentTickValue), tickLabel, anchor, rotationAnchor, angle); ticks.add(tick); } } return ticks; } }; // } xAxis.setTickLabelFont(font); xAxis.setTickLabelInsets(new RectangleInsets(2, 20, 2, 20)); xAxis.setAutoRangeStickyZero(true); xAxis.setTickMarksVisible(false); xAxis.setUpperBound(diseaseGroupslabelsColor.length - 1); xAxis.setGridBandsVisible(false); xAxis.setAxisLinePaint(Color.LIGHT_GRAY); int scale = XYBubbleRenderer.SCALE_ON_RANGE_AXIS; XYItemRenderer xyitemrenderer = new XYBubbleRenderer(scale) { private int counter = 0; private int localSerious = -1; private final Map<Integer, Color[]> localSeriousColorMap = seriousColorMap; @Override public Paint getSeriesPaint(int series) { if (series != localSerious || isNewImge || localSeriousColorMap.get(series).length == counter) { counter = 0; isNewImge = false; } localSerious = series; Color c = localSeriousColorMap.get(series)[counter]; counter++; return c; } }; XYPlot xyplot = new XYPlot(defaultxyzdataset, xAxis, yAxis, xyitemrenderer) { @Override protected void drawRangeGridlines(Graphics2D g2, Rectangle2D area, List ticks) { try { if (!ticks.isEmpty()) { ticks.remove(0); } if (!ticks.isEmpty()) { ticks.remove(ticks.size() - 1); } } catch (Exception e) { } super.drawRangeGridlines(g2, area, ticks); //To change body of generated methods, choose Tools | Templates. } // private final Color[] labelsColor = new Color[]{new Color(0, 153, 0), new Color(0, 229, 132), new Color(1, 141, 244), new Color(255, 51, 51), new Color(204, 0, 0), Color.decode("#b5babb")}; // // private final Font font = new Font("Verdana", Font.PLAIN, 12); // private final String[] labels = new String[]{"Decreased 100%", "Decreased <100% ", "Equal", " Increased <100%", "Increased 100%", "No Quant. Info."}; // // @Override // public LegendItemCollection getLegendItems() { // LegendItemCollection legendItemCollection = new LegendItemCollection(); // for (int i = 0; i < labelsColor.length; i++) { // LegendItem item = new LegendItem(labels[i], labelsColor[i]); // item.setLabelFont(font); // // legendItemCollection.add(item); // // } // // return legendItemCollection;//To change body of generated methods, choose Tools | Templates. // } }; JFreeChart generatedChart = new JFreeChart(xyplot) { }; xyplot.setOutlineVisible(false); LegendTitle legend = generatedChart.getLegend(); legend.setVisible(false); // legend.setMargin(20, 0, 0, 0); //// legend.setBorder(1, 1, 1, 1); // legend.setFrame(new BlockBorder(1, 0, 1, 0, Color.LIGHT_GRAY)); // generatedChart.removeLegend(); // xyplot.setForegroundAlpha(0.65F); xyplot.setBackgroundPaint(Color.WHITE); generatedChart.setBackgroundPaint(Color.WHITE); generatedChart.setPadding(new RectangleInsets(0, 0, 0, 0)); Quant_Central_Manager.setProteinsOverviewBubbleChart(generatedChart); // exporter.writeChartToPDFFile(generatedChart, 595, 842, "bublechart.pdf"); return generatedChart; }
From source file:probe.com.view.body.quantdatasetsoverview.diseasegroupsfilters.ComparisonsSelectionOverviewBubbleChart.java
private JFreeChart updateBubbleChartChartWithCustUserData( Set<QuantDiseaseGroupsComparison> selectedComparisonList) { tooltipsProtNumberMap.clear();/*from ww w . j a v a2 s . c om*/ DefaultXYZDataset defaultxyzdataset = new DefaultXYZDataset(); int counter = 0; int upper = -1; boolean significantOnly = this.Quant_Central_Manager.isSignificantOnly(); if (userCustomizedComparison.getComparProtsMap().size() > upper) { upper = userCustomizedComparison.getComparProtsMap().size(); } for (QuantDiseaseGroupsComparison qc : selectedComparisonList) { if (significantOnly) { int upperCounter = 0; for (DiseaseGroupsComparisonsProteinLayout qp : qc.getComparProtsMap().values()) { if (qp == null) { continue; } if (qp.getSignificantTrindCategory() == 2) { continue; } upperCounter++; } if (upperCounter > upper) { upper = upperCounter; } } else { if (qc.getComparProtsMap() == null) { System.out.println("null qc " + qc.getComparisonHeader()); } if (qc.getComparProtsMap().size() > upper) { upper = qc.getComparProtsMap().size(); } } } final Map<Integer, Color[]> seriousColorMap = new HashMap<Integer, Color[]>(); Color[] dataColor = new Color[] { Color.WHITE, new Color(0, 153, 0), new Color(0, 229, 132), stableColor, new Color(247, 119, 119), new Color(204, 0, 0), Color.WHITE }; double[] tempWidthValue = new double[8]; double[] yAxisValueI = new double[] { 0, 0, 0, 0, 0, 0, 0 }; double[] xAxisValueI = new double[] { 0, 0, 0, 0, 0, 0, 0 }; double[] widthValueI = new double[] { 0, 0, 0, 0, 0, 0, 0 }; double[][] seriesValuesI = { yAxisValueI, xAxisValueI, widthValueI }; seriousColorMap.put(0, new Color[] { Color.WHITE, Color.WHITE, Color.WHITE, Color.WHITE, Color.WHITE, Color.WHITE, Color.WHITE }); defaultxyzdataset.addSeries(" ", seriesValuesI); for (String key : userCustomizedComparison.getComparProtsMap().keySet()) { userCustomizedComparison.getComparProtsMap().get(key).updateLabelLayout(); { tempWidthValue[userCustomizedComparison.getComparProtsMap().get(key).getSignificantTrindCategory() + 1] = tempWidthValue[userCustomizedComparison.getComparProtsMap().get(key) .getSignificantTrindCategory() + 1] + 1; } } int length = 0; if (upper < 10) { upper = 10; } double[] tooltipNumbess = new double[tempWidthValue.length]; System.arraycopy(tempWidthValue, 0, tooltipNumbess, 0, tempWidthValue.length); this.tooltipsProtNumberMap.put(userCustomizedComparison.getComparisonHeader(), tooltipNumbess); for (int z = 0; z < tempWidthValue.length; z++) { if (tempWidthValue[z] > 0) { tempWidthValue[z] = scaleValues(tempWidthValue[z], upper, 2.5, 0.05);//Math.max(tempWidthValue[z] * 1.5 / upper, 0.05); length++; } } double[] yAxisValue = new double[length]; double[] xAxisValue = new double[length]; double[] widthValue = new double[length]; Color[] serColorArr = new Color[length]; length = 0; for (int z = 0; z < tempWidthValue.length; z++) { if (tempWidthValue[z] > 0) { xAxisValue[length] = z; yAxisValue[length] = counter + 1; widthValue[length] = tempWidthValue[z]; serColorArr[length] = dataColor[z]; length++; } } if (length == 1 && selectedComparisonList.size() == 1) { widthValue[0] = 1; } seriousColorMap.put(++counter, serColorArr); double[][] seriesValues = { yAxisValue, xAxisValue, widthValue }; defaultxyzdataset.addSeries(userCustomizedComparison.getComparisonHeader(), seriesValues); for (QuantDiseaseGroupsComparison qc : selectedComparisonList) { tempWidthValue = new double[8]; if (qc.getComparProtsMap() == null) { continue; } for (String key : qc.getComparProtsMap().keySet()) { qc.getComparProtsMap().get(key).updateLabelLayout(); if (significantOnly && (qc.getComparProtsMap().get(key).getSignificantTrindCategory() == 2 || qc.getComparProtsMap().get(key).getSignificantTrindCategory() == 5)) { tempWidthValue[3] = 0; tempWidthValue[6] = 0; } else { tempWidthValue[qc.getComparProtsMap().get(key).getSignificantTrindCategory() + 1] = tempWidthValue[qc.getComparProtsMap().get(key).getSignificantTrindCategory() + 1] + 1; } } if (tempWidthValue[3] > 0 && tempWidthValue[6] >= 0) { stableColor = new Color(1, 141, 244); } else { stableColor = Color.decode("#b5babb"); } tempWidthValue[3] = tempWidthValue[3] + tempWidthValue[6]; tempWidthValue[6] = 0; dataColor[3] = stableColor; length = 0; if (upper < 10) { upper = 10; } tooltipNumbess = new double[tempWidthValue.length]; System.arraycopy(tempWidthValue, 0, tooltipNumbess, 0, tempWidthValue.length); this.tooltipsProtNumberMap.put(qc.getComparisonHeader(), tooltipNumbess); for (int x = 0; x < tempWidthValue.length; x++) { if (tempWidthValue[x] > 0) { tempWidthValue[x] = scaleValues(tempWidthValue[x], upper, 2.5, 0.05);//Math.max(tempWidthValue[z] * 1.5 / upper, 0.05); length++; } } yAxisValue = new double[length]; xAxisValue = new double[length]; widthValue = new double[length]; serColorArr = new Color[length]; length = 0; for (int x = 0; x < tempWidthValue.length; x++) { if (tempWidthValue[x] > 0) { xAxisValue[length] = x; yAxisValue[length] = counter + 1; widthValue[length] = tempWidthValue[x]; serColorArr[length] = dataColor[x]; length++; } } if (length == 1 && selectedComparisonList.size() == 1) { widthValue[0] = 1; } seriousColorMap.put(counter + 1, serColorArr); seriesValues = new double[][] { yAxisValue, xAxisValue, widthValue }; defaultxyzdataset.addSeries(qc.getComparisonHeader(), seriesValues); counter++; } double[] yAxisValueII = new double[0]; double[] xAxisValueII = new double[0]; double[] widthValueII = new double[0]; seriousColorMap.put(counter + 1, new Color[] {}); double[][] seriesValuesII = { yAxisValueII, xAxisValueII, widthValueII }; defaultxyzdataset.addSeries(" ", seriesValuesII); final Color[] labelsColor = new Color[] { Color.WHITE, new Color(80, 183, 71), Color.LIGHT_GRAY, new Color(1, 141, 244), Color.LIGHT_GRAY, new Color(204, 0, 0), Color.WHITE }; Font font = new Font("Verdana", Font.BOLD, 13); SymbolAxis yAxis = new SymbolAxis(null, new String[] { " ", "Decreased", " ", "Equal", " ", "Increased", " " }) { int x = 0; @Override public Paint getTickLabelPaint() { if (x >= labelsColor.length) { x = 0; } return labelsColor[x++]; } }; yAxis.setAutoRangeStickyZero(true); yAxis.setFixedAutoRange(8); yAxis.setTickLabelFont(font); yAxis.setGridBandsVisible(false); yAxis.setAxisLinePaint(Color.LIGHT_GRAY); yAxis.setTickMarksVisible(false); yAxis.setUpperBound(6); String[] xAxisLabels = new String[selectedComparisonList.size() + 3]; xAxisLabels[0] = " "; final Color[] diseaseGroupslabelsColor = new Color[selectedComparisonList.size() + 3]; int x = 0; int maxLength = -1; //init labels color String updatedHeader = userCustomizedComparison.getComparisonHeader().split(" / ")[0].split("\n")[0] + " / " + userCustomizedComparison.getComparisonHeader().split(" / ")[1].split("\n")[0] + ""; diseaseGroupslabelsColor[0] = Color.WHITE; diseaseGroupslabelsColor[x + 1] = diseaseColorMap.get("UserData"); xAxisLabels[x + 1] = updatedHeader + " (" + userCustomizedComparison.getDatasetIndexes().length + ") "; if (xAxisLabels[x + 1].length() > maxLength) { maxLength = xAxisLabels[++x].length(); } for (QuantDiseaseGroupsComparison comp : selectedComparisonList) { String header = comp.getComparisonHeader(); updatedHeader = header.split(" / ")[0].split("\n")[0] + " / " + header.split(" / ")[1].split("\n")[0] + ""; xAxisLabels[x + 1] = updatedHeader + " (" + comp.getDatasetIndexes().length + ") "; if (xAxisLabels[x + 1].length() > maxLength) { maxLength = xAxisLabels[x + 1].length(); } diseaseGroupslabelsColor[x + 1] = diseaseColorMap.get(header.split(" / ")[0].split("\n")[1]); x++; } xAxisLabels[x + 1] = " "; SymbolAxis xAxis; final boolean finalNum; finalNum = maxLength > 30 && selectedComparisonList.size() > 4; xAxis = new SymbolAxis(null, xAxisLabels) { int x = 0; @Override public Paint getTickLabelPaint() { if (x >= diseaseGroupslabelsColor.length) { x = 0; } return diseaseGroupslabelsColor[x++]; } private final boolean localfinal = finalNum; @Override protected List refreshTicksHorizontal(Graphics2D g2, Rectangle2D dataArea, RectangleEdge edge) { if (localfinal) { setVerticalTickLabels(localfinal); return super.refreshTicksHorizontal(g2, dataArea, edge); } List ticks = new java.util.ArrayList(); Font tickLabelFont = getTickLabelFont(); g2.setFont(tickLabelFont); double size = getTickUnit().getSize(); int count = calculateVisibleTickCount(); double lowestTickValue = calculateLowestVisibleTickValue(); double previousDrawnTickLabelPos = 0.0; double previousDrawnTickLabelLength = 0.0; if (count <= ValueAxis.MAXIMUM_TICK_COUNT) { for (int i = 0; i < count; i++) { double currentTickValue = lowestTickValue + (i * size); double xx = valueToJava2D(currentTickValue, dataArea, edge); String tickLabel; NumberFormat formatter = getNumberFormatOverride(); if (formatter != null) { tickLabel = formatter.format(currentTickValue) + " "; } else { tickLabel = valueToString(currentTickValue) + " "; } // avoid to draw overlapping tick labels Rectangle2D bounds = TextUtilities.getTextBounds(tickLabel, g2, g2.getFontMetrics()); double tickLabelLength = isVerticalTickLabels() ? bounds.getHeight() : bounds.getWidth(); boolean tickLabelsOverlapping = false; if (i > 0) { double avgTickLabelLength = (previousDrawnTickLabelLength + tickLabelLength) / 2.0; if (Math.abs(xx - previousDrawnTickLabelPos) < avgTickLabelLength) { tickLabelsOverlapping = true; } } if (tickLabelsOverlapping) { setVerticalTickLabels(true); } else { // remember these values for next comparison previousDrawnTickLabelPos = xx; previousDrawnTickLabelLength = tickLabelLength; } TextAnchor anchor; TextAnchor rotationAnchor; double angle = 0.0; if (isVerticalTickLabels()) { anchor = TextAnchor.CENTER_RIGHT; rotationAnchor = TextAnchor.CENTER_RIGHT; if (edge == RectangleEdge.TOP) { angle = 76.5; } else { angle = -76.5; } } else { if (edge == RectangleEdge.TOP) { anchor = TextAnchor.BOTTOM_CENTER; rotationAnchor = TextAnchor.BOTTOM_CENTER; } else { anchor = TextAnchor.TOP_CENTER; rotationAnchor = TextAnchor.TOP_CENTER; } } Tick tick = new NumberTick(new Double(currentTickValue), tickLabel, anchor, rotationAnchor, angle); ticks.add(tick); } } return ticks; } }; // } xAxis.setTickLabelFont(font); xAxis.setTickLabelInsets(new RectangleInsets(2, 20, 2, 20)); xAxis.setAutoRangeStickyZero(true); xAxis.setAutoRangeStickyZero(true); xAxis.setTickMarksVisible(false); xAxis.setUpperBound(diseaseGroupslabelsColor.length - 1); xAxis.setGridBandsVisible(false); xAxis.setAxisLinePaint(Color.LIGHT_GRAY); int scale = XYBubbleRenderer.SCALE_ON_RANGE_AXIS; XYItemRenderer xyitemrenderer = new XYBubbleRenderer(scale) { private int counter = 0; private int localSerious = -1; private final Map<Integer, Color[]> localSeriousColorMap = seriousColorMap; @Override public Paint getSeriesPaint(int series) { if (series != localSerious || isNewImge || localSeriousColorMap.get(series).length == counter) { counter = 0; isNewImge = false; } localSerious = series; Color c = localSeriousColorMap.get(series)[counter]; counter++; return c; } }; XYPlot xyplot = new XYPlot(defaultxyzdataset, xAxis, yAxis, xyitemrenderer) { @Override protected void drawRangeGridlines(Graphics2D g2, Rectangle2D area, List ticks) { try { if (!ticks.isEmpty()) { ticks.remove(0); } if (!ticks.isEmpty()) { ticks.remove(ticks.size() - 1); } } catch (Exception e) { } super.drawRangeGridlines(g2, area, ticks); //To change body of generated methods, choose Tools | Templates. } // private final Color[] labelsColor = new Color[]{new Color(0, 153, 0), new Color(0, 229, 132), new Color(1, 141, 244), new Color(255, 51, 51), new Color(204, 0, 0), Color.decode("#b5babb")}; // // private final Font font = new Font("Verdana", Font.PLAIN, 12); // private final String[] labels = new String[]{"Decreased 100%", "Decreased <100% ", "Equal", " Increased <100%", "Increased 100%", "No Quant. Info."}; // // @Override // public LegendItemCollection getLegendItems() { // LegendItemCollection legendItemCollection = new LegendItemCollection(); // for (int i = 0; i < labelsColor.length; i++) { // LegendItem item = new LegendItem(labels[i], labelsColor[i]); // item.setLabelFont(font); // legendItemCollection.add(item); // // } // // return legendItemCollection;//To change body of generated methods, choose Tools | Templates. // } }; JFreeChart generatedChart = new JFreeChart(xyplot) { }; xyplot.setOutlineVisible(false); LegendTitle legend = generatedChart.getLegend(); legend.setVisible(false); xyplot.setBackgroundPaint(Color.WHITE); generatedChart.setBackgroundPaint(Color.WHITE); generatedChart.setPadding(new RectangleInsets(0, 0, 0, 0)); Quant_Central_Manager.setProteinsOverviewBubbleChart(generatedChart); return generatedChart; }
From source file:edu.dlnu.liuwenpeng.ChartFactory.ChartFactory.java
/** * Creates a bubble chart with default settings. The chart is composed of * an {@link XYPlot}, with a {@link NumberAxis} for the domain axis, * a {@link NumberAxis} for the range axis, and an {@link XYBubbleRenderer} * to draw the data items. // w ww .j a va2s .c o m * * @param title the chart title (<code>null</code> permitted). * @param xAxisLabel a label for the X-axis (<code>null</code> permitted). * @param yAxisLabel a label for the Y-axis (<code>null</code> permitted). * @param dataset the dataset for the chart (<code>null</code> permitted). * @param orientation the orientation (horizontal or vertical) * (<code>null</code> NOT permitted). * @param legend a flag specifying whether or not a legend is required. * @param tooltips configure chart to generate tool tips? * @param urls configure chart to generate URLs? * * @return A bubble chart. */ public static JFreeChart createBubbleChart(String title, String xAxisLabel, String yAxisLabel, XYZDataset dataset, PlotOrientation orientation, boolean legend, boolean tooltips, boolean urls) { if (orientation == null) { throw new IllegalArgumentException("Null 'orientation' argument."); } NumberAxis xAxis = new NumberAxis(xAxisLabel); xAxis.setAutoRangeIncludesZero(false); NumberAxis yAxis = new NumberAxis(yAxisLabel); yAxis.setAutoRangeIncludesZero(false); XYPlot plot = new XYPlot(dataset, xAxis, yAxis, null); XYItemRenderer renderer = new XYBubbleRenderer(XYBubbleRenderer.SCALE_ON_RANGE_AXIS); if (tooltips) { renderer.setBaseToolTipGenerator(new StandardXYZToolTipGenerator()); } if (urls) { renderer.setURLGenerator(new StandardXYZURLGenerator()); } plot.setRenderer(renderer); plot.setOrientation(orientation); JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend); return chart; }
From source file:KIDLYFactory.java
/** * Creates a bubble chart with default settings. The chart is composed of * an {@link XYPlot}, with a {@link NumberAxis} for the domain axis, * a {@link NumberAxis} for the range axis, and an {@link XYBubbleRenderer} * to draw the data items./*from w w w . ja v a 2 s . c o m*/ * * @param title the chart title (<code>null</code> permitted). * @param xAxisLabel a label for the X-axis (<code>null</code> permitted). * @param yAxisLabel a label for the Y-axis (<code>null</code> permitted). * @param dataset the dataset for the chart (<code>null</code> permitted). * @param orientation the orientation (horizontal or vertical) * (<code>null</code> NOT permitted). * @param legend a flag specifying whether or not a legend is required. * @param tooltips configure chart to generate tool tips? * @param urls configure chart to generate URLs? * * @return A bubble chart. */ public static JFreeChart createBubbleChart(String title, String xAxisLabel, String yAxisLabel, XYZDataset dataset, PlotOrientation orientation, boolean legend, boolean tooltips, boolean urls) { if (orientation == null) { throw new IllegalArgumentException("Null 'orientation' argument."); } NumberAxis xAxis = new NumberAxis(xAxisLabel); xAxis.setAutoRangeIncludesZero(false); NumberAxis yAxis = new NumberAxis(yAxisLabel); yAxis.setAutoRangeIncludesZero(false); XYPlot plot = new XYPlot(dataset, xAxis, yAxis, null); XYItemRenderer renderer = new XYBubbleRenderer(XYBubbleRenderer.SCALE_ON_RANGE_AXIS); if (tooltips) { renderer.setBaseToolTipGenerator(new StandardXYZToolTipGenerator()); } if (urls) { renderer.setURLGenerator(new StandardXYZURLGenerator()); } plot.setRenderer(renderer); plot.setOrientation(orientation); JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend); currentTheme.apply(chart); return chart; }
From source file:net.sf.jasperreports.engine.xml.JRXmlConstants.java
/** * @deprecated Replaced by {@link ScaleTypeEnum}. */// www . ja v a 2s . c o m public static Map getScaleTypeMap() { if (scaleTypeMap == null) { Map map = new HashMap(8); map.put(SCALE_ON_BOTH_AXES, Integer.valueOf(XYBubbleRenderer.SCALE_ON_BOTH_AXES)); map.put(SCALE_ON_DOMAIN_AXIS, Integer.valueOf(XYBubbleRenderer.SCALE_ON_DOMAIN_AXIS)); map.put(SCALE_ON_RANGE_AXIS, Integer.valueOf(XYBubbleRenderer.SCALE_ON_RANGE_AXIS)); map.put(Integer.valueOf(XYBubbleRenderer.SCALE_ON_BOTH_AXES), SCALE_ON_BOTH_AXES); map.put(Integer.valueOf(XYBubbleRenderer.SCALE_ON_DOMAIN_AXIS), SCALE_ON_DOMAIN_AXIS); map.put(Integer.valueOf(XYBubbleRenderer.SCALE_ON_RANGE_AXIS), SCALE_ON_RANGE_AXIS); scaleTypeMap = Collections.unmodifiableMap(map); } return scaleTypeMap; }