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>
29 using namespace ::com::sun::star
;
31 MergedMinimumAndMaximumSupplier::MergedMinimumAndMaximumSupplier()
35 MergedMinimumAndMaximumSupplier::~MergedMinimumAndMaximumSupplier()
39 void MergedMinimumAndMaximumSupplier::addMinimumAndMaximumSupplier( MinimumAndMaximumSupplier
* pMinimumAndMaximumSupplier
)
41 m_aMinimumAndMaximumSupplierList
.insert( pMinimumAndMaximumSupplier
);
44 bool MergedMinimumAndMaximumSupplier::hasMinimumAndMaximumSupplier( MinimumAndMaximumSupplier
* pMinimumAndMaximumSupplier
)
46 return m_aMinimumAndMaximumSupplierList
.count( pMinimumAndMaximumSupplier
) != 0;
49 double MergedMinimumAndMaximumSupplier::getMinimumX()
51 double fGlobalExtremum
= std::numeric_limits
<double>::infinity();
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 return std::numeric_limits
<double>::quiet_NaN();
60 return fGlobalExtremum
;
63 double MergedMinimumAndMaximumSupplier::getMaximumX()
65 double fGlobalExtremum
= -std::numeric_limits
<double>::infinity();
66 for (auto const& elem
: m_aMinimumAndMaximumSupplierList
)
68 double fLocalExtremum
= elem
->getMaximumX();
69 if(fLocalExtremum
>fGlobalExtremum
)
70 fGlobalExtremum
=fLocalExtremum
;
72 if(std::isinf(fGlobalExtremum
))
73 return std::numeric_limits
<double>::quiet_NaN();
74 return fGlobalExtremum
;
77 double MergedMinimumAndMaximumSupplier::getMinimumYInRange( double fMinimumX
, double fMaximumX
, sal_Int32 nAxisIndex
)
79 double fGlobalExtremum
= std::numeric_limits
<double>::infinity();
80 for (auto const& elem
: m_aMinimumAndMaximumSupplierList
)
82 double fLocalExtremum
= elem
->getMinimumYInRange( fMinimumX
, fMaximumX
, nAxisIndex
);
83 if(fLocalExtremum
<fGlobalExtremum
)
84 fGlobalExtremum
=fLocalExtremum
;
86 if(std::isinf(fGlobalExtremum
))
87 return std::numeric_limits
<double>::quiet_NaN();
88 return fGlobalExtremum
;
91 double MergedMinimumAndMaximumSupplier::getMaximumYInRange( double fMinimumX
, double fMaximumX
, sal_Int32 nAxisIndex
)
93 double fGlobalExtremum
= -std::numeric_limits
<double>::infinity();
94 for (auto const& elem
: m_aMinimumAndMaximumSupplierList
)
96 double fLocalExtremum
= elem
->getMaximumYInRange( fMinimumX
, fMaximumX
, nAxisIndex
);
97 if(fLocalExtremum
>fGlobalExtremum
)
98 fGlobalExtremum
=fLocalExtremum
;
100 if(std::isinf(fGlobalExtremum
))
101 return std::numeric_limits
<double>::quiet_NaN();
102 return fGlobalExtremum
;
105 double MergedMinimumAndMaximumSupplier::getMinimumZ()
107 double fGlobalExtremum
= std::numeric_limits
<double>::infinity();
108 for (auto const& elem
: m_aMinimumAndMaximumSupplierList
)
110 double fLocalExtremum
= elem
->getMinimumZ();
111 if(fLocalExtremum
<fGlobalExtremum
)
112 fGlobalExtremum
=fLocalExtremum
;
114 if(std::isinf(fGlobalExtremum
))
115 return std::numeric_limits
<double>::quiet_NaN();
116 return fGlobalExtremum
;
119 double MergedMinimumAndMaximumSupplier::getMaximumZ()
121 double fGlobalExtremum
= -std::numeric_limits
<double>::infinity();
122 for (auto const& elem
: m_aMinimumAndMaximumSupplierList
)
124 double fLocalExtremum
= elem
->getMaximumZ();
125 if(fLocalExtremum
>fGlobalExtremum
)
126 fGlobalExtremum
=fLocalExtremum
;
128 if(std::isinf(fGlobalExtremum
))
129 return std::numeric_limits
<double>::quiet_NaN();
130 return fGlobalExtremum
;
133 bool MergedMinimumAndMaximumSupplier::isExpandBorderToIncrementRhythm( sal_Int32 nDimensionIndex
)
135 // only return true, if *all* suppliers want to scale to the main tick marks
136 for (auto const& elem
: m_aMinimumAndMaximumSupplierList
)
137 if( !elem
->isExpandBorderToIncrementRhythm( nDimensionIndex
) )
142 bool MergedMinimumAndMaximumSupplier::isExpandIfValuesCloseToBorder( sal_Int32 nDimensionIndex
)
144 // only return true, if *all* suppliers want to expand the range
145 for (auto const& elem
: m_aMinimumAndMaximumSupplierList
)
146 if( !elem
->isExpandIfValuesCloseToBorder( nDimensionIndex
) )
151 bool MergedMinimumAndMaximumSupplier::isExpandWideValuesToZero( sal_Int32 nDimensionIndex
)
153 // already return true, if at least one supplier wants to expand the range
154 for (auto const& elem
: m_aMinimumAndMaximumSupplierList
)
155 if( elem
->isExpandWideValuesToZero( nDimensionIndex
) )
160 bool MergedMinimumAndMaximumSupplier::isExpandNarrowValuesTowardZero( sal_Int32 nDimensionIndex
)
162 // already return true, if at least one supplier wants to expand the range
163 for (auto const& elem
: m_aMinimumAndMaximumSupplierList
)
164 if( elem
->isExpandNarrowValuesTowardZero( nDimensionIndex
) )
169 bool MergedMinimumAndMaximumSupplier::isSeparateStackingForDifferentSigns( sal_Int32 nDimensionIndex
)
171 // should not be called
172 for (auto const& elem
: m_aMinimumAndMaximumSupplierList
)
173 if( elem
->isSeparateStackingForDifferentSigns( nDimensionIndex
) )
178 void MergedMinimumAndMaximumSupplier::clearMinimumAndMaximumSupplierList()
180 m_aMinimumAndMaximumSupplierList
.clear();
183 tools::Long
MergedMinimumAndMaximumSupplier::calculateTimeResolutionOnXAxis()
185 tools::Long nRet
= css::chart::TimeUnit::YEAR
;
186 for (auto const& elem
: m_aMinimumAndMaximumSupplierList
)
188 tools::Long nCurrent
= elem
->calculateTimeResolutionOnXAxis();
195 void MergedMinimumAndMaximumSupplier::setTimeResolutionOnXAxis( tools::Long nTimeResolution
, const Date
& rNullDate
)
197 for (auto const& elem
: m_aMinimumAndMaximumSupplierList
)
198 elem
->setTimeResolutionOnXAxis( nTimeResolution
, rNullDate
);
203 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */