1 | package de.uka.ipd.sdq.sensorframework.visualisation.jfreechartvisualisation; |
2 | |
3 | import java.awt.BasicStroke; |
4 | |
5 | import org.eclipse.jface.action.MenuManager; |
6 | import org.eclipse.swt.widgets.Composite; |
7 | import org.jfree.chart.ChartFactory; |
8 | import org.jfree.chart.plot.PlotOrientation; |
9 | import org.jfree.chart.plot.XYPlot; |
10 | import org.jfree.data.xy.XYSeries; |
11 | |
12 | import de.uka.ipd.sdq.codegen.simudatavisualisation.datatypes.Histogram; |
13 | import de.uka.ipd.sdq.codegen.simudatavisualisation.datatypes.HistogramBucketInformation; |
14 | |
15 | |
16 | public class JFreeChartCDFViewer extends AbstractJFreeChartWidthViewer implements IHistogramAccepter, ISeriesExporter { |
17 | |
18 | public XYSeries getSeries() { |
19 | return densityDataset.getSeries(0); |
20 | } |
21 | |
22 | public JFreeChartCDFViewer(Composite parent, int style) { |
23 | super(parent, style); |
24 | } |
25 | |
26 | @Override |
27 | protected void initializeContextMenu(MenuManager menu_manager) { |
28 | super.initializeContextMenu(menu_manager); |
29 | menu_manager.add(new LoadCSVHistogram(this)); |
30 | menu_manager.add(new ExportCSV(this)); |
31 | } |
32 | |
33 | /* (non-Javadoc) |
34 | * @see de.uka.ipd.sdq.sensorframework.visualisation.jfreechartvisualisation.IHistogramAccepter#addHistogram(de.uka.ipd.sdq.codegen.simudatavisualisation.datatypes.Histogram) |
35 | */ |
36 | public void addHistogram(Histogram histogram) { |
37 | XYSeries density = new XYSeries(histogram.getTitle(),true,false); |
38 | double sum = 0; |
39 | for (HistogramBucketInformation e : histogram.getBucketInformation()) { |
40 | sum += e.getProbability(); |
41 | density.add(e.getValue(), sum); |
42 | } |
43 | densityDataset.addSeries(density); |
44 | initChart(); |
45 | this.redraw(); |
46 | } |
47 | |
48 | |
49 | @SuppressWarnings("deprecation") |
50 | protected void initChart() { |
51 | chart = ChartFactory.createXYLineChart("Cumulative Distribution Function", "Time", "Probability", densityDataset, PlotOrientation.VERTICAL, true, true, true); |
52 | XYPlot plot = (XYPlot)chart.getPlot(); |
53 | |
54 | plot.getRangeAxis().setAutoRange(true); |
55 | plot.getRenderer().setStroke(new BasicStroke(3)); |
56 | } |
57 | |
58 | protected XYSeries computeDensities(Histogram hist) { |
59 | double sum = 0; |
60 | XYSeries density; |
61 | density = new XYSeries(hist.getTitle(),true,false); |
62 | for (HistogramBucketInformation bucketInformation : hist.getBucketInformation()) { |
63 | if (sum == 0) // is only executed the first time in the loop. |
64 | density.add(bucketInformation.getValue(), sum); |
65 | sum += bucketInformation.getProbability(); |
66 | if (sum != 0) |
67 | density.add(bucketInformation.getValue() + hist.getBucketWidth(), sum); |
68 | // if (sum == 1) |
69 | // density.add(bucketInformation.getValue() + hist.getBucketWidth(), sum); |
70 | } |
71 | return density; |
72 | } |
73 | |
74 | } |