| 1 | package de.uka.ipd.sdq.sensorframework.visualisation.rvisualisation.reportitems; |
| 2 | |
| 3 | |
| 4 | |
| 5 | /**This report item displays a histogram. |
| 6 | * @author groenda |
| 7 | */ |
| 8 | public class HistogramReportItem extends AbstractPlotReportItem { |
| 9 | /** Default label for the x axis. */ |
| 10 | public static final String DEFAULT_X_AXIS_LABEL = ""; |
| 11 | /** Default number of classes. */ |
| 12 | public static final int DEFAULT_NUMBER_CLASSES = 10; |
| 13 | |
| 14 | /** Label of the x axis. */ |
| 15 | private String xAxisLabel = DEFAULT_X_AXIS_LABEL; |
| 16 | /** Number of classes of the histogram. */ |
| 17 | private int columns = DEFAULT_NUMBER_CLASSES; |
| 18 | |
| 19 | /**Constructs a new report item containing a histogram graphic. |
| 20 | * The graphic is stored in a temporary file. This is accessible via the |
| 21 | * getFilename method. |
| 22 | * @param title Title of the plotted graphic. |
| 23 | * @param xAxisLabel Label for the x axis. |
| 24 | */ |
| 25 | public HistogramReportItem(final String title, final String xAxisLabel) { |
| 26 | super(title); |
| 27 | this.xAxisLabel = xAxisLabel; |
| 28 | } |
| 29 | |
| 30 | /**Constructs a new report item containing a histogram graphic. |
| 31 | * The graphic is stored in a temporary file. This is accessible via the |
| 32 | * getFilename method. |
| 33 | * @param title Title of the plotted graphic. |
| 34 | * @param height height of the plotted graphic. |
| 35 | * @param width width of the plotted graphics. |
| 36 | * @param fontSize the default pointsize of plotted text, interpreted at |
| 37 | * 72 dpi, so one point is approximately one pixel. |
| 38 | * @param xAxisLabel Label for the x axis. |
| 39 | */ |
| 40 | public HistogramReportItem(final String title, final int height, |
| 41 | final int width, final int fontSize, final String xAxisLabel) { |
| 42 | super(title, height, width, fontSize); |
| 43 | this.xAxisLabel = DEFAULT_X_AXIS_LABEL; |
| 44 | } |
| 45 | |
| 46 | /** {@inheritDoc} |
| 47 | */ |
| 48 | @Override |
| 49 | protected String generatePlotCommand() { |
| 50 | |
| 51 | String rCommand = "require(plotrix)\n"; |
| 52 | |
| 53 | String list = "l = list("; |
| 54 | String legend= "leg = list("; |
| 55 | int pos = 0; |
| 56 | for (String id : getDataSeries()) { |
| 57 | String data = getDataCommand(id); |
| 58 | String sep = (pos == 0 ? "" : ", "); |
| 59 | list += sep + data; |
| 60 | legend += sep + "\""+getName(id)+"\""; |
| 61 | pos++; |
| 62 | } |
| 63 | list += ")\n"; |
| 64 | legend += ")\n"; |
| 65 | rCommand += list; |
| 66 | rCommand += legend; |
| 67 | rCommand += "multhist(l, breaks=" + columns + ", freq=FALSE, probability=TRUE," |
| 68 | + "main=\"" + getDescription() + "\", " |
| 69 | + "title=\"Histogram\", " |
| 70 | + "xlab=\"" + xAxisLabel + "\", " + "ylab=\"Probability\""; |
| 71 | if (getDataSeries().length>=2){ |
| 72 | rCommand+=", legend.text=leg"; |
| 73 | } |
| 74 | rCommand+=")\n"; |
| 75 | return rCommand; |
| 76 | } |
| 77 | |
| 78 | /**Returns the number of classes of the histogram. |
| 79 | * @return The number of classes. |
| 80 | */ |
| 81 | public int getColumns() { |
| 82 | return columns; |
| 83 | } |
| 84 | |
| 85 | /**Set s the number of classes of the histogram. |
| 86 | * @param columns The number of classes. |
| 87 | */ |
| 88 | public void setColumns(final int columns) { |
| 89 | this.columns = columns; |
| 90 | } |
| 91 | |
| 92 | } |