create changelog entry
[debian/openrocket] / android-libraries / achartengine / src / org / achartengine / chart / RangeBarChart.java
1 /**\r
2  * Copyright (C) 2009 - 2012 SC 4ViewSoft SRL\r
3  *  \r
4  * Licensed under the Apache License, Version 2.0 (the "License");\r
5  * you may not use this file except in compliance with the License.\r
6  * You may obtain a copy of the License at\r
7  *  \r
8  *      http://www.apache.org/licenses/LICENSE-2.0\r
9  *  \r
10  * Unless required by applicable law or agreed to in writing, software\r
11  * distributed under the License is distributed on an "AS IS" BASIS,\r
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
13  * See the License for the specific language governing permissions and\r
14  * limitations under the License.\r
15  */\r
16 package org.achartengine.chart;\r
17 \r
18 import org.achartengine.model.XYMultipleSeriesDataset;\r
19 import org.achartengine.model.XYSeries;\r
20 import org.achartengine.renderer.SimpleSeriesRenderer;\r
21 import org.achartengine.renderer.XYMultipleSeriesRenderer;\r
22 \r
23 import android.graphics.Canvas;\r
24 import android.graphics.Paint;\r
25 import android.graphics.Paint.Style;\r
26 \r
27 /**\r
28  * The range bar chart rendering class.\r
29  */\r
30 public class RangeBarChart extends BarChart {\r
31   /** The chart type. */\r
32   public static final String TYPE = "RangeBar";\r
33 \r
34   RangeBarChart() {\r
35   }\r
36 \r
37   RangeBarChart(Type type) {\r
38     super(type);\r
39   }\r
40 \r
41   /**\r
42    * Builds a new range bar chart instance.\r
43    * \r
44    * @param dataset the multiple series dataset\r
45    * @param renderer the multiple series renderer\r
46    * @param type the range bar chart type\r
47    */\r
48   public RangeBarChart(XYMultipleSeriesDataset dataset, XYMultipleSeriesRenderer renderer, Type type) {\r
49     super(dataset, renderer, type);\r
50   }\r
51 \r
52   /**\r
53    * The graphical representation of a series.\r
54    * \r
55    * @param canvas the canvas to paint to\r
56    * @param paint the paint to be used for drawing\r
57    * @param points the array of points to be used for drawing the series\r
58    * @param seriesRenderer the series renderer\r
59    * @param yAxisValue the minimum value of the y axis\r
60    * @param seriesIndex the index of the series currently being drawn\r
61    * @param startIndex the start index of the rendering points\r
62    */\r
63   public void drawSeries(Canvas canvas, Paint paint, float[] points,\r
64       SimpleSeriesRenderer seriesRenderer, float yAxisValue, int seriesIndex, int startIndex) {\r
65     int seriesNr = mDataset.getSeriesCount();\r
66     int length = points.length;\r
67     paint.setColor(seriesRenderer.getColor());\r
68     paint.setStyle(Style.FILL);\r
69     float halfDiffX = getHalfDiffX(points, length, seriesNr);\r
70     int start = 0;\r
71     if (startIndex > 0) {\r
72       start = 2;\r
73     }\r
74     for (int i = start; i < length; i += 4) {\r
75       if (points.length > i + 3) {\r
76         float xMin = points[i];\r
77         float yMin = points[i + 1];\r
78         // xMin = xMax\r
79         float xMax = points[i + 2];\r
80         float yMax = points[i + 3];\r
81         drawBar(canvas, xMin, yMin, xMax, yMax, halfDiffX, seriesNr, seriesIndex, paint);\r
82       }\r
83     }\r
84     paint.setColor(seriesRenderer.getColor());\r
85   }\r
86 \r
87   /**\r
88    * The graphical representation of the series values as text.\r
89    * \r
90    * @param canvas the canvas to paint to\r
91    * @param series the series to be painted\r
92    * @param renderer the series renderer\r
93    * @param paint the paint to be used for drawing\r
94    * @param points the array of points to be used for drawing the series\r
95    * @param seriesIndex the index of the series currently being drawn\r
96    * @param startIndex the start index of the rendering points\r
97    */\r
98   protected void drawChartValuesText(Canvas canvas, XYSeries series, SimpleSeriesRenderer renderer,\r
99       Paint paint, float[] points, int seriesIndex, int startIndex) {\r
100     int seriesNr = mDataset.getSeriesCount();\r
101     float halfDiffX = getHalfDiffX(points, points.length, seriesNr);\r
102     int start = 0;\r
103     if (startIndex > 0) {\r
104       start = 2;\r
105     }\r
106     for (int i = start; i < points.length; i += 4) {\r
107       int index = startIndex + i / 2;\r
108       float x = points[i];\r
109       if (mType == Type.DEFAULT) {\r
110         x += seriesIndex * 2 * halfDiffX - (seriesNr - 1.5f) * halfDiffX;\r
111       }\r
112 \r
113       if (!isNullValue(series.getY(index + 1)) && points.length > i + 3) {\r
114         // draw the maximum value\r
115         drawText(canvas, getLabel(series.getY(index + 1)), x,\r
116             points[i + 3] - renderer.getChartValuesSpacing(), paint, 0);\r
117       }\r
118       if (!isNullValue(series.getY(index)) && points.length > i + 1) {\r
119         // draw the minimum value\r
120         drawText(canvas, getLabel(series.getY(index)), x,\r
121             points[i + 1] + renderer.getChartValuesTextSize() + renderer.getChartValuesSpacing()\r
122                 - 3, paint, 0);\r
123       }\r
124     }\r
125   }\r
126 \r
127   /**\r
128    * Returns the value of a constant used to calculate the half-distance.\r
129    * \r
130    * @return the constant value\r
131    */\r
132   protected float getCoeficient() {\r
133     return 0.5f;\r
134   }\r
135 \r
136   /**\r
137    * Returns the chart type identifier.\r
138    * \r
139    * @return the chart type\r
140    */\r
141   public String getChartType() {\r
142     return TYPE;\r
143   }\r
144 \r
145 }\r