Merge commit '42b2e5ca519766e37ce6941ba4faecc9691cc403' into upstream
[debian/openrocket] / android-libraries / achartengine / src / org / achartengine / model / RangeCategorySeries.java
diff --git a/android-libraries/achartengine/src/org/achartengine/model/RangeCategorySeries.java b/android-libraries/achartengine/src/org/achartengine/model/RangeCategorySeries.java
new file mode 100644 (file)
index 0000000..c004fa1
--- /dev/null
@@ -0,0 +1,111 @@
+/**\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.model;\r
+\r
+import java.util.ArrayList;\r
+import java.util.List;\r
+/**\r
+ * A series for the range category charts like the range bar.\r
+ */\r
+public class RangeCategorySeries extends CategorySeries {\r
+  /** The series values. */\r
+  private List<Double> mMaxValues = new ArrayList<Double>();\r
+  /**\r
+   * Builds a new category series.\r
+   * \r
+   * @param title the series title\r
+   */\r
+  public RangeCategorySeries(String title) {\r
+    super(title);\r
+  }\r
+  /**\r
+   * Adds new values to the series\r
+   * \r
+   * @param minValue the new minimum value\r
+   * @param maxValue the new maximum value\r
+   */\r
+  public synchronized void add(double minValue, double maxValue) {\r
+    super.add(minValue);\r
+    mMaxValues.add(maxValue);\r
+  }\r
+\r
+  /**\r
+   * Adds new values to the series.\r
+   * \r
+   * @param category the category\r
+   * @param minValue the new minimum value\r
+   * @param maxValue the new maximum value\r
+   */\r
+  public synchronized void add(String category, double minValue, double maxValue) {\r
+    super.add(category, minValue);\r
+    mMaxValues.add(maxValue);\r
+  }\r
+\r
+  /**\r
+   * Removes existing values from the series.\r
+   * \r
+   * @param index the index in the series of the values to remove\r
+   */\r
+  public synchronized void remove(int index) {\r
+    super.remove(index);\r
+    mMaxValues.remove(index);\r
+  }\r
+\r
+  /**\r
+   * Removes all the existing values from the series.\r
+   */\r
+  public synchronized void clear() {\r
+    super.clear();\r
+    mMaxValues.clear();\r
+  }\r
+\r
+  /**\r
+   * Returns the minimum value at the specified index.\r
+   * \r
+   * @param index the index\r
+   * @return the minimum value at the index\r
+   */\r
+  public double getMinimumValue(int index) {\r
+    return getValue(index);\r
+  }\r
+\r
+  /**\r
+   * Returns the maximum value at the specified index.\r
+   * \r
+   * @param index the index\r
+   * @return the maximum value at the index\r
+   */\r
+  public double getMaximumValue(int index) {\r
+    return mMaxValues.get(index);\r
+  }\r
+\r
+  /**\r
+   * Transforms the range category series to an XY series.\r
+   * \r
+   * @return the XY series\r
+   */\r
+  public XYSeries toXYSeries() {\r
+    XYSeries xySeries = new XYSeries(getTitle());\r
+    int length = getItemCount();\r
+    for (int k = 0; k < length; k++) {\r
+      xySeries.add(k + 1, getMinimumValue(k));\r
+      // the new fast XYSeries implementation doesn't allow 2 values at the same X,\r
+      // so I had to do a hack until I find a better solution\r
+      xySeries.add(k + 1.000001, getMaximumValue(k));\r
+    }\r
+    return xySeries;\r
+  }\r
+}\r