summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--sc/inc/colorscale.hxx3
-rw-r--r--sc/source/core/data/colorscale.cxx53
-rw-r--r--sc/source/filter/oox/condformatbuffer.cxx6
3 files changed, 50 insertions, 12 deletions
diff --git a/sc/inc/colorscale.hxx b/sc/inc/colorscale.hxx
index 65a2fd6a824a..b71c38b87845 100644
--- a/sc/inc/colorscale.hxx
+++ b/sc/inc/colorscale.hxx
@@ -69,12 +69,13 @@ private:
double GetMinValue() const;
double GetMaxValue() const;
- void calcMinMax(double& nMin, double nMax) const;
+ void calcMinMax(double& nMin, double& nMax) const;
public:
ScColorScaleFormat(ScDocument* pDoc);
Color* GetColor(const ScAddress& rAddr) const;
void AddEntry(ScColorScaleEntry* pEntry);
+ void SetRange(const ScRangeList& rList);
typedef ColorScaleEntries::iterator iterator;
typedef ColorScaleEntries::const_iterator const_iterator;
diff --git a/sc/source/core/data/colorscale.cxx b/sc/source/core/data/colorscale.cxx
index c970f37a4410..3cc0e5ad84c5 100644
--- a/sc/source/core/data/colorscale.cxx
+++ b/sc/source/core/data/colorscale.cxx
@@ -32,14 +32,19 @@
ScColorScaleEntry::ScColorScaleEntry(double nVal, const Color& rCol):
mnVal(nVal),
- maColor(rCol)
-{
+ maColor(rCol),
+ mbMin(false),
+ mbMax(false),
+ mbPercent(false){
}
ScColorScaleEntry::ScColorScaleEntry(const ScColorScaleEntry& rEntry):
mnVal(rEntry.mnVal),
- maColor(rEntry.maColor)
+ maColor(rEntry.maColor),
+ mbMin(false),
+ mbMax(false),
+ mbPercent(false)
{
}
@@ -204,12 +209,17 @@ double ScColorScaleFormat::GetMaxValue() const
return aMaxVal;;
}
-void ScColorScaleFormat::calcMinMax(double& rMin, double rMax) const
+void ScColorScaleFormat::calcMinMax(double& rMin, double& rMax) const
{
rMin = GetMinValue();
rMax = GetMaxValue();
}
+void ScColorScaleFormat::SetRange(const ScRangeList& rList)
+{
+ maRanges = rList;
+}
+
namespace {
sal_uInt8 GetColorValue( double nVal, double nVal1, sal_uInt8 nColVal1, double nVal2, sal_uInt8 nColVal2 )
@@ -233,6 +243,24 @@ Color CalcColor( double nVal, double nVal1, const Color& rCol1, double nVal2, co
return Color(nColRed, nColGreen, nColBlue);
}
+double CalcValue(double nMin, double nMax, ScColorScaleFormat::const_iterator& itr)
+{
+ if(itr->GetPercent())
+ {
+ return nMin + (nMax-nMin)*(itr->GetValue()/100);
+ }
+ else if(itr->GetMin())
+ {
+ return nMin;
+ }
+ else if(itr->GetMax())
+ {
+ return nMax;
+ }
+
+ return itr->GetValue();
+}
+
}
Color* ScColorScaleFormat::GetColor( const ScAddress& rAddr ) const
@@ -253,23 +281,28 @@ Color* ScColorScaleFormat::GetColor( const ScAddress& rAddr ) const
if (maColorScales.size() < 2)
return NULL;
+ double nMin = std::numeric_limits<double>::max();
+ double nMax = std::numeric_limits<double>::min();
+ calcMinMax(nMin, nMax);
+
+ // this check is for safety
+ if(nMin >= nMax)
+ return NULL;
+
const_iterator itr = begin();
- double nValMin = itr->GetValue();
+ double nValMin = CalcValue(nMin, nMax, itr);
Color rColMin = itr->GetColor();
++itr;
- double nValMax = itr->GetValue();
+ double nValMax = CalcValue(nMin, nMax, itr);
Color rColMax = itr->GetColor();
- double nMin;
- double nMax;
- calcMinMax(nMin, nMax);
-
++itr;
while(itr != end() && nVal > nValMin)
{
rColMin = rColMax;
nValMin = nValMax;
rColMax = itr->GetColor();
+ nValMax = CalcValue(nMin, nMax, itr);
nValMax = itr->GetValue();
++itr;
}
diff --git a/sc/source/filter/oox/condformatbuffer.cxx b/sc/source/filter/oox/condformatbuffer.cxx
index 0b6ddf7b3768..89ba949caee0 100644
--- a/sc/source/filter/oox/condformatbuffer.cxx
+++ b/sc/source/filter/oox/condformatbuffer.cxx
@@ -172,7 +172,7 @@ void ColorScaleRule::importCfvo( const AttributeList& rAttribs )
{
maColorScaleRuleEntries[mnCfvo].mbMax = true;
}
- else if( aType == "percent" )
+ else if( aType == "percentile" )
{
maColorScaleRuleEntries[mnCfvo].mbPercent = true;
}
@@ -696,6 +696,7 @@ void CondFormatRule::finalizeImport( const Reference< XSheetConditionalEntries >
mpColor->AddEntries( pFormat );
sal_Int32 nIndex = rDoc.AddColorScaleFormat(pFormat);
+ ScRangeList aList;
// apply attributes to cells
//
const ApiCellRangeList& rRanges = mrCondFormat.getRanges();
@@ -709,7 +710,10 @@ void CondFormatRule::finalizeImport( const Reference< XSheetConditionalEntries >
ScMarkData aMarkData;
aMarkData.SetMarkArea(aRange);
pShell->GetDocFunc().ApplyAttributes( aMarkData, aPattern, sal_True, sal_True );
+
+ aList.Append(aRange);
}
+ pFormat->SetRange(aList);
}
}