1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_chart2.hxx"
26 
27 #include "MinimumAndMaximumSupplier.hxx"
28 
29 #include <com/sun/star/chart/TimeUnit.hpp>
30 
31 #include <rtl/math.hxx>
32 #include <com/sun/star/awt/Size.hpp>
33 
34 //.............................................................................
35 namespace chart
36 {
37 //.............................................................................
38 using namespace ::com::sun::star;
39 
MergedMinimumAndMaximumSupplier()40 MergedMinimumAndMaximumSupplier::MergedMinimumAndMaximumSupplier()
41 {
42 }
43 
~MergedMinimumAndMaximumSupplier()44 MergedMinimumAndMaximumSupplier::~MergedMinimumAndMaximumSupplier()
45 {
46 }
47 
addMinimumAndMaximumSupplier(MinimumAndMaximumSupplier * pMinimumAndMaximumSupplier)48 void MergedMinimumAndMaximumSupplier::addMinimumAndMaximumSupplier( MinimumAndMaximumSupplier* pMinimumAndMaximumSupplier )
49 {
50     m_aMinimumAndMaximumSupplierList.insert( pMinimumAndMaximumSupplier );
51 }
52 
hasMinimumAndMaximumSupplier(MinimumAndMaximumSupplier * pMinimumAndMaximumSupplier)53 bool MergedMinimumAndMaximumSupplier::hasMinimumAndMaximumSupplier( MinimumAndMaximumSupplier* pMinimumAndMaximumSupplier )
54 {
55     return m_aMinimumAndMaximumSupplierList.count( pMinimumAndMaximumSupplier ) != 0;
56 }
57 
getMinimumX()58 double MergedMinimumAndMaximumSupplier::getMinimumX()
59 {
60     double fGlobalExtremum;
61     ::rtl::math::setInf(&fGlobalExtremum, false);
62     for( MinimumAndMaximumSupplierSet::iterator aIt = begin(), aEnd = end(); aIt != aEnd; ++aIt )
63     {
64         double fLocalExtremum = (*aIt)->getMinimumX();
65         if(fLocalExtremum<fGlobalExtremum)
66             fGlobalExtremum=fLocalExtremum;
67     }
68     if(::rtl::math::isInf(fGlobalExtremum))
69         ::rtl::math::setNan(&fGlobalExtremum);
70     return fGlobalExtremum;
71 }
72 
getMaximumX()73 double MergedMinimumAndMaximumSupplier::getMaximumX()
74 {
75     double fGlobalExtremum;
76     ::rtl::math::setInf(&fGlobalExtremum, true);
77     for( MinimumAndMaximumSupplierSet::iterator aIt = begin(), aEnd = end(); aIt != aEnd; ++aIt )
78     {
79         double fLocalExtremum = (*aIt)->getMaximumX();
80         if(fLocalExtremum>fGlobalExtremum)
81             fGlobalExtremum=fLocalExtremum;
82     }
83     if(::rtl::math::isInf(fGlobalExtremum))
84         ::rtl::math::setNan(&fGlobalExtremum);
85     return fGlobalExtremum;
86 }
87 
getMinimumYInRange(double fMinimumX,double fMaximumX,sal_Int32 nAxisIndex)88 double MergedMinimumAndMaximumSupplier::getMinimumYInRange( double fMinimumX, double fMaximumX, sal_Int32 nAxisIndex )
89 {
90     double fGlobalExtremum;
91     ::rtl::math::setInf(&fGlobalExtremum, false);
92     for( MinimumAndMaximumSupplierSet::iterator aIt = begin(), aEnd = end(); aIt != aEnd; ++aIt )
93     {
94         double fLocalExtremum = (*aIt)->getMinimumYInRange( fMinimumX, fMaximumX, nAxisIndex );
95         if(fLocalExtremum<fGlobalExtremum)
96             fGlobalExtremum=fLocalExtremum;
97     }
98     if(::rtl::math::isInf(fGlobalExtremum))
99         ::rtl::math::setNan(&fGlobalExtremum);
100     return fGlobalExtremum;
101 }
102 
getMaximumYInRange(double fMinimumX,double fMaximumX,sal_Int32 nAxisIndex)103 double MergedMinimumAndMaximumSupplier::getMaximumYInRange( double fMinimumX, double fMaximumX, sal_Int32 nAxisIndex )
104 {
105     double fGlobalExtremum;
106     ::rtl::math::setInf(&fGlobalExtremum, true);
107     for( MinimumAndMaximumSupplierSet::iterator aIt = begin(), aEnd = end(); aIt != aEnd; ++aIt )
108     {
109         double fLocalExtremum = (*aIt)->getMaximumYInRange( fMinimumX, fMaximumX, nAxisIndex );
110         if(fLocalExtremum>fGlobalExtremum)
111             fGlobalExtremum=fLocalExtremum;
112     }
113     if(::rtl::math::isInf(fGlobalExtremum))
114         ::rtl::math::setNan(&fGlobalExtremum);
115     return fGlobalExtremum;
116 }
117 
getMinimumZ()118 double MergedMinimumAndMaximumSupplier::getMinimumZ()
119 {
120     double fGlobalExtremum;
121     ::rtl::math::setInf(&fGlobalExtremum, false);
122     for( MinimumAndMaximumSupplierSet::iterator aIt = begin(), aEnd = end(); aIt != aEnd; ++aIt )
123     {
124         double fLocalExtremum = (*aIt)->getMinimumZ();
125         if(fLocalExtremum<fGlobalExtremum)
126             fGlobalExtremum=fLocalExtremum;
127     }
128     if(::rtl::math::isInf(fGlobalExtremum))
129         ::rtl::math::setNan(&fGlobalExtremum);
130     return fGlobalExtremum;
131 }
132 
getMaximumZ()133 double MergedMinimumAndMaximumSupplier::getMaximumZ()
134 {
135     double fGlobalExtremum;
136     ::rtl::math::setInf(&fGlobalExtremum, true);
137     for( MinimumAndMaximumSupplierSet::iterator aIt = begin(), aEnd = end(); aIt != aEnd; ++aIt )
138     {
139         double fLocalExtremum = (*aIt)->getMaximumZ();
140         if(fLocalExtremum>fGlobalExtremum)
141             fGlobalExtremum=fLocalExtremum;
142     }
143     if(::rtl::math::isInf(fGlobalExtremum))
144         ::rtl::math::setNan(&fGlobalExtremum);
145     return fGlobalExtremum;
146 }
147 
isExpandBorderToIncrementRhythm(sal_Int32 nDimensionIndex)148 bool MergedMinimumAndMaximumSupplier::isExpandBorderToIncrementRhythm( sal_Int32 nDimensionIndex )
149 {
150     // only return true, if *all* suppliers want to scale to the main tick marks
151     for( MinimumAndMaximumSupplierSet::iterator aIt = begin(), aEnd = end(); aIt != aEnd; ++aIt )
152         if( !(*aIt)->isExpandBorderToIncrementRhythm( nDimensionIndex ) )
153             return false;
154     return true;
155 }
156 
isExpandIfValuesCloseToBorder(sal_Int32 nDimensionIndex)157 bool MergedMinimumAndMaximumSupplier::isExpandIfValuesCloseToBorder( sal_Int32 nDimensionIndex )
158 {
159     // only return true, if *all* suppliers want to expand the range
160     for( MinimumAndMaximumSupplierSet::iterator aIt = begin(), aEnd = end(); aIt != aEnd; ++aIt )
161         if( !(*aIt)->isExpandIfValuesCloseToBorder( nDimensionIndex ) )
162             return false;
163     return true;
164 }
165 
isExpandWideValuesToZero(sal_Int32 nDimensionIndex)166 bool MergedMinimumAndMaximumSupplier::isExpandWideValuesToZero( sal_Int32 nDimensionIndex )
167 {
168     // already return true, if at least one supplier wants to expand the range
169     for( MinimumAndMaximumSupplierSet::iterator aIt = begin(), aEnd = end(); aIt != aEnd; ++aIt )
170         if( (*aIt)->isExpandWideValuesToZero( nDimensionIndex ) )
171             return true;
172     return false;
173 }
174 
isExpandNarrowValuesTowardZero(sal_Int32 nDimensionIndex)175 bool MergedMinimumAndMaximumSupplier::isExpandNarrowValuesTowardZero( sal_Int32 nDimensionIndex )
176 {
177     // already return true, if at least one supplier wants to expand the range
178     for( MinimumAndMaximumSupplierSet::iterator aIt = begin(), aEnd = end(); aIt != aEnd; ++aIt )
179         if( (*aIt)->isExpandNarrowValuesTowardZero( nDimensionIndex ) )
180             return true;
181     return false;
182 }
183 
isSeperateStackingForDifferentSigns(sal_Int32 nDimensionIndex)184 bool MergedMinimumAndMaximumSupplier::isSeperateStackingForDifferentSigns( sal_Int32 nDimensionIndex )
185 {
186     // should not be called
187     for( MinimumAndMaximumSupplierSet::iterator aIt = begin(), aEnd = end(); aIt != aEnd; ++aIt )
188         if( (*aIt)->isSeperateStackingForDifferentSigns( nDimensionIndex ) )
189             return true;
190     return false;
191 }
192 
clearMinimumAndMaximumSupplierList()193 void MergedMinimumAndMaximumSupplier::clearMinimumAndMaximumSupplierList()
194 {
195     m_aMinimumAndMaximumSupplierList.clear();
196 }
197 
calculateTimeResolutionOnXAxis()198 long MergedMinimumAndMaximumSupplier::calculateTimeResolutionOnXAxis()
199 {
200     long nRet = ::com::sun::star::chart::TimeUnit::YEAR;
201     for( MinimumAndMaximumSupplierSet::iterator aIt = begin(), aEnd = end(); aIt != aEnd; ++aIt )
202     {
203         long nCurrent = (*aIt)->calculateTimeResolutionOnXAxis();
204         if(nRet>nCurrent)
205             nRet=nCurrent;
206     }
207     return nRet;
208 }
209 
setTimeResolutionOnXAxis(long nTimeResolution,const Date & rNullDate)210 void MergedMinimumAndMaximumSupplier::setTimeResolutionOnXAxis( long nTimeResolution, const Date& rNullDate )
211 {
212     for( MinimumAndMaximumSupplierSet::iterator aIt = begin(), aEnd = end(); aIt != aEnd; ++aIt )
213         (*aIt)->setTimeResolutionOnXAxis( nTimeResolution, rNullDate );
214 }
215 
216 //.............................................................................
217 } //namespace chart
218 //.............................................................................
219