2 * Copyright (C) 2009 - 2012 SC 4ViewSoft SRL
\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
8 * http://www.apache.org/licenses/LICENSE-2.0
\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
16 package org.achartengine.model;
\r
18 import java.util.ArrayList;
\r
19 import java.util.List;
\r
21 import org.achartengine.util.MathHelper;
\r
24 * An extension of the XY series which adds a third dimension. It is used for XY
\r
25 * charts like bubble.
\r
27 public class XYValueSeries extends XYSeries {
\r
28 /** A list to contain the series values. */
\r
29 private List<Double> mValue = new ArrayList<Double>();
\r
30 /** The minimum value. */
\r
31 private double mMinValue = MathHelper.NULL_VALUE;
\r
32 /** The maximum value. */
\r
33 private double mMaxValue = -MathHelper.NULL_VALUE;
\r
36 * Builds a new XY value series.
\r
38 * @param title the series title.
\r
40 public XYValueSeries(String title) {
\r
45 * Adds a new value to the series.
\r
47 * @param x the value for the X axis
\r
48 * @param y the value for the Y axis
\r
49 * @param value the value
\r
51 public synchronized void add(double x, double y, double value) {
\r
58 * Initializes the values range.
\r
60 private void initRange() {
\r
61 mMinValue = MathHelper.NULL_VALUE;
\r
62 mMaxValue = MathHelper.NULL_VALUE;
\r
63 int length = getItemCount();
\r
64 for (int k = 0; k < length; k++) {
\r
65 updateRange(getValue(k));
\r
70 * Updates the values range.
\r
72 * @param value the new value
\r
74 private void updateRange(double value) {
\r
75 mMinValue = Math.min(mMinValue, value);
\r
76 mMaxValue = Math.max(mMaxValue, value);
\r
80 * Adds a new value to the series.
\r
82 * @param x the value for the X axis
\r
83 * @param y the value for the Y axis
\r
85 public synchronized void add(double x, double y) {
\r
90 * Removes an existing value from the series.
\r
92 * @param index the index in the series of the value to remove
\r
94 public synchronized void remove(int index) {
\r
95 super.remove(index);
\r
96 double removedValue = mValue.remove(index);
\r
97 if (removedValue == mMinValue || removedValue == mMaxValue) {
\r
103 * Removes all the values from the series.
\r
105 public synchronized void clear() {
\r
112 * Returns the value at the specified index.
\r
114 * @param index the index
\r
115 * @return the value
\r
117 public synchronized double getValue(int index) {
\r
118 return mValue.get(index);
\r
122 * Returns the minimum value.
\r
124 * @return the minimum value
\r
126 public double getMinValue() {
\r
131 * Returns the maximum value.
\r
133 * @return the maximum value
\r
135 public double getMaxValue() {
\r