001: /*
002: * Version: MPL 1.1/GPL 2.0/LGPL 2.1
003: *
004: * "The contents of this file are subject to the Mozilla Public License
005: * Version 1.1 (the "License"); you may not use this file except in
006: * compliance with the License. You may obtain a copy of the License at
007: * http://www.mozilla.org/MPL/
008: *
009: * Software distributed under the License is distributed on an "AS IS"
010: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
011: * License for the specific language governing rights and limitations under
012: * the License.
013: *
014: * The Original Code is ICEfaces 1.5 open source software code, released
015: * November 5, 2006. The Initial Developer of the Original Code is ICEsoft
016: * Technologies Canada, Corp. Portions created by ICEsoft are Copyright (C)
017: * 2004-2006 ICEsoft Technologies Canada, Corp. All Rights Reserved.
018: *
019: * Contributor(s): _____________________.
020: *
021: * Alternatively, the contents of this file may be used under the terms of
022: * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"
023: * License), in which case the provisions of the LGPL License are
024: * applicable instead of those above. If you wish to allow use of your
025: * version of this file only under the terms of the LGPL License and not to
026: * allow others to use your version of this file under the MPL, indicate
027: * your decision by deleting the provisions above and replace them with
028: * the notice and other provisions required by the LGPL License. If you do
029: * not delete the provisions above, a recipient may use your version of
030: * this file under either the MPL or the LGPL License."
031: *
032: */
033:
034: package com.icesoft.faces.component.outputchart;
035:
036: import org.krysalis.jcharts.Chart;
037: import org.krysalis.jcharts.chartData.PieChartDataSet;
038: import org.krysalis.jcharts.nonAxisChart.PieChart2D;
039: import org.krysalis.jcharts.nonAxisChart.PieChart3D;
040: import org.krysalis.jcharts.properties.ChartProperties;
041: import org.krysalis.jcharts.properties.LegendProperties;
042: import org.krysalis.jcharts.properties.PieChart2DProperties;
043: import org.krysalis.jcharts.properties.PieChart3DProperties;
044: import org.krysalis.jcharts.properties.util.ChartStroke;
045: import org.krysalis.jcharts.types.PieLabelType;
046:
047: import javax.faces.component.UIComponent;
048: import java.awt.*;
049:
050: public class PieChart extends AbstractChart {
051:
052: public PieChart(UIComponent outputChart) throws Throwable {
053: super (outputChart);
054: }
055:
056: protected void buildChart() {
057: try {
058: if (type.equalsIgnoreCase("pie2d")) {
059: chart = getPie2dChart();
060: } else if (type.equalsIgnoreCase("pie3d")) {
061: chart = getPie3dChart();
062: }
063: } catch (Throwable e) {
064: e.printStackTrace();
065: }
066: }
067:
068: double data[] = null;
069:
070: public double[] getData(Object obj) {
071: if (data != null && obj instanceof String) {
072: return data;
073: }
074: return data = super .getAsDoubleArray(obj);
075: }
076:
077: String[] labels = null;
078:
079: public String[] getLabels(Object obj) {
080: if (obj == null && labels == null) {
081: return labels = getGeneratedLabels("label", data.length);
082: } else if ((obj == null || obj instanceof String)
083: && labels != null) {
084: return labels;
085: } else {
086: return labels = getAsStringArray(obj);
087: }
088: }
089:
090: public Paint[] getPaints(Object obj) {
091: return getPaints(obj, data.length);
092: }
093:
094: private Chart getPie2dChart() throws Throwable {
095: PieChart2DProperties pieChart2DProperties = new PieChart2DProperties();
096: PieChartDataSet pieChartDataSet;
097: pieChartDataSet = new PieChartDataSet(outputChart
098: .getChartTitle(), getData(outputChart.getData()),
099: getLabels(outputChart.getLabels()),
100: getPaints(outputChart.getColors()),
101: pieChart2DProperties);
102:
103: return new PieChart2D(pieChartDataSet, getLegendProperties(),
104: new ChartProperties(), new Integer(outputChart
105: .getWidth()).intValue(), new Integer(
106: outputChart.getHeight()).intValue());
107:
108: }
109:
110: private Chart getPie3dChart() throws Throwable {
111: PieChart3DProperties pieChart3DProperties = new PieChart3DProperties();
112: pieChart3DProperties.setDepth(30);
113: pieChart3DProperties.setBorderChartStroke(new ChartStroke(
114: new BasicStroke(1f), Color.black));
115: pieChart3DProperties
116: .setPieLabelType(PieLabelType.LEGEND_LABELS);
117: PieChartDataSet pieChartDataSet = new PieChartDataSet(
118: outputChart.getChartTitle(), getData(outputChart
119: .getData()),
120: getLabels(outputChart.getLabels()),
121: getPaints(outputChart.getColors()),
122: pieChart3DProperties);
123: return new PieChart3D(pieChartDataSet, null,
124: new ChartProperties(), new Integer(outputChart
125: .getWidth()).intValue(), new Integer(
126: outputChart.getHeight()).intValue());
127: }
128: }
|