Merge commit '42b2e5ca519766e37ce6941ba4faecc9691cc403' into upstream
[debian/openrocket] / android-libraries / achartengine / src / org / achartengine / chart / RangeBarChart.java
diff --git a/android-libraries/achartengine/src/org/achartengine/chart/RangeBarChart.java b/android-libraries/achartengine/src/org/achartengine/chart/RangeBarChart.java
new file mode 100644 (file)
index 0000000..105f509
--- /dev/null
@@ -0,0 +1,145 @@
+/**\r
+ * Copyright (C) 2009 - 2012 SC 4ViewSoft SRL\r
+ *  \r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *  \r
+ *      http://www.apache.org/licenses/LICENSE-2.0\r
+ *  \r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+package org.achartengine.chart;\r
+\r
+import org.achartengine.model.XYMultipleSeriesDataset;\r
+import org.achartengine.model.XYSeries;\r
+import org.achartengine.renderer.SimpleSeriesRenderer;\r
+import org.achartengine.renderer.XYMultipleSeriesRenderer;\r
+\r
+import android.graphics.Canvas;\r
+import android.graphics.Paint;\r
+import android.graphics.Paint.Style;\r
+\r
+/**\r
+ * The range bar chart rendering class.\r
+ */\r
+public class RangeBarChart extends BarChart {\r
+  /** The chart type. */\r
+  public static final String TYPE = "RangeBar";\r
+\r
+  RangeBarChart() {\r
+  }\r
+\r
+  RangeBarChart(Type type) {\r
+    super(type);\r
+  }\r
+\r
+  /**\r
+   * Builds a new range bar chart instance.\r
+   * \r
+   * @param dataset the multiple series dataset\r
+   * @param renderer the multiple series renderer\r
+   * @param type the range bar chart type\r
+   */\r
+  public RangeBarChart(XYMultipleSeriesDataset dataset, XYMultipleSeriesRenderer renderer, Type type) {\r
+    super(dataset, renderer, type);\r
+  }\r
+\r
+  /**\r
+   * The graphical representation of a series.\r
+   * \r
+   * @param canvas the canvas to paint to\r
+   * @param paint the paint to be used for drawing\r
+   * @param points the array of points to be used for drawing the series\r
+   * @param seriesRenderer the series renderer\r
+   * @param yAxisValue the minimum value of the y axis\r
+   * @param seriesIndex the index of the series currently being drawn\r
+   * @param startIndex the start index of the rendering points\r
+   */\r
+  public void drawSeries(Canvas canvas, Paint paint, float[] points,\r
+      SimpleSeriesRenderer seriesRenderer, float yAxisValue, int seriesIndex, int startIndex) {\r
+    int seriesNr = mDataset.getSeriesCount();\r
+    int length = points.length;\r
+    paint.setColor(seriesRenderer.getColor());\r
+    paint.setStyle(Style.FILL);\r
+    float halfDiffX = getHalfDiffX(points, length, seriesNr);\r
+    int start = 0;\r
+    if (startIndex > 0) {\r
+      start = 2;\r
+    }\r
+    for (int i = start; i < length; i += 4) {\r
+      if (points.length > i + 3) {\r
+        float xMin = points[i];\r
+        float yMin = points[i + 1];\r
+        // xMin = xMax\r
+        float xMax = points[i + 2];\r
+        float yMax = points[i + 3];\r
+        drawBar(canvas, xMin, yMin, xMax, yMax, halfDiffX, seriesNr, seriesIndex, paint);\r
+      }\r
+    }\r
+    paint.setColor(seriesRenderer.getColor());\r
+  }\r
+\r
+  /**\r
+   * The graphical representation of the series values as text.\r
+   * \r
+   * @param canvas the canvas to paint to\r
+   * @param series the series to be painted\r
+   * @param renderer the series renderer\r
+   * @param paint the paint to be used for drawing\r
+   * @param points the array of points to be used for drawing the series\r
+   * @param seriesIndex the index of the series currently being drawn\r
+   * @param startIndex the start index of the rendering points\r
+   */\r
+  protected void drawChartValuesText(Canvas canvas, XYSeries series, SimpleSeriesRenderer renderer,\r
+      Paint paint, float[] points, int seriesIndex, int startIndex) {\r
+    int seriesNr = mDataset.getSeriesCount();\r
+    float halfDiffX = getHalfDiffX(points, points.length, seriesNr);\r
+    int start = 0;\r
+    if (startIndex > 0) {\r
+      start = 2;\r
+    }\r
+    for (int i = start; i < points.length; i += 4) {\r
+      int index = startIndex + i / 2;\r
+      float x = points[i];\r
+      if (mType == Type.DEFAULT) {\r
+        x += seriesIndex * 2 * halfDiffX - (seriesNr - 1.5f) * halfDiffX;\r
+      }\r
+\r
+      if (!isNullValue(series.getY(index + 1)) && points.length > i + 3) {\r
+        // draw the maximum value\r
+        drawText(canvas, getLabel(series.getY(index + 1)), x,\r
+            points[i + 3] - renderer.getChartValuesSpacing(), paint, 0);\r
+      }\r
+      if (!isNullValue(series.getY(index)) && points.length > i + 1) {\r
+        // draw the minimum value\r
+        drawText(canvas, getLabel(series.getY(index)), x,\r
+            points[i + 1] + renderer.getChartValuesTextSize() + renderer.getChartValuesSpacing()\r
+                - 3, paint, 0);\r
+      }\r
+    }\r
+  }\r
+\r
+  /**\r
+   * Returns the value of a constant used to calculate the half-distance.\r
+   * \r
+   * @return the constant value\r
+   */\r
+  protected float getCoeficient() {\r
+    return 0.5f;\r
+  }\r
+\r
+  /**\r
+   * Returns the chart type identifier.\r
+   * \r
+   * @return the chart type\r
+   */\r
+  public String getChartType() {\r
+    return TYPE;\r
+  }\r
+\r
+}\r