1 | package de.uka.ipd.sdq.sensorframework.visualisation.jfreechartvisualisation; |
2 | |
3 | import org.eclipse.jface.action.MenuManager; |
4 | import org.eclipse.swt.widgets.Composite; |
5 | import org.jfree.chart.ChartFactory; |
6 | import org.jfree.chart.plot.PlotOrientation; |
7 | import org.jfree.chart.plot.XYPlot; |
8 | import org.jfree.data.xy.XYSeries; |
9 | |
10 | import de.uka.ipd.sdq.codegen.simudatavisualisation.datatypes.Histogram; |
11 | import de.uka.ipd.sdq.codegen.simudatavisualisation.datatypes.HistogramBucketInformation; |
12 | |
13 | |
14 | public class JFreeChartHistogramViewer extends AbstractJFreeChartWidthViewer |
15 | implements IHistogramAccepter, IHistSeriesExporter { |
16 | |
17 | public JFreeChartHistogramViewer(Composite parent, int style) { |
18 | super(parent, style); |
19 | } |
20 | |
21 | @Override |
22 | protected void initializeContextMenu(MenuManager menu_manager) { |
23 | super.initializeContextMenu(menu_manager); |
24 | menu_manager.add(new LoadCSVHistogram(this)); |
25 | menu_manager.add(new ExportCSV(this)); |
26 | menu_manager.add(new ExportDoublePDF(this)); |
27 | } |
28 | |
29 | public void addHistogram(Histogram histogram) { |
30 | XYSeries density = new XYSeries(histogram.getTitle(),true,false); |
31 | for (HistogramBucketInformation e : histogram.getBucketInformation()) |
32 | density.add(e.getValue(), e.getProbability()); |
33 | densityDataset.addSeries(density); |
34 | densityDataset.setAutoWidth(true); |
35 | initChart(); |
36 | this.redraw(); |
37 | } |
38 | |
39 | protected void initChart() { |
40 | chart = ChartFactory.createHistogram("Histogram","Time","Probability", densityDataset,PlotOrientation.VERTICAL,true,true,true); |
41 | |
42 | XYPlot plot = (XYPlot)chart.getPlot(); |
43 | plot.getRangeAxis().setAutoRange(true); |
44 | plot.setForegroundAlpha(0.8f); // for transparency |
45 | if (densityDataset != null) |
46 | densityDataset.setAutoWidth(true); |
47 | } |
48 | |
49 | protected XYSeries computeDensities(Histogram hist) { |
50 | XYSeries density; |
51 | density = new XYSeries(hist.getTitle(),true,false); |
52 | for (HistogramBucketInformation bucketInformation : hist.getBucketInformation()) { |
53 | density.add(bucketInformation.getValue() + hist.getBucketWidth() / 2, bucketInformation.getProbability()); |
54 | } |
55 | return density; |
56 | } |
57 | |
58 | public XYSeries getSeries() { |
59 | return densityDataset.getSeries(0); |
60 | } |
61 | |
62 | public double getHistogramWidth() { |
63 | return densityDataset.getIntervalWidth(); |
64 | } |
65 | |
66 | } |