36#include <unonames.hxx>
38#include <com/sun/star/uno/XComponentContext.hpp>
39#include <com/sun/star/chart2/AxisType.hpp>
40#include <com/sun/star/chart2/StackingDirection.hpp>
41#include <com/sun/star/chart2/XColorScheme.hpp>
53using ::com::sun::star::uno::Sequence;
54using ::com::sun::star::uno::Reference;
59void lcl_applyDefaultStyle(
66 if( xSeries.is() && xDiagram.is())
68 Reference< chart2::XColorScheme > xColorScheme( xDiagram->getDefaultColorScheme());
69 if( xColorScheme.is() )
70 xSeries->setPropertyValue(
72 uno::Any( xColorScheme->getColorByIndex( nIndex )));
76void lcl_ensureCorrectLabelPlacement(
const Reference< beans::XPropertySet >& xProp,
const uno::Sequence < sal_Int32 >& rAvailablePlacements )
78 sal_Int32 nLabelPlacement=0;
79 if( !(xProp.is() && (xProp->getPropertyValue(
"LabelPlacement" ) >>= nLabelPlacement)) )
83 for( sal_Int32 i : rAvailablePlacements )
85 if( i == nLabelPlacement )
95 if( rAvailablePlacements.hasElements() )
96 aNewValue <<=rAvailablePlacements[0];
97 xProp->setPropertyValue(
"LabelPlacement", aNewValue );
101void lcl_resetLabelPlacementIfDefault(
const Reference< beans::XPropertySet >& xProp, sal_Int32 nDefaultPlacement )
104 sal_Int32 nLabelPlacement=0;
105 if( xProp.is() && (xProp->getPropertyValue(
"LabelPlacement" ) >>= nLabelPlacement) )
107 if( nDefaultPlacement == nLabelPlacement )
108 xProp->setPropertyValue(
"LabelPlacement",
uno::Any() );
116 uno::Sequence < sal_Int32 > aAvailableMissingValueTreatment(
119 if( aAvailableMissingValueTreatment.hasElements() )
120 xDiagram->setPropertyValue(
"MissingValueTreatment",
uno::Any( aAvailableMissingValueTreatment[0] ) );
122 xDiagram->setPropertyValue(
"MissingValueTreatment",
uno::Any() );
133 OUString aServiceName ) :
135 m_aServiceName(
std::move( aServiceName ))
157 xInterpreter->interpretDataSource(
161 for(
auto const &
i :
aData.Series )
162 for(
auto const & j :
i )
163 lcl_applyDefaultStyle( j,
nCount++, xDia );
165 std::vector< rtl::Reference< ChartType > > aOldChartTypesSeq;
168 catch(
const uno::Exception & )
188 std::vector< std::vector< rtl::Reference< DataSeries > > > aSeriesSeq =
189 xDiagram->getDataSeriesGroups();
190 std::vector< rtl::Reference< DataSeries > > aFlatSeriesSeq(
FlattenSequence( aSeriesSeq ));
191 const sal_Int32 nFormerSeriesCount = aFlatSeriesSeq.size();
196 aData.Series = aSeriesSeq;
197 aData.Categories = xDiagram->getCategories();
199 if( xInterpreter->isDataCompatible( aData ) )
201 aData = xInterpreter->reinterpretDataSeries( aData );
210 Sequence< beans::PropertyValue > aParam;
211 if(
aData.Categories.is())
213 aParam = { beans::PropertyValue(
"HasCategories", -1,
uno::Any(
true ),
214 beans::PropertyState_DIRECT_VALUE ) };
216 aData = xInterpreter->interpretDataSource( xSource, aParam, aFlatSeriesSeq );
218 aSeriesSeq =
aData.Series;
221 for(
auto const & i : std::as_const(aSeriesSeq) )
222 for(
auto const & j : i )
224 if( nIndex >= nFormerSeriesCount )
225 lcl_applyDefaultStyle( j, nIndex++, xDiagram );
229 std::vector< rtl::Reference< ChartType > > aOldChartTypesSeq =
230 xDiagram->getChartTypes();
234 coords->setChartTypes( Sequence< Reference< XChartType > >() );
239 catch(
const uno::Exception & )
247 const Reference< chart2::data::XDataSource >& xDataSource,
248 const Sequence< beans::PropertyValue >& aArguments )
250 if( ! (xDiagram.is() &&
257 std::vector< rtl::Reference< DataSeries > > aFlatSeriesSeq =
258 xDiagram->getDataSeries();
259 const sal_Int32 nFormerSeriesCount = aFlatSeriesSeq.size();
261 InterpretedData
aData =
262 xInterpreter->interpretDataSource( xDataSource, aArguments, aFlatSeriesSeq );
266 for( std::size_t i=0;
i<
aData.Series.size(); ++
i )
267 for( std::size_t j=0; j<
aData.Series[
i].size(); ++j, ++
nIndex )
269 if( nIndex >= nFormerSeriesCount )
271 lcl_applyDefaultStyle(
aData.Series[i][j], nIndex, xDiagram );
279 std::vector< rtl::Reference< ChartType > > aChartTypes =
280 xDiagram->getChartTypes();
281 sal_Int32 nMax = std::min( aChartTypes.size(),
aData.Series.size());
282 for( sal_Int32 i=0;
i<nMax; ++
i )
284 aChartTypes[
i]->setDataSeries(
aData.Series[i] );
287 catch(
const uno::Exception & )
297 bool bResult =
false;
304 const std::vector< rtl::Reference< BaseCoordinateSystem > > & aCooSysSeq(
305 xDiagram->getBaseCoordinateSystems());
308 bResult = !aCooSysSeq.empty();
311 std::vector< rtl::Reference< ChartType > > aFormerlyUsedChartTypes;
316 const OUString aChartTypeToMatch = xOldCT->getChartType();
318 for( std::size_t nCooSysIdx=0; bResult && (nCooSysIdx < aCooSysSeq.size()); ++nCooSysIdx )
321 bResult = bResult && (aCooSysSeq[nCooSysIdx]->getDimension() == nDimensionToMatch);
323 const std::vector< rtl::Reference< ChartType > > & aChartTypeSeq( aCooSysSeq[nCooSysIdx]->getChartTypes2());
324 for( std::size_t nCTIdx=0; bResult && (nCTIdx < aChartTypeSeq.size()); ++nCTIdx )
327 bResult = bResult && aChartTypeSeq[nCTIdx]->getChartType() == aChartTypeToMatch;
329 bool bAmbiguous=
false;
333 aChartTypeSeq[nCTIdx], bFound, bAmbiguous,
334 aCooSysSeq[nCooSysIdx] )
340 catch(
const uno::Exception & )
358 ::sal_Int32 nChartTypeIndex,
372 ? chart2::StackingDirection_Y_STACKING
374 ? chart2::StackingDirection_Z_STACKING
375 : chart2::StackingDirection_NO_STACKING );
376 xSeries->setPropertyValue(
"StackingDirection", aPropValue );
382 lcl_ensureCorrectLabelPlacement( xSeries, aAvailablePlacements );
387 for(sal_Int32 nN=aAttributedDataPointIndexList.getLength();nN--;)
388 lcl_ensureCorrectLabelPlacement( xSeries->getDataPointByIndex(aAttributedDataPointIndexList[nN]), aAvailablePlacements );
391 catch(
const uno::Exception & )
400 std::vector< std::vector< rtl::Reference< DataSeries > > > aNewSeriesSeq(
401 xDiagram->getDataSeriesGroups());
402 for( std::size_t
i=0;
i<aNewSeriesSeq.size(); ++
i )
404 const sal_Int32 nNumSeries = aNewSeriesSeq[
i].size();
405 for( sal_Int32 j=0; j<nNumSeries; ++j )
442 if(!aAvailablePlacements.hasElements())
445 sal_Int32 nDefaultPlacement = aAvailablePlacements[0];
447 lcl_resetLabelPlacementIfDefault( xSeries, nDefaultPlacement );
452 for(sal_Int32 nN=aAttributedDataPointIndexList.getLength();nN--;)
453 lcl_resetLabelPlacementIfDefault( xSeries->getDataPointByIndex(aAttributedDataPointIndexList[nN]), nDefaultPlacement );
486 std::vector< rtl::Reference< ChartType > > aFormerlyUsedChartTypes;
488 if( ! xChartType.is())
498 if( xCooSys->getDimension() >= 2 )
505 std::vector< rtl::Reference< BaseCoordinateSystem > > aCoordinateSystems(
506 xDiagram->getBaseCoordinateSystems());
508 if( !aCoordinateSystems.empty() )
511 for( std::size_t
i=0; bOk &&
i<aCoordinateSystems.size(); ++
i )
512 bOk = bOk && ( xCooSys->getCoordinateSystemType() == aCoordinateSystems[
i]->getCoordinateSystemType() &&
513 (xCooSys->getDimension() == aCoordinateSystems[
i]->getDimension()) );
521 if( !aCoordinateSystems.empty() )
524 sal_Int32 nMaxDimensionCount = std::min( xCooSys->getDimension(), xOldCooSys->getDimension() );
526 for(sal_Int32 nDimensionIndex=0; nDimensionIndex<nMaxDimensionCount; nDimensionIndex++)
528 const sal_Int32 nMaximumAxisIndex = xOldCooSys->getMaximumAxisIndexByDimension(nDimensionIndex);
529 for(sal_Int32 nAxisIndex=0; nAxisIndex<=nMaximumAxisIndex; ++nAxisIndex)
534 xCooSys->setAxisByDimension( nDimensionIndex, xAxis, nAxisIndex );
541 aCoordinateSystems = { xCooSys };
543 xDiagram->setCoordinateSystems( aCoordinateSystems );
557 sal_Int32 nDim( xCooSys->getDimension());
560 const sal_Int32 nDimensionX = 0;
561 const sal_Int32 nMaxIndex = xCooSys->getMaximumAxisIndexByDimension(nDimensionX);
562 for(sal_Int32 nI=0; nI<=nMaxIndex; ++nI)
567 ScaleData
aData( xAxis->getScaleData() );
568 aData.Categories = xCategories;
569 if(bSupportsCategories)
572 if(
aData.AxisType == AxisType::CATEGORY )
577 if(
aData.AxisType != AxisType::CATEGORY && (
aData.AxisType != AxisType::DATE || !bSupportsDates) )
579 aData.AxisType = AxisType::CATEGORY;
580 aData.AutoDateAxis =
true;
585 aData.AxisType = AxisType::REALNUMBER;
587 xAxis->setScaleData(
aData );
594 const sal_Int32 nMaxIndex = xCooSys->getMaximumAxisIndexByDimension(1);
595 for(sal_Int32 nI=0; nI<=nMaxIndex; ++nI)
601 chart2::ScaleData aScaleData = xAxis->getScaleData();
603 if( bPercent != (aScaleData.AxisType==AxisType::PERCENT) )
606 aScaleData.AxisType = AxisType::PERCENT;
608 aScaleData.AxisType = AxisType::REALNUMBER;
609 xAxis->setScaleData( aScaleData );
615 catch(
const uno::Exception & )
630 if( rCoordSys.empty() )
638 sal_Int32
nDimCount = xCooSys->getDimension();
646 for( sal_Int32 nAxisIndex = 0; nAxisIndex < nAxisCount; ++nAxisIndex )
664 if( rCoordSys.empty() )
671 sal_Int32
nDimCount = xCooSys->getDimension();
672 for( sal_Int32 nDim=0; nDim<
nDimCount; ++nDim )
674 sal_Int32 nMaxAxisIndex = xCooSys->getMaximumAxisIndexByDimension( nDim );
675 for( sal_Int32 nAxisIndex=0; nAxisIndex<=nMaxAxisIndex; nAxisIndex++ )
685 if( bPercent && nDim == 1 )
714 std::vector< rtl::Reference< BaseCoordinateSystem > > aCoordinateSystems( xDiagram->getBaseCoordinateSystems());
723 catch(
const uno::Exception & )
734 if( rCoordSys.empty() )
739 std::size_t nCooSysIdx=0;
741 if( aSeriesSeq.empty() )
745 rCoordSys[nCooSysIdx]->setChartTypes(std::vector{ xCT });
749 for( std::size_t nSeriesIdx=0; nSeriesIdx<aSeriesSeq.size(); ++nSeriesIdx )
751 if( nSeriesIdx == nCooSysIdx )
755 std::vector< rtl::Reference< ChartType > > aCTSeq( rCoordSys[nCooSysIdx]->getChartTypes2());
759 rCoordSys[nCooSysIdx]->setChartTypes( aCTSeq );
762 rCoordSys[nCooSysIdx]->addChartType( xCT );
764 xCT->setDataSeries( aSeriesSeq[nSeriesIdx] );
769 OSL_ASSERT( xCT.is());
770 std::vector< rtl::Reference< DataSeries > > aNewSeriesSeq = xCT->getDataSeries2();
771 sal_Int32 nNewStartIndex = aNewSeriesSeq.size();
772 aNewSeriesSeq.resize( nNewStartIndex + aSeriesSeq[nSeriesIdx].
size() );
773 std::copy( aSeriesSeq[nSeriesIdx].
begin(),
774 aSeriesSeq[nSeriesIdx].
end(),
775 aNewSeriesSeq.begin() + nNewStartIndex );
776 xCT->setDataSeries( aNewSeriesSeq );
780 if( rCoordSys.size() > (nCooSysIdx + 1) )
785 catch(
const uno::Exception & )
795 if( !xNewChartType.is() )
798 OUString aNewChartType( xNewChartType->getChartType() );
803 if( xOldType.is() && xOldType->getChartType() == aNewChartType )
819 const css::uno::Reference< css::chart2::data::XDataSource >& xDataSource,
820 const css::uno::Sequence< css::beans::PropertyValue >& aArguments )
825 const css::uno::Reference< css::chart2::XDiagram >& xDiagram )
830 const css::uno::Reference< css::chart2::XDiagram >& xDiagram,
831 const css::uno::Reference< css::chart2::data::XDataSource >& xDataSource,
832 const css::uno::Sequence< css::beans::PropertyValue >& aArguments )
837 const css::uno::Reference<css::chart2::XDiagram >& xDiagram,
843 const css::uno::Sequence< css::uno::Reference< css::chart2::XChartType > >& aFormerlyUsedChartTypes )
845 std::vector< rtl::Reference< ::chart::ChartType > > aTmp;
846 aTmp.reserve(aFormerlyUsedChartTypes.getLength());
847 for (
auto const & rxChartType : aFormerlyUsedChartTypes)
848 aTmp.push_back(
dynamic_cast<ChartType*
>(rxChartType.get()));
852 const css::uno::Reference< css::chart2::XDataSeries >& xSeries,
853 ::sal_Int32 nChartTypeIndex,
854 ::sal_Int32 nSeriesIndex,
855 ::sal_Int32 nSeriesCount )
860 const css::uno::Reference< css::chart2::XDiagram >& xDiagram )
Reference< uno::XComponentContext > m_xContext
static rtl::Reference< ::chart::Axis > getAxis(sal_Int32 nDimensionIndex, bool bMainAxis, const rtl::Reference< ::chart::Diagram > &xDiagram)
static rtl::Reference< ::chart::Axis > createAxis(sal_Int32 nDimensionIndex, bool bMainAxis, const rtl::Reference< ::chart::Diagram > &xDiagram, const css::uno::Reference< css::uno::XComponentContext > &xContext, ReferenceSizeProvider *pRefSizeProvider=nullptr)
static std::vector< rtl::Reference< ::chart::Axis > > getAllAxesOfDiagram(const rtl::Reference< ::chart::Diagram > &xDiagram, bool bOnlyVisible=false)
static sal_Int32 getDimensionIndexOfAxis(const rtl::Reference< ::chart::Axis > &xAxis, const rtl::Reference< ::chart::Diagram > &xDiagram)
static void removeExplicitScaling(css::chart2::ScaleData &rScaleData)
static void makeGridVisible(const rtl::Reference< ::chart::GridProperties > &xGridProperties)
static bool isSecondaryYAxisNeeded(const rtl::Reference< ::chart::BaseCoordinateSystem > &xCooSys)
static css::uno::Sequence< sal_Int32 > getSupportedLabelPlacements(const rtl::Reference< ::chart::ChartType > &xChartType, bool bSwapXAndY, const rtl::Reference< ::chart::DataSeries > &xSeries)
static css::uno::Sequence< sal_Int32 > getSupportedMissingValueTreatments(const rtl::Reference< ::chart::ChartType > &xChartType)
static bool isSupportingDateAxis(const rtl::Reference< ::chart::ChartType > &xChartType, sal_Int32 nDimensionIndex)
virtual sal_Bool SAL_CALL matchesTemplate(const css::uno::Reference< css::chart2::XDiagram > &xDiagram, sal_Bool bAdaptProperties) override final
void FillDiagram(const rtl::Reference< ::chart::Diagram > &xDiagram, const std::vector< std::vector< rtl::Reference< ::chart::DataSeries > > > &aSeriesSeq, const css::uno::Reference< css::chart2::data::XLabeledDataSequence > &xCategories, const std::vector< rtl::Reference< ChartType > > &aOldChartTypesSeq)
modifies the given diagram
virtual css::uno::Reference< ::css::chart2::XChartType > SAL_CALL getChartTypeForNewSeries(const css::uno::Sequence< css::uno::Reference< css::chart2::XChartType > > &aFormerlyUsedChartTypes) override final
rtl::Reference< ::chart::Diagram > createDiagramByDataSource2(const css::uno::Reference< css::chart2::data::XDataSource > &xDataSource, const css::uno::Sequence< css::beans::PropertyValue > &aArguments)
virtual sal_Bool SAL_CALL supportsCategories() override
denotes if the chart needs categories at the first scale
virtual sal_Int32 getAxisCountByDimension(sal_Int32 nDimension)
Give the number of requested axis per dimension here.
virtual bool matchesTemplate2(const rtl::Reference< ::chart::Diagram > &xDiagram, bool bAdaptProperties)
virtual void SAL_CALL applyStyle(const css::uno::Reference< css::chart2::XDataSeries > &xSeries, ::sal_Int32 nChartTypeIndex, ::sal_Int32 nSeriesIndex, ::sal_Int32 nSeriesCount) override final
virtual sal_Int32 getDimension() const
returns 2 by default. Supported are 2 and 3
virtual OUString SAL_CALL getServiceName() override
virtual rtl::Reference< ::chart::ChartType > getChartTypeForIndex(sal_Int32 nChartTypeIndex)=0
void createAxes(const std::vector< rtl::Reference< ::chart::BaseCoordinateSystem > > &rCoordSys)
create axes and add them to the given container.
virtual void createChartTypes(const std::vector< std::vector< rtl::Reference< ::chart::DataSeries > > > &aSeriesSeq, const std::vector< rtl::Reference< ::chart::BaseCoordinateSystem > > &rCoordSys, const std::vector< rtl::Reference< ChartType > > &aOldChartTypesSeq)
create a data series tree, that fits the requirements of the chart type.
virtual void adaptAxes(const std::vector< rtl::Reference< ::chart::BaseCoordinateSystem > > &rCoordSys)
adapt properties of existing axes and remove superfluous axes
virtual StackMode getStackMode(sal_Int32 nChartTypeIndex) const
returns StackMode::NONE by default.
virtual void adaptScales(const std::vector< rtl::Reference< ::chart::BaseCoordinateSystem > > &aCooSysSeq, const css::uno::Reference< css::chart2::data::XLabeledDataSequence > &xCategories)
Sets categories at the scales of dimension 0 and the percent stacking at the scales of dimension 1 of...
virtual css::uno::Reference< css::uno::XInterface > SAL_CALL getDataInterpreter() override final
virtual void SAL_CALL changeDiagram(const css::uno::Reference< css::chart2::XDiagram > &xDiagram) override final
ChartTypeTemplate(css::uno::Reference< css::uno::XComponentContext > const &xContext, OUString aServiceName)
virtual rtl::Reference< ::chart::DataInterpreter > getDataInterpreter2()
static void copyPropertiesFromOldToNewCoordinateSystem(const std::vector< rtl::Reference< ChartType > > &rOldChartTypesSeq, const rtl::Reference< ChartType > &xNewChartType)
virtual void SAL_CALL changeDiagramData(const css::uno::Reference< css::chart2::XDiagram > &xDiagram, const css::uno::Reference< css::chart2::data::XDataSource > &xDataSource, const css::uno::Sequence< css::beans::PropertyValue > &aArguments) override final
virtual void SAL_CALL resetStyles(const css::uno::Reference< css::chart2::XDiagram > &xDiagram) override final
const css::uno::Reference< css::uno::XComponentContext > & GetComponentContext() const
virtual bool isSwapXAndY() const
virtual void adaptDiagram(const rtl::Reference< ::chart::Diagram > &xDiagram)
Allows derived classes to manipulate the diagrams whole, like changing the wall color.
void applyStyles(const rtl::Reference< ::chart::Diagram > &xDiagram)
const OUString m_aServiceName
rtl::Reference< ::chart::DataInterpreter > m_xDataInterpreter
virtual void applyStyle2(const rtl::Reference< ::chart::DataSeries > &xSeries, ::sal_Int32 nChartTypeIndex, ::sal_Int32 nSeriesIndex, ::sal_Int32 nSeriesCount)
virtual void createCoordinateSystems(const rtl::Reference< ::chart::Diagram > &xDiagram)
Creates a 2d or 3d cartesian coordinate system with mathematically oriented, linear scales with auto-...
virtual rtl::Reference< ::chart::ChartType > getChartTypeForNewSeries2(const std::vector< rtl::Reference< ::chart::ChartType > > &aFormerlyUsedChartTypes)=0
virtual css::uno::Reference< css::chart2::XDiagram > SAL_CALL createDiagramByDataSource(const css::uno::Reference< css::chart2::data::XDataSource > &xDataSource, const css::uno::Sequence< css::beans::PropertyValue > &aArguments) override final
virtual ~ChartTypeTemplate() override
virtual void resetStyles2(const rtl::Reference< ::chart::Diagram > &xDiagram)
offers tooling to interpret different data sources in a structural and chart-type-dependent way.
static rtl::Reference< ::chart::DataSource > mergeInterpretedData(const InterpretedData &aInterpretedData)
Try to reverse the operation done in interpretDataSource().
static StackMode getStackModeFromChartType(const rtl::Reference< ::chart::ChartType > &xChartType, bool &rbFound, bool &rbAmbiguous, const rtl::Reference< ::chart::BaseCoordinateSystem > &xCorrespondingCoordinateSystem)
Retrieves the stackmode of the first DataSeries or none.
#define DBG_UNHANDLED_EXCEPTION(...)
Sequence< PropertyValue > aArguments
constexpr OUStringLiteral aData
@ PROP_DATASERIES_ATTRIBUTED_DATA_POINTS
const sal_Int32 SECONDARY_AXIS_INDEX
std::vector< T > FlattenSequence(const std::vector< std::vector< T > > &aSeqSeq)
std::vector< std::vector< T > > -> std::vector< T >
const sal_Int32 MAIN_AXIS_INDEX
void copyProperties(const Reference< XPropertySet > &_rxSource, const Reference< XPropertySet > &_rxDest)
enumrange< T >::Iterator begin(enumrange< T >)
offers tooling to interpret different data sources in a structural and chart-type-dependent way.
constexpr OUStringLiteral CHART_UNONAME_LINK_TO_SRC_NUMFMT
constexpr OUStringLiteral CHART_UNONAME_NUMFMT