chart2/source/view/axes/VCartesianAxis.cxx         |    7 +
 chart2/source/view/main/DataTableView.cxx          |    9 +-
 chart2/source/view/main/SeriesPlotterContainer.cxx |    7 -
 chart2/source/view/main/SeriesPlotterContainer.hxx |    2 
 sw/qa/extras/layout/data/charttable.odt            |binary
 sw/qa/extras/layout/data/tdf159443.odt             |binary
 sw/qa/extras/layout/layout3.cxx                    |   91 +++++++++++++++++++++
 7 files changed, 106 insertions(+), 10 deletions(-)

New commits:
commit 5b9bf5fac2fc0fc3a9ab7b2a4c23d63f13b1a212
Author:     Balazs Varga <balazs.varga.ext...@allotropia.de>
AuthorDate: Thu Mar 7 14:32:44 2024 +0100
Commit:     Balazs Varga <balazs.varga.ext...@allotropia.de>
CommitDate: Fri Mar 8 11:04:00 2024 +0100

    tdf#159456 - chart view: fix wrongly shifted value Y axis
    
    We only have to shift the category axis only, and not the
    value axis, if we have a chart data table.
    
    Change-Id: Ie77ea829e8f8987702dce7d17cb3e20054f3d8cc
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/164539
    Tested-by: Jenkins
    Reviewed-by: Balazs Varga <balazs.varga.ext...@allotropia.de>

diff --git a/chart2/source/view/main/SeriesPlotterContainer.cxx 
b/chart2/source/view/main/SeriesPlotterContainer.cxx
index bcc5b0f482a3..7623992a3e08 100644
--- a/chart2/source/view/main/SeriesPlotterContainer.cxx
+++ b/chart2/source/view/main/SeriesPlotterContainer.cxx
@@ -171,7 +171,7 @@ void 
SeriesPlotterContainer::initializeCooSysAndSeriesPlotter(ChartModel& rChart
     }
 
     if (xDiagram->getDataTable().is())
-        m_bForceShiftPosition = true;
+        m_bTableShiftPosition = true;
 
     //prepare for autoscaling and shape creation
     // - create plotter for charttypes (for each first scale group at each 
plotter, as they are independent)
@@ -340,12 +340,9 @@ void 
SeriesPlotterContainer::initializeCooSysAndSeriesPlotter(ChartModel& rChart
 bool SeriesPlotterContainer::isCategoryPositionShifted(const 
chart2::ScaleData& rSourceScale,
                                                        bool 
bHasComplexCategories)
 {
-    if (m_bForceShiftPosition)
-        return true;
-
     if (rSourceScale.AxisType == AxisType::CATEGORY)
         return bHasComplexCategories || rSourceScale.ShiftedCategoryPosition
-               || m_bChartTypeUsesShiftedCategoryPositionPerDefault;
+               || m_bTableShiftPosition || 
m_bChartTypeUsesShiftedCategoryPositionPerDefault;
 
     if (rSourceScale.AxisType == AxisType::DATE)
         return rSourceScale.ShiftedCategoryPosition;
diff --git a/chart2/source/view/main/SeriesPlotterContainer.hxx 
b/chart2/source/view/main/SeriesPlotterContainer.hxx
index 578f2ba2760c..38f3c8b909c8 100644
--- a/chart2/source/view/main/SeriesPlotterContainer.hxx
+++ b/chart2/source/view/main/SeriesPlotterContainer.hxx
@@ -151,7 +151,7 @@ private:
     sal_Int32 m_nMaxAxisIndex;
 
     bool m_bChartTypeUsesShiftedCategoryPositionPerDefault;
-    bool m_bForceShiftPosition = false;
+    bool m_bTableShiftPosition = false;
     sal_Int32 m_nDefaultDateNumberFormat;
 };
 
diff --git a/sw/qa/extras/layout/layout3.cxx b/sw/qa/extras/layout/layout3.cxx
index eae1d65e7a90..26186d36ea72 100644
--- a/sw/qa/extras/layout/layout3.cxx
+++ b/sw/qa/extras/layout/layout3.cxx
@@ -1965,6 +1965,31 @@ CPPUNIT_TEST_FIXTURE(SwLayoutWriter3, testTdf159422)
     CPPUNIT_ASSERT_DOUBLES_EQUAL(6573, nYSymbol3, 20);
 }
 
+CPPUNIT_TEST_FIXTURE(SwLayoutWriter3, testTdf159456)
+{
+    // Given a document with chart, which have a datatable
+    createSwDoc("charttable.odt");
+    SwDoc* pDoc = getSwDoc();
+    SwDocShell* pShell = pDoc->GetDocShell();
+
+    // Dump the rendering of the first page as an XML file.
+    std::shared_ptr<GDIMetaFile> xMetaFile = pShell->GetPreviewMetaFile();
+    MetafileXmlDump dumper;
+    xmlDocUniquePtr pXmlDoc = dumpAndParse(dumper, *xMetaFile);
+    //// Without the fix, this would fail:
+    //// - Expected: 1
+    //// - Actual  : 1.5
+    //// - In <>, XPath contents of child does not match
+    assertXPathContent(pXmlDoc,
+                       
"/metafile/push[1]/push[1]/push[1]/push[3]/push[1]/push[1]/push[1]/"
+                       "push[103]/textarray/text",
+                       "1");
+    assertXPathContent(pXmlDoc,
+                       
"/metafile/push[1]/push[1]/push[1]/push[3]/push[1]/push[1]/push[1]/"
+                       "push[104]/textarray/text",
+                       "2");
+}
+
 CPPUNIT_PLUGIN_IMPLEMENT();
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
commit 2ddbe0a75a82b8833b1d4b2f9143e70db1569434
Author:     Balazs Varga <balazs.varga.ext...@allotropia.de>
AuthorDate: Wed Mar 6 22:52:44 2024 +0100
Commit:     Balazs Varga <balazs.varga.ext...@allotropia.de>
CommitDate: Fri Mar 8 11:01:04 2024 +0100

    tdf#159422 - chart view: fix symbols position of data table legend
    
    Calculate the correct/optimal row height after calculating and set
    correct width of a table cell. Then we will have the correct row height
    for the symbol positions.
    
    Change-Id: I65bc0f0579ea100906b0b32449c2200a54c2a353
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/164512
    Tested-by: Jenkins
    Reviewed-by: Balazs Varga <balazs.varga.ext...@allotropia.de>

diff --git a/chart2/source/view/main/DataTableView.cxx 
b/chart2/source/view/main/DataTableView.cxx
index c3c807ca099b..eacd91a6a651 100644
--- a/chart2/source/view/main/DataTableView.cxx
+++ b/chart2/source/view/main/DataTableView.cxx
@@ -455,11 +455,9 @@ void DataTableView::createShapes(basegfx::B2DVector const& 
rStart, basegfx::B2DV
         nRow++;
     }
 
+    // force recalculation of column widths in the table shape
     xBroadcaster->unlockBroadcasts();
-
-    // force recalculation of all cells in the table shape
     pTableObject->DistributeColumns(0, nColumnCount, true, true);
-    pTableObject->DistributeRows(0, nRowCount, true, true);
 
     xBroadcaster->lockBroadcasts();
 
@@ -477,6 +475,10 @@ void DataTableView::createShapes(basegfx::B2DVector const& 
rStart, basegfx::B2DV
         xPropertySet->setPropertyValue("Width", uno::Any(nColumnWidth));
     }
 
+    // force recalculation of row heights in the table shape
+    xBroadcaster->unlockBroadcasts();
+    pTableObject->DistributeRows(0, nRowCount, true, true);
+
     if (bKeys)
     {
         sal_Int32 nTotalHeight = 0;
@@ -501,7 +503,6 @@ void DataTableView::createShapes(basegfx::B2DVector const& 
rStart, basegfx::B2DV
             }
         }
     }
-    xBroadcaster->unlockBroadcasts();
 }
 
 void DataTableView::changePosition(sal_Int32 x, sal_Int32 y)
diff --git a/sw/qa/extras/layout/data/charttable.odt 
b/sw/qa/extras/layout/data/charttable.odt
new file mode 100644
index 000000000000..e8dfa37d8006
Binary files /dev/null and b/sw/qa/extras/layout/data/charttable.odt differ
diff --git a/sw/qa/extras/layout/layout3.cxx b/sw/qa/extras/layout/layout3.cxx
index 5535299df050..eae1d65e7a90 100644
--- a/sw/qa/extras/layout/layout3.cxx
+++ b/sw/qa/extras/layout/layout3.cxx
@@ -1929,6 +1929,42 @@ CPPUNIT_TEST_FIXTURE(SwLayoutWriter3, testTdf159443)
         "4.3");
 }
 
+CPPUNIT_TEST_FIXTURE(SwLayoutWriter3, testTdf159422)
+{
+    // Given a document with chart, which have a datatable
+    createSwDoc("charttable.odt");
+    SwDoc* pDoc = getSwDoc();
+    SwDocShell* pShell = pDoc->GetDocShell();
+
+    // Dump the rendering of the first page as an XML file.
+    std::shared_ptr<GDIMetaFile> xMetaFile = pShell->GetPreviewMetaFile();
+    MetafileXmlDump dumper;
+    xmlDocUniquePtr pXmlDoc = dumpAndParse(dumper, *xMetaFile);
+    CPPUNIT_ASSERT(pXmlDoc);
+    //// Without the fix, this would fail:
+    //// - Expected: 5877
+    //// - Actual  : 5649
+    //// - Delta   : 20
+    sal_Int32 nYSymbol1 = getXPath(pXmlDoc,
+                                   
"/metafile/push[1]/push[1]/push[1]/push[3]/push[1]/push[1]/"
+                                   
"push[1]/push[99]/polypolygon/polygon/point[1]",
+                                   "y")
+                              .toInt32();
+    CPPUNIT_ASSERT_DOUBLES_EQUAL(5877, nYSymbol1, 20);
+    sal_Int32 nYSymbol2 = getXPath(pXmlDoc,
+                                   
"/metafile/push[1]/push[1]/push[1]/push[3]/push[1]/push[1]/"
+                                   
"push[1]/push[100]/polypolygon/polygon/point[1]",
+                                   "y")
+                              .toInt32();
+    CPPUNIT_ASSERT_DOUBLES_EQUAL(6225, nYSymbol2, 20);
+    sal_Int32 nYSymbol3 = getXPath(pXmlDoc,
+                                   
"/metafile/push[1]/push[1]/push[1]/push[3]/push[1]/push[1]/"
+                                   
"push[1]/push[101]/polypolygon/polygon/point[1]",
+                                   "y")
+                              .toInt32();
+    CPPUNIT_ASSERT_DOUBLES_EQUAL(6573, nYSymbol3, 20);
+}
+
 CPPUNIT_PLUGIN_IMPLEMENT();
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
commit 200ccd29bd70066c3eb91e52853ce1f0e5f648ed
Author:     Balazs Varga <balazs.varga.ext...@allotropia.de>
AuthorDate: Wed Mar 6 14:54:22 2024 +0100
Commit:     Balazs Varga <balazs.varga.ext...@allotropia.de>
CommitDate: Fri Mar 8 10:57:42 2024 +0100

    tdf#159443 - chart view: fix Data table is not rendered below chart
    
    If we have 1 dataseries we will have no tickmarks, in that case the
    distance between two tickmarks is the width of the chart.
    
    Change-Id: Ifea11329f1dcb80e8e390c1408306d1df7d49ded
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/164471
    Tested-by: Jenkins
    Reviewed-by: Balazs Varga <balazs.varga.ext...@allotropia.de>

diff --git a/chart2/source/view/axes/VCartesianAxis.cxx 
b/chart2/source/view/axes/VCartesianAxis.cxx
index 8bd6690ff3ca..3046d66dffcf 100644
--- a/chart2/source/view/axes/VCartesianAxis.cxx
+++ b/chart2/source/view/axes/VCartesianAxis.cxx
@@ -1687,6 +1687,13 @@ void 
VCartesianAxis::createDataTableShape(std::unique_ptr<TickFactory2D> const&
             nDistance *= 2;
     }
 
+    if (nDistance <= 0)
+    {
+        // we only have one data series so we have no TickMarks, therefor 
calculate and use the table size
+        auto rDelta = aEnd - aStart;
+        nDistance = basegfx::fround(rDelta.getX());
+    }
+
     if (nDistance > 0)
     {
         m_pDataTableView->createShapes(aStart, aEnd, nDistance);
diff --git a/sw/qa/extras/layout/data/tdf159443.odt 
b/sw/qa/extras/layout/data/tdf159443.odt
new file mode 100644
index 000000000000..8ec733aedb06
Binary files /dev/null and b/sw/qa/extras/layout/data/tdf159443.odt differ
diff --git a/sw/qa/extras/layout/layout3.cxx b/sw/qa/extras/layout/layout3.cxx
index cda801c4334c..5535299df050 100644
--- a/sw/qa/extras/layout/layout3.cxx
+++ b/sw/qa/extras/layout/layout3.cxx
@@ -1899,6 +1899,36 @@ CPPUNIT_TEST_FIXTURE(SwLayoutWriter3, testTdf155611)
     // Also must not crash on close because of a frame that accidentally fell 
off of the layout
 }
 
+CPPUNIT_TEST_FIXTURE(SwLayoutWriter3, testTdf159443)
+{
+    // Given a document with chart, which have a datatable
+    createSwDoc("tdf159443.odt");
+    SwDoc* pDoc = getSwDoc();
+    SwDocShell* pShell = pDoc->GetDocShell();
+
+    // Dump the rendering of the first page as an XML file.
+    std::shared_ptr<GDIMetaFile> xMetaFile = pShell->GetPreviewMetaFile();
+    MetafileXmlDump dumper;
+    xmlDocUniquePtr pXmlDoc = dumpAndParse(dumper, *xMetaFile);
+    CPPUNIT_ASSERT(pXmlDoc);
+    //// Without the fix, this would fail:
+    //// - Expected: DataSeries1
+    //// - Actual  : 1.25
+    //// - In <>, XPath contents of child does not match
+    assertXPathContent(
+        pXmlDoc,
+        
"/metafile/push[1]/push[1]/push[1]/push[3]/push[1]/push[1]/push[1]/push[47]/textarray/text",
+        "DataSeries1");
+    assertXPathContent(
+        pXmlDoc,
+        
"/metafile/push[1]/push[1]/push[1]/push[3]/push[1]/push[1]/push[1]/push[49]/textarray/text",
+        "Category1");
+    assertXPathContent(
+        pXmlDoc,
+        
"/metafile/push[1]/push[1]/push[1]/push[3]/push[1]/push[1]/push[1]/push[51]/textarray/text",
+        "4.3");
+}
+
 CPPUNIT_PLUGIN_IMPLEMENT();
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Reply via email to