1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <MinimumAndMaximumSupplier.hxx>
22 #include <com/sun/star/chart/TimeUnit.hpp>
24 #include <rtl/math.hxx>
28 using namespace ::com::sun::star
;
30 MergedMinimumAndMaximumSupplier::MergedMinimumAndMaximumSupplier()
34 MergedMinimumAndMaximumSupplier::~MergedMinimumAndMaximumSupplier()
38 void MergedMinimumAndMaximumSupplier::addMinimumAndMaximumSupplier( MinimumAndMaximumSupplier
* pMinimumAndMaximumSupplier
)
40 m_aMinimumAndMaximumSupplierList
.insert( pMinimumAndMaximumSupplier
);
43 bool MergedMinimumAndMaximumSupplier::hasMinimumAndMaximumSupplier( MinimumAndMaximumSupplier
* pMinimumAndMaximumSupplier
)
45 return m_aMinimumAndMaximumSupplierList
.count( pMinimumAndMaximumSupplier
) != 0;
48 double MergedMinimumAndMaximumSupplier::getMinimumX()
50 double fGlobalExtremum
;
51 ::rtl::math::setInf(&fGlobalExtremum
, false);
52 for (auto const& elem
: m_aMinimumAndMaximumSupplierList
)
54 double fLocalExtremum
= elem
->getMinimumX();
55 if(fLocalExtremum
<fGlobalExtremum
)
56 fGlobalExtremum
=fLocalExtremum
;
58 if(std::isinf(fGlobalExtremum
))
59 ::rtl::math::setNan(&fGlobalExtremum
);
60 return fGlobalExtremum
;
63 double MergedMinimumAndMaximumSupplier::getMaximumX()
65 double fGlobalExtremum
;
66 ::rtl::math::setInf(&fGlobalExtremum
, true);
67 for (auto const& elem
: m_aMinimumAndMaximumSupplierList
)
69 double fLocalExtremum
= elem
->getMaximumX();
70 if(fLocalExtremum
>fGlobalExtremum
)
71 fGlobalExtremum
=fLocalExtremum
;
73 if(std::isinf(fGlobalExtremum
))
74 ::rtl::math::setNan(&fGlobalExtremum
);
75 return fGlobalExtremum
;
78 double MergedMinimumAndMaximumSupplier::getMinimumYInRange( double fMinimumX
, double fMaximumX
, sal_Int32 nAxisIndex
)
80 double fGlobalExtremum
;
81 ::rtl::math::setInf(&fGlobalExtremum
, false);
82 for (auto const& elem
: m_aMinimumAndMaximumSupplierList
)
84 double fLocalExtremum
= elem
->getMinimumYInRange( fMinimumX
, fMaximumX
, nAxisIndex
);
85 if(fLocalExtremum
<fGlobalExtremum
)
86 fGlobalExtremum
=fLocalExtremum
;
88 if(std::isinf(fGlobalExtremum
))
89 ::rtl::math::setNan(&fGlobalExtremum
);
90 return fGlobalExtremum
;
93 double MergedMinimumAndMaximumSupplier::getMaximumYInRange( double fMinimumX
, double fMaximumX
, sal_Int32 nAxisIndex
)
95 double fGlobalExtremum
;
96 ::rtl::math::setInf(&fGlobalExtremum
, true);
97 for (auto const& elem
: m_aMinimumAndMaximumSupplierList
)
99 double fLocalExtremum
= elem
->getMaximumYInRange( fMinimumX
, fMaximumX
, nAxisIndex
);
100 if(fLocalExtremum
>fGlobalExtremum
)
101 fGlobalExtremum
=fLocalExtremum
;
103 if(std::isinf(fGlobalExtremum
))
104 ::rtl::math::setNan(&fGlobalExtremum
);
105 return fGlobalExtremum
;
108 double MergedMinimumAndMaximumSupplier::getMinimumZ()
110 double fGlobalExtremum
;
111 ::rtl::math::setInf(&fGlobalExtremum
, false);
112 for (auto const& elem
: m_aMinimumAndMaximumSupplierList
)
114 double fLocalExtremum
= elem
->getMinimumZ();
115 if(fLocalExtremum
<fGlobalExtremum
)
116 fGlobalExtremum
=fLocalExtremum
;
118 if(std::isinf(fGlobalExtremum
))
119 ::rtl::math::setNan(&fGlobalExtremum
);
120 return fGlobalExtremum
;
123 double MergedMinimumAndMaximumSupplier::getMaximumZ()
125 double fGlobalExtremum
;
126 ::rtl::math::setInf(&fGlobalExtremum
, true);
127 for (auto const& elem
: m_aMinimumAndMaximumSupplierList
)
129 double fLocalExtremum
= elem
->getMaximumZ();
130 if(fLocalExtremum
>fGlobalExtremum
)
131 fGlobalExtremum
=fLocalExtremum
;
133 if(std::isinf(fGlobalExtremum
))
134 ::rtl::math::setNan(&fGlobalExtremum
);
135 return fGlobalExtremum
;
138 bool MergedMinimumAndMaximumSupplier::isExpandBorderToIncrementRhythm( sal_Int32 nDimensionIndex
)
140 // only return true, if *all* suppliers want to scale to the main tick marks
141 for (auto const& elem
: m_aMinimumAndMaximumSupplierList
)
142 if( !elem
->isExpandBorderToIncrementRhythm( nDimensionIndex
) )
147 bool MergedMinimumAndMaximumSupplier::isExpandIfValuesCloseToBorder( sal_Int32 nDimensionIndex
)
149 // only return true, if *all* suppliers want to expand the range
150 for (auto const& elem
: m_aMinimumAndMaximumSupplierList
)
151 if( !elem
->isExpandIfValuesCloseToBorder( nDimensionIndex
) )
156 bool MergedMinimumAndMaximumSupplier::isExpandWideValuesToZero( sal_Int32 nDimensionIndex
)
158 // already return true, if at least one supplier wants to expand the range
159 for (auto const& elem
: m_aMinimumAndMaximumSupplierList
)
160 if( elem
->isExpandWideValuesToZero( nDimensionIndex
) )
165 bool MergedMinimumAndMaximumSupplier::isExpandNarrowValuesTowardZero( sal_Int32 nDimensionIndex
)
167 // already return true, if at least one supplier wants to expand the range
168 for (auto const& elem
: m_aMinimumAndMaximumSupplierList
)
169 if( elem
->isExpandNarrowValuesTowardZero( nDimensionIndex
) )
174 bool MergedMinimumAndMaximumSupplier::isSeparateStackingForDifferentSigns( sal_Int32 nDimensionIndex
)
176 // should not be called
177 for (auto const& elem
: m_aMinimumAndMaximumSupplierList
)
178 if( elem
->isSeparateStackingForDifferentSigns( nDimensionIndex
) )
183 void MergedMinimumAndMaximumSupplier::clearMinimumAndMaximumSupplierList()
185 m_aMinimumAndMaximumSupplierList
.clear();
188 tools::Long
MergedMinimumAndMaximumSupplier::calculateTimeResolutionOnXAxis()
190 tools::Long nRet
= css::chart::TimeUnit::YEAR
;
191 for (auto const& elem
: m_aMinimumAndMaximumSupplierList
)
193 tools::Long nCurrent
= elem
->calculateTimeResolutionOnXAxis();
200 void MergedMinimumAndMaximumSupplier::setTimeResolutionOnXAxis( tools::Long nTimeResolution
, const Date
& rNullDate
)
202 for (auto const& elem
: m_aMinimumAndMaximumSupplierList
)
203 elem
->setTimeResolutionOnXAxis( nTimeResolution
, rNullDate
);
208 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */