diff options
author | Tomaž Vajngerl <tomaz.vajngerl@collabora.co.uk> | 2022-05-06 16:04:47 +0900 |
---|---|---|
committer | Tomaž Vajngerl <quikee@gmail.com> | 2022-07-17 09:19:11 +0200 |
commit | 53c71a0fa29b98d997ced6c9684c627442cfff94 (patch) | |
tree | 49b74f0c66f99e71cc206b5177c87ae76e4b8cc0 /chart2 | |
parent | 3c8e81669f2311dd35aa6787cbf3e5a6a0520433 (diff) |
chart2: add initial code for rendering the Data Table
Create a (svx) table with the data from the chart and place it below
the x-axis line.
Data table rendering is disabled in the code until the data table
properties are available.
Change-Id: I07d282c0b5e8df6b843516c8bdad538862d6575e
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/136788
Tested-by: Tomaž Vajngerl <quikee@gmail.com>
Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
Diffstat (limited to 'chart2')
18 files changed, 386 insertions, 42 deletions
diff --git a/chart2/Library_chartcore.mk b/chart2/Library_chartcore.mk index 2f1a1a9587f8..3d3806e14c27 100644 --- a/chart2/Library_chartcore.mk +++ b/chart2/Library_chartcore.mk @@ -97,6 +97,7 @@ $(eval $(call gb_Library_add_exception_objects,chartcore,\ chart2/source/view/main/ChartView \ chart2/source/view/main/Clipping \ chart2/source/view/main/DataPointSymbolSupplier \ + chart2/source/view/main/DataTableView \ chart2/source/view/main/DrawModelWrapper \ chart2/source/view/main/ExplicitValueProvider \ chart2/source/view/main/LabelPositionHelper \ diff --git a/chart2/source/view/axes/VAxisBase.cxx b/chart2/source/view/axes/VAxisBase.cxx index ace362a9b964..95125beed1cf 100644 --- a/chart2/source/view/axes/VAxisBase.cxx +++ b/chart2/source/view/axes/VAxisBase.cxx @@ -22,6 +22,7 @@ #include <ExplicitCategoriesProvider.hxx> #include "Tickmarks.hxx" #include <Axis.hxx> +#include <VSeriesPlotter.hxx> #include <com/sun/star/chart2/AxisType.hpp> #include <com/sun/star/chart2/data/XTextualDataSequence.hpp> @@ -183,8 +184,10 @@ bool VAxisBase::prepareShapeCreation() //create named group shape m_xGroupShape_Shapes = createGroupShape( m_xLogicTarget, m_nDimension==2 ? m_aCID : ""); - if( m_aAxisProperties.m_bDisplayLabels ) + if (m_aAxisProperties.m_bDisplayLabels) m_xTextTarget = ShapeFactory::createGroup2D( m_xFinalTarget, m_aCID ); + if (m_aAxisProperties.m_bDisplayDataTable) + m_xDataTableTarget = ShapeFactory::createGroup2D(m_xFinalTarget, m_aCID); return true; } @@ -239,6 +242,11 @@ void VAxisBase::updateUnscaledValuesAtTicks( TickIter& rIter ) } } +void VAxisBase::createDataTableView(std::vector<std::unique_ptr<VSeriesPlotter>>& /*rSeriesPlotterList*/, + uno::Reference<util::XNumberFormatsSupplier> const& /*xNumberFormatsSupplier*/) +{ +} + } //namespace chart /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/chart2/source/view/axes/VAxisBase.hxx b/chart2/source/view/axes/VAxisBase.hxx index 31badb749c9d..4da1936a452b 100644 --- a/chart2/source/view/axes/VAxisBase.hxx +++ b/chart2/source/view/axes/VAxisBase.hxx @@ -27,6 +27,9 @@ namespace com::sun::star::util { class XNumberFormatsSupplier; } namespace chart { +class VSeriesPlotter; +class DataTableView; + class VAxisBase : public VAxisOrGridBase { public: @@ -59,6 +62,11 @@ public: void setExtraLinePositionAtOtherAxis( double fCrossingAt ); + virtual void createDataTableView(std::vector<std::unique_ptr<VSeriesPlotter>>& rSeriesPlotterList, + css::uno::Reference<css::util::XNumberFormatsSupplier> const& xNumberFormatsSupplier); + + std::shared_ptr<DataTableView> getDataTableView() { return m_pDataTableView; } + protected: //methods static size_t getIndexOfLongestLabel( const css::uno::Sequence<OUString>& rLabels ); void removeTextShapesFromTicks(); @@ -79,6 +87,9 @@ protected: //member rtl::Reference< SvxShapeGroupAnyD > m_xGroupShape_Shapes; rtl::Reference< SvxShapeGroupAnyD > m_xTextTarget; + rtl::Reference< SvxShapeGroupAnyD > m_xDataTableTarget; + + std::shared_ptr<DataTableView> m_pDataTableView; /** * This typically consists of 2 TickInfo vectors (i.e. the outer vector diff --git a/chart2/source/view/axes/VAxisProperties.cxx b/chart2/source/view/axes/VAxisProperties.cxx index ff02c9edd8fe..d07cc33d8b9a 100644 --- a/chart2/source/view/axes/VAxisProperties.cxx +++ b/chart2/source/view/axes/VAxisProperties.cxx @@ -164,6 +164,7 @@ AxisProperties::AxisProperties( rtl::Reference< Axis > xAxisModel , m_eTickmarkPos( css::chart::ChartAxisMarkPosition_AT_LABELS_AND_AXIS ) , m_bCrossingAxisHasReverseDirection(false) , m_bCrossingAxisIsCategoryAxes(false) + , m_bDisplayDataTable(false) , m_bDisplayLabels( true ) , m_bTryStaggeringFirst( false ) , m_nNumberFormatKey(0) @@ -254,6 +255,9 @@ void AxisProperties::init( bool bCartesian ) if( bCartesian ) { + if (m_nDimensionIndex == 0) + m_bDisplayDataTable = false; + if( m_nDimensionIndex == 0 && m_nAxisType == AxisType::CATEGORY && m_pExplicitCategoriesProvider && m_pExplicitCategoriesProvider->hasComplexCategories() ) m_bComplexCategories = true; diff --git a/chart2/source/view/axes/VAxisProperties.hxx b/chart2/source/view/axes/VAxisProperties.hxx index d4ef653dc71f..d66b2f3a919e 100644 --- a/chart2/source/view/axes/VAxisProperties.hxx +++ b/chart2/source/view/axes/VAxisProperties.hxx @@ -110,7 +110,8 @@ struct AxisProperties final AxisLabelAlignment maLabelAlignment; - bool m_bDisplayLabels; + bool m_bDisplayDataTable; + bool m_bDisplayLabels; // Compatibility option: starting from LibreOffice 5.1 the rotated // layout is preferred to staggering for axis labels. diff --git a/chart2/source/view/axes/VCartesianAxis.cxx b/chart2/source/view/axes/VCartesianAxis.cxx index 0ea37f9a7848..2266dd143d2e 100644 --- a/chart2/source/view/axes/VCartesianAxis.cxx +++ b/chart2/source/view/axes/VCartesianAxis.cxx @@ -35,6 +35,8 @@ #include <tools/color.hxx> #include <svx/unoshape.hxx> #include <svx/unoshtxt.hxx> +#include <VSeriesPlotter.hxx> +#include <DataTableView.hxx> #include <comphelper/scopeguard.hxx> @@ -1666,11 +1668,35 @@ void VCartesianAxis::createLabels() if( !prepareShapeCreation() ) return; + std::unique_ptr<TickFactory2D> apTickFactory2D(createTickFactory2D()); // throws on failure + + if (m_pDataTableView && m_aAxisProperties.m_bDisplayDataTable) + { + m_pDataTableView->initializeShapes(m_xDataTableTarget); + basegfx::B2DVector aStart = apTickFactory2D->getXaxisStartPos(); + basegfx::B2DVector aEnd = apTickFactory2D->getXaxisEndPos(); + + apTickFactory2D->updateScreenValues(m_aAllTickInfos); + + sal_Int32 nDistance = -1; + + 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); + return; + } + //create labels if (!m_aAxisProperties.m_bDisplayLabels) return; - std::unique_ptr<TickFactory2D> apTickFactory2D(createTickFactory2D()); // throws on failure TickFactory2D* pTickFactory2D = apTickFactory2D.get(); //get the transformed screen values for all tickmarks in aAllTickInfos @@ -1966,6 +1992,18 @@ void VCartesianAxis::createShapes() createLabels(); } +void VCartesianAxis::createDataTableView(std::vector<std::unique_ptr<VSeriesPlotter>>& rSeriesPlotterList, + Reference<util::XNumberFormatsSupplier> const& xNumberFormatsSupplier) +{ + if (m_aAxisProperties.m_bDisplayDataTable) + { + m_pDataTableView.reset(new DataTableView); + m_pDataTableView->initializeValues(rSeriesPlotterList); + m_xNumberFormatsSupplier = xNumberFormatsSupplier; + } +} + + } //namespace chart /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/chart2/source/view/axes/VCartesianAxis.hxx b/chart2/source/view/axes/VCartesianAxis.hxx index 94e9b2ab967a..9f396fef43b8 100644 --- a/chart2/source/view/axes/VCartesianAxis.hxx +++ b/chart2/source/view/axes/VCartesianAxis.hxx @@ -99,6 +99,8 @@ public: ::basegfx::B2DVector aScreenPos; }; + void createDataTableView(std::vector<std::unique_ptr<VSeriesPlotter>>& rSeriesPlotterList, + css::uno::Reference<css::util::XNumberFormatsSupplier> const& xNumberFormatsSupplier) override; private: //methods /** * Go through all tick label positions and decide which labels to display diff --git a/chart2/source/view/axes/VCartesianCoordinateSystem.cxx b/chart2/source/view/axes/VCartesianCoordinateSystem.cxx index 1257ff6f4e77..e1a2ba5046e3 100644 --- a/chart2/source/view/axes/VCartesianCoordinateSystem.cxx +++ b/chart2/source/view/axes/VCartesianCoordinateSystem.cxx @@ -98,11 +98,11 @@ void VCartesianCoordinateSystem::createGridShapes() } void VCartesianCoordinateSystem::createVAxisList( - const rtl::Reference<::chart::ChartModel> & xChartDoc - , const awt::Size& rFontReferenceSize - , const awt::Rectangle& rMaximumSpaceForLabels - , bool bLimitSpaceForLabels - ) + const rtl::Reference<::chart::ChartModel> & xChartDoc, + const awt::Size& rFontReferenceSize, + const awt::Rectangle& rMaximumSpaceForLabels, + bool bLimitSpaceForLabels, + std::vector<std::unique_ptr<VSeriesPlotter>>& rSeriesPlotterList) { // note: using xChartDoc itself as XNumberFormatsSupplier would cause // a leak from VCartesianAxis due to cyclic reference @@ -163,6 +163,7 @@ void VCartesianCoordinateSystem::createVAxisList( apVAxis->set3DWallPositions( m_eLeftWallPos, m_eBackWallPos, m_eBottomPos ); apVAxis->initAxisLabelProperties(rFontReferenceSize,rMaximumSpaceForLabels); + apVAxis->createDataTableView(rSeriesPlotterList, xNumberFormatsSupplier); } } } diff --git a/chart2/source/view/axes/VCartesianCoordinateSystem.hxx b/chart2/source/view/axes/VCartesianCoordinateSystem.hxx index e9d684821445..4b7acf227867 100644 --- a/chart2/source/view/axes/VCartesianCoordinateSystem.hxx +++ b/chart2/source/view/axes/VCartesianCoordinateSystem.hxx @@ -31,10 +31,11 @@ public: virtual ~VCartesianCoordinateSystem() override; virtual void createVAxisList( - const rtl::Reference<::chart::ChartModel> &ChartDoc - , const css::awt::Size& rFontReferenceSize - , const css::awt::Rectangle& rMaximumSpaceForLabels - , bool bLimitSpaceForLabels ) override; + const rtl::Reference<::chart::ChartModel> &ChartDoc, + const css::awt::Size& rFontReferenceSize, + const css::awt::Rectangle& rMaximumSpaceForLabels, + bool bLimitSpaceForLabels, + std::vector<std::unique_ptr<VSeriesPlotter>>& rSeriesPlotterList) override; virtual void initVAxisInList() override; virtual void updateScalesAndIncrementsOnAxes() override; diff --git a/chart2/source/view/axes/VCoordinateSystem.cxx b/chart2/source/view/axes/VCoordinateSystem.cxx index 1fc249954e52..1dc9aaac91e4 100644 --- a/chart2/source/view/axes/VCoordinateSystem.cxx +++ b/chart2/source/view/axes/VCoordinateSystem.cxx @@ -323,11 +323,11 @@ sal_Int32 VCoordinateSystem::getMaximumAxisIndexByDimension( sal_Int32 nDimensio } void VCoordinateSystem::createVAxisList( - const rtl::Reference<::chart::ChartModel> & /* xChartDoc */ - , const awt::Size& /* rFontReferenceSize */ - , const awt::Rectangle& /* rMaximumSpaceForLabels */ - , bool /* bLimitSpaceForLabels */ - ) + const rtl::Reference<::chart::ChartModel> & /* xChartDoc */, + const awt::Size& /* rFontReferenceSize */, + const awt::Rectangle& /* rMaximumSpaceForLabels */, + bool /* bLimitSpaceForLabels */, + std::vector<std::unique_ptr<VSeriesPlotter>>& /*rSeriesPlotterList*/) { } diff --git a/chart2/source/view/axes/VPolarCoordinateSystem.cxx b/chart2/source/view/axes/VPolarCoordinateSystem.cxx index e287120f965e..3a3351a54fc3 100644 --- a/chart2/source/view/axes/VPolarCoordinateSystem.cxx +++ b/chart2/source/view/axes/VPolarCoordinateSystem.cxx @@ -66,11 +66,11 @@ uno::Sequence< sal_Int32 > VPolarCoordinateSystem::getCoordinateSystemResolution } void VPolarCoordinateSystem::createVAxisList( - const rtl::Reference<::chart::ChartModel> & xChartDoc - , const awt::Size& rFontReferenceSize - , const awt::Rectangle& rMaximumSpaceForLabels - , bool //bLimitSpaceForLabels - ) + const rtl::Reference<::chart::ChartModel> & xChartDoc, + const awt::Size& rFontReferenceSize, + const awt::Rectangle& rMaximumSpaceForLabels, + bool /*bLimitSpaceForLabels*/, + std::vector<std::unique_ptr<VSeriesPlotter>>& /*rSeriesPlotterList*/) { // note: using xChartDoc itself as XNumberFormatsSupplier would cause // a leak from VPolarAxis due to cyclic reference diff --git a/chart2/source/view/axes/VPolarCoordinateSystem.hxx b/chart2/source/view/axes/VPolarCoordinateSystem.hxx index 9659660a5e8c..ecfb2ce4d19d 100644 --- a/chart2/source/view/axes/VPolarCoordinateSystem.hxx +++ b/chart2/source/view/axes/VPolarCoordinateSystem.hxx @@ -35,10 +35,11 @@ public: , const css::awt::Size& rPageResolution ) override; virtual void createVAxisList( - const rtl::Reference<::chart::ChartModel> & xChartDoc - , const css::awt::Size& rFontReferenceSize - , const css::awt::Rectangle& rMaximumSpaceForLabels - , bool bLimitSpaceForLabels ) override; + const rtl::Reference<::chart::ChartModel> &ChartDoc, + const css::awt::Size& rFontReferenceSize, + const css::awt::Rectangle& rMaximumSpaceForLabels, + bool bLimitSpaceForLabels, + std::vector<std::unique_ptr<VSeriesPlotter>>& rSeriesPlotterList) override; virtual void initVAxisInList() override; virtual void updateScalesAndIncrementsOnAxes() override; diff --git a/chart2/source/view/charttypes/VSeriesPlotter.cxx b/chart2/source/view/charttypes/VSeriesPlotter.cxx index 09e6860c3465..fb93c6fd35fe 100644 --- a/chart2/source/view/charttypes/VSeriesPlotter.cxx +++ b/chart2/source/view/charttypes/VSeriesPlotter.cxx @@ -2317,6 +2317,7 @@ std::vector<VDataSeries const*> VSeriesPlotter::getAllSeries() const return aAllSeries; } + std::vector<VDataSeries*> VSeriesPlotter::getAllSeries() { std::vector<VDataSeries*> aAllSeries; @@ -2359,6 +2360,25 @@ uno::Sequence<OUString> VSeriesPlotter::getSeriesNames() const return comphelper::containerToSequence( aRetVector ); } +uno::Sequence<OUString> VSeriesPlotter::getAllSeriesNames() const +{ + std::vector<OUString> aRetVector; + + OUString aRole; + if (m_xChartTypeModel.is()) + aRole = m_xChartTypeModel->getRoleOfSequenceForSeriesLabel(); + + for (VDataSeries const* pSeries : getAllSeries()) + { + if (pSeries) + { + OUString aSeriesName(DataSeriesHelper::getDataSeriesLabel(pSeries->getModel(), aRole)); + aRetVector.push_back(aSeriesName); + } + } + return comphelper::containerToSequence(aRetVector); +} + void VSeriesPlotter::setPageReferenceSize( const css::awt::Size & rPageRefSize ) { m_aPageReferenceSize = rPageRefSize; diff --git a/chart2/source/view/inc/DataTableView.hxx b/chart2/source/view/inc/DataTableView.hxx new file mode 100644 index 000000000000..517de9699d9e --- /dev/null +++ b/chart2/source/view/inc/DataTableView.hxx @@ -0,0 +1,39 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + */ +#pragma once + +#include <svx/unoshape.hxx> +#include <svx/unodraw/SvxTableShape.hxx> +#include <com/sun/star/awt/Rectangle.hpp> + +namespace chart +{ +class VSeriesPlotter; + +class DataTableView final +{ + rtl::Reference<SvxShapeGroupAnyD> m_xTarget; + rtl::Reference<SvxTableShape> m_xTableShape; + + std::vector<OUString> m_aDataSeriesNames; + std::vector<OUString> m_aXValues; + std::vector<std::vector<OUString>> m_pDataSeriesValues; + +public: + DataTableView(); + void initializeShapes(const rtl::Reference<SvxShapeGroupAnyD>& xTarget); + void initializeValues(std::vector<std::unique_ptr<VSeriesPlotter>>& rSeriesPlotterList); + void createShapes(basegfx::B2DVector const& rStart, basegfx::B2DVector const& rEnd, + sal_Int32 nDistance); +}; + +} //namespace chart + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/chart2/source/view/inc/VCoordinateSystem.hxx b/chart2/source/view/inc/VCoordinateSystem.hxx index b096233e8f03..50d1cd9b2c4f 100644 --- a/chart2/source/view/inc/VCoordinateSystem.hxx +++ b/chart2/source/view/inc/VCoordinateSystem.hxx @@ -20,6 +20,7 @@ #include "MinimumAndMaximumSupplier.hxx" #include <ThreeDHelper.hxx> +#include "VSeriesPlotter.hxx" #include <chartview/ExplicitScaleValues.hxx> #include <com/sun/star/drawing/HomogenMatrix.hpp> #include <com/sun/star/uno/Sequence.h> @@ -30,9 +31,6 @@ #include <memory> #include <vector> -namespace chart { class ExplicitCategoriesProvider; } -namespace chart { class ScaleAutomatism; } -namespace chart { class ChartModel; } namespace com::sun::star::awt { struct Rectangle; } namespace com::sun::star::awt { struct Size; } namespace com::sun::star::beans { class XPropertySet; } @@ -42,9 +40,11 @@ namespace com::sun::star::chart2 { class XCoordinateSystem; } namespace com::sun::star::drawing { class XShapes; } namespace com::sun::star::lang { class XMultiServiceFactory; } - namespace chart { +class ExplicitCategoriesProvider; +class ScaleAutomatism; +class ChartModel; class Axis; class BaseCoordinateSystem; class VAxisBase; @@ -116,10 +116,11 @@ public: * Create "view" axis objects 'VAxis' from the coordinate system model. */ virtual void createVAxisList( - const rtl::Reference<::chart::ChartModel> & xChartDoc - , const css::awt::Size& rFontReferenceSize - , const css::awt::Rectangle& rMaximumSpaceForLabels - , bool bLimitSpaceForLabels ); + const rtl::Reference<::chart::ChartModel> & xChartDoc, + const css::awt::Size& rFontReferenceSize, + const css::awt::Rectangle& rMaximumSpaceForLabels, + bool bLimitSpaceForLabels, + std::vector<std::unique_ptr<VSeriesPlotter>>& rSeriesPlotterList); virtual void initVAxisInList(); virtual void updateScalesAndIncrementsOnAxes(); diff --git a/chart2/source/view/inc/VSeriesPlotter.hxx b/chart2/source/view/inc/VSeriesPlotter.hxx index 1b7961194ab2..50901bf64a5a 100644 --- a/chart2/source/view/inc/VSeriesPlotter.hxx +++ b/chart2/source/view/inc/VSeriesPlotter.hxx @@ -239,6 +239,9 @@ public: //get series names for the z axis labels css::uno::Sequence<OUString> getSeriesNames() const; + //get all series names + css::uno::Sequence<OUString> getAllSeriesNames() const; + void setPageReferenceSize( const css::awt::Size & rPageRefSize ); //better performance for big data void setCoordinateSystemResolution( const css::uno::Sequence< sal_Int32 >& rCoordinateSystemResolution ); @@ -256,6 +259,11 @@ public: bool WantToPlotInFrontOfAxisLine(); virtual bool shouldSnapRectToUsedArea(); + /// This method returns a text string representation of the passed numeric + /// value by exploiting a NumberFormatterWrapper object. + OUString getLabelTextForValue(VDataSeries const & rDataSeries, sal_Int32 nPointIndex, + double fValue, bool bAsPercentage); + protected: VSeriesPlotter( rtl::Reference< ::chart::ChartType > xChartTypeModel @@ -324,13 +332,6 @@ protected: , sal_Int32 nOffset=0 , sal_Int32 nTextWidth = 0 ); - /// This method returns a text string representation of the passed numeric - /// value by exploiting a NumberFormatterWrapper object. - OUString getLabelTextForValue( VDataSeries const & rDataSeries - , sal_Int32 nPointIndex - , double fValue - , bool bAsPercentage ); - /** creates two T-shaped error bars in both directions (up/down or left/right depending on the bVertical parameter) diff --git a/chart2/source/view/main/ChartView.cxx b/chart2/source/view/main/ChartView.cxx index e9b7cafd2c69..14ec725cadd2 100644 --- a/chart2/source/view/main/ChartView.cxx +++ b/chart2/source/view/main/ChartView.cxx @@ -537,7 +537,7 @@ awt::Rectangle ChartView::impl_createDiagramAndContent( const CreateShapeParam2D rpVCooSys->set3DWallPositions( eLeftWallPos, eBackWallPos, eBottomPos ); } - rpVCooSys->createVAxisList(&mrChartModel, rPageSize, rParam.maRemainingSpace, rParam.mbUseFixedInnerSize); + rpVCooSys->createVAxisList(&mrChartModel, rPageSize, rParam.maRemainingSpace, rParam.mbUseFixedInnerSize, rSeriesPlotterList); } // - prepare list of all axis and how they are used diff --git a/chart2/source/view/main/DataTableView.cxx b/chart2/source/view/main/DataTableView.cxx new file mode 100644 index 000000000000..cbb52ba02ccf --- /dev/null +++ b/chart2/source/view/main/DataTableView.cxx @@ -0,0 +1,215 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + */ + +#include <DataTableView.hxx> +#include <VSeriesPlotter.hxx> +#include <ShapeFactory.hxx> +#include <ExplicitCategoriesProvider.hxx> + +#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/style/ParagraphAdjust.hpp> +#include <com/sun/star/drawing/TextHorizontalAdjust.hpp> +#include <com/sun/star/drawing/TextVerticalAdjust.hpp> +#include <com/sun/star/util/XBroadcaster.hpp> + +#include <o3tl/unit_conversion.hxx> + +using namespace css; + +namespace chart +{ +DataTableView::DataTableView() = default; + +namespace +{ +void setCellDefaults(uno::Reference<beans::XPropertySet>& xPropertySet) +{ + xPropertySet->setPropertyValue("FillColor", uno::Any(Color(0xFFFFFF))); + xPropertySet->setPropertyValue("TextVerticalAdjust", uno::Any(drawing::TextVerticalAdjust_TOP)); + xPropertySet->setPropertyValue("ParaAdjust", uno::Any(style::ParagraphAdjust_CENTER)); + + table::BorderLine2 aBorderLine; + aBorderLine.LineWidth = o3tl::convert(0.5, o3tl::Length::pt, o3tl::Length::mm100); + aBorderLine.Color = 0x000000; + + xPropertySet->setPropertyValue("TopBorder", uno::Any(aBorderLine)); + xPropertySet->setPropertyValue("BottomBorder", uno::Any(aBorderLine)); + xPropertySet->setPropertyValue("LeftBorder", uno::Any(aBorderLine)); + xPropertySet->setPropertyValue("RightBorder", uno::Any(aBorderLine)); +} + +void setTopCell(uno::Reference<beans::XPropertySet>& xPropertySet) +{ + xPropertySet->setPropertyValue("FillColor", uno::Any(Color(0xFFFFFF))); + xPropertySet->setPropertyValue("TextVerticalAdjust", uno::Any(drawing::TextVerticalAdjust_TOP)); + xPropertySet->setPropertyValue("ParaAdjust", uno::Any(style::ParagraphAdjust_CENTER)); + + table::BorderLine2 aBorderLine; + aBorderLine.LineWidth = 0; + aBorderLine.Color = 0x000000; + + xPropertySet->setPropertyValue("TopBorder", uno::Any(aBorderLine)); + xPropertySet->setPropertyValue("LeftBorder", uno::Any(aBorderLine)); +} +} +void DataTableView::createShapes(basegfx::B2DVector const& rStart, basegfx::B2DVector const& rEnd, + sal_Int32 nColumnSize) +{ + if (!m_xTarget.is()) + return; + + ShapeFactory::removeSubShapes(m_xTarget); + m_xTableShape = ShapeFactory::createTable(m_xTarget); + + uno::Reference<table::XTable> xTable; + uno::Reference<util::XBroadcaster> xBroadcaster; + try + { + auto rDelta = rEnd - rStart; + m_xTableShape->setSize({ basegfx::fround(rDelta.getX()), 0 }); + m_xTableShape->getPropertyValue("Model") >>= xTable; + } + catch (const uno::Exception&) + { + return; + } + + if (xTable.is()) + xBroadcaster.set(xTable, uno::UNO_QUERY); + + if (!xBroadcaster.is()) + return; + + xBroadcaster->lockBroadcasts(); + uno::Reference<table::XTableColumns> xTableColumns = xTable->getColumns(); + xTableColumns->insertByIndex(0, m_aXValues.size()); + + uno::Reference<table::XTableRows> xTableRows = xTable->getRows(); + xTableRows->insertByIndex(0, m_aDataSeriesNames.size()); + + { + uno::Reference<table::XCell> xCell = xTable->getCellByPosition(0, 0); + uno::Reference<beans::XPropertySet> xPropertySet(xCell, uno::UNO_QUERY); + if (xPropertySet.is()) + { + setTopCell(xPropertySet); + } + } + + sal_Int32 nColumn; + sal_Int32 nRow; + + nColumn = 1; + for (auto const& rString : m_aXValues) + { + uno::Reference<table::XCell> xCell = 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()) + { + xCellTextRange->setString(rString); + setCellDefaults(xPropertySet); + } + nColumn++; + } + + nRow = 1; + for (auto const& rSeriesName : m_aDataSeriesNames) + { + uno::Reference<table::XCell> xCell = xTable->getCellByPosition(0, nRow); + uno::Reference<beans::XPropertySet> xPropertySet(xCell, uno::UNO_QUERY); + uno::Reference<text::XTextRange> xCellTextRange(xCell, uno::UNO_QUERY); + if (xCellTextRange.is()) + { + xCellTextRange->setString(rSeriesName); + setCellDefaults(xPropertySet); + } + nRow++; + } + + nRow = 1; + for (auto const& rSeries : m_pDataSeriesValues) + { + nColumn = 1; + for (auto const& rValue : rSeries) + { + uno::Reference<table::XCell> xCell = xTable->getCellByPosition(nColumn, nRow); + uno::Reference<beans::XPropertySet> xPropertySet(xCell, uno::UNO_QUERY); + uno::Reference<text::XTextRange> xCellTextRange(xCell, uno::UNO_QUERY); + if (xCellTextRange.is()) + { + xCellTextRange->setString(rValue); + setCellDefaults(xPropertySet); + } + nColumn++; + } + nRow++; + } + + xBroadcaster->unlockBroadcasts(); + + auto* pTableObject = static_cast<sdr::table::SdrTableObj*>(m_xTableShape->GetSdrObject()); + pTableObject->DistributeColumns(0, pTableObject->getColumnCount() - 1, true, true); + + uno::Reference<beans::XPropertySet> xPropertySet(xTableColumns->getByIndex(0), uno::UNO_QUERY); + sal_Int32 nWidth = 0; + xPropertySet->getPropertyValue("Width") >>= nWidth; + + m_xTableShape->setPosition( + { basegfx::fround(rStart.getX() - nWidth), basegfx::fround(rStart.getY()) }); + + for (sal_Int32 i = 1; i < xTableColumns->getCount(); ++i) + { + xPropertySet.set(xTableColumns->getByIndex(i), uno::UNO_QUERY); + xPropertySet->setPropertyValue("Width", uno::Any(nColumnSize)); + } +} + +void DataTableView::initializeShapes(const rtl::Reference<SvxShapeGroupAnyD>& xTarget) +{ + m_xTarget = xTarget; +} + +void DataTableView::initializeValues( + std::vector<std::unique_ptr<VSeriesPlotter>>& rSeriesPlotterList) +{ + for (auto& rSeriesPlotter : rSeriesPlotterList) + { + for (auto const& rCategory : + rSeriesPlotter->getExplicitCategoriesProvider()->getSimpleCategories()) + { + m_aXValues.push_back(rCategory); + } + + for (auto const& rString : rSeriesPlotter->getAllSeriesNames()) + { + m_aDataSeriesNames.push_back(rString); + } + + for (VDataSeries* pSeries : rSeriesPlotter->getAllSeries()) + { + auto& rValues = m_pDataSeriesValues.emplace_back(); + for (int i = 0; i < pSeries->getTotalPointCount(); i++) + { + double nValue = pSeries->getYValue(i); + rValues.push_back(rSeriesPlotter->getLabelTextForValue(*pSeries, i, nValue, false)); + } + } + } +} + +} //namespace chart + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |