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.file.raw.ChannelWiseActionsMiner;
008: import com.sun.portal.ubt.report.data.file.aggregate.ChannelWiseActionsMinerAggregator;
009: import com.sun.portal.ubt.report.data.DataMiner;
010: import com.sun.portal.ubt.report.data.UBTActions;
011: import com.sun.portal.ubt.report.view.IllegalMinerException;
012: import com.sun.portal.ubt.report.util.UBTReportResourceBundle;
013: import org.jfree.chart.JFreeChart;
014: import org.jfree.chart.ChartFactory;
015: import org.jfree.chart.plot.PlotOrientation;
016: import org.jfree.data.category.CategoryDataset;
017: import org.jfree.data.category.DefaultIntervalCategoryDataset;
018:
019: import java.util.Arrays;
020: import java.util.Vector;
021: import java.util.TreeMap;
022: import java.util.Iterator;
023: import java.util.Locale;
024:
025: /**
026: *
027: */
028: public class ChannelWiseActionsChart implements UBTChartI {
029: DataMiner miner;
030: public static final String XAxisLabel = "Channels";
031: public static final String YAxisLabel = "Activities";
032: public static final String ChannelPopularityInteractions = "ChannelPopularityInteractions";
033: private UBTReportResourceBundle reportsResource;
034:
035: public ChannelWiseActionsChart(DataMiner miner, Locale locale)
036: throws IllegalMinerException {
037: if (!(miner instanceof ChannelWiseActionsMiner || miner instanceof ChannelWiseActionsMinerAggregator))
038: throw new IllegalMinerException();
039: this .miner = miner;
040: reportsResource = new UBTReportResourceBundle(locale);
041: }
042:
043: private JFreeChart createChart(String container) {
044: CategoryDataset dataset = createDataSet(container);
045: JFreeChart chart = ChartFactory
046: .createStackedBarChart(
047: reportsResource
048: .getReportProperty(ChannelPopularityInteractions)
049: + " " + container, reportsResource
050: .getReportProperty(XAxisLabel), // X-Axis label
051: reportsResource.getReportProperty(YAxisLabel), // Y-Axis label
052: dataset, // Dataset
053: PlotOrientation.VERTICAL,// Orientation
054: true, false, false // Show legend
055: );
056: UBTChartUtil.customizeChart(chart);
057: return chart;
058: }
059:
060: private CategoryDataset createDataSet(String container) {
061: String[] channels; //chaannels
062: String[] actions; //actions
063: Number[][] startValues;
064: TreeMap containerMap = (TreeMap) ((TreeMap) miner.getData())
065: .get(container);
066: Object[] objArray = (Object[]) containerMap.keySet().toArray();
067: channels = new String[objArray.length];
068: copy(objArray, channels);
069: actions = new String[UBTActions.getProviderValidSet().size()];
070: copy(UBTActions.getProviderValidSet().toArray(), actions);
071: startValues = new Number[actions.length][channels.length];
072: for (int i = 0; i < startValues.length; i++) {
073: Arrays.fill(startValues[i], new Integer(0));
074: }
075: for (int i = 0; i < channels.length; i++) {
076: TreeMap channelMap = (TreeMap) containerMap
077: .get(channels[i]);
078: for (int k = 0; k < actions.length; k++) {
079: if (channelMap.containsKey(actions[k])) {
080: startValues[k][i] = (Integer) channelMap
081: .get(actions[k]);
082: }
083: }
084: }
085: return new DefaultIntervalCategoryDataset(actions, channels,
086: startValues, startValues);
087: }
088:
089: private void copy(Object[] objArray, String[] series) {
090: for (int i = 0; i < objArray.length; i++) {
091: series[i] = (String) objArray[i];
092: }
093: }
094:
095: public Vector getChart() {
096: TreeMap data = (TreeMap) miner.getData();
097: Vector containers = new Vector();
098: int j = 0;
099: Iterator containerI = data.keySet().iterator();
100: while (containerI.hasNext()) {
101: containers.add(j, containerI.next());
102: j++;
103: }
104: Vector charts = new Vector(containers.size());
105: for (int k = 0; k < containers.size(); k++) {
106: charts.add(k, new UBTChartRenderer(
107: createChart((String) containers.get(k))));
108: }
109: return charts;
110: }
111: }
|