001/*
002 * Copyright 2006 - 2013
003 *     Stefan Balev     <stefan.balev@graphstream-project.org>
004 *     Julien Baudry    <julien.baudry@graphstream-project.org>
005 *     Antoine Dutot    <antoine.dutot@graphstream-project.org>
006 *     Yoann Pigné      <yoann.pigne@graphstream-project.org>
007 *     Guilhelm Savin   <guilhelm.savin@graphstream-project.org>
008 * 
009 * This file is part of GraphStream <http://graphstream-project.org>.
010 * 
011 * GraphStream is a library whose purpose is to handle static or dynamic
012 * graph, create them from scratch, file or any source and display them.
013 * 
014 * This program is free software distributed under the terms of two licenses, the
015 * CeCILL-C license that fits European law, and the GNU Lesser General Public
016 * License. You can  use, modify and/ or redistribute the software under the terms
017 * of the CeCILL-C license as circulated by CEA, CNRS and INRIA at the following
018 * URL <http://www.cecill.info> or under the terms of the GNU LGPL as published by
019 * the Free Software Foundation, either version 3 of the License, or (at your
020 * option) any later version.
021 * 
022 * This program is distributed in the hope that it will be useful, but WITHOUT ANY
023 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
024 * PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more details.
025 * 
026 * You should have received a copy of the GNU Lesser General Public License
027 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
028 * 
029 * The fact that you are presently reading this means that you have had
030 * knowledge of the CeCILL-C and LGPL licenses and that you accept their terms.
031 */
032package org.graphstream.algorithm.measure;
033
034import org.apache.commons.math.stat.descriptive.DescriptiveStatistics;
035
036/**
037 * A measure allowing to add 2D entries (x,y).
038 */
039public class ChartSeries2DMeasure extends ChartSeriesMeasure {
040        /**
041         * Data containing x values.
042         */
043        protected DescriptiveStatistics xData;
044        /**
045         * Data containing y values.
046         */
047        protected DescriptiveStatistics yData;
048
049        /**
050         * Default constructor.
051         * 
052         * @param name
053         *            names of the measure
054         */
055        public ChartSeries2DMeasure(String name) {
056                super(name);
057
058                this.xData = new DescriptiveStatistics();
059                this.yData = new DescriptiveStatistics();
060                this.xData.setWindowSize(DEFAULT_WINDOW_SIZE);
061                this.yData.setWindowSize(DEFAULT_WINDOW_SIZE);
062        }
063
064        /*
065         * (non-Javadoc)
066         * 
067         * @see org.graphstream.algorithm.measure.ChartMeasure#setWindowSize(int)
068         */
069        public void setWindowSize(int size) {
070                super.setWindowSize(size);
071                xData.setWindowSize(size);
072                yData.setWindowSize(size);
073        }
074
075        /**
076         * Add a new point to the series.
077         * 
078         * @param x
079         *            x value of the new point
080         * @param y
081         *            y value osf the new point
082         */
083        public void addValue(double x, double y) {
084                xData.addValue(x);
085                yData.addValue(y);
086                series.add(x, y);
087        }
088
089        /**
090         * Get the count of points added to this series.
091         * 
092         * @return count of points.s
093         */
094        public long getCount() {
095                return xData.getN();
096        }
097
098        /**
099         * Get the mean of x values.
100         * 
101         * @return x values means
102         */
103        public double getXMean() {
104                return xData.getMean();
105        }
106
107        /**
108         * Get the max of x values.
109         * 
110         * @return x values max
111         */
112        public double getXMax() {
113                return xData.getMax();
114        }
115
116        /**
117         * Get the min of x values.
118         * 
119         * @return x values min
120         */
121        public double getXMin() {
122                return xData.getMin();
123        }
124
125        /**
126         * Get the variance of x values.
127         * 
128         * @return x values variance
129         */
130        public double getXVariance() {
131                return xData.getVariance();
132        }
133
134        /**
135         * Get the mean of y values.
136         * 
137         * @return y values means
138         */
139        public double getYMean() {
140                return yData.getMean();
141        }
142
143        /**
144         * Get the max of y values.
145         * 
146         * @return y values max
147         */
148        public double getYMax() {
149                return yData.getMax();
150        }
151
152        /**
153         * Get the min of y values.
154         * 
155         * @return y values min
156         */
157        public double getYMin() {
158                return yData.getMin();
159        }
160
161        /**
162         * Get the variance of y values.
163         * 
164         * @return y values variance
165         */
166        public double getYVariance() {
167                return yData.getVariance();
168        }
169
170}