summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTibor Nagy <nagy.tibor2@nisz.hu>2023-05-22 14:20:59 +0200
committerLászló Németh <nemeth@numbertext.org>2023-05-31 20:17:16 +0200
commit6a059f8d1b0a7a5b64bd272e1e7b8291979bcd56 (patch)
tree9ecbede7722fc6eca6b08f622408484c44877942
parent6aec73de12a56a56b3ffd9bb86b559bf0609bf58 (diff)
tdf#155321 sc: fix color of the highest value on percentile color scale
if the highest value occurs multiple times in the data set. Also for coloring based on the percentile, use always the end of the color scale for the highest values, like other spreadsheets do, i.e. not the first possible color in the case of repeating values. For example, the corner case in the test document is not a red and two yellow cells any more, but a red and two green cells. Note: color of the other repeating values still differs from MSO, but the same as in Google Sheets. Change-Id: I1d7eacec6e442c1112a9568e64dd6461e2ff2fbd Reviewed-on: https://gerrit.libreoffice.org/c/core/+/152117 Reviewed-by: László Németh <nemeth@numbertext.org> Tested-by: László Németh <nemeth@numbertext.org>
-rw-r--r--sc/inc/conditio.hxx2
-rw-r--r--sc/qa/unit/data/xlsx/tdf155321.xlsxbin0 -> 8267 bytes
-rw-r--r--sc/qa/unit/subsequent_filters_test.cxx11
-rw-r--r--sc/source/core/data/colorscale.cxx8
4 files changed, 18 insertions, 3 deletions
diff --git a/sc/inc/conditio.hxx b/sc/inc/conditio.hxx
index 51786d3dc712..47f5fdb3addb 100644
--- a/sc/inc/conditio.hxx
+++ b/sc/inc/conditio.hxx
@@ -208,7 +208,7 @@ class ScConditionalFormat;
struct ScDataBarInfo;
struct ScIconSetInfo;
-struct ScCondFormatData
+struct SC_DLLPUBLIC ScCondFormatData
{
ScCondFormatData();
ScCondFormatData(ScCondFormatData&&);
diff --git a/sc/qa/unit/data/xlsx/tdf155321.xlsx b/sc/qa/unit/data/xlsx/tdf155321.xlsx
new file mode 100644
index 000000000000..42299ff746cb
--- /dev/null
+++ b/sc/qa/unit/data/xlsx/tdf155321.xlsx
Binary files differ
diff --git a/sc/qa/unit/subsequent_filters_test.cxx b/sc/qa/unit/subsequent_filters_test.cxx
index 535afe72d818..d206ce2cbf69 100644
--- a/sc/qa/unit/subsequent_filters_test.cxx
+++ b/sc/qa/unit/subsequent_filters_test.cxx
@@ -123,6 +123,17 @@ void testContentImpl(ScDocument& rDoc, bool bCheckMergedCells)
}
}
+CPPUNIT_TEST_FIXTURE(ScFiltersTest, testTdf155321_CondFormatColor_XLSX)
+{
+ createScDoc("xlsx/tdf155321.xlsx");
+
+ ScDocument* pDoc = getScDoc();
+ ScConditionalFormat* pCondFormat = pDoc->GetCondFormat(0, 0, 0);
+ ScRefCellValue aCellB1(*pDoc, ScAddress(1, 0, 0));
+ Color aColor = pCondFormat->GetData(aCellB1, ScAddress(1, 0, 0)).mxColorScale.value();
+ CPPUNIT_ASSERT_EQUAL(Color(99, 190, 123), aColor);
+}
+
CPPUNIT_TEST_FIXTURE(ScFiltersTest, testTdf138601_CondFormatXLSX)
{
createScDoc("xlsx/tdf138601.xlsx");
diff --git a/sc/source/core/data/colorscale.cxx b/sc/source/core/data/colorscale.cxx
index 1d713c447c5b..4e61dbdbc228 100644
--- a/sc/source/core/data/colorscale.cxx
+++ b/sc/source/core/data/colorscale.cxx
@@ -657,11 +657,15 @@ std::optional<Color> ScColorScaleFormat::GetColor( const ScAddress& rAddr ) cons
double nValMax = CalcValue(nMin, nMax, itr);
Color rColMax = (*itr)->GetColor();
+ // tdf#155321 for the last percentile value, use always the end of the color scale,
+ // i.e. not the first possible color in the case of repeating values
+ bool bEqual = COLORSCALE_PERCENTILE == (*itr)->GetType() && nVal == nMax && nVal == nValMax;
+
++itr;
- while(itr != end() && nVal > nValMax)
+ while(itr != end() && (nVal > nValMax || bEqual))
{
rColMin = rColMax;
- nValMin = nValMax;
+ nValMin = !bEqual ? nValMax : nValMax - 1;
rColMax = (*itr)->GetColor();
nValMax = CalcValue(nMin, nMax, itr);
++itr;