~desarrollokumbia/kumbia/0.5

« back to all changes in this revision

Viewing changes to library/libchart/classes/view/axis/Bound.php

  • Committer: Joan Miquel
  • Date: 2008-11-07 01:12:54 UTC
  • Revision ID: joan@ubuntu-black-20081107011254-lc0jk82y3yg7jvpl
commit inicial para kumbia 0.5 RC1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
        /* Libchart - PHP chart library
 
3
         * Copyright (C) 2005-2008 Jean-Marc Tr�meaux (jm.tremeaux at gmail.com)
 
4
         * 
 
5
         * This program is free software: you can redistribute it and/or modify
 
6
         * it under the terms of the GNU General Public License as published by
 
7
         * the Free Software Foundation, either version 3 of the License, or
 
8
         * (at your option) any later version.
 
9
         * 
 
10
         * This program is distributed in the hope that it will be useful,
 
11
         * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
         * GNU General Public License for more details.
 
14
         *
 
15
         * You should have received a copy of the GNU General Public License
 
16
         * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
17
         * 
 
18
         */
 
19
        
 
20
        /**
 
21
         * Object representing the bounds of a dataset (its minimal and maximal values) on its vertical axis.
 
22
         * The bounds are automatically calculated from a XYDataSet or XYSeriesDataSet.
 
23
         * Default (calculated) bounds can be overriden using the setLowerBound() and setUpperBound() methods.
 
24
         *
 
25
         * @author Jean-Marc Tr�meaux (jm.tremeaux at gmail.com)
 
26
         * Created on 25 july 2007
 
27
         */
 
28
         class Bound {
 
29
                /**
 
30
                 * Manually set lower bound, overrides the value calculated by computeBound().
 
31
                 */
 
32
                private $lowerBound = null;
 
33
 
 
34
                /**
 
35
                 * Manually set upper bound, overrides the value calculated by computeBound().
 
36
                 */
 
37
                private $upperBound = null;
 
38
                
 
39
                /**
 
40
                 * Computed min bound.
 
41
                 */
 
42
                private $yMinValue = null;
 
43
                
 
44
                /**
 
45
                 * Computed max bound.
 
46
                 */
 
47
                private $yMaxValue = null;
 
48
                
 
49
                /**
 
50
                 * Compute the boundaries on the axis.
 
51
                 *
 
52
                 * @param dataSet The data set
 
53
                 */
 
54
                public function computeBound($dataSet) {
 
55
                        // Check if the data set is empty
 
56
                        $dataSetEmpty = true;
 
57
                        $serieList = null;
 
58
                        if ($dataSet instanceof XYDataSet) {
 
59
                                $pointList = $dataSet->getPointList();
 
60
                                $dataSetEmpty = count($pointList) == 0;
 
61
                                
 
62
                                if (!$dataSetEmpty) {
 
63
                                        // Process it as a serie
 
64
                                        $serieList = array();
 
65
                                        array_push($serieList, $dataSet);
 
66
                                }
 
67
                        } else if ($dataSet instanceof XYSeriesDataSet) {
 
68
                                $serieList = $dataSet->getSerieList();
 
69
                                if (count($serieList) > 0) {
 
70
                                        $serie = current($serieList);
 
71
                                        $dataSetEmpty = count($serie) == 0;
 
72
                                }
 
73
                        } else {
 
74
                                die("Error: unknown dataset type");
 
75
                        }
 
76
                        
 
77
                        // If the dataset is empty, default some bounds
 
78
                        $yMin = 0;
 
79
                        $yMax = 1;
 
80
                        if (!$dataSetEmpty) {
 
81
                                // Compute lower and upper bound on the value axis
 
82
                                unset($yMin);
 
83
                                unset($yMax);
 
84
 
 
85
                                foreach ($serieList as $serie) {
 
86
                                        foreach ($serie->getPointList() as $point) {
 
87
                                                $y = $point->getY();
 
88
                                                
 
89
                                                if (!isset($yMin)) {
 
90
                                                        $yMin = $y;
 
91
                                                        $yMax = $y;
 
92
                                                } else {
 
93
                                                        if ($y < $yMin) {
 
94
                                                                $yMin = $y;
 
95
                                                        }
 
96
                        
 
97
                                                        if ($y > $yMax) {
 
98
                                                                $yMax = $y;
 
99
                                                        }
 
100
                                                }
 
101
                                        }
 
102
                                }
 
103
                        }
 
104
 
 
105
                        // If user specified bounds and they are actually greater than computer bounds, override computed bounds
 
106
                        if (isset($this->lowerBound) && $this->lowerBound < $yMin) {
 
107
                                $this->yMinValue = $this->lowerBound;
 
108
                        } else {
 
109
                                $this->yMinValue = $yMin;
 
110
                        }
 
111
 
 
112
                        if (isset($this->upperBound) && $this->upperBound > $yMax) {
 
113
                                $this->yMaxValue = $this->upperBound;
 
114
                        } else {
 
115
                                $this->yMaxValue = $yMax;
 
116
                        }
 
117
                }
 
118
 
 
119
                /**
 
120
                 * Getter of yMinValue.
 
121
                 *
 
122
                 * @return min bound
 
123
                 */
 
124
                public function getYMinValue() {
 
125
                        return $this->yMinValue;
 
126
                }
 
127
 
 
128
                /**
 
129
                 * Getter of yMaxValue.
 
130
                 *
 
131
                 * @return max bound
 
132
                 */
 
133
                public function getYMaxValue() {
 
134
                        return $this->yMaxValue;
 
135
                }
 
136
 
 
137
                /**
 
138
                 * Set manually the lower boundary value (overrides the automatic formatting).
 
139
                 * Typical usage is to set the bars starting from zero.
 
140
                 *
 
141
                 * @param double lower boundary value
 
142
                 */
 
143
                public function setLowerBound($lowerBound) {
 
144
                        $this->lowerBound = $lowerBound;
 
145
                }
 
146
 
 
147
                /**
 
148
                 * Set manually the upper boundary value (overrides the automatic formatting).
 
149
                 *
 
150
                 * @param double upper boundary value
 
151
                 */
 
152
                public function setUpperBound($upperBound) {
 
153
                        $this->upperBound = $upperBound;
 
154
                }
 
155
         }
 
156
?>
 
 
b'\\ No newline at end of file'