[Libreoffice-commits] .: 2 commits - sc/inc sc/source
Markus Mohrhard
mmohrhard at kemper.freedesktop.org
Fri May 18 08:38:13 PDT 2012
sc/inc/colorscale.hxx | 3
sc/source/core/data/colorscale.cxx | 152 +++++++++++++++++++++++++++++--------
2 files changed, 124 insertions(+), 31 deletions(-)
New commits:
commit e3fea48ac8523bf3cd4c50906ca85819390594f9
Author: Markus Mohrhard <markus.mohrhard at googlemail.com>
Date: Fri May 18 17:31:29 2012 +0200
correctly get the min value and the max value for data bars
Change-Id: I5e46bf534d1b70536810e9d9ac0a67210b271109
diff --git a/sc/inc/colorscale.hxx b/sc/inc/colorscale.hxx
index b63bc66..0f72475 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 f9adede..2a34fd9 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);
commit 726051277d90d0dfe384111d03b97835517bb69c
Author: Markus Mohrhard <markus.mohrhard at googlemail.com>
Date: Fri May 18 17:09:26 2012 +0200
update data bars correctly
Change-Id: Icddd688dbf5da8154dd470539b03b6a2d02ca755
diff --git a/sc/source/core/data/colorscale.cxx b/sc/source/core/data/colorscale.cxx
index 975e6e9..f9adede 100644
--- a/sc/source/core/data/colorscale.cxx
+++ b/sc/source/core/data/colorscale.cxx
@@ -416,15 +416,17 @@ Color* ScColorScaleFormat::GetColor( const ScAddress& rAddr ) const
return new Color(aColor);
}
-void ScColorScaleFormat::UpdateMoveTab(SCTAB nOldTab, SCTAB nNewTab)
+namespace {
+
+SCTAB UpdateMoveTabRangeList( ScRangeList& rList, SCTAB nOldTab, SCTAB nNewTab )
{
- size_t n = maRanges.size();
+ size_t n = rList.size();
SCTAB nMinTab = std::min<SCTAB>(nOldTab, nNewTab);
SCTAB nMaxTab = std::max<SCTAB>(nOldTab, nNewTab);
SCTAB nThisTab = -1;
for(size_t i = 0; i < n; ++i)
{
- ScRange* pRange = maRanges[i];
+ ScRange* pRange = rList[i];
SCTAB nTab = pRange->aStart.Tab();
if(nTab < nMinTab || nTab > nMaxTab)
{
@@ -456,6 +458,15 @@ void ScColorScaleFormat::UpdateMoveTab(SCTAB nOldTab, SCTAB nNewTab)
if(nThisTab == -1)
nThisTab = 0;
+
+ return nThisTab;
+}
+
+}
+
+void ScColorScaleFormat::UpdateMoveTab(SCTAB nOldTab, SCTAB nNewTab)
+{
+ SCTAB nThisTab = UpdateMoveTabRangeList(maRanges, nOldTab, nNewTab);
for(iterator itr = begin(); itr != end(); ++itr)
{
itr->UpdateMoveTab(nOldTab, nNewTab, nThisTab);
@@ -558,18 +569,58 @@ ScColorFormatType ScDataBarFormat::GetType() const
return DATABAR;
}
-void ScDataBarFormat::UpdateReference( UpdateRefMode ,
- const ScRange& , SCsCOL , SCsROW , SCsTAB )
+void ScDataBarFormat::UpdateReference( UpdateRefMode eRefMode,
+ const ScRange& rRange, SCsCOL nDx, SCsROW nDy, SCsTAB nDz )
+{
+ maRanges.UpdateReference( eRefMode, mpDoc, rRange, nDx, nDy, nDz );
+
+ mpFormatData->mpUpperLimit->UpdateReference( eRefMode, rRange, nDx, nDy, nDz );
+ mpFormatData->mpLowerLimit->UpdateReference( eRefMode, rRange, nDx, nDy, nDz );
+}
+
+namespace {
+
+bool NeedUpdate(ScColorScaleEntry* pEntry)
{
+ if(pEntry->GetMin())
+ return true;
+
+ if(pEntry->GetMax())
+ return true;
+
+ if(pEntry->GetFormula())
+ return true;
+
+ return false;
+}
+
}
-void ScDataBarFormat::DataChanged(const ScRange& )
+void ScDataBarFormat::DataChanged(const ScRange& rRange)
{
+ bool bNeedUpdate = false;
+
+ bNeedUpdate = NeedUpdate(mpFormatData->mpUpperLimit.get());
+ bNeedUpdate &= NeedUpdate(mpFormatData->mpLowerLimit.get());
+ bNeedUpdate &= maRanges.Intersects(rRange);
+
+ if(bNeedUpdate)
+ {
+ size_t n = maRanges.size();
+ for(size_t i = 0; i < n; ++i)
+ {
+ ScRange* pRange = maRanges[i];
+ mpDoc->RepaintRange(*pRange);
+ }
+ }
}
-void ScDataBarFormat::UpdateMoveTab(SCTAB , SCTAB )
+void ScDataBarFormat::UpdateMoveTab(SCTAB nOldTab, SCTAB nNewTab)
{
+ SCTAB nThisTab = UpdateMoveTabRangeList(maRanges, nOldTab, nNewTab);
+ mpFormatData->mpUpperLimit->UpdateMoveTab(nOldTab, nNewTab, nThisTab);
+ mpFormatData->mpLowerLimit->UpdateMoveTab(nOldTab, nNewTab, nThisTab);
}
ScDataBarInfo* ScDataBarFormat::GetDataBarInfo(const ScAddress& rAddr) const
More information about the Libreoffice-commits
mailing list