001: /*
002: * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
003: * PROPRIETARY/CONFIDENTIAL. Use of this product is subject to license terms.
004: */
005: package com.sun.portal.ubt.report.view.chart;
006:
007: import com.sun.portal.ubt.report.data.DataMiner;
008: import com.sun.portal.ubt.report.data.file.raw.ContainerWiseActionsMiner;
009: import com.sun.portal.ubt.report.data.file.aggregate.ContainerWiseActionsMinerAggregator;
010: import com.sun.portal.ubt.report.view.IllegalMinerException;
011: import com.sun.portal.ubt.report.util.UBTReportResourceBundle;
012:
013: import java.util.Vector;
014: import java.util.TreeMap;
015: import java.util.Arrays;
016: import java.util.Locale;
017:
018: import org.jfree.chart.JFreeChart;
019: import org.jfree.chart.ChartFactory;
020: import org.jfree.chart.plot.PlotOrientation;
021: import org.jfree.data.category.CategoryDataset;
022: import org.jfree.data.category.DefaultIntervalCategoryDataset;
023: import org.jfree.data.category.DefaultCategoryDataset;
024:
025: /**
026: *
027: */
028: public class ContainerActionsChart implements UBTChartI {
029: public static final String INTENDED_vs_SUCCESS = "IntentVsSuccess";
030: public static final String INTENDED = "IntendedCustom";
031: public static final String SUCCESS = "SuccessCustom";
032: public static final String Container = "Container";
033: public static final String NoCustomization = "NoCustomization";
034: public static final String TotalCustomization = "TotalCustomization";
035: public static final String Intended = "Intended";
036: public static final String Successful = "Successful";
037: private DataMiner miner;
038: String[] IntendedContainers;
039: Number[] IntendedCounts;
040: String[] SuccessfulContainers;
041: Number[] SuccessfulCounts;
042: private UBTReportResourceBundle reportsResource;
043:
044: public ContainerActionsChart(DataMiner miner, Locale locale)
045: throws IllegalMinerException {
046: if (!(miner instanceof ContainerWiseActionsMiner || miner instanceof ContainerWiseActionsMinerAggregator))
047: throw new IllegalMinerException();
048: this .miner = miner;
049: reportsResource = new UBTReportResourceBundle(locale);
050: }
051:
052: private JFreeChart createBarChart() {
053: CategoryDataset dataset = createDataSet();
054: JFreeChart chart = ChartFactory.createBarChart(reportsResource
055: .getReportProperty(INTENDED_vs_SUCCESS),
056: reportsResource.getReportProperty(Container), // X-Axis label
057: reportsResource.getReportProperty(NoCustomization), // Y-Axis label
058: dataset, // Dataset
059: PlotOrientation.VERTICAL,// Orientation
060: true, false, false // Show legend
061: );
062: UBTChartUtil.customizeChart(chart);
063: return chart;
064: }
065:
066: private JFreeChart createWaterFallChart(String key) {
067: CategoryDataset dataset = createDataSet(key);
068: JFreeChart chart = ChartFactory
069: .createWaterfallChart(
070: key
071: .equals(ContainerWiseActionsMiner.INTENTIONS) ? reportsResource
072: .getReportProperty(INTENDED)
073: : reportsResource
074: .getReportProperty(SUCCESS),
075: reportsResource.getReportProperty(Container),
076: reportsResource
077: .getReportProperty(NoCustomization),
078: dataset, PlotOrientation.VERTICAL, true, true,
079: false);
080:
081: UBTChartUtil.customizeChart(chart);
082: return chart;
083: }
084:
085: private DefaultIntervalCategoryDataset createDataSet() {
086: String[] containers = IntendedContainers;
087: String[] yaxis = { reportsResource.getReportProperty(Intended),
088: reportsResource.getReportProperty(Successful) };
089: Number[][] startValues = new Number[yaxis.length][containers.length];
090: for (int i = 0; i < yaxis.length; i++) {
091: Arrays.fill(startValues[i], new Integer(0));
092: }
093: for (int i = 0; i < IntendedContainers.length; i++) {
094: startValues[0][i] = IntendedCounts[i];
095: startValues[1][i] = getSuccessValue(IntendedContainers[i]);
096: }
097: return new DefaultIntervalCategoryDataset(yaxis, containers,
098: startValues, startValues);
099: }
100:
101: private Number getSuccessValue(String intendedContainer) {
102: for (int i = 0; i < SuccessfulContainers.length; i++) {
103: if (SuccessfulContainers[i].equals(intendedContainer))
104: return SuccessfulCounts[i];
105: }
106: return new Integer(0);
107: }
108:
109: private CategoryDataset createDataSet(String key) {
110: String[] containers; //chaannels
111: Number[] startValues;
112: TreeMap keyMap = (TreeMap) ((TreeMap) miner.getData()).get(key);
113: Object[] objArray = (Object[]) keyMap.keySet().toArray();
114: containers = new String[objArray.length];
115: copy(objArray, containers);
116: startValues = new Number[containers.length];
117: for (int i = 0; i < startValues.length; i++) {
118: startValues[i] = new Integer(0);
119: }
120: for (int i = 0; i < containers.length; i++) {
121: startValues[i] = new Integer(((Integer) keyMap
122: .get(containers[i])).intValue());
123: }
124: if (key.equals(ContainerWiseActionsMiner.INTENTIONS)) {
125: this .IntendedContainers = containers;
126: this .IntendedCounts = startValues;
127: } else {
128: this .SuccessfulContainers = containers;
129: this .SuccessfulCounts = startValues;
130: }
131: return fillDataset(containers, startValues);
132: }
133:
134: private CategoryDataset fillDataset(String[] containers,
135: Number[] values) {
136: DefaultCategoryDataset dataset = new DefaultCategoryDataset();
137: int total = 0;
138: for (int i = 0; i < containers.length; i++) {
139: dataset.addValue(values[i], "", containers[i]);
140: total += values[i].intValue();
141: }
142: dataset.addValue(total, "", reportsResource
143: .getReportProperty(TotalCustomization));
144: return dataset;
145: }
146:
147: private void copy(Object[] objArray, String[] series) {
148: for (int i = 0; i < objArray.length; i++) {
149: series[i] = (String) objArray[i];
150: }
151: }
152:
153: public Vector getChart() {
154: Vector charts = new Vector();
155: charts
156: .add(
157: 0,
158: new UBTChartRenderer(
159: createWaterFallChart(ContainerWiseActionsMiner.INTENTIONS)));
160: charts
161: .add(
162: 1,
163: new UBTChartRenderer(
164: createWaterFallChart(ContainerWiseActionsMiner.SUCCESSFUL)));
165: charts.add(2, new UBTChartRenderer(createBarChart()));
166: return charts;
167: }
168: }
|