chart2/source/controller/itemsetwrapper/SchWhichPairs.hxx |    1 
 chart2/source/view/axes/VAxisProperties.cxx               |   13 ++
 chart2/source/view/axes/VAxisProperties.hxx               |    3 
 chart2/source/view/axes/VCartesianAxis.cxx                |   72 ++++++++------
 chart2/source/view/axes/VCartesianAxis.hxx                |    2 
 chart2/source/view/inc/DataTableView.hxx                  |    9 +
 chart2/source/view/main/DataTableView.cxx                 |   70 +++++++++----
 7 files changed, 119 insertions(+), 51 deletions(-)

New commits:
commit 387e01bb088c958a4dbc3eec5bb98bf655b48ccb
Author:     Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk>
AuthorDate: Sat Aug 13 14:14:00 2022 +0200
Commit:     Tomaž Vajngerl <qui...@gmail.com>
CommitDate: Thu Aug 25 07:28:35 2022 +0200

    chart2: support data table rendering when the X axis is swapped
    
    In case when the X axis is swapped, so the Y axis is rendered in
    the place of X axis, we need to render the data table below the
    Y-axis labels. This is best done to put the data table into the
    Y-axis instead, so we get the correct size and position of the
    data table, and then just allow rendering of the axis labels and
    (re)position the table below Y-axis.
    
    Change-Id: I74aa79402a5638133b0d1ed83bbd8aad6f6c9d1d
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/138336
    Tested-by: Jenkins
    Reviewed-by: Tomaž Vajngerl <qui...@gmail.com>
    (cherry picked from commit addcd016bf1bed16299697fd18b8f9b1faf2cf3f)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/138783
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com>

diff --git a/chart2/source/view/axes/VAxisProperties.cxx 
b/chart2/source/view/axes/VAxisProperties.cxx
index 48cc3569f46d..0cbf487453f5 100644
--- a/chart2/source/view/axes/VAxisProperties.cxx
+++ b/chart2/source/view/axes/VAxisProperties.cxx
@@ -258,7 +258,7 @@ void AxisProperties::init( bool bCartesian )
 
     if( bCartesian )
     {
-        if (m_nDimensionIndex == 0)
+        if ((!m_bSwapXAndY && m_nDimensionIndex == 0) || (m_bSwapXAndY && 
m_nDimensionIndex == 1))
         {
             m_bDisplayDataTable = m_xDataTableModel.is();
         }
@@ -333,6 +333,17 @@ void AxisProperties::init( bool bCartesian )
     {
         TOOLS_WARN_EXCEPTION("chart2", "" );
     }
+
+    if (m_bDisplayDataTable)
+    {
+        m_bDataTableAlignAxisValuesWithColumns = (m_nDimensionIndex == 0);
+
+        if (m_nDimensionIndex == 0)
+        {
+            m_bDisplayLabels = false;
+        }
+
+    }
 }
 
 AxisLabelProperties::AxisLabelProperties()
diff --git a/chart2/source/view/axes/VAxisProperties.hxx 
b/chart2/source/view/axes/VAxisProperties.hxx
index 425792da689b..15f9da910e5d 100644
--- a/chart2/source/view/axes/VAxisProperties.hxx
+++ b/chart2/source/view/axes/VAxisProperties.hxx
@@ -109,7 +109,10 @@ struct AxisProperties final
 
     AxisLabelAlignment maLabelAlignment;
 
+    // Data table
     bool m_bDisplayDataTable;
+    bool m_bDataTableAlignAxisValuesWithColumns;
+
     bool m_bDisplayLabels;
 
     // Compatibility option: starting from LibreOffice 5.1 the rotated
diff --git a/chart2/source/view/axes/VCartesianAxis.cxx 
b/chart2/source/view/axes/VCartesianAxis.cxx
index 76884e8fc255..d5da1d3bf966 100644
--- a/chart2/source/view/axes/VCartesianAxis.cxx
+++ b/chart2/source/view/axes/VCartesianAxis.cxx
@@ -1675,35 +1675,43 @@ void VCartesianAxis::doStaggeringOfLabels( const 
AxisLabelProperties& rAxisLabel
     }
 }
 
-void VCartesianAxis::createLabels()
+void VCartesianAxis::createDataTableShape(std::unique_ptr<TickFactory2D> 
const& rpTickFactory2D)
 {
-    if( !prepareShapeCreation() )
+    // Check if we can create the data table shape
+    // Data table view and m_bDisplayDataTable must be true
+    if (!m_pDataTableView || !m_aAxisProperties.m_bDisplayDataTable)
         return;
 
-    std::unique_ptr<TickFactory2D> apTickFactory2D(createTickFactory2D()); // 
throws on failure
+    m_pDataTableView->initializeShapes(m_xDataTableTarget);
+    basegfx::B2DVector aStart = rpTickFactory2D->getXaxisStartPos();
+    basegfx::B2DVector aEnd = rpTickFactory2D->getXaxisEndPos();
 
-    if (m_pDataTableView && m_aAxisProperties.m_bDisplayDataTable)
-    {
-        m_pDataTableView->initializeShapes(m_xDataTableTarget);
-        basegfx::B2DVector aStart = apTickFactory2D->getXaxisStartPos();
-        basegfx::B2DVector aEnd = apTickFactory2D->getXaxisEndPos();
+    rpTickFactory2D->updateScreenValues(m_aAllTickInfos);
 
-        apTickFactory2D->updateScreenValues(m_aAllTickInfos);
+    sal_Int32 nDistance = -1;
 
-        sal_Int32 nDistance = -1;
+    std::unique_ptr<TickIter> apTickIter(createLabelTickIterator(0));
+    if (apTickIter)
+    {
+        nDistance = TickFactory2D::getTickScreenDistance(*apTickIter);
+        if (getTextLevelCount() > 1)
+            nDistance *= 2;
+    }
 
-        std::unique_ptr<TickIter> apTickIter(createLabelTickIterator(0));
-        if (apTickIter)
-        {
-            nDistance = TickFactory2D::getTickScreenDistance(*apTickIter);
-            if (getTextLevelCount() > 1)
-                nDistance *= 2;
-        }
+    if (nDistance > 0)
+    {
+        m_pDataTableView->createShapes(aStart, aEnd, nDistance);
+    }
+}
 
-        if (nDistance > 0)
-            m_pDataTableView->createShapes(aStart, aEnd, nDistance);
+void VCartesianAxis::createLabels()
+{
+    if( !prepareShapeCreation() )
         return;
-    }
+
+    std::unique_ptr<TickFactory2D> apTickFactory2D(createTickFactory2D()); // 
throws on failure
+
+    createDataTableShape(apTickFactory2D);
 
     //create labels
     if (!m_aAxisProperties.m_bDisplayLabels)
@@ -1755,6 +1763,18 @@ void VCartesianAxis::createLabels()
         }
     }
     doStaggeringOfLabels( m_aAxisLabelProperties, pTickFactory2D );
+
+    if (m_pDataTableView)
+    {
+        uno::Reference<drawing::XShape> xShape(m_xTextTarget, uno::UNO_QUERY);
+        if (xShape.is())
+        {
+            sal_Int32 x = xShape->getPosition().X;
+            sal_Int32 y = xShape->getPosition().Y;
+            sal_Int32 height = xShape->getSize().Height;
+            m_pDataTableView->changePosition(x, y + height);
+        }
+    }
 }
 
 void VCartesianAxis::createMaximumLabels()
@@ -2012,12 +2032,12 @@ void 
VCartesianAxis::createDataTableView(std::vector<std::unique_ptr<VSeriesPlot
                                          
uno::Reference<chart2::XChartDocument> const& xChartDoc,
                                          
uno::Reference<uno::XComponentContext> const& rComponentContext)
 {
-    if (m_aAxisProperties.m_bDisplayDataTable)
-    {
-        m_pDataTableView.reset(new DataTableView(xChartDoc, 
m_aAxisProperties.m_xDataTableModel, rComponentContext));
-        m_pDataTableView->initializeValues(rSeriesPlotterList);
-        m_xNumberFormatsSupplier = xNumberFormatsSupplier;
-    }
+    if (!m_aAxisProperties.m_bDisplayDataTable)
+        return;
+
+    m_pDataTableView.reset(new DataTableView(xChartDoc, 
m_aAxisProperties.m_xDataTableModel, rComponentContext, 
m_aAxisProperties.m_bDataTableAlignAxisValuesWithColumns));
+    m_pDataTableView->initializeValues(rSeriesPlotterList);
+    m_xNumberFormatsSupplier = xNumberFormatsSupplier;
 }
 
 
diff --git a/chart2/source/view/axes/VCartesianAxis.hxx 
b/chart2/source/view/axes/VCartesianAxis.hxx
index 2be55c239c67..6ded7ac125a8 100644
--- a/chart2/source/view/axes/VCartesianAxis.hxx
+++ b/chart2/source/view/axes/VCartesianAxis.hxx
@@ -156,6 +156,8 @@ private: //methods
 
     ::basegfx::B2DVector getScreenPosition( double fLogicX, double fLogicY, 
double fLogicZ ) const;
     ScreenPosAndLogicPos getScreenPosAndLogicPos( double fLogicX, double 
fLogicY, double fLogicZ ) const;
+
+    void createDataTableShape(std::unique_ptr<TickFactory2D> const& 
rTickFactory2D);
 };
 
 } //namespace chart
diff --git a/chart2/source/view/inc/DataTableView.hxx 
b/chart2/source/view/inc/DataTableView.hxx
index edeb7e6a8310..4cd92a24ef11 100644
--- a/chart2/source/view/inc/DataTableView.hxx
+++ b/chart2/source/view/inc/DataTableView.hxx
@@ -15,6 +15,7 @@
 #include <com/sun/star/chart2/XChartDocument.hpp>
 #include <com/sun/star/text/XTextRange.hpp>
 #include <com/sun/star/text/XText.hpp>
+#include <com/sun/star/table/XTable.hpp>
 #include <com/sun/star/uno/XComponentContext.hpp>
 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
 #include <DataTable.hxx>
@@ -33,12 +34,14 @@ private:
     rtl::Reference<DataTable> m_xDataTableModel;
     css::uno::Reference<css::lang::XMultiServiceFactory> m_xShapeFactory;
     css::uno::Reference<css::uno::XComponentContext> m_xComponentContext;
+    css::uno::Reference<css::table::XTable> m_xTable;
     VLineProperties m_aLineProperties;
     std::vector<VSeriesPlotter*> m_pSeriesPlotterList;
 
     std::vector<OUString> m_aDataSeriesNames;
     std::vector<OUString> m_aXValues;
     std::vector<std::vector<OUString>> m_pDataSeriesValues;
+    bool m_bAlignAxisValuesWithColumns;
 
     void
     
setCellCharAndParagraphProperties(css::uno::Reference<css::beans::XPropertySet>&
 xPropertySet);
@@ -49,11 +52,13 @@ private:
 public:
     DataTableView(css::uno::Reference<css::chart2::XChartDocument> const& 
xChartDoc,
                   rtl::Reference<DataTable> const& rDataTableModel,
-                  css::uno::Reference<css::uno::XComponentContext> const& 
rComponentContext);
+                  css::uno::Reference<css::uno::XComponentContext> const& 
rComponentContext,
+                  bool bAlignAxisValuesWithColumns);
     void initializeShapes(const css::uno::Reference<css::drawing::XShapes>& 
xTarget);
     void initializeValues(std::vector<std::unique_ptr<VSeriesPlotter>>& 
rSeriesPlotterList);
     void createShapes(basegfx::B2DVector const& rStart, basegfx::B2DVector 
const& rEnd,
-                      sal_Int32 nColumnWidth);
+                      sal_Int32 nAxisStepWidth);
+    void changePosition(sal_Int32 x, sal_Int32 y);
 };
 
 } //namespace chart
diff --git a/chart2/source/view/main/DataTableView.cxx 
b/chart2/source/view/main/DataTableView.cxx
index e8de2ff0846c..ab4c224ddf18 100644
--- a/chart2/source/view/main/DataTableView.cxx
+++ b/chart2/source/view/main/DataTableView.cxx
@@ -16,11 +16,12 @@
 
 #include <svx/svdotable.hxx>
 
-#include <com/sun/star/table/XTable.hpp>
 #include <com/sun/star/table/BorderLine.hpp>
 #include <com/sun/star/table/BorderLine2.hpp>
 #include <com/sun/star/table/TableBorder.hpp>
 #include <com/sun/star/table/BorderLineStyle.hpp>
+#include <com/sun/star/text/XTextRange.hpp>
+#include <com/sun/star/text/XText.hpp>
 #include <com/sun/star/style/ParagraphAdjust.hpp>
 #include <com/sun/star/drawing/TextHorizontalAdjust.hpp>
 #include <com/sun/star/drawing/TextVerticalAdjust.hpp>
@@ -85,10 +86,12 @@ getFirstParagraphProperties(uno::Reference<text::XText> 
const& xText)
 
 DataTableView::DataTableView(uno::Reference<chart2::XChartDocument> const& 
xChartDoc,
                              rtl::Reference<DataTable> const& rDataTableModel,
-                             uno::Reference<uno::XComponentContext> const& 
rComponentContext)
+                             uno::Reference<uno::XComponentContext> const& 
rComponentContext,
+                             bool bAlignAxisValuesWithColumns)
     : m_xChartModel(xChartDoc)
     , m_xDataTableModel(rDataTableModel)
     , m_xComponentContext(rComponentContext)
+    , m_bAlignAxisValuesWithColumns(bAlignAxisValuesWithColumns)
 {
     uno::Reference<beans::XPropertySet> xPropertySet(m_xDataTableModel);
     m_aLineProperties.initFromPropertySet(xPropertySet);
@@ -225,7 +228,7 @@ void 
DataTableView::setCellProperties(css::uno::Reference<beans::XPropertySet>&
 }
 
 void DataTableView::createShapes(basegfx::B2DVector const& rStart, 
basegfx::B2DVector const& rEnd,
-                                 sal_Int32 nColumnWidth)
+                                 sal_Int32 nAxisStepWidth)
 {
     if (!m_xTarget.is())
         return;
@@ -235,22 +238,23 @@ void DataTableView::createShapes(basegfx::B2DVector 
const& rStart, basegfx::B2DV
     auto sCID = 
ObjectIdentifier::createClassifiedIdentifierForParticle(sParticle);
     m_xTableShape = ShapeFactory::createTable(m_xTarget, sCID);
 
-    uno::Reference<table::XTable> xTable;
+    auto rDelta = rEnd - rStart;
+    sal_Int32 nTableSize = basegfx::fround(rDelta.getX());
+    m_xTableShape->setSize({ nTableSize, 0 });
+
     try
     {
-        auto rDelta = rEnd - rStart;
-        m_xTableShape->setSize({ basegfx::fround(rDelta.getX()), 0 });
-        m_xTableShape->getPropertyValue("Model") >>= xTable;
+        m_xTableShape->getPropertyValue("Model") >>= m_xTable;
     }
     catch (const uno::Exception&)
     {
         return;
     }
 
-    if (!xTable.is())
+    if (!m_xTable.is())
         return;
 
-    uno::Reference<util::XBroadcaster> xBroadcaster(xTable, uno::UNO_QUERY);
+    uno::Reference<util::XBroadcaster> xBroadcaster(m_xTable, uno::UNO_QUERY);
 
     if (!xBroadcaster.is())
         return;
@@ -272,15 +276,24 @@ void DataTableView::createShapes(basegfx::B2DVector 
const& rStart, basegfx::B2DV
     m_xDataTableModel->getPropertyValue("Keys") >>= bKeys;
 
     sal_Int32 nColumnCount = m_aXValues.size();
-    uno::Reference<table::XTableColumns> xTableColumns = xTable->getColumns();
+    uno::Reference<table::XTableColumns> xTableColumns = 
m_xTable->getColumns();
     xTableColumns->insertByIndex(0, nColumnCount);
 
     sal_Int32 nRowCount = m_aDataSeriesNames.size();
-    uno::Reference<table::XTableRows> xTableRows = xTable->getRows();
+    uno::Reference<table::XTableRows> xTableRows = m_xTable->getRows();
     xTableRows->insertByIndex(0, nRowCount);
 
+    sal_Int32 nColumnWidth = 0.0;
+
+    // If we don't align, we have to calculate the column width ourselves
+    if (m_bAlignAxisValuesWithColumns)
+        nColumnWidth = nAxisStepWidth;
+    else
+        nColumnWidth = double(nTableSize) / nColumnCount;
+
+    // Setup empty top-left cell
     {
-        uno::Reference<table::XCell> xCell = xTable->getCellByPosition(0, 0);
+        uno::Reference<table::XCell> xCell = m_xTable->getCellByPosition(0, 0);
         uno::Reference<beans::XPropertySet> xPropertySet(xCell, 
uno::UNO_QUERY);
         if (xPropertySet.is())
         {
@@ -296,7 +309,7 @@ void DataTableView::createShapes(basegfx::B2DVector const& 
rStart, basegfx::B2DV
     nColumn = 1;
     for (auto const& rString : m_aXValues)
     {
-        uno::Reference<table::XCell> xCell = 
xTable->getCellByPosition(nColumn, 0);
+        uno::Reference<table::XCell> xCell = 
m_xTable->getCellByPosition(nColumn, 0);
         uno::Reference<beans::XPropertySet> xPropertySet(xCell, 
uno::UNO_QUERY);
         uno::Reference<text::XTextRange> xCellTextRange(xCell, uno::UNO_QUERY);
         if (xCellTextRange.is())
@@ -343,7 +356,7 @@ void DataTableView::createShapes(basegfx::B2DVector const& 
rStart, basegfx::B2DV
     nRow = 1;
     for (auto const& rSeriesName : m_aDataSeriesNames)
     {
-        uno::Reference<table::XCell> xCell = xTable->getCellByPosition(0, 
nRow);
+        uno::Reference<table::XCell> xCell = m_xTable->getCellByPosition(0, 
nRow);
         uno::Reference<beans::XPropertySet> xCellPropertySet(xCell, 
uno::UNO_QUERY);
         uno::Reference<text::XTextRange> xCellTextRange(xCell, uno::UNO_QUERY);
         if (xCellTextRange.is())
@@ -378,7 +391,7 @@ void DataTableView::createShapes(basegfx::B2DVector const& 
rStart, basegfx::B2DV
         nColumn = 1;
         for (auto const& rValue : rSeries)
         {
-            uno::Reference<table::XCell> xCell = 
xTable->getCellByPosition(nColumn, nRow);
+            uno::Reference<table::XCell> xCell = 
m_xTable->getCellByPosition(nColumn, nRow);
             uno::Reference<beans::XPropertySet> xCellPropertySet(xCell, 
uno::UNO_QUERY);
             uno::Reference<text::XTextRange> xCellTextRange(xCell, 
uno::UNO_QUERY);
             if (xCellTextRange.is())
@@ -420,13 +433,13 @@ void DataTableView::createShapes(basegfx::B2DVector 
const& rStart, basegfx::B2DV
     pTableObject->DistributeRows(0, nRowCount - 1, true, true);
 
     xBroadcaster->lockBroadcasts();
-    uno::Reference<beans::XPropertySet> 
xPropertySet(xTableColumns->getByIndex(0), uno::UNO_QUERY);
-    sal_Int32 nWidth = 0;
-    xPropertySet->getPropertyValue("Width") >>= nWidth;
 
-    sal_Int32 nTableX = basegfx::fround(rStart.getX() - nWidth);
-    sal_Int32 nTableY = basegfx::fround(rStart.getY());
-    m_xTableShape->setPosition({ nTableX, nTableY });
+    changePosition(basegfx::fround(rStart.getX()), 
basegfx::fround(rStart.getY()));
+
+    sal_Int32 nTableX = m_xTableShape->getPosition().X;
+    sal_Int32 nTableY = m_xTableShape->getPosition().Y;
+
+    uno::Reference<beans::XPropertySet> 
xPropertySet(xTableColumns->getByIndex(0), uno::UNO_QUERY);
 
     for (sal_Int32 i = 1; i < xTableColumns->getCount(); ++i)
     {
@@ -456,6 +469,21 @@ void DataTableView::createShapes(basegfx::B2DVector const& 
rStart, basegfx::B2DV
     xBroadcaster->unlockBroadcasts();
 }
 
+void DataTableView::changePosition(sal_Int32 x, sal_Int32 y)
+{
+    if (!m_xTable.is())
+        return;
+
+    uno::Reference<table::XTableColumns> xTableColumns = 
m_xTable->getColumns();
+    uno::Reference<beans::XPropertySet> 
xPropertySet(xTableColumns->getByIndex(0), uno::UNO_QUERY);
+
+    sal_Int32 nWidth = 0;
+    xPropertySet->getPropertyValue("Width") >>= nWidth;
+    uno::Reference<drawing::XShape> xTargetShape(m_xTarget, uno::UNO_QUERY);
+    if (xTargetShape.is())
+        xTargetShape->setPosition({ x - nWidth, y });
+}
+
 void DataTableView::initializeShapes(const 
css::uno::Reference<css::drawing::XShapes>& xTarget)
 {
     m_xTarget = xTarget;
commit aefb99aa99710538f27b3bc054586f2dd9d49672
Author:     Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk>
AuthorDate: Fri Aug 12 23:22:54 2022 +0200
Commit:     Tomaž Vajngerl <qui...@gmail.com>
CommitDate: Thu Aug 25 07:28:20 2022 +0200

    chart2: we don't need SCHATTR_TEXT_* text ranges for data table
    
    Change-Id: I1c857ebe1ce4851f15da05291daecc09e7e74209
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/138335
    Tested-by: Tomaž Vajngerl <qui...@gmail.com>
    Reviewed-by: Tomaž Vajngerl <qui...@gmail.com>
    (cherry picked from commit 089f7b437326021beb0f61a05bdd180f1de8bb59)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/138782

diff --git a/chart2/source/controller/itemsetwrapper/SchWhichPairs.hxx 
b/chart2/source/controller/itemsetwrapper/SchWhichPairs.hxx
index 8d3f405573c5..93935677b738 100644
--- a/chart2/source/controller/itemsetwrapper/SchWhichPairs.hxx
+++ b/chart2/source/controller/itemsetwrapper/SchWhichPairs.hxx
@@ -171,7 +171,6 @@ const WhichRangesContainer 
nRegEquationWhichPairs(svl::Items<
 >);
 
 const WhichRangesContainer nDataTableWhichPairs(svl::Items<
-    SCHATTR_TEXT_START, SCHATTR_TEXT_END,
     SCHATTR_DATA_TABLE_START, SCHATTR_DATA_TABLE_END,
     XATTR_LINE_FIRST, XATTR_LINE_LAST,              //  1000 -  1016  
svx/xdef.hxx
     XATTR_FILL_FIRST, XATTR_FILL_LAST,              //  1018 -  1046  
svx/xdef.hxx

Reply via email to