summaryrefslogtreecommitdiffstats
path: root/sc
diff options
context:
space:
mode:
authorMarkus Mohrhard <markus.mohrhard@googlemail.com>2012-05-18 17:31:29 +0200
committerMarkus Mohrhard <markus.mohrhard@googlemail.com>2012-05-18 17:36:47 +0200
commite3fea48ac8523bf3cd4c50906ca85819390594f9 (patch)
treee287c18c40a67f3de776dbdc6bb1472e09ef08dc /sc
parentupdate data bars correctly (diff)
downloadcore-e3fea48ac8523bf3cd4c50906ca85819390594f9.tar.gz
core-e3fea48ac8523bf3cd4c50906ca85819390594f9.zip
correctly get the min value and the max value for data bars
Change-Id: I5e46bf534d1b70536810e9d9ac0a67210b271109
Diffstat (limited to 'sc')
-rw-r--r--sc/inc/colorscale.hxx3
-rw-r--r--sc/source/core/data/colorscale.cxx87
2 files changed, 66 insertions, 24 deletions
diff --git a/sc/inc/colorscale.hxx b/sc/inc/colorscale.hxx
index b63bc66baa39..0f72475b8ad1 100644
--- a/sc/inc/colorscale.hxx
+++ b/sc/inc/colorscale.hxx
@@ -198,6 +198,9 @@ public:
virtual ScColorFormatType GetType() const;
private:
+ double getMin(double nMin, double nMax) const;
+ double getMax(double nMin, double nMax) const;
+
boost::scoped_ptr<ScDataBarFormatData> mpFormatData;
};
diff --git a/sc/source/core/data/colorscale.cxx b/sc/source/core/data/colorscale.cxx
index f9adede55ecb..2a34fd9623ae 100644
--- a/sc/source/core/data/colorscale.cxx
+++ b/sc/source/core/data/colorscale.cxx
@@ -263,50 +263,61 @@ double getMaxValue(const ScRange& rRange, ScDocument* pDoc)
return aMaxValue;
}
+double getMinValue(const ScRangeList& rList, ScDocument* pDoc)
+{
+ double aMinValue = std::numeric_limits<double>::max();
+
+ size_t n = rList.size();
+ for(size_t i = 0; i < n; ++i)
+ {
+ const ScRange* pRange = rList[i];
+ double aVal = getMinValue(*pRange, pDoc);
+ if( aVal < aMinValue )
+ aMinValue = aVal;
+ }
+ return aMinValue;
+}
+
+double getMaxValue(const ScRangeList& rList, ScDocument* pDoc)
+{
+ double aMaxVal = std::numeric_limits<double>::min();
+
+ size_t n = rList.size();
+ for(size_t i = 0; i < n; ++i)
+ {
+ const ScRange* pRange = rList[i];
+ double aVal = getMaxValue(*pRange, pDoc);
+ if( aVal > aMaxVal )
+ aMaxVal = aVal;
+ }
+
+ return aMaxVal;
+}
+
}
double ScColorScaleFormat::GetMinValue() const
{
const_iterator itr = maColorScales.begin();
- double aMinValue = std::numeric_limits<double>::max();
if(!itr->GetMin())
return itr->GetValue();
else
{
- size_t n = maRanges.size();
- for(size_t i = 0; i < n; ++i)
- {
- const ScRange* pRange = maRanges[i];
- double aVal = getMinValue(*pRange, mpDoc);
- if( aVal < aMinValue )
- aMinValue = aVal;
- }
+ return getMinValue(maRanges, mpDoc);
}
-
- return aMinValue;
}
double ScColorScaleFormat::GetMaxValue() const
{
ColorScaleEntries::const_reverse_iterator itr = maColorScales.rbegin();
- double aMaxVal = std::numeric_limits<double>::min();
if(!itr->GetMax())
return itr->GetValue();
else
{
- size_t n = maRanges.size();
- for(size_t i = 0; i < n; ++i)
- {
- const ScRange* pRange = maRanges[i];
- double aVal = getMaxValue(*pRange, mpDoc);
- if( aVal > aMaxVal )
- aMaxVal = aVal;
- }
+ return getMaxValue(maRanges, mpDoc);
}
-
- return aMaxVal;;
}
void ScColorScaleFormat::calcMinMax(double& rMin, double& rMax) const
@@ -623,6 +634,32 @@ void ScDataBarFormat::UpdateMoveTab(SCTAB nOldTab, SCTAB nNewTab)
mpFormatData->mpLowerLimit->UpdateMoveTab(nOldTab, nNewTab, nThisTab);
}
+double ScDataBarFormat::getMin(double nMin, double nMax) const
+{
+ if(mpFormatData->mpLowerLimit->GetMin())
+ return nMin;
+
+ if(mpFormatData->mpLowerLimit->GetPercent())
+ {
+ return nMin + (nMax-nMin)/100*mpFormatData->mpLowerLimit->GetValue();
+ }
+
+ return mpFormatData->mpLowerLimit->GetValue();
+}
+
+double ScDataBarFormat::getMax(double nMin, double nMax) const
+{
+ if(mpFormatData->mpUpperLimit->GetMax())
+ return nMax;
+
+ if(mpFormatData->mpUpperLimit->GetPercent())
+ {
+ return nMin + (nMax-nMin)/100*mpFormatData->mpLowerLimit->GetValue();
+ }
+
+ return mpFormatData->mpLowerLimit->GetValue();
+}
+
ScDataBarInfo* ScDataBarFormat::GetDataBarInfo(const ScAddress& rAddr) const
{
CellType eCellType = mpDoc->GetCellType(rAddr);
@@ -637,8 +674,10 @@ ScDataBarInfo* ScDataBarFormat::GetDataBarInfo(const ScAddress& rAddr) const
// now we have for sure a value
//
- double nMin = -2;
- double nMax = 10;
+ double nValMin = getMinValue(maRanges, mpDoc);
+ double nValMax = getMaxValue(maRanges, mpDoc);
+ double nMin = getMin(nValMin, nValMax);
+ double nMax = getMax(nValMin, nValMax);
double nValue = mpDoc->GetValue(rAddr);