| 1 | package de.uka.ipd.sdq.sensorframework.visualisation.rvisualisation.reportitems; |
| 2 | |
| 3 | /**Report item that displays cumulative distribution functions. |
| 4 | * @author groenda |
| 5 | */ |
| 6 | public class CdfReportItem extends AbstractPlotReportItem { |
| 7 | /** Default label for the x axis. */ |
| 8 | public static final String DEFAULT_X_AXIS_LABEL = ""; |
| 9 | |
| 10 | /** Label of the x axis. */ |
| 11 | private String xAxisLabel = DEFAULT_X_AXIS_LABEL; |
| 12 | |
| 13 | /**Constructs a new report item containing a plotted cdf graphic. |
| 14 | * The graphic is stored in a temporary file. This is accessible via the |
| 15 | * getFilename method. |
| 16 | * @param title Title of the plotted graphic. |
| 17 | * @param xAxisLabel Label for the x axis. |
| 18 | */ |
| 19 | public CdfReportItem(final String title, final String xAxisLabel) { |
| 20 | super(title); |
| 21 | this.xAxisLabel = xAxisLabel; |
| 22 | } |
| 23 | |
| 24 | /**Constructs a new report item containing a plotted cdf graphic. |
| 25 | * The graphic is stored in a temporary file. This is accessible via the |
| 26 | * getFilename method. |
| 27 | * @param title Title of the plotted graphic. |
| 28 | * @param height height of the plotted graphic. |
| 29 | * @param width width of the plotted graphics. |
| 30 | * @param fontSize the default pointsize of plotted text, interpreted at |
| 31 | * 72 dpi, so one point is approximately one pixel. |
| 32 | * @param xAxisLabel Label for the x axis. |
| 33 | */ |
| 34 | public CdfReportItem(final String title, final int height, |
| 35 | final int width, final int fontSize, final String xAxisLabel) { |
| 36 | super(title, height, width, fontSize); |
| 37 | this.xAxisLabel = DEFAULT_X_AXIS_LABEL; |
| 38 | } |
| 39 | |
| 40 | /** {@inheritDoc} |
| 41 | */ |
| 42 | @Override |
| 43 | protected String generatePlotCommand() { |
| 44 | |
| 45 | int pos = 0; |
| 46 | String sort = ""; |
| 47 | String range = "r = range("; |
| 48 | String plot = ""; |
| 49 | |
| 50 | for (String id : getDataSeries()) { |
| 51 | String data = getDataCommand(id); |
| 52 | String sdata = "s_" + data; |
| 53 | String sep = (pos == 0 ? "" : ", "); |
| 54 | |
| 55 | range += sep + data; |
| 56 | sort += sdata + " = sort(" + data + ")\n"; |
| 57 | |
| 58 | if (pos == 0) { |
| 59 | plot += "plot(ecdf(" + sdata + "), xlim=r, " |
| 60 | + "do.points=FALSE, " + "verticals=TRUE, " |
| 61 | + "main=\"" + getDescription() + "\", " |
| 62 | + "xlab=\"" + xAxisLabel + "\", " + "ylab=\"Cumulated Density\")\n"; |
| 63 | } else { |
| 64 | plot += "lines(" + sdata + ", (1:length(" + sdata + "))/length(" |
| 65 | + sdata + " ),type=\"s\", lty=" + (pos + 1) + ")\n"; |
| 66 | } |
| 67 | |
| 68 | pos++; |
| 69 | } |
| 70 | range += ")\n"; |
| 71 | |
| 72 | String rCommand = sort + range + plot; |
| 73 | rCommand += generateLinesLegend(); |
| 74 | return rCommand; |
| 75 | } |
| 76 | } |