Merge commit '42b2e5ca519766e37ce6941ba4faecc9691cc403' into upstream
[debian/openrocket] / android-libraries / achartengine / src / org / achartengine / model / XYValueSeries.java
diff --git a/android-libraries/achartengine/src/org/achartengine/model/XYValueSeries.java b/android-libraries/achartengine/src/org/achartengine/model/XYValueSeries.java
new file mode 100644 (file)
index 0000000..81aff28
--- /dev/null
@@ -0,0 +1,139 @@
+/**\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
+import org.achartengine.util.MathHelper;\r
+\r
+/**\r
+ * An extension of the XY series which adds a third dimension. It is used for XY\r
+ * charts like bubble.\r
+ */\r
+public class XYValueSeries extends XYSeries {\r
+  /** A list to contain the series values. */\r
+  private List<Double> mValue = new ArrayList<Double>();\r
+  /** The minimum value. */\r
+  private double mMinValue = MathHelper.NULL_VALUE;\r
+  /** The maximum value. */\r
+  private double mMaxValue = -MathHelper.NULL_VALUE;\r
+\r
+  /**\r
+   * Builds a new XY value series.\r
+   * \r
+   * @param title the series title.\r
+   */\r
+  public XYValueSeries(String title) {\r
+    super(title);\r
+  }\r
+\r
+  /**\r
+   * Adds a new value to the series.\r
+   * \r
+   * @param x the value for the X axis\r
+   * @param y the value for the Y axis\r
+   * @param value the value\r
+   */\r
+  public synchronized void add(double x, double y, double value) {\r
+    super.add(x, y);\r
+    mValue.add(value);\r
+    updateRange(value);\r
+  }\r
+\r
+  /**\r
+   * Initializes the values range.\r
+   */\r
+  private void initRange() {\r
+    mMinValue = MathHelper.NULL_VALUE;\r
+    mMaxValue = MathHelper.NULL_VALUE;\r
+    int length = getItemCount();\r
+    for (int k = 0; k < length; k++) {\r
+      updateRange(getValue(k));\r
+    }\r
+  }\r
+\r
+  /**\r
+   * Updates the values range.\r
+   * \r
+   * @param value the new value\r
+   */\r
+  private void updateRange(double value) {\r
+    mMinValue = Math.min(mMinValue, value);\r
+    mMaxValue = Math.max(mMaxValue, value);\r
+  }\r
+\r
+  /**\r
+   * Adds a new value to the series.\r
+   * \r
+   * @param x the value for the X axis\r
+   * @param y the value for the Y axis\r
+   */\r
+  public synchronized void add(double x, double y) {\r
+    add(x, y, 0d);\r
+  }\r
+\r
+  /**\r
+   * Removes an existing value from the series.\r
+   * \r
+   * @param index the index in the series of the value to remove\r
+   */\r
+  public synchronized void remove(int index) {\r
+    super.remove(index);\r
+    double removedValue = mValue.remove(index);\r
+    if (removedValue == mMinValue || removedValue == mMaxValue) {\r
+      initRange();\r
+    }\r
+  }\r
+\r
+  /**\r
+   * Removes all the values from the series.\r
+   */\r
+  public synchronized void clear() {\r
+    super.clear();\r
+    mValue.clear();\r
+    initRange();\r
+  }\r
+\r
+  /**\r
+   * Returns the value at the specified index.\r
+   * \r
+   * @param index the index\r
+   * @return the value\r
+   */\r
+  public synchronized double getValue(int index) {\r
+    return mValue.get(index);\r
+  }\r
+\r
+  /**\r
+   * Returns the minimum value.\r
+   * \r
+   * @return the minimum value\r
+   */\r
+  public double getMinValue() {\r
+    return mMinValue;\r
+  }\r
+\r
+  /**\r
+   * Returns the maximum value.\r
+   * \r
+   * @return the maximum value\r
+   */\r
+  public double getMaxValue() {\r
+    return mMaxValue;\r
+  }\r
+\r
+}\r