List of usage examples for org.jfree.chart.plot XYPlot addAnnotation
public void addAnnotation(XYAnnotation annotation)
From source file:asl.plotmaker.PlotMaker2.java
public void writePlot(String fileName) { // System.out.format("== plotTitle=[%s] fileName=[%s]\n", plotTitle, // fileName); File outputFile = new File(fileName); // Check that we will be able to output the file without problems and if // not --> return if (!checkFileOut(outputFile)) { // System.out.format("== plotMaker: request to output plot=[%s] but we are unable to create it " // + " --> skip plot\n", fileName ); logger.warn("== Request to output plot=[{}] but we are unable to create it " + " --> skip plot\n", fileName);/*from w ww. jav a2 s .co m*/ return; } NumberAxis horizontalAxis = new NumberAxis("x-axis default"); // x = // domain if (fileName.contains("alnm") || fileName.contains("nlnm") || fileName.contains("coher") || fileName.contains("stn")) { // NLNM or StationDeviation horizontalAxis = new LogarithmicAxis("Period (sec)"); horizontalAxis.setRange(new Range(1, 11000)); horizontalAxis.setTickUnit(new NumberTickUnit(5.0)); } else { // EventCompareSynthetics/StrongMotion horizontalAxis = new NumberAxis("Time (s)"); double x[] = panels.get(0).getTraces().get(0).getxData(); horizontalAxis.setRange(new Range(x[0], x[x.length - 1])); } CombinedDomainXYPlot combinedPlot = new CombinedDomainXYPlot(horizontalAxis); combinedPlot.setGap(15.); // Loop over (3) panels for this plot: for (Panel panel : panels) { NumberAxis verticalAxis = new NumberAxis("y-axis default"); // y = // range if (fileName.contains("alnm") || fileName.contains("nlnm") || fileName.contains("stn")) { // NLNM // or // StationDeviation verticalAxis = new NumberAxis("PSD 10log10(m**2/s**4)/Hz dB"); verticalAxis.setRange(new Range(-190, -80)); verticalAxis.setTickUnit(new NumberTickUnit(5.0)); } else if (fileName.contains("coher")) { // Coherence verticalAxis = new NumberAxis("Coherence, Gamma"); verticalAxis.setRange(new Range(0, 1.2)); verticalAxis.setTickUnit(new NumberTickUnit(0.1)); } else { // EventCompareSynthetics/StrongMotion verticalAxis = new NumberAxis("Displacement (m)"); } Font fontPlain = new Font("Verdana", Font.PLAIN, 14); Font fontBold = new Font("Verdana", Font.BOLD, 18); verticalAxis.setLabelFont(fontBold); verticalAxis.setTickLabelFont(fontPlain); horizontalAxis.setLabelFont(fontBold); horizontalAxis.setTickLabelFont(fontPlain); XYSeriesCollection seriesCollection = new XYSeriesCollection(); XYDotRenderer renderer = new XYDotRenderer(); XYPlot xyplot = new XYPlot(seriesCollection, horizontalAxis, verticalAxis, renderer); xyplot.setDomainGridlinesVisible(true); xyplot.setRangeGridlinesVisible(true); xyplot.setRangeGridlinePaint(Color.black); xyplot.setDomainGridlinePaint(Color.black); // Plot each trace on this panel: int iTrace = 0; for (Trace trace : panel.getTraces()) { XYSeries series = new XYSeries(trace.getName()); double xdata[] = trace.getxData(); double ydata[] = trace.getyData(); for (int k = 0; k < xdata.length; k++) { series.add(xdata[k], ydata[k]); } renderer.setSeriesPaint(iTrace, trace.getColor()); renderer.setSeriesStroke(iTrace, trace.getStroke()); seriesCollection.addSeries(series); iTrace++; } // Add Annotations for each trace - This is done in a separate loop // so that // the upper/lower limits for this panel will be known double xmin = horizontalAxis.getRange().getLowerBound(); double xmax = horizontalAxis.getRange().getUpperBound(); double ymin = verticalAxis.getRange().getLowerBound(); double ymax = verticalAxis.getRange().getUpperBound(); double delX = Math.abs(xmax - xmin); double delY = Math.abs(ymax - ymin); // Annotation (x,y) in normalized units - where upper-right corner = // (1,1) double xAnn = 0.97; // Right center coords of the trace name (e.g., // "00-LHZ") double yAnn = 0.95; double yOff = 0.05; // Vertical distance between different trace // legends iTrace = 0; for (Trace trace : panel.getTraces()) { if (!trace.getName().contains("NLNM") && !trace.getName().contains("NHNM") && !trace.getName().contains("ALNM")) { // x1 > x2 > x3, e.g.: // o-------o 00-LHZ // x3 x2 x1 double scale = .01; // Controls distance between trace label // and line segment double xL = .04; // Length of trace line segment in legend double xAnn2 = xAnn - scale * trace.getName().length(); double xAnn3 = xAnn - scale * trace.getName().length() - xL; double x1 = xAnn * delX + xmin; // Right hand x-coord of // text in range units double x2 = xAnn2 * delX + xmin; // x-coord of line segment // end in range units double x3 = xAnn3 * delX + xmin; // x-coord of line segment // end in range units double y = (yAnn - (iTrace * yOff)) * delY + ymin; if (horizontalAxis instanceof LogarithmicAxis) { double logMin = Math.log10(xmin); double logMax = Math.log10(xmax); delX = logMax - logMin; x1 = Math.pow(10, xAnn * delX + logMin); x2 = Math.pow(10, xAnn2 * delX + logMin); x3 = Math.pow(10, xAnn3 * delX + logMin); } xyplot.addAnnotation(new XYLineAnnotation(x3, y, x2, y, trace.getStroke(), trace.getColor())); XYTextAnnotation xyText = new XYTextAnnotation(trace.getName(), x1, y); xyText.setFont(new Font("Verdana", Font.BOLD, 18)); xyText.setTextAnchor(TextAnchor.CENTER_RIGHT); xyplot.addAnnotation(xyText); } iTrace++; } combinedPlot.add(xyplot, 1); } // panel final JFreeChart chart = new JFreeChart(combinedPlot); chart.setTitle(new TextTitle(plotTitle, new Font("Verdana", Font.BOLD, 18))); chart.removeLegend(); try { ChartUtilities.saveChartAsPNG(outputFile, chart, 1400, 1400); } catch (IOException e) { // System.err.println("Problem occurred creating chart."); logger.error("IOException:", e); } }
From source file:org.owasp.benchmark.score.report.ScatterScores.java
private JFreeChart display(String title, int height, int width, List<Report> toolResults) { JFrame f = new JFrame(title); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); XYSeriesCollection dataset = new XYSeriesCollection(); XYSeries series = new XYSeries("Scores"); for (int i = 0; i < toolResults.size(); i++) { Report toolReport = toolResults.get(i); OverallResults overallResults = toolReport.getOverallResults(); series.add(overallResults.getFalsePositiveRate() * 100, overallResults.getTruePositiveRate() * 100); }//from w ww . j a v a 2 s .c o m dataset.addSeries(series); chart = ChartFactory.createScatterPlot(title, "False Positive Rate", "True Positive Rate", dataset, PlotOrientation.VERTICAL, true, true, false); String fontName = "Arial"; DecimalFormat pctFormat = new DecimalFormat("0'%'"); theme = (StandardChartTheme) org.jfree.chart.StandardChartTheme.createJFreeTheme(); theme.setExtraLargeFont(new Font(fontName, Font.PLAIN, 24)); // title theme.setLargeFont(new Font(fontName, Font.PLAIN, 20)); // axis-title theme.setRegularFont(new Font(fontName, Font.PLAIN, 16)); theme.setSmallFont(new Font(fontName, Font.PLAIN, 12)); theme.setRangeGridlinePaint(Color.decode("#C0C0C0")); theme.setPlotBackgroundPaint(Color.white); theme.setChartBackgroundPaint(Color.white); theme.setGridBandPaint(Color.red); theme.setAxisOffset(new RectangleInsets(0, 0, 0, 0)); theme.setBarPainter(new StandardBarPainter()); theme.setAxisLabelPaint(Color.decode("#666666")); theme.apply(chart); XYPlot xyplot = chart.getXYPlot(); NumberAxis rangeAxis = (NumberAxis) xyplot.getRangeAxis(); NumberAxis domainAxis = (NumberAxis) xyplot.getDomainAxis(); xyplot.setOutlineVisible(true); rangeAxis.setRange(-5, 109.99); rangeAxis.setNumberFormatOverride(pctFormat); rangeAxis.setTickLabelPaint(Color.decode("#666666")); rangeAxis.setMinorTickCount(5); rangeAxis.setTickUnit(new NumberTickUnit(10)); rangeAxis.setAxisLineVisible(true); rangeAxis.setMinorTickMarksVisible(true); rangeAxis.setTickMarksVisible(true); rangeAxis.setLowerMargin(10); rangeAxis.setUpperMargin(10); xyplot.setRangeGridlineStroke(new BasicStroke()); xyplot.setRangeGridlinePaint(Color.lightGray); xyplot.setRangeMinorGridlinePaint(Color.decode("#DDDDDD")); xyplot.setRangeMinorGridlinesVisible(true); domainAxis.setRange(-5, 105); domainAxis.setNumberFormatOverride(pctFormat); domainAxis.setTickLabelPaint(Color.decode("#666666")); domainAxis.setMinorTickCount(5); domainAxis.setTickUnit(new NumberTickUnit(10)); domainAxis.setAxisLineVisible(true); domainAxis.setTickMarksVisible(true); domainAxis.setMinorTickMarksVisible(true); domainAxis.setLowerMargin(10); domainAxis.setUpperMargin(10); xyplot.setDomainGridlineStroke(new BasicStroke()); xyplot.setDomainGridlinePaint(Color.lightGray); xyplot.setDomainMinorGridlinePaint(Color.decode("#DDDDDD")); xyplot.setDomainMinorGridlinesVisible(true); chart.setTextAntiAlias(true); chart.setAntiAlias(true); chart.removeLegend(); chart.setPadding(new RectangleInsets(20, 20, 20, 20)); xyplot.getRenderer().setSeriesPaint(0, Color.decode("#4572a7")); // // setup item labels // XYItemRenderer renderer = xyplot.getRenderer(); // Shape circle = new Ellipse2D.Float(-2.0f, -2.0f, 7.0f, 7.0f); // for ( int i = 0; i < dataset.getSeriesCount(); i++ ) { // renderer.setSeriesShape(i, circle); // renderer.setSeriesPaint(i, Color.blue); // String label = ""+((String)dataset.getSeries(i).getKey()); // int idx = label.indexOf( ':'); // label = label.substring( 0, idx ); // StandardXYItemLabelGenerator generator = new StandardXYItemLabelGenerator(label); // renderer.setSeriesItemLabelGenerator(i, generator); // renderer.setSeriesItemLabelsVisible(i, true); // ItemLabelPosition position = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.BASELINE_CENTER ); // renderer.setSeriesPositiveItemLabelPosition(i, position); // } makeDataLabels(toolResults, xyplot); makeLegend(toolResults, 57, 48, dataset, xyplot); Stroke dashed = new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 0, new float[] { 6, 3 }, 0); for (XYDataItem item : (List<XYDataItem>) series.getItems()) { double x = item.getX().doubleValue(); double y = item.getY().doubleValue(); double z = (x + y) / 2; XYLineAnnotation score = new XYLineAnnotation(x, y, z, z, dashed, Color.blue); xyplot.addAnnotation(score); } // // put legend inside plot // LegendTitle lt = new LegendTitle(xyplot); // lt.setItemFont(theme.getSmallFont()); // lt.setPosition(RectangleEdge.RIGHT); // lt.setItemFont(theme.getSmallFont()); // XYTitleAnnotation ta = new XYTitleAnnotation(.7, .55, lt, RectangleAnchor.TOP_LEFT); // ta.setMaxWidth(0.48); // xyplot.addAnnotation(ta); // draw guessing line XYLineAnnotation guessing = new XYLineAnnotation(-5, -5, 105, 105, dashed, Color.red); xyplot.addAnnotation(guessing); XYPointerAnnotation worse = makePointer(75, 5, "Worse than guessing", TextAnchor.TOP_CENTER, 90); xyplot.addAnnotation(worse); XYPointerAnnotation better = makePointer(25, 100, "Better than guessing", TextAnchor.BOTTOM_CENTER, 270); xyplot.addAnnotation(better); XYTextAnnotation stroketext = new XYTextAnnotation(" Random Guess", 88, 107); stroketext.setTextAnchor(TextAnchor.CENTER_RIGHT); stroketext.setBackgroundPaint(Color.white); stroketext.setPaint(Color.red); stroketext.setFont(theme.getRegularFont()); xyplot.addAnnotation(stroketext); XYLineAnnotation strokekey = new XYLineAnnotation(58, 107, 68, 107, dashed, Color.red); xyplot.setBackgroundPaint(Color.white); xyplot.addAnnotation(strokekey); ChartPanel cp = new ChartPanel(chart, height, width, 400, 400, 1200, 1200, false, false, false, false, false, false); f.add(cp); f.pack(); f.setLocationRelativeTo(null); // f.setVisible(true); return chart; }
From source file:com.att.aro.ui.view.diagnostictab.plot.AlarmPlot.java
@Override public void populate(XYPlot plot, AROTraceData analysis) { if (analysis == null) { logger.info("analysis data is null"); } else {/*from w w w .ja v a 2 s .c o m*/ alarmDataCollection.removeAllSeries(); pointerAnnotation.clear(); TraceResultType resultType = analysis.getAnalyzerResult().getTraceresult().getTraceResultType(); if (resultType.equals(TraceResultType.TRACE_FILE)) { logger.info("didn't get analysis trace data!"); } else { // Remove old annotation from previous plots Iterator<XYPointerAnnotation> pointers = pointerAnnotation.iterator(); while (pointers.hasNext()) { plot.removeAnnotation(pointers.next()); } for (AlarmType eventType : AlarmType.values()) { XYIntervalSeries series = new XYIntervalSeries(eventType); seriesMap.put(eventType, series); alarmDataCollection.addSeries(series); } TraceDirectoryResult traceresult = (TraceDirectoryResult) analysis.getAnalyzerResult() .getTraceresult(); List<AlarmInfo> alarmInfos = traceresult.getAlarmInfos(); List<ScheduledAlarmInfo> pendingAlarms = getHasFiredAlarms(traceresult.getScheduledAlarms()); Iterator<ScheduledAlarmInfo> iterPendingAlarms = pendingAlarms.iterator(); double firedTime = 0; while (iterPendingAlarms.hasNext()) { ScheduledAlarmInfo scheduledEvent = iterPendingAlarms.next(); AlarmType pendingAlarmType = scheduledEvent.getAlarmType(); if (pendingAlarmType != null) { firedTime = (scheduledEvent.getTimeStamp() - scheduledEvent.getRepeatInterval()) / 1000; seriesMap.get(pendingAlarmType).add(firedTime, firedTime, firedTime, 1, 0.8, 1); eventMapPending.put(firedTime, scheduledEvent); // logger.fine("populateAlarmScheduledPlot type:\n" + // pendingAlarmType // + "\ntime " + scheduledEvent.getTimeStamp() // + "\nrepeating " + firedTime); } } Iterator<AlarmInfo> iter = alarmInfos.iterator(); while (iter.hasNext()) { AlarmInfo currEvent = iter.next(); if (currEvent != null) { AlarmType alarmType = currEvent.getAlarmType(); if (alarmType != null) { firedTime = currEvent.getTimeStamp() / 1000; /* * Catching any alarms align to quanta as being * inexactRepeating alarms */ if ((currEvent.getTimestampElapsed() / 1000) % 900 < 1) { seriesMap.get(alarmType).add(firedTime, firedTime, firedTime, 1, 0, 0.7); // Adding an arrow to mark these // inexactRepeating alarms XYPointerAnnotation xypointerannotation = new XYPointerAnnotation(alarmType.name(), firedTime, 0.6, 3.92699082D); xypointerannotation.setBaseRadius(20D); xypointerannotation.setTipRadius(1D); pointerAnnotation.add(xypointerannotation); plot.addAnnotation(xypointerannotation); // logger.info("SetInexactRepeating alarm type: " // + alarmType // + " time " + firedTime // + " epoch " + currEvent.getTimestampEpoch() // + " elapsed:\n" + // currEvent.getTimestampElapsed()/1000); } else { seriesMap.get(alarmType).add(firedTime, firedTime, firedTime, 1, 0, 0.5); } eventMap.put(firedTime, currEvent); } } } XYItemRenderer renderer = plot.getRenderer(); renderer.setSeriesPaint(alarmDataCollection.indexOf(AlarmType.RTC_WAKEUP), Color.red); renderer.setSeriesPaint(alarmDataCollection.indexOf(AlarmType.RTC), Color.pink); renderer.setSeriesPaint(alarmDataCollection.indexOf(AlarmType.ELAPSED_REALTIME_WAKEUP), Color.blue); renderer.setSeriesPaint(alarmDataCollection.indexOf(AlarmType.ELAPSED_REALTIME), Color.cyan); renderer.setSeriesPaint(alarmDataCollection.indexOf(AlarmType.UNKNOWN), Color.black); // Assign ToolTip to renderer renderer.setBaseToolTipGenerator(new XYToolTipGenerator() { @Override public String generateToolTip(XYDataset dataset, int series, int item) { AlarmInfo info = eventMap.get(dataset.getX(series, item)); Date epochTime = new Date(); if (info != null) { epochTime.setTime((long) info.getTimestampEpoch()); StringBuffer displayInfo = new StringBuffer( ResourceBundleHelper.getMessageString("alarm.tooltip.prefix")); displayInfo.append(MessageFormat.format( ResourceBundleHelper.getMessageString("alarm.tooltip.content"), info.getAlarmType(), info.getTimeStamp() / 1000, epochTime.toString())); if ((info.getTimestampElapsed() / 1000) % 900 < 1) { displayInfo.append( ResourceBundleHelper.getMessageString("alarm.tooltip.setInexactRepeating")); } displayInfo.append(ResourceBundleHelper.getMessageString("alarm.tooltip.suffix")); return displayInfo.toString(); } ScheduledAlarmInfo infoPending = eventMapPending.get(dataset.getX(series, item)); if (infoPending != null) { epochTime.setTime( (long) (infoPending.getTimestampEpoch() - infoPending.getRepeatInterval())); StringBuffer displayInfo = new StringBuffer( ResourceBundleHelper.getMessageString("alarm.tooltip.prefix")); displayInfo.append(MessageFormat.format( ResourceBundleHelper.getMessageString("alarm.tooltip.contentWithName"), infoPending.getAlarmType(), (infoPending.getTimeStamp() - infoPending.getRepeatInterval()) / 1000, epochTime.toString(), infoPending.getApplication(), infoPending.getRepeatInterval() / 1000)); displayInfo.append(ResourceBundleHelper.getMessageString("alarm.tooltip.suffix")); return displayInfo.toString(); } return null; } }); } } plot.setDataset(alarmDataCollection); // return plot; }
From source file:org.owasp.benchmark.score.report.Scatter.java
private JFreeChart display(String title, int height, int width, OverallResults or) { JFrame f = new JFrame(title); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // Note: this is a little weird, since each point is a separate series XYSeriesCollection dataset = new XYSeriesCollection(); XYSeries series = new XYSeries("Scores"); for (OverallResult r : or.getResults()) { series.add(r.fpr * 100, r.tpr * 100); }//ww w . j a va 2s . c o m dataset.addSeries(series); chart = ChartFactory.createScatterPlot(title, "False Positive Rate", "True Positive Rate", dataset, PlotOrientation.VERTICAL, true, true, false); String fontName = "Arial"; DecimalFormat pctFormat = new DecimalFormat("0'%'"); theme = (StandardChartTheme) org.jfree.chart.StandardChartTheme.createJFreeTheme(); theme.setExtraLargeFont(new Font(fontName, Font.PLAIN, 24)); // title theme.setLargeFont(new Font(fontName, Font.PLAIN, 20)); // axis-title theme.setRegularFont(new Font(fontName, Font.PLAIN, 16)); theme.setSmallFont(new Font(fontName, Font.PLAIN, 12)); theme.setRangeGridlinePaint(Color.decode("#C0C0C0")); theme.setPlotBackgroundPaint(Color.white); theme.setChartBackgroundPaint(Color.white); theme.setGridBandPaint(Color.red); theme.setAxisOffset(new RectangleInsets(0, 0, 0, 0)); theme.setBarPainter(new StandardBarPainter()); theme.setAxisLabelPaint(Color.decode("#666666")); theme.apply(chart); XYPlot xyplot = chart.getXYPlot(); NumberAxis rangeAxis = (NumberAxis) xyplot.getRangeAxis(); NumberAxis domainAxis = (NumberAxis) xyplot.getDomainAxis(); xyplot.setOutlineVisible(true); rangeAxis.setRange(-9.99, 109.99); rangeAxis.setNumberFormatOverride(pctFormat); rangeAxis.setTickLabelPaint(Color.decode("#666666")); rangeAxis.setMinorTickCount(5); rangeAxis.setTickUnit(new NumberTickUnit(10)); rangeAxis.setAxisLineVisible(true); rangeAxis.setMinorTickMarksVisible(true); rangeAxis.setTickMarksVisible(true); rangeAxis.setLowerMargin(10); rangeAxis.setUpperMargin(10); xyplot.setRangeGridlineStroke(new BasicStroke()); xyplot.setRangeGridlinePaint(Color.lightGray); xyplot.setRangeMinorGridlinePaint(Color.decode("#DDDDDD")); xyplot.setRangeMinorGridlinesVisible(true); domainAxis.setRange(-5, 105); domainAxis.setNumberFormatOverride(pctFormat); domainAxis.setTickLabelPaint(Color.decode("#666666")); domainAxis.setMinorTickCount(5); domainAxis.setTickUnit(new NumberTickUnit(10)); domainAxis.setAxisLineVisible(true); domainAxis.setTickMarksVisible(true); domainAxis.setMinorTickMarksVisible(true); domainAxis.setLowerMargin(10); domainAxis.setUpperMargin(10); xyplot.setDomainGridlineStroke(new BasicStroke()); xyplot.setDomainGridlinePaint(Color.lightGray); xyplot.setDomainMinorGridlinePaint(Color.decode("#DDDDDD")); xyplot.setDomainMinorGridlinesVisible(true); chart.setTextAntiAlias(true); chart.setAntiAlias(true); chart.removeLegend(); chart.setPadding(new RectangleInsets(20, 20, 20, 20)); xyplot.getRenderer().setSeriesPaint(0, Color.decode("#4572a7")); // // setup item labels // XYItemRenderer renderer = xyplot.getRenderer(); // Shape circle = new Ellipse2D.Float(-2.0f, -2.0f, 7.0f, 7.0f); // for ( int i = 0; i < dataset.getSeriesCount(); i++ ) { // renderer.setSeriesShape(i, circle); // renderer.setSeriesPaint(i, Color.blue); // String letter = "" + ((String)dataset.getSeries(i).getKey()).charAt(0); // StandardXYItemLabelGenerator generator = new StandardXYItemLabelGenerator(letter); // renderer.setSeriesItemLabelGenerator(i, generator); // renderer.setSeriesItemLabelsVisible(i, true); // ItemLabelPosition position = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.BASELINE_CENTER ); // renderer.setSeriesPositiveItemLabelPosition(i, position); // } makeDataLabels(or, xyplot); makeLegend(or, 57, 48, dataset, xyplot); // put legend inside plot // LegendTitle lt = new LegendTitle(xyplot); // lt.setItemFont(theme.getSmallFont()); // lt.setPosition(RectangleEdge.RIGHT); // lt.setItemFont(theme.getSmallFont()); // XYTitleAnnotation ta = new XYTitleAnnotation(.7, .55, lt, RectangleAnchor.TOP_LEFT); // ta.setMaxWidth(0.48); // xyplot.addAnnotation(ta); // draw guessing line Stroke dashed = new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 0, new float[] { 6, 3 }, 0); XYLineAnnotation guessing = new XYLineAnnotation(-5, -5, 105, 105, dashed, Color.red); xyplot.addAnnotation(guessing); XYPointerAnnotation worse = makePointer(75, 0, "Worse than guessing", TextAnchor.TOP_CENTER, 90); xyplot.addAnnotation(worse); XYPointerAnnotation better = makePointer(25, 100, "Better than guessing", TextAnchor.BOTTOM_CENTER, 270); xyplot.addAnnotation(better); XYTextAnnotation time = new XYTextAnnotation("Tool run time: " + or.getTime(), 12, -5.6); time.setTextAnchor(TextAnchor.TOP_LEFT); time.setFont(theme.getRegularFont()); time.setPaint(Color.red); xyplot.addAnnotation(time); XYTextAnnotation stroketext = new XYTextAnnotation(" Random Guess", 88, 107); stroketext.setTextAnchor(TextAnchor.CENTER_RIGHT); stroketext.setBackgroundPaint(Color.white); stroketext.setPaint(Color.red); stroketext.setFont(theme.getRegularFont()); xyplot.addAnnotation(stroketext); XYLineAnnotation strokekey = new XYLineAnnotation(58, 107, 68, 107, dashed, Color.red); xyplot.setBackgroundPaint(Color.white); xyplot.addAnnotation(strokekey); ChartPanel cp = new ChartPanel(chart, height, width, 400, 400, 1200, 1200, false, false, false, false, false, false); f.add(cp); f.pack(); f.setLocationRelativeTo(null); // f.setVisible(true); return chart; }
From source file:org.fhcrc.cpl.viewer.gui.MRMDialog.java
protected void createChartInPanelDaughterTasksOnly(XYPlot xyp) { XYSeries coloredDataset = transitionOnPlot.getCurrentDaughter().getGraphData(); Paint daughterColor = Utils.paleColor((Color) transitionOnPlot.getCurrentDaughter().getGraphColor()); ArrayList<XYLineAnnotation> coloredDaughters = new ArrayList<XYLineAnnotation>(); //Trace calculated elution curves over data spikes if (transitionOnPlot.getElutionCurves() != null && !transitionOnPlot.getElutionCurves().isEmpty()) { MRMDaughter curDaughter = transitionOnPlot.getCurrentDaughter(); ElutionCurveStrategy ecs = transitionOnPlot.getElutionCurves().get(curDaughter); //Is current daughter rejected? Boolean accepted = (Boolean) ((PeaksTableModel) peaksTable.getModel()).data[curDaughter .getElutionDataTableRow()][peaksData.Accept.colno]; if (accepted == null || !accepted) { xyp.setBackgroundPaint(new Color(255, 230, 230)); }/*from w w w. ja v a2s .c o m*/ List<ElutionCurve> ecl = ecs.getDaughterCurves(); if (ecl != null) { for (ElutionCurve e : ecl) { List<Line2D.Double> ll2dd = e.getSegments(); for (Line2D.Double l2dd : ll2dd) { xyp.addAnnotation(Utils.line2Annotation(l2dd, new BasicStroke(2.0f), ecs.isBestDaughterCurve(e) ? Color.BLACK : Color.LIGHT_GRAY)); } } } } // If there is a valid "current" daughter draw the spikes in the daughter's color // as annotations (sensu JFree) if (coloredDataset != null) { int nOfPoints = coloredDataset.getItemCount(); for (int i = 0; i < (nOfPoints - 1); i++) { XYDataItem p1 = coloredDataset.getDataItem(i); XYDataItem p2 = coloredDataset.getDataItem(i + 1); coloredDaughters.add(new XYLineAnnotation(p1.getX().doubleValue(), p1.getY().doubleValue(), p2.getX().doubleValue(), p2.getY().doubleValue(), new BasicStroke(1.5f), transitionOnPlot.getCurrentDaughter().getGraphColor()) // new XYLineAnnotation(p1.getX().doubleValue(),p1.getY().doubleValue(),p2.getX().doubleValue(),p2.getY().doubleValue(),new BasicStroke(1.5f),daughterColor) ); } } if (_traceAllFragments) { for (MRMDaughter d : transitionOnPlot.getDaughters().values()) { if (d == transitionOnPlot.getCurrentDaughter()) continue; XYSeries curXYSeries = d.getContinDaughterData(); if (curXYSeries == null || curXYSeries.getItemCount() == 0) continue; if (d.getBestElutionCurve() == null) continue; int nOfPoints = curXYSeries.getItemCount(); for (int i = 0; i < (nOfPoints - 1); i++) { XYDataItem p1 = curXYSeries.getDataItem(i); XYDataItem p2 = curXYSeries.getDataItem(i + 1); coloredDaughters.add( // new XYLineAnnotation(p1.getX().doubleValue(),p1.getY().doubleValue(),p2.getX().doubleValue(),p2.getY().doubleValue(),new BasicStroke(1f),Utils.paleColor((Color)d.getGraphColor())) new XYLineAnnotation(p1.getX().doubleValue(), p1.getY().doubleValue(), p2.getX().doubleValue(), p2.getY().doubleValue(), new BasicStroke(1f), d.getGraphColor())); } } } if (coloredDaughters != null) { for (XYLineAnnotation xyla : coloredDaughters) { xyp.addAnnotation(xyla); } } coloredDaughters.clear(); //Display L or H label in upper left hand corner Range xRange = xyp.getDomainAxis().getRange(); Range yRange = xyp.getRangeAxis().getRange(); XYTextAnnotation lab = new XYTextAnnotation( (String) ((PeaksTableModel) peaksTable.getModel()).data[transitionOnPlot.getCurrentDaughter() .getElutionDataTableRow()][peaksData.Label.colno], xRange.getUpperBound() - (0.05 * xRange.getLength()), yRange.getUpperBound() - (0.05 * yRange.getLength())); lab.setFont(lab.getFont().deriveFont(Font.BOLD, 40.0F)); xyp.addAnnotation(lab); XYTextAnnotation midMarker = new XYTextAnnotation("\u25BC", ((MRMTransition) transitionOnPlot).getCalcXatMaxYAllDaughters(), ((MRMTransition) transitionOnPlot).getCalcMaxYAllDaughters()); midMarker.setPaint(Color.RED); midMarker.setFont(midMarker.getFont().deriveFont(Font.BOLD, 20F)); XYTextAnnotation midMarkerOutline = new XYTextAnnotation("\u25BC", ((MRMTransition) transitionOnPlot).getCalcXatMaxYAllDaughters(), ((MRMTransition) transitionOnPlot).getCalcMaxYAllDaughters()); midMarkerOutline.setPaint(Color.BLACK); midMarkerOutline.setFont(midMarker.getFont().deriveFont(Font.BOLD, 23F)); xyp.addAnnotation(midMarkerOutline); xyp.addAnnotation(midMarker); }
From source file:edu.umn.ecology.populus.plot.BasicPlotInfo.java
public ChartTheme getJFreeChartTheme() { class PopChartTheme implements ChartTheme { private BasicPlotInfo bpiRef; public PopChartTheme(BasicPlotInfo bpi) { this.bpiRef = bpi; }/* w ww.j av a2 s.co m*/ public void apply(JFreeChart chart) { JFCXYAdapter jfca = new JFCXYAdapter(); XYPlot plot = chart.getXYPlot(); plot.setDataset(jfca); if (isLogPlot) { plot.setRangeAxis(new LogarithmicAxis("")); } if (isFrequencies) { ValueAxis va = plot.getRangeAxis(); if (va instanceof NumberAxis) { NumberAxis na = (NumberAxis) va; na.setTickUnit(new NumberTickUnit(0.1)); } else { Logging.log("Range Axis is not NumberAxis, why?", Logging.kWarn); } } if (xMinSet) plot.getDomainAxis().setLowerBound(xAxisMin); if (xMaxSet) plot.getDomainAxis().setUpperBound(xAxisMax); if (yMinSet) plot.getRangeAxis().setLowerBound(yAxisMin); if (yMaxSet) plot.getRangeAxis().setUpperBound(yAxisMax); //TODO - just use this renderer plot.setRenderer(new ChartRendererWithOrientatedShapes(bpiRef)); XYItemRenderer r = plot.getRenderer(); // AbstractXYItemRenderer r = plot.getRenderer(); if (r instanceof XYLineAndShapeRenderer) { XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) r; for (int i = 0; i < getNumSeries(); i++) { //Set Line renderer.setSeriesPaint(i, getLineColor(i)); renderer.setSeriesStroke(i, getLineStroke(i)); //Set Symbol renderer.setSeriesFillPaint(i, getSymbolColor(i)); renderer.setSeriesOutlinePaint(i, getSymbolColor(i)); Shape shape = getSymbolShape(i); if (shape != null) { renderer.setSeriesShape(i, shape); renderer.setSeriesShapesFilled(i, isSymbolOpaque(i)); renderer.setUseFillPaint(true); renderer.setUseOutlinePaint(true); renderer.setSeriesShapesVisible(i, true); } } } else if (r instanceof XYBarRenderer) { XYBarRenderer barRenderer = (XYBarRenderer) r; barRenderer.setBarPainter(new StandardXYBarPainter()); } else { Logging.log("Unknown renderer type: " + r.getClass(), Logging.kWarn); } //inner labels, used in AIDS: Therapy plot.clearAnnotations(); Enumeration<InnerLabel> e = innerLabels.elements(); while (e.hasMoreElements()) { InnerLabel lab = (InnerLabel) e.nextElement(); Logging.log("Adding " + lab.caption + " at " + lab.x + ", " + lab.y); XYTextAnnotation annotation = new XYTextAnnotation(lab.caption, lab.x, lab.y); annotation.setTextAnchor(TextAnchor.BOTTOM_CENTER); annotation.setOutlineVisible(true); plot.addAnnotation(annotation); //I actually think the annotation above is ugly. We can use one of these instead in the future, maybe... /*PointerAnnotation may look cool... * That 2.0 is the angle, randomly picked * XYPointerAnnotation annotation = new XYPointerAnnotation(lab.caption, lab.x, lab.y, 2.0); */ /* ValueMarker marker = new ValueMarker(lab.x); marker.setLabel(lab.caption); marker.setLabelAnchor(RectangleAnchor.BOTTOM_LEFT); plot.addDomainMarker(marker); */ } //This is set for GD: AMCM if (startGridded) { plot.setDomainGridlinesVisible(true); plot.setDomainGridlinePaint(Color.BLACK); plot.setRangeGridlinesVisible(true); plot.setRangeGridlinePaint(Color.BLACK); } } } return new PopChartTheme(this); }
From source file:com.att.aro.diagnostics.GraphPanel.java
/** * Creating Alarm triggered data for graph plot *///from w w w . j av a 2 s .c om private static void populateAlarmPlot(XYPlot plot, TraceData.Analysis analysis) { final XYIntervalSeriesCollection alarmDataCollection = new XYIntervalSeriesCollection(); if (analysis != null) { // Remove old annotation from previous plots Iterator<XYPointerAnnotation> pointers = pointerAnnotation.iterator(); while (pointers.hasNext()) { plot.removeAnnotation(pointers.next()); } pointerAnnotation.clear(); final Map<AlarmType, XYIntervalSeries> seriesMap = new EnumMap<AlarmType, XYIntervalSeries>( AlarmType.class); for (AlarmType eventType : AlarmType.values()) { XYIntervalSeries series = new XYIntervalSeries(eventType); seriesMap.put(eventType, series); alarmDataCollection.addSeries(series); } final List<AlarmInfo> alarmInfos = analysis.getAlarmInfos(); final Map<Double, AlarmInfo> eventMap = new HashMap<Double, AlarmInfo>(); final Map<Double, ScheduledAlarmInfo> eventMapPending = new HashMap<Double, ScheduledAlarmInfo>(); List<ScheduledAlarmInfo> pendingAlarms = getHasFiredAlarms(analysis.getScheduledAlarms()); Iterator<ScheduledAlarmInfo> iterPendingAlarms = pendingAlarms.iterator(); double firedTime = 0; while (iterPendingAlarms.hasNext()) { ScheduledAlarmInfo scheduledEvent = iterPendingAlarms.next(); AlarmType pendingAlarmType = scheduledEvent.getAlarmType(); if (pendingAlarmType != null) { firedTime = (scheduledEvent.getTimeStamp() - scheduledEvent.getRepeatInterval()) / 1000; seriesMap.get(pendingAlarmType).add(firedTime, firedTime, firedTime, 1, 0.8, 1); eventMapPending.put(firedTime, scheduledEvent); logger.fine("populateAlarmScheduledPlot type:\n" + pendingAlarmType + "\ntime " + scheduledEvent.getTimeStamp() + "\nrepeating " + firedTime); } } Iterator<AlarmInfo> iter = alarmInfos.iterator(); while (iter.hasNext()) { AlarmInfo currEvent = iter.next(); if (currEvent != null) { AlarmType alarmType = currEvent.getAlarmType(); if (alarmType != null) { firedTime = currEvent.getTimeStamp() / 1000; /* * Catching any alarms align to quanta as being * inexactRepeating alarms */ if ((currEvent.getTimestampElapsed() / 1000) % 900 < 1) { seriesMap.get(alarmType).add(firedTime, firedTime, firedTime, 1, 0, 0.7); // Adding an arrow to mark these inexactRepeating alarms XYPointerAnnotation xypointerannotation = new XYPointerAnnotation(alarmType.name(), firedTime, 0.6, 3.92699082D); xypointerannotation.setBaseRadius(20D); xypointerannotation.setTipRadius(1D); pointerAnnotation.add(xypointerannotation); plot.addAnnotation(xypointerannotation); logger.info("SetInexactRepeating alarm type: " + alarmType + " time " + firedTime + " epoch " + currEvent.getTimestampEpoch() + " elapsed:\n" + currEvent.getTimestampElapsed() / 1000); } else { seriesMap.get(alarmType).add(firedTime, firedTime, firedTime, 1, 0, 0.5); } eventMap.put(firedTime, currEvent); } } } XYItemRenderer renderer = plot.getRenderer(); renderer.setSeriesPaint(alarmDataCollection.indexOf(AlarmType.RTC_WAKEUP), Color.red); renderer.setSeriesPaint(alarmDataCollection.indexOf(AlarmType.RTC), Color.pink); renderer.setSeriesPaint(alarmDataCollection.indexOf(AlarmType.ELAPSED_REALTIME_WAKEUP), Color.blue); renderer.setSeriesPaint(alarmDataCollection.indexOf(AlarmType.ELAPSED_REALTIME), Color.cyan); renderer.setSeriesPaint(alarmDataCollection.indexOf(AlarmType.UNKNOWN), Color.black); // Assign ToolTip to renderer renderer.setBaseToolTipGenerator(new XYToolTipGenerator() { @Override public String generateToolTip(XYDataset dataset, int series, int item) { AlarmInfo info = eventMap.get(dataset.getX(series, item)); Date epochTime = new Date(); if (info != null) { epochTime.setTime((long) info.getTimestampEpoch()); StringBuffer displayInfo = new StringBuffer(rb.getString("alarm.tooltip.prefix")); displayInfo.append(MessageFormat.format(rb.getString("alarm.tooltip.content"), info.getAlarmType(), info.getTimeStamp() / 1000, epochTime.toString())); if ((info.getTimestampElapsed() / 1000) % 900 < 1) { displayInfo.append(rb.getString("alarm.tooltip.setInexactRepeating")); } displayInfo.append(rb.getString("alarm.tooltip.suffix")); return displayInfo.toString(); } ScheduledAlarmInfo infoPending = eventMapPending.get(dataset.getX(series, item)); if (infoPending != null) { epochTime.setTime( (long) (infoPending.getTimestampEpoch() - infoPending.getRepeatInterval())); StringBuffer displayInfo = new StringBuffer(rb.getString("alarm.tooltip.prefix")); displayInfo.append(MessageFormat.format(rb.getString("alarm.tooltip.contentWithName"), infoPending.getAlarmType(), (infoPending.getTimeStamp() - infoPending.getRepeatInterval()) / 1000, epochTime.toString(), infoPending.getApplication(), infoPending.getRepeatInterval() / 1000)); displayInfo.append(rb.getString("alarm.tooltip.suffix")); return displayInfo.toString(); } return null; } }); } plot.setDataset(alarmDataCollection); }
From source file:it.eng.spagobi.engines.chart.bo.charttypes.scattercharts.MarkerScatter.java
public JFreeChart createChart(DatasetMap datasets) { DefaultXYDataset dataset = (DefaultXYDataset) datasets.getDatasets().get("1"); JFreeChart chart = ChartFactory.createScatterPlot(name, yLabel, xLabel, dataset, PlotOrientation.HORIZONTAL, false, true, false);//from w w w. ja v a2s. c o m TextTitle title = setStyleTitle(name, styleTitle); chart.setTitle(title); chart.setBackgroundPaint(Color.white); if (subName != null && !subName.equals("")) { TextTitle subTitle = setStyleTitle(subName, styleSubTitle); chart.addSubtitle(subTitle); } XYPlot plot = (XYPlot) chart.getPlot(); plot.setForegroundAlpha(0.65f); XYItemRenderer renderer = plot.getRenderer(); //defines colors int seriesN = dataset.getSeriesCount(); if ((colorMap != null && colorMap.size() > 0) || (defaultColor != null && !defaultColor.equals(""))) { for (int i = 0; i < seriesN; i++) { String serieName = (String) dataset.getSeriesKey(i); Color color = new Color(Integer.decode(defaultColor).intValue()); if (colorMap != null && colorMap.size() > 0) color = (Color) colorMap.get(serieName); if (color != null) renderer.setSeriesPaint(i, color); } } // add un interval marker for the Y axis... if (yMarkerStartInt != null && yMarkerEndInt != null && !yMarkerStartInt.equals("") && !yMarkerEndInt.equals("")) { Marker intMarkerY = new IntervalMarker(Double.parseDouble(yMarkerStartInt), Double.parseDouble(yMarkerEndInt)); intMarkerY.setLabelOffsetType(LengthAdjustmentType.EXPAND); intMarkerY.setPaint( new Color(Integer.decode((yMarkerIntColor.equals("")) ? "0" : yMarkerIntColor).intValue())); //intMarkerY.setLabel(yMarkerLabel); intMarkerY.setLabelAnchor(RectangleAnchor.BOTTOM_RIGHT); intMarkerY.setLabelTextAnchor(TextAnchor.TOP_RIGHT); plot.addDomainMarker(intMarkerY, Layer.BACKGROUND); } // add un interval marker for the X axis... if (xMarkerStartInt != null && xMarkerEndInt != null && !xMarkerStartInt.equals("") && !xMarkerEndInt.equals("")) { Marker intMarkerX = new IntervalMarker(Double.parseDouble(xMarkerStartInt), Double.parseDouble(xMarkerEndInt)); intMarkerX.setLabelOffsetType(LengthAdjustmentType.EXPAND); intMarkerX.setPaint( new Color(Integer.decode((xMarkerIntColor.equals("")) ? "0" : xMarkerIntColor).intValue())); //intMarkerX.setLabel(xMarkerLabel); intMarkerX.setLabelAnchor(RectangleAnchor.BOTTOM_RIGHT); intMarkerX.setLabelTextAnchor(TextAnchor.TOP_RIGHT); plot.addRangeMarker(intMarkerX, Layer.BACKGROUND); } // add a labelled marker for the Y axis... if (yMarkerValue != null && !yMarkerValue.equals("")) { Marker markerY = new ValueMarker(Double.parseDouble(yMarkerValue)); markerY.setLabelOffsetType(LengthAdjustmentType.EXPAND); if (!yMarkerColor.equals("")) markerY.setPaint(new Color(Integer.decode(yMarkerColor).intValue())); markerY.setLabel(yMarkerLabel); markerY.setLabelFont(new Font("Arial", Font.BOLD, 11)); markerY.setLabelAnchor(RectangleAnchor.TOP_RIGHT); markerY.setLabelTextAnchor(TextAnchor.TOP_RIGHT); plot.addDomainMarker(markerY, Layer.BACKGROUND); } // add a labelled marker for the X axis... if (xMarkerValue != null && !xMarkerValue.equals("")) { Marker markerX = new ValueMarker(Double.parseDouble(xMarkerValue)); markerX.setLabelOffsetType(LengthAdjustmentType.EXPAND); if (!xMarkerColor.equals("")) markerX.setPaint(new Color(Integer.decode(xMarkerColor).intValue())); markerX.setLabel(xMarkerLabel); markerX.setLabelAnchor(RectangleAnchor.BOTTOM_RIGHT); markerX.setLabelTextAnchor(TextAnchor.TOP_RIGHT); plot.addRangeMarker(markerX, Layer.BACKGROUND); } if (xRangeLow != null && !xRangeLow.equals("") && xRangeHigh != null && !xRangeHigh.equals("")) { if (Double.valueOf(xRangeLow).doubleValue() > xMin) xRangeLow = String.valueOf(xMin); if (Double.valueOf(xRangeHigh).doubleValue() < xMax) xRangeHigh = String.valueOf(xMax); ValueAxis rangeAxis = plot.getRangeAxis(); //rangeAxis.setRange(Double.parseDouble(xRangeLow), Double.parseDouble(xRangeHigh)); rangeAxis.setRangeWithMargins(Double.parseDouble(xRangeLow), Double.parseDouble(xRangeHigh)); } else { NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setAutoRange(true); rangeAxis.setRange(xMin, xMax); } if (yRangeLow != null && !yRangeLow.equals("") && yRangeHigh != null && !yRangeHigh.equals("")) { if (Double.valueOf(yRangeLow).doubleValue() > yMin) yRangeLow = String.valueOf(yMin); if (Double.valueOf(yRangeHigh).doubleValue() < yMax) yRangeHigh = String.valueOf(yMax); NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis(); //domainAxis.setRange(Double.parseDouble(yRangeLow), Double.parseDouble(yRangeHigh)); domainAxis.setRangeWithMargins(Double.parseDouble(yRangeLow), Double.parseDouble(yRangeHigh)); domainAxis.setAutoRangeIncludesZero(false); } else { NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis(); domainAxis.setAutoRange(true); domainAxis.setRange(yMin, yMax); domainAxis.setAutoRangeIncludesZero(false); } //add annotations if requested if (viewAnnotations != null && viewAnnotations.equalsIgnoreCase("true")) { if (annotationMap == null || annotationMap.size() == 0) logger.error("Annotations on the chart are requested but the annotationMap is null!"); else { int cont = 1; for (Iterator iterator = annotationMap.keySet().iterator(); iterator.hasNext();) { String text = (String) iterator.next(); String pos = (String) annotationMap.get(text); double x = Double.parseDouble(pos.substring(0, pos.indexOf("__"))); double y = Double.parseDouble(pos.substring(pos.indexOf("__") + 2)); //default up position XYTextAnnotation annotation = new XYTextAnnotation(text, y - 1, x + ((text.length() > 20) ? text.length() / 3 + 1 : text.length() / 2 + 1)); if (cont % 2 != 0) //dx annotation = new XYTextAnnotation(text, y, x + ((text.length() > 20) ? text.length() / 3 + 1 : text.length() / 2 + 1)); else //sx //annotation = new XYTextAnnotation(text, y, x-((text.length()%2==0)?text.length():text.length()-1)); annotation = new XYTextAnnotation(text, y, x - (text.length() - 1)); annotation.setFont(new Font("SansSerif", Font.PLAIN, 11)); //annotation.setRotationAngle(Math.PI / 4.0); annotation.setRotationAngle(0.0); // horizontal plot.addAnnotation(annotation); cont++; } renderer.setShape(new Ellipse2D.Double(-3, -5, 8, 8)); } } else if (viewAnnotations != null && viewAnnotations.equalsIgnoreCase("false")) { renderer.setShape(new Ellipse2D.Double(-3, -5, 8, 8)); } if (legend == true) { drawLegend(chart); } return chart; }