sc/inc/conditio.hxx                    |    2 +-
 sc/qa/unit/data/xlsx/tdf155321.xlsx    |binary
 sc/qa/unit/subsequent_filters_test.cxx |   13 +++++++++++++
 sc/source/core/data/colorscale.cxx     |    8 ++++++--
 4 files changed, 20 insertions(+), 3 deletions(-)

New commits:
commit 808cc62e2f43e638598fc1f4869735138ccf8217
Author:     Tibor Nagy <nagy.tib...@nisz.hu>
AuthorDate: Mon May 22 14:20:59 2023 +0200
Commit:     László Németh <nem...@numbertext.org>
CommitDate: Mon Jun 5 13:20:32 2023 +0200

    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 <nem...@numbertext.org>
    Tested-by: László Németh <nem...@numbertext.org>
    Signed-off-by: Xisco Fauli <xiscofa...@libreoffice.org>
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/152491
    Tested-by: Jenkins

diff --git a/sc/inc/conditio.hxx b/sc/inc/conditio.hxx
index afd16ba27365..50b74bd8721c 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
Binary files /dev/null and b/sc/qa/unit/data/xlsx/tdf155321.xlsx differ
diff --git a/sc/qa/unit/subsequent_filters_test.cxx 
b/sc/qa/unit/subsequent_filters_test.cxx
index c080942d486d..2df33b125e66 100644
--- a/sc/qa/unit/subsequent_filters_test.cxx
+++ b/sc/qa/unit/subsequent_filters_test.cxx
@@ -78,6 +78,7 @@ public:
     ScFiltersTest();
 
     //ods, xls, xlsx filter tests
+    void testTdf155321_CondFormatColor_XLSX();
     void testTdf138601_CondFormatXLSX();
     void testContentODS();
     void testContentXLS();
@@ -210,6 +211,7 @@ public:
     void testForcepoint107();
 
     CPPUNIT_TEST_SUITE(ScFiltersTest);
+    CPPUNIT_TEST(testTdf155321_CondFormatColor_XLSX);
     CPPUNIT_TEST(testTdf138601_CondFormatXLSX);
     CPPUNIT_TEST(testContentODS);
     CPPUNIT_TEST(testContentXLS);
@@ -421,6 +423,17 @@ void testContentImpl(ScDocument& rDoc, bool 
bCheckMergedCells)
 }
 }
 
+void 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);
+}
+
 void ScFiltersTest::testTdf138601_CondFormatXLSX()
 {
     createScDoc("xlsx/tdf138601.xlsx");
diff --git a/sc/source/core/data/colorscale.cxx 
b/sc/source/core/data/colorscale.cxx
index 43be13b5f320..876d100840bf 100644
--- a/sc/source/core/data/colorscale.cxx
+++ b/sc/source/core/data/colorscale.cxx
@@ -636,11 +636,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;

Reply via email to