1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_chart2.hxx"
30 
31 #include "MinimumAndMaximumSupplier.hxx"
32 
33 #include <com/sun/star/chart/TimeUnit.hpp>
34 
35 #include <rtl/math.hxx>
36 #include <com/sun/star/awt/Size.hpp>
37 
38 //.............................................................................
39 namespace chart
40 {
41 //.............................................................................
42 using namespace ::com::sun::star;
43 
44 MergedMinimumAndMaximumSupplier::MergedMinimumAndMaximumSupplier()
45 {
46 }
47 
48 MergedMinimumAndMaximumSupplier::~MergedMinimumAndMaximumSupplier()
49 {
50 }
51 
52 void MergedMinimumAndMaximumSupplier::addMinimumAndMaximumSupplier( MinimumAndMaximumSupplier* pMinimumAndMaximumSupplier )
53 {
54     m_aMinimumAndMaximumSupplierList.insert( pMinimumAndMaximumSupplier );
55 }
56 
57 bool MergedMinimumAndMaximumSupplier::hasMinimumAndMaximumSupplier( MinimumAndMaximumSupplier* pMinimumAndMaximumSupplier )
58 {
59     return m_aMinimumAndMaximumSupplierList.count( pMinimumAndMaximumSupplier ) != 0;
60 }
61 
62 double MergedMinimumAndMaximumSupplier::getMinimumX()
63 {
64     double fGlobalExtremum;
65     ::rtl::math::setInf(&fGlobalExtremum, false);
66     for( MinimumAndMaximumSupplierSet::iterator aIt = begin(), aEnd = end(); aIt != aEnd; ++aIt )
67     {
68         double fLocalExtremum = (*aIt)->getMinimumX();
69         if(fLocalExtremum<fGlobalExtremum)
70             fGlobalExtremum=fLocalExtremum;
71     }
72     if(::rtl::math::isInf(fGlobalExtremum))
73         ::rtl::math::setNan(&fGlobalExtremum);
74     return fGlobalExtremum;
75 }
76 
77 double MergedMinimumAndMaximumSupplier::getMaximumX()
78 {
79     double fGlobalExtremum;
80     ::rtl::math::setInf(&fGlobalExtremum, true);
81     for( MinimumAndMaximumSupplierSet::iterator aIt = begin(), aEnd = end(); aIt != aEnd; ++aIt )
82     {
83         double fLocalExtremum = (*aIt)->getMaximumX();
84         if(fLocalExtremum>fGlobalExtremum)
85             fGlobalExtremum=fLocalExtremum;
86     }
87     if(::rtl::math::isInf(fGlobalExtremum))
88         ::rtl::math::setNan(&fGlobalExtremum);
89     return fGlobalExtremum;
90 }
91 
92 double MergedMinimumAndMaximumSupplier::getMinimumYInRange( double fMinimumX, double fMaximumX, sal_Int32 nAxisIndex )
93 {
94     double fGlobalExtremum;
95     ::rtl::math::setInf(&fGlobalExtremum, false);
96     for( MinimumAndMaximumSupplierSet::iterator aIt = begin(), aEnd = end(); aIt != aEnd; ++aIt )
97     {
98         double fLocalExtremum = (*aIt)->getMinimumYInRange( fMinimumX, fMaximumX, nAxisIndex );
99         if(fLocalExtremum<fGlobalExtremum)
100             fGlobalExtremum=fLocalExtremum;
101     }
102     if(::rtl::math::isInf(fGlobalExtremum))
103         ::rtl::math::setNan(&fGlobalExtremum);
104     return fGlobalExtremum;
105 }
106 
107 double MergedMinimumAndMaximumSupplier::getMaximumYInRange( double fMinimumX, double fMaximumX, sal_Int32 nAxisIndex )
108 {
109     double fGlobalExtremum;
110     ::rtl::math::setInf(&fGlobalExtremum, true);
111     for( MinimumAndMaximumSupplierSet::iterator aIt = begin(), aEnd = end(); aIt != aEnd; ++aIt )
112     {
113         double fLocalExtremum = (*aIt)->getMaximumYInRange( fMinimumX, fMaximumX, nAxisIndex );
114         if(fLocalExtremum>fGlobalExtremum)
115             fGlobalExtremum=fLocalExtremum;
116     }
117     if(::rtl::math::isInf(fGlobalExtremum))
118         ::rtl::math::setNan(&fGlobalExtremum);
119     return fGlobalExtremum;
120 }
121 
122 double MergedMinimumAndMaximumSupplier::getMinimumZ()
123 {
124     double fGlobalExtremum;
125     ::rtl::math::setInf(&fGlobalExtremum, false);
126     for( MinimumAndMaximumSupplierSet::iterator aIt = begin(), aEnd = end(); aIt != aEnd; ++aIt )
127     {
128         double fLocalExtremum = (*aIt)->getMinimumZ();
129         if(fLocalExtremum<fGlobalExtremum)
130             fGlobalExtremum=fLocalExtremum;
131     }
132     if(::rtl::math::isInf(fGlobalExtremum))
133         ::rtl::math::setNan(&fGlobalExtremum);
134     return fGlobalExtremum;
135 }
136 
137 double MergedMinimumAndMaximumSupplier::getMaximumZ()
138 {
139     double fGlobalExtremum;
140     ::rtl::math::setInf(&fGlobalExtremum, true);
141     for( MinimumAndMaximumSupplierSet::iterator aIt = begin(), aEnd = end(); aIt != aEnd; ++aIt )
142     {
143         double fLocalExtremum = (*aIt)->getMaximumZ();
144         if(fLocalExtremum>fGlobalExtremum)
145             fGlobalExtremum=fLocalExtremum;
146     }
147     if(::rtl::math::isInf(fGlobalExtremum))
148         ::rtl::math::setNan(&fGlobalExtremum);
149     return fGlobalExtremum;
150 }
151 
152 bool MergedMinimumAndMaximumSupplier::isExpandBorderToIncrementRhythm( sal_Int32 nDimensionIndex )
153 {
154     // only return true, if *all* suppliers want to scale to the main tick marks
155     for( MinimumAndMaximumSupplierSet::iterator aIt = begin(), aEnd = end(); aIt != aEnd; ++aIt )
156         if( !(*aIt)->isExpandBorderToIncrementRhythm( nDimensionIndex ) )
157             return false;
158     return true;
159 }
160 
161 bool MergedMinimumAndMaximumSupplier::isExpandIfValuesCloseToBorder( sal_Int32 nDimensionIndex )
162 {
163     // only return true, if *all* suppliers want to expand the range
164     for( MinimumAndMaximumSupplierSet::iterator aIt = begin(), aEnd = end(); aIt != aEnd; ++aIt )
165         if( !(*aIt)->isExpandIfValuesCloseToBorder( nDimensionIndex ) )
166             return false;
167     return true;
168 }
169 
170 bool MergedMinimumAndMaximumSupplier::isExpandWideValuesToZero( sal_Int32 nDimensionIndex )
171 {
172     // already return true, if at least one supplier wants to expand the range
173     for( MinimumAndMaximumSupplierSet::iterator aIt = begin(), aEnd = end(); aIt != aEnd; ++aIt )
174         if( (*aIt)->isExpandWideValuesToZero( nDimensionIndex ) )
175             return true;
176     return false;
177 }
178 
179 bool MergedMinimumAndMaximumSupplier::isExpandNarrowValuesTowardZero( sal_Int32 nDimensionIndex )
180 {
181     // already return true, if at least one supplier wants to expand the range
182     for( MinimumAndMaximumSupplierSet::iterator aIt = begin(), aEnd = end(); aIt != aEnd; ++aIt )
183         if( (*aIt)->isExpandNarrowValuesTowardZero( nDimensionIndex ) )
184             return true;
185     return false;
186 }
187 
188 bool MergedMinimumAndMaximumSupplier::isSeperateStackingForDifferentSigns( sal_Int32 nDimensionIndex )
189 {
190     // should not be called
191     for( MinimumAndMaximumSupplierSet::iterator aIt = begin(), aEnd = end(); aIt != aEnd; ++aIt )
192         if( (*aIt)->isSeperateStackingForDifferentSigns( nDimensionIndex ) )
193             return true;
194     return false;
195 }
196 
197 void MergedMinimumAndMaximumSupplier::clearMinimumAndMaximumSupplierList()
198 {
199     m_aMinimumAndMaximumSupplierList.clear();
200 }
201 
202 long MergedMinimumAndMaximumSupplier::calculateTimeResolutionOnXAxis()
203 {
204     long nRet = ::com::sun::star::chart::TimeUnit::YEAR;
205     for( MinimumAndMaximumSupplierSet::iterator aIt = begin(), aEnd = end(); aIt != aEnd; ++aIt )
206     {
207         long nCurrent = (*aIt)->calculateTimeResolutionOnXAxis();
208         if(nRet>nCurrent)
209             nRet=nCurrent;
210     }
211     return nRet;
212 }
213 
214 void MergedMinimumAndMaximumSupplier::setTimeResolutionOnXAxis( long nTimeResolution, const Date& rNullDate )
215 {
216     for( MinimumAndMaximumSupplierSet::iterator aIt = begin(), aEnd = end(); aIt != aEnd; ++aIt )
217         (*aIt)->setTimeResolutionOnXAxis( nTimeResolution, rNullDate );
218 }
219 
220 //.............................................................................
221 } //namespace chart
222 //.............................................................................
223