summaryrefslogtreecommitdiff
path: root/sc
diff options
context:
space:
mode:
authorMarkus Mohrhard <markus.mohrhard@googlemail.com>2012-05-10 07:06:40 +0200
committerMarkus Mohrhard <markus.mohrhard@googlemail.com>2012-05-10 12:41:46 +0200
commitf26bf2ba01fc8ed453f3a42a39c26e2cf809c40f (patch)
tree808b552e3ff23bdf821af7b671815d3b08a443e7 /sc
parentd16c1b9290e11ca31850523a2b01426bca0937a3 (diff)
first part for min/max in color scales
Change-Id: Ib397b93ac0a5a72052fdaa5bf41199e5967ad559
Diffstat (limited to 'sc')
-rw-r--r--sc/inc/colorscale.hxx18
-rw-r--r--sc/source/core/data/colorscale.cxx150
2 files changed, 167 insertions, 1 deletions
diff --git a/sc/inc/colorscale.hxx b/sc/inc/colorscale.hxx
index 01ff306ba45d..65a2fd6a824a 100644
--- a/sc/inc/colorscale.hxx
+++ b/sc/inc/colorscale.hxx
@@ -39,21 +39,37 @@ class SC_DLLPUBLIC ScColorScaleEntry
private:
double mnVal;
Color maColor;
+
+ bool mbMin;
+ bool mbMax;
+ bool mbPercent;
public:
ScColorScaleEntry(double nVal, const Color& rCol);
ScColorScaleEntry(const ScColorScaleEntry& rEntry);
const Color& GetColor() const;
double GetValue() const;
+
+ bool GetMin() const;
+ bool GetMax() const;
+ bool GetPercent() const;
+ void SetMin(bool bMin);
+ void SetMax(bool bMax);
+ void SetPercent(bool bPercent);
};
class SC_DLLPUBLIC ScColorScaleFormat
{
private:
- ScRangeList maRange;
+ ScRangeList maRanges;
ScDocument* mpDoc;
typedef boost::ptr_vector<ScColorScaleEntry> ColorScaleEntries;
ColorScaleEntries maColorScales;
+
+ double GetMinValue() const;
+ double GetMaxValue() const;
+
+ void calcMinMax(double& nMin, double nMax) const;
public:
ScColorScaleFormat(ScDocument* pDoc);
diff --git a/sc/source/core/data/colorscale.cxx b/sc/source/core/data/colorscale.cxx
index f05afb015fbb..c970f37a4410 100644
--- a/sc/source/core/data/colorscale.cxx
+++ b/sc/source/core/data/colorscale.cxx
@@ -64,6 +64,152 @@ void ScColorScaleFormat::AddEntry( ScColorScaleEntry* pEntry )
maColorScales.push_back( pEntry );
}
+bool ScColorScaleEntry::GetMin() const
+{
+ return mbMin;
+}
+
+bool ScColorScaleEntry::GetMax() const
+{
+ return mbMax;
+}
+
+bool ScColorScaleEntry::GetPercent() const
+{
+ return mbPercent;
+}
+
+void ScColorScaleEntry::SetMin(bool bMin)
+{
+ mbMin = bMin;
+}
+
+void ScColorScaleEntry::SetMax(bool bMax)
+{
+ mbMax = bMax;
+}
+
+void ScColorScaleEntry::SetPercent(bool bPercent)
+{
+ mbPercent = bPercent;
+}
+
+namespace {
+
+double getMinValue(const ScRange& rRange, ScDocument* pDoc)
+{
+ double aMinValue = std::numeric_limits<double>::max();
+ //iterate through columns
+ SCTAB nTab = rRange.aStart.Tab();
+ for(SCCOL nCol = rRange.aStart.Col(); nCol <= rRange.aEnd.Col(); ++nCol)
+ {
+ for(SCROW nRow = rRange.aStart.Row(); nRow <= rRange.aEnd.Row(); ++nRow)
+ {
+ ScAddress aAddr(nCol, nRow, rRange.aStart.Tab());
+ CellType eType = pDoc->GetCellType(aAddr);
+ if(eType == CELLTYPE_VALUE)
+ {
+ double aVal = pDoc->GetValue(nCol, nRow, nTab);
+ if( aVal < aMinValue )
+ aMinValue = aVal;
+ }
+ else if(eType == CELLTYPE_FORMULA)
+ {
+ if(static_cast<ScFormulaCell*>(pDoc->GetCell(aAddr))->IsValue())
+ {
+ double aVal = pDoc->GetValue(nCol, nRow, nTab);
+ if( aVal < aMinValue )
+ aMinValue = aVal;
+ }
+ }
+ }
+ }
+ return aMinValue;
+}
+
+double getMaxValue(const ScRange& rRange, ScDocument* pDoc)
+{
+ double aMaxValue = std::numeric_limits<double>::min();
+ //iterate through columns
+ SCTAB nTab = rRange.aStart.Tab();
+ for(SCCOL nCol = rRange.aStart.Col(); nCol <= rRange.aEnd.Col(); ++nCol)
+ {
+ for(SCROW nRow = rRange.aStart.Row(); nRow <= rRange.aEnd.Row(); ++nRow)
+ {
+ ScAddress aAddr(nCol, nRow, rRange.aStart.Tab());
+ CellType eType = pDoc->GetCellType(aAddr);
+ if(eType == CELLTYPE_VALUE)
+ {
+ double aVal = pDoc->GetValue(nCol, nRow, nTab);
+ if( aVal > aMaxValue )
+ aMaxValue = aVal;
+ }
+ else if(eType == CELLTYPE_FORMULA)
+ {
+ if(static_cast<ScFormulaCell*>(pDoc->GetCell(aAddr))->IsValue())
+ {
+ double aVal = pDoc->GetValue(nCol, nRow, nTab);
+ if( aVal > aMaxValue )
+ aMaxValue = aVal;
+ }
+ }
+ }
+ }
+ return aMaxValue;
+}
+
+}
+
+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 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 aMaxVal;;
+}
+
+void ScColorScaleFormat::calcMinMax(double& rMin, double rMax) const
+{
+ rMin = GetMinValue();
+ rMax = GetMaxValue();
+}
+
namespace {
sal_uInt8 GetColorValue( double nVal, double nVal1, sal_uInt8 nColVal1, double nVal2, sal_uInt8 nColVal2 )
@@ -114,6 +260,10 @@ Color* ScColorScaleFormat::GetColor( const ScAddress& rAddr ) const
double nValMax = itr->GetValue();
Color rColMax = itr->GetColor();
+ double nMin;
+ double nMax;
+ calcMinMax(nMin, nMax);
+
++itr;
while(itr != end() && nVal > nValMin)
{