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

New commits:
commit 6a059f8d1b0a7a5b64bd272e1e7b8291979bcd56
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: Wed May 31 20:17:16 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>

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
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 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;

Reply via email to