View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.myfaces.trinidad.model;
20  
21  import java.awt.Color;
22  
23  import java.util.ArrayList;
24  import java.util.Arrays;
25  import java.util.List;
26  
27  
28  /**
29   * The data model used by chart components.
30   * The chart is draw using values from the yValues 2D array. The yValues are returned by
31   * {@link #getYValues} method. The maximum and the minimum are controlled by 
32   * {@link #getMaxYValue} method and {@link #getMinYValue} method. The default maximum value
33   * is 120% of the maximum of the yValues if no value is specified. The default minimum value 
34   * is 0. For XYLine and Scatter plots xValues are also required. The xValues are controlled by
35   * {@link #getXValues} method, {@link #getMaxXValue} method and {@link #getMinXValue} method.
36   * 
37   * The labels on y-axis of the graph are calculated from the yValues. However the labels on the
38   * x-axis are controlled by the group labels array returned by  {@link #getGroupLabels} method.
39   * 
40   * Each group of values in the chart may contain multiple series. The number of series in a
41   * group are controlled by {@link #getSeriesLabels} method. 
42   * 
43   * The colors of the series are controlled by {@link #getSeriesColors} method.
44   * 
45   * The chart title, sub-title and the footnote can be specified using 
46   * {@link #getTitle} method, {@link #getSubTitle} method and {@link #getFootNote} method
47   */
48  public abstract class ChartModel
49  {
50    public abstract List<String> getSeriesLabels();
51    
52    public abstract List<String> getGroupLabels();
53    
54    public List<Color> getSeriesColors()
55    {
56      return _defaultColors;
57    }
58    
59    public List<List<Double>> getXValues()
60    {
61      return null; 
62    }
63  
64    public abstract List<List<Double>> getYValues();
65  
66    public Double getMaxYValue()
67    {
68      return null; 
69    }
70  
71  
72    public Double getMinYValue()
73    {
74      return null; 
75    }
76  
77  
78    public Double getMaxXValue()
79    {
80      return null; 
81    }
82  
83  
84    public Double getMinXValue()
85    {
86      return null; 
87    }
88  
89  
90    public String getTitle()
91    {
92      return null; 
93    }
94  
95    public String getSubTitle()
96    {
97      return null; 
98    }
99  
100 
101   public String getFootNote()
102   {
103     return null; 
104   }
105   
106   
107   private static final List<Color> _defaultColors = new ArrayList<Color>();  
108   static
109   {
110     _defaultColors.addAll(
111       Arrays.asList(new Color[]{new Color(231,109,72,0),new Color(110,166,243,0),new Color(157,206,110,0),new Color(252,196,111,0),new Color(114,126,142,0),new Color(109,44,145,0)}));
112   }  
113 }