Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 :
21 : #include "MinimumAndMaximumSupplier.hxx"
22 :
23 : #include <com/sun/star/chart/TimeUnit.hpp>
24 :
25 : #include <rtl/math.hxx>
26 : #include <com/sun/star/awt/Size.hpp>
27 :
28 : //.............................................................................
29 : namespace chart
30 : {
31 : //.............................................................................
32 : using namespace ::com::sun::star;
33 :
34 531 : MergedMinimumAndMaximumSupplier::MergedMinimumAndMaximumSupplier()
35 : {
36 531 : }
37 :
38 531 : MergedMinimumAndMaximumSupplier::~MergedMinimumAndMaximumSupplier()
39 : {
40 531 : }
41 :
42 531 : void MergedMinimumAndMaximumSupplier::addMinimumAndMaximumSupplier( MinimumAndMaximumSupplier* pMinimumAndMaximumSupplier )
43 : {
44 531 : m_aMinimumAndMaximumSupplierList.insert( pMinimumAndMaximumSupplier );
45 531 : }
46 :
47 2124 : bool MergedMinimumAndMaximumSupplier::hasMinimumAndMaximumSupplier( MinimumAndMaximumSupplier* pMinimumAndMaximumSupplier )
48 : {
49 2124 : return m_aMinimumAndMaximumSupplierList.count( pMinimumAndMaximumSupplier ) != 0;
50 : }
51 :
52 1053 : double MergedMinimumAndMaximumSupplier::getMinimumX()
53 : {
54 : double fGlobalExtremum;
55 1053 : ::rtl::math::setInf(&fGlobalExtremum, false);
56 2106 : for( MinimumAndMaximumSupplierSet::iterator aIt = begin(), aEnd = end(); aIt != aEnd; ++aIt )
57 : {
58 1053 : double fLocalExtremum = (*aIt)->getMinimumX();
59 1053 : if(fLocalExtremum<fGlobalExtremum)
60 1051 : fGlobalExtremum=fLocalExtremum;
61 : }
62 1053 : if(::rtl::math::isInf(fGlobalExtremum))
63 2 : ::rtl::math::setNan(&fGlobalExtremum);
64 1053 : return fGlobalExtremum;
65 : }
66 :
67 1053 : double MergedMinimumAndMaximumSupplier::getMaximumX()
68 : {
69 : double fGlobalExtremum;
70 1053 : ::rtl::math::setInf(&fGlobalExtremum, true);
71 2106 : for( MinimumAndMaximumSupplierSet::iterator aIt = begin(), aEnd = end(); aIt != aEnd; ++aIt )
72 : {
73 1053 : double fLocalExtremum = (*aIt)->getMaximumX();
74 1053 : if(fLocalExtremum>fGlobalExtremum)
75 1051 : fGlobalExtremum=fLocalExtremum;
76 : }
77 1053 : if(::rtl::math::isInf(fGlobalExtremum))
78 2 : ::rtl::math::setNan(&fGlobalExtremum);
79 1053 : return fGlobalExtremum;
80 : }
81 :
82 1053 : double MergedMinimumAndMaximumSupplier::getMinimumYInRange( double fMinimumX, double fMaximumX, sal_Int32 nAxisIndex )
83 : {
84 : double fGlobalExtremum;
85 1053 : ::rtl::math::setInf(&fGlobalExtremum, false);
86 2106 : for( MinimumAndMaximumSupplierSet::iterator aIt = begin(), aEnd = end(); aIt != aEnd; ++aIt )
87 : {
88 1053 : double fLocalExtremum = (*aIt)->getMinimumYInRange( fMinimumX, fMaximumX, nAxisIndex );
89 1053 : if(fLocalExtremum<fGlobalExtremum)
90 1049 : fGlobalExtremum=fLocalExtremum;
91 : }
92 1053 : if(::rtl::math::isInf(fGlobalExtremum))
93 4 : ::rtl::math::setNan(&fGlobalExtremum);
94 1053 : return fGlobalExtremum;
95 : }
96 :
97 1053 : double MergedMinimumAndMaximumSupplier::getMaximumYInRange( double fMinimumX, double fMaximumX, sal_Int32 nAxisIndex )
98 : {
99 : double fGlobalExtremum;
100 1053 : ::rtl::math::setInf(&fGlobalExtremum, true);
101 2106 : for( MinimumAndMaximumSupplierSet::iterator aIt = begin(), aEnd = end(); aIt != aEnd; ++aIt )
102 : {
103 1053 : double fLocalExtremum = (*aIt)->getMaximumYInRange( fMinimumX, fMaximumX, nAxisIndex );
104 1053 : if(fLocalExtremum>fGlobalExtremum)
105 1049 : fGlobalExtremum=fLocalExtremum;
106 : }
107 1053 : if(::rtl::math::isInf(fGlobalExtremum))
108 4 : ::rtl::math::setNan(&fGlobalExtremum);
109 1053 : return fGlobalExtremum;
110 : }
111 :
112 16 : double MergedMinimumAndMaximumSupplier::getMinimumZ()
113 : {
114 : double fGlobalExtremum;
115 16 : ::rtl::math::setInf(&fGlobalExtremum, false);
116 32 : for( MinimumAndMaximumSupplierSet::iterator aIt = begin(), aEnd = end(); aIt != aEnd; ++aIt )
117 : {
118 16 : double fLocalExtremum = (*aIt)->getMinimumZ();
119 16 : if(fLocalExtremum<fGlobalExtremum)
120 16 : fGlobalExtremum=fLocalExtremum;
121 : }
122 16 : if(::rtl::math::isInf(fGlobalExtremum))
123 0 : ::rtl::math::setNan(&fGlobalExtremum);
124 16 : return fGlobalExtremum;
125 : }
126 :
127 16 : double MergedMinimumAndMaximumSupplier::getMaximumZ()
128 : {
129 : double fGlobalExtremum;
130 16 : ::rtl::math::setInf(&fGlobalExtremum, true);
131 32 : for( MinimumAndMaximumSupplierSet::iterator aIt = begin(), aEnd = end(); aIt != aEnd; ++aIt )
132 : {
133 16 : double fLocalExtremum = (*aIt)->getMaximumZ();
134 16 : if(fLocalExtremum>fGlobalExtremum)
135 16 : fGlobalExtremum=fLocalExtremum;
136 : }
137 16 : if(::rtl::math::isInf(fGlobalExtremum))
138 0 : ::rtl::math::setNan(&fGlobalExtremum);
139 16 : return fGlobalExtremum;
140 : }
141 :
142 2122 : bool MergedMinimumAndMaximumSupplier::isExpandBorderToIncrementRhythm( sal_Int32 nDimensionIndex )
143 : {
144 : // only return true, if *all* suppliers want to scale to the main tick marks
145 3184 : for( MinimumAndMaximumSupplierSet::iterator aIt = begin(), aEnd = end(); aIt != aEnd; ++aIt )
146 2122 : if( !(*aIt)->isExpandBorderToIncrementRhythm( nDimensionIndex ) )
147 1060 : return false;
148 1062 : return true;
149 : }
150 :
151 2122 : bool MergedMinimumAndMaximumSupplier::isExpandIfValuesCloseToBorder( sal_Int32 nDimensionIndex )
152 : {
153 : // only return true, if *all* suppliers want to expand the range
154 3164 : for( MinimumAndMaximumSupplierSet::iterator aIt = begin(), aEnd = end(); aIt != aEnd; ++aIt )
155 2122 : if( !(*aIt)->isExpandIfValuesCloseToBorder( nDimensionIndex ) )
156 1080 : return false;
157 1042 : return true;
158 : }
159 :
160 2122 : bool MergedMinimumAndMaximumSupplier::isExpandWideValuesToZero( sal_Int32 nDimensionIndex )
161 : {
162 : // already return true, if at least one supplier wants to expand the range
163 3204 : for( MinimumAndMaximumSupplierSet::iterator aIt = begin(), aEnd = end(); aIt != aEnd; ++aIt )
164 2122 : if( (*aIt)->isExpandWideValuesToZero( nDimensionIndex ) )
165 1040 : return true;
166 1082 : return false;
167 : }
168 :
169 2122 : bool MergedMinimumAndMaximumSupplier::isExpandNarrowValuesTowardZero( sal_Int32 nDimensionIndex )
170 : {
171 : // already return true, if at least one supplier wants to expand the range
172 3204 : for( MinimumAndMaximumSupplierSet::iterator aIt = begin(), aEnd = end(); aIt != aEnd; ++aIt )
173 2122 : if( (*aIt)->isExpandNarrowValuesTowardZero( nDimensionIndex ) )
174 1040 : return true;
175 1082 : return false;
176 : }
177 :
178 0 : bool MergedMinimumAndMaximumSupplier::isSeparateStackingForDifferentSigns( sal_Int32 nDimensionIndex )
179 : {
180 : // should not be called
181 0 : for( MinimumAndMaximumSupplierSet::iterator aIt = begin(), aEnd = end(); aIt != aEnd; ++aIt )
182 0 : if( (*aIt)->isSeparateStackingForDifferentSigns( nDimensionIndex ) )
183 0 : return true;
184 0 : return false;
185 : }
186 :
187 531 : void MergedMinimumAndMaximumSupplier::clearMinimumAndMaximumSupplierList()
188 : {
189 531 : m_aMinimumAndMaximumSupplierList.clear();
190 531 : }
191 :
192 0 : long MergedMinimumAndMaximumSupplier::calculateTimeResolutionOnXAxis()
193 : {
194 0 : long nRet = ::com::sun::star::chart::TimeUnit::YEAR;
195 0 : for( MinimumAndMaximumSupplierSet::iterator aIt = begin(), aEnd = end(); aIt != aEnd; ++aIt )
196 : {
197 0 : long nCurrent = (*aIt)->calculateTimeResolutionOnXAxis();
198 0 : if(nRet>nCurrent)
199 0 : nRet=nCurrent;
200 : }
201 0 : return nRet;
202 : }
203 :
204 0 : void MergedMinimumAndMaximumSupplier::setTimeResolutionOnXAxis( long nTimeResolution, const Date& rNullDate )
205 : {
206 0 : for( MinimumAndMaximumSupplierSet::iterator aIt = begin(), aEnd = end(); aIt != aEnd; ++aIt )
207 0 : (*aIt)->setTimeResolutionOnXAxis( nTimeResolution, rNullDate );
208 0 : }
209 :
210 : //.............................................................................
211 : } //namespace chart
212 : //.............................................................................
213 :
214 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|