25#include <unonames.hxx>
30#include <com/sun/star/beans/XPropertySet.hpp>
31#include <com/sun/star/chart2/DataPointLabel.hpp>
32#include <com/sun/star/chart2/data/XTextualDataSequence.hpp>
33#include <com/sun/star/chart2/StackingDirection.hpp>
34#include <com/sun/star/chart2/data/LabelOrigin.hpp>
35#include <com/sun/star/chart2/AxisType.hpp>
36#include <com/sun/star/chart2/SymbolStyle.hpp>
37#include <com/sun/star/chart2/Symbol.hpp>
38#include <com/sun/star/chart2/XDiagram.hpp>
39#include <com/sun/star/drawing/LineStyle.hpp>
42#include <rtl/ustrbuf.hxx>
55using ::com::sun::star::uno::Reference;
56using ::com::sun::star::uno::Sequence;
64 explicit lcl_MatchesRole( OUString aRole,
bool bMatchPrefix ) :
66 m_bMatchPrefix( bMatchPrefix )
73 Reference< beans::XPropertySet > xProp( xSeq->getValues(), uno::UNO_QUERY );
77 return ( xProp.is() &&
78 (xProp->getPropertyValue(
"Role" ) >>= aRole ) &&
81 return ( xProp.is() &&
82 (xProp->getPropertyValue(
"Role" ) >>= aRole ) &&
91void lcl_getCooSysAndChartTypeOfSeries(
93 const Reference< chart2::XDiagram > & xDiagram,
107 if( dataSeries == xSeries )
110 xOutChartType = chartType;
123 DataPointLabel aLabelAtSeries;
125 aLabelAtSeries.ShowNumber = bInsert;
128 aLabelAtSeries.ShowNumberInPercent =
false;
129 aLabelAtSeries.ShowCategoryName =
false;
132 uno::Sequence< sal_Int32 > aAttributedDataPointIndexList;
136 for(sal_Int32 nN=aAttributedDataPointIndexList.getLength();nN--;)
138 Reference< beans::XPropertySet > xPointProp( xSeries->getDataPointByIndex(aAttributedDataPointIndexList[nN]) );
139 if( xPointProp.is() )
143 aLabel.ShowNumber = bInsert;
146 aLabel.ShowNumberInPercent =
false;
147 aLabel.ShowCategoryName =
false;
148 aLabel.ShowCustomLabel =
false;
149 aLabel.ShowSeriesName =
false;
158 catch(
const uno::Exception &)
172 if( xLabeledDataSequence.is() )
176 xProp->getPropertyValue(
"Role" ) >>= aRet;
184 const OUString& aRole,
193 for (
auto const &
i : aLabeledSeq)
195 if (lcl_MatchesRole(aRole, bMatchPrefix)(
i))
199 catch (
const lang::DisposedException&)
207std::vector< uno::Reference< chart2::data::XLabeledDataSequence > >
209 const OUString& aRole )
211 std::vector< uno::Reference< chart2::data::XLabeledDataSequence > > aResultVec;
212 for (
const auto &
i : aDataSequences)
214 if (lcl_MatchesRole(aRole,
true)(
i))
215 aResultVec.push_back(
i);
220std::vector< css::uno::Reference< css::chart2::data::XLabeledDataSequence > >
222 const OUString& aRole )
224 std::vector< css::uno::Reference< css::chart2::data::XLabeledDataSequence > > aResultVec;
225 std::copy_if( aDataSequences.begin(), aDataSequences.end(),
226 std::back_inserter( aResultVec ),
227 lcl_MatchesRole(aRole,
true) );
231std::vector<uno::Reference<chart2::data::XLabeledDataSequence> >
234 std::vector< uno::Reference< chart2::data::XLabeledDataSequence > > aSeqVec;
238 const std::vector< uno::Reference< chart2::data::XLabeledDataSequence > > &
aSeq( dataSeries->getDataSequences2());
239 aSeqVec.insert( aSeqVec.end(),
aSeq.begin(),
aSeq.end() );
259 ? chart2::StackingDirection_Y_STACKING
261 ? chart2::StackingDirection_Z_STACKING
262 : chart2::StackingDirection_NO_STACKING );
264 std::set< sal_Int32 > aAxisIndexSet;
269 if( dataSeries.is() )
271 dataSeries->setPropertyValue(
"StackingDirection", aPropValue );
273 sal_Int32 nAxisIndex = 0;
274 dataSeries->getPropertyValue(
"AttachedAxisIndex" ) >>= nAxisIndex;
275 aAxisIndexSet.insert(nAxisIndex);
278 catch(
const uno::Exception & )
284 if( !(xCorrespondingCoordinateSystem.is() &&
285 1 < xCorrespondingCoordinateSystem->getDimension()) )
288 if( aAxisIndexSet.empty() )
290 aAxisIndexSet.insert(0);
293 for (
auto const& axisIndex : aAxisIndexSet)
296 xCorrespondingCoordinateSystem->getAxisByDimension2(1, axisIndex);
300 chart2::ScaleData aScaleData = xAxis->getScaleData();
302 if( bPercent != (aScaleData.AxisType==chart2::AxisType::PERCENT) )
305 aScaleData.AxisType = chart2::AxisType::PERCENT;
307 aScaleData.AxisType = chart2::AxisType::REALNUMBER;
308 xAxis->setScaleData( aScaleData );
321 xSeries->getPropertyValue(
"AttachedAxisIndex" ) >>= nRet;
324 catch(
const uno::Exception & )
334 sal_Int32 nDimensionIndex,
335 sal_Int32 nAxisIndex )
337 sal_Int32 nResult = 0;
338 if( nAxisIndex == -1 )
343 xCorrespondingCoordinateSystem->getAxisByDimension2( nDimensionIndex, nAxisIndex );
347 catch(
const uno::Exception & )
361 lcl_getCooSysAndChartTypeOfSeries( xSeries, xDiagram, xResult, xDummy );
372 lcl_getCooSysAndChartTypeOfSeries( xSeries, xDiagram, xDummy, xResult );
383 std::vector< rtl::Reference< DataSeries > > aSeries = xChartType->getDataSeries2();
384 auto aIt = std::find( aSeries.begin(), aSeries.end(), xSeries );
385 if( aIt != aSeries.end())
387 aSeries.erase( aIt );
388 xChartType->setDataSeries( aSeries );
391 catch(
const uno::Exception & )
398 bool bSymbolsOn, sal_Int32 nSeriesIndex )
403 chart2::Symbol aSymbProp;
404 if( xSeries->getPropertyValue(
"Symbol") >>= aSymbProp )
407 aSymbProp.Style = chart2::SymbolStyle_NONE;
408 else if( aSymbProp.Style == chart2::SymbolStyle_NONE )
410 aSymbProp.Style = chart2::SymbolStyle_STANDARD;
411 aSymbProp.StandardSymbol = nSeriesIndex;
413 xSeries->setPropertyValue(
"Symbol",
uno::Any( aSymbProp ));
426 drawing::LineStyle eLineStyle;
427 if( (xSeries->getPropertyValue(
"LineStyle") >>= eLineStyle ) &&
428 eLineStyle == drawing::LineStyle_NONE )
430 xSeries->setPropertyValue(
"LineStyle",
uno::Any( drawing::LineStyle_SOLID ) );
434 xSeries->setPropertyValue(
"LineStyle",
uno::Any( drawing::LineStyle_NONE ) );
442 sal_Int32 nNewValue = bThick ? 80 : 0;
443 sal_Int32 nOldValue = 0;
444 if( (xSeries->getPropertyValue(
"LineWidth") >>= nOldValue ) &&
445 nOldValue != nNewValue )
447 if( !(bThick && nOldValue>0))
448 xSeries->setPropertyValue(
"LineWidth",
uno::Any( nNewValue ) );
453 const OUString& rPropertyName,
const uno::Any& rPropertyValue )
458 xSeries->setPropertyValue( rPropertyName, rPropertyValue );
463 for(sal_Int32 nN=aAttributedDataPointIndexList.getLength();nN--;)
468 xPointProp->setPropertyValue( rPropertyName, rPropertyValue );
469 if( rPropertyName ==
"LabelPlacement" )
470 xPointProp->setPropertyValue(
"CustomLabelPosition",
uno::Any());
476 const OUString& rPropertyName,
const uno::Any& rPropertyValue )
485 for(sal_Int32 nN=aAttributedDataPointIndexList.getLength();nN--;)
490 uno::Any aPointValue( xPointProp->getPropertyValue( rPropertyName ) );
491 if( rPropertyValue != aPointValue )
514 xProp->getPropertyValue(
"HiddenValues" ) >>= aHiddenIndicesSeq;
515 if( aHiddenIndicesSeq.hasElements() )
518 std::sort( aHiddenIndices.begin(), aHiddenIndices.end() );
520 sal_Int32 nHiddenCount =
static_cast<sal_Int32
>(aHiddenIndices.size());
521 for( sal_Int32 nN = 0; nN < nHiddenCount; ++nN)
523 if( aHiddenIndices[nN] <=
nIndex )
531 catch (
const beans::UnknownPropertyException&)
550 catch(
const uno::Exception &)
568 for(sal_Int32 nN=aAttributedDataPointIndexList.getLength();nN--;)
571 if( xPointProp.is() )
585 catch(
const uno::Exception &)
604 auto aIt = std::find( std::as_const(aAttributedDataPointIndexList).
begin(), std::as_const(aAttributedDataPointIndexList).
end(), nPointIndex );
605 if( aIt != std::as_const(aAttributedDataPointIndexList).
end())
606 xProp = xSeries->getDataPointByIndex(nPointIndex);
620 catch(
const uno::Exception &)
629 lcl_insertOrDeleteDataLabelsToSeriesAndAllPoints( xSeries,
true );
634 lcl_insertOrDeleteDataLabelsToSeriesAndAllPoints( xSeries,
false );
641 if( xPointProp.is() )
649 catch(
const uno::Exception &)
659 if( xPointProp.is() )
663 aLabel.ShowNumber =
false;
664 aLabel.ShowNumberInPercent =
false;
665 aLabel.ShowCategoryName =
false;
666 aLabel.ShowCustomLabel =
false;
667 aLabel.ShowSeriesName =
false;
672 catch(
const uno::Exception &)
tCoordinateSystemContainerType getBaseCoordinateSystems() const
#define TOOLS_WARN_EXCEPTION(area, stream)
#define DBG_UNHANDLED_EXCEPTION(...)
Sequence< sal_Int8 > aSeq
OOO_DLLPUBLIC_CHARTTOOLS bool hasDataLabelAtPoint(const rtl::Reference< ::chart::DataSeries > &xSeries, sal_Int32 nPointIndex)
OOO_DLLPUBLIC_CHARTTOOLS rtl::Reference< ::chart::BaseCoordinateSystem > getCoordinateSystemOfSeries(const rtl::Reference< ::chart::DataSeries > &xSeries, const rtl::Reference< ::chart::Diagram > &xDiagram)
OOO_DLLPUBLIC_CHARTTOOLS void switchLinesOnOrOff(const rtl::Reference< ::chart::DataSeries > &xSeries, bool bLinesOn)
OOO_DLLPUBLIC_CHARTTOOLS std::vector< css::uno::Reference< css::chart2::data::XLabeledDataSequence > > getAllDataSequences(const std::vector< rtl::Reference<::chart::DataSeries > > &aSeries)
OOO_DLLPUBLIC_CHARTTOOLS void insertDataLabelToPoint(const css::uno::Reference< css::beans::XPropertySet > &xPointPropertySet)
OOO_DLLPUBLIC_CHARTTOOLS void setStackModeAtSeries(const std::vector< rtl::Reference< ::chart::DataSeries > > &aSeries, const rtl::Reference< ::chart::BaseCoordinateSystem > &xCorrespondingCoordinateSystem, StackMode eStackMode)
OOO_DLLPUBLIC_CHARTTOOLS bool hasDataLabelsAtSeries(const rtl::Reference< ::chart::DataSeries > &xSeries)
OOO_DLLPUBLIC_CHARTTOOLS void insertDataLabelsToSeriesAndAllPoints(const rtl::Reference< ::chart::DataSeries > &xSeries)
OOO_DLLPUBLIC_CHARTTOOLS void setPropertyAlsoToAllAttributedDataPoints(const rtl::Reference< ::chart::DataSeries > &xSeries, const OUString &rPropertyName, const css::uno::Any &rPropertyValue)
OOO_DLLPUBLIC_CHARTTOOLS sal_Int32 getNumberFormatKeyFromAxis(const rtl::Reference< ::chart::DataSeries > &xSeries, const rtl::Reference< ::chart::BaseCoordinateSystem > &xCorrespondingCoordinateSystem, sal_Int32 nDimensionIndex, sal_Int32 nAxisIndex=-1)
OOO_DLLPUBLIC_CHARTTOOLS void deleteSeries(const rtl::Reference< ::chart::DataSeries > &xSeries, const rtl::Reference< ::chart::ChartType > &xChartType)
OOO_DLLPUBLIC_CHARTTOOLS rtl::Reference< ::chart::DataSource > getDataSource(const std::vector< rtl::Reference< ::chart::DataSeries > > &aSeries)
Retrieves all data sequences found in the given data series and puts them into a data source.
OOO_DLLPUBLIC_CHARTTOOLS css::uno::Reference< css::chart2::data::XLabeledDataSequence > getDataSequenceByRole(const css::uno::Reference< css::chart2::data::XDataSource > &xSource, const OUString &aRole, bool bMatchPrefix=false)
Retrieves the data sequence in the given data source that matches the given role.
OOO_DLLPUBLIC_CHARTTOOLS void deleteDataLabelsFromSeriesAndAllPoints(const rtl::Reference< ::chart::DataSeries > &xSeries)
OOO_DLLPUBLIC_CHARTTOOLS sal_Int32 translateIndexFromHiddenToFullSequence(sal_Int32 nClippedIndex, const css::uno::Reference< css::chart2::data::XDataSequence > &xDataSequence, bool bTranslate)
OOO_DLLPUBLIC_CHARTTOOLS std::vector< css::uno::Reference< css::chart2::data::XLabeledDataSequence > > getAllDataSequencesByRole(const css::uno::Sequence< css::uno::Reference< css::chart2::data::XLabeledDataSequence > > &aDataSequences, const OUString &aRole)
Retrieves all data sequences in the given data source that match the given role prefix.
OOO_DLLPUBLIC_CHARTTOOLS OUString getRole(const css::uno::Reference< css::chart2::data::XLabeledDataSequence > &xLabeledDataSequence)
OOO_DLLPUBLIC_CHARTTOOLS rtl::Reference< ::chart::ChartType > getChartTypeOfSeries(const rtl::Reference< ::chart::DataSeries > &xSeries, const rtl::Reference< ::chart::Diagram > &xDiagram)
OOO_DLLPUBLIC_CHARTTOOLS bool hasAttributedDataPointDifferentValue(const rtl::Reference< ::chart::DataSeries > &xSeries, const OUString &rPropertyName, const css::uno::Any &rPropertyValue)
OOO_DLLPUBLIC_CHARTTOOLS sal_Int32 getAttachedAxisIndex(const rtl::Reference< ::chart::DataSeries > &xSeries)
OOO_DLLPUBLIC_CHARTTOOLS void makeLinesThickOrThin(const rtl::Reference< ::chart::DataSeries > &xSeries, bool bThick)
OOO_DLLPUBLIC_CHARTTOOLS void switchSymbolsOnOrOff(const rtl::Reference< ::chart::DataSeries > &xSeries, bool bSymbolsOn, sal_Int32 nSeriesIndex)
OOO_DLLPUBLIC_CHARTTOOLS bool hasDataLabelsAtPoints(const rtl::Reference< ::chart::DataSeries > &xSeries)
OOO_DLLPUBLIC_CHARTTOOLS void deleteDataLabelsFromPoint(const css::uno::Reference< css::beans::XPropertySet > &xPointPropertySet)
@ PROP_DATASERIES_ATTRIBUTED_DATA_POINTS
DstType sequenceToContainer(const css::uno::Sequence< SrcType > &i_Sequence)
enumrange< T >::Iterator begin(enumrange< T >)
constexpr OUStringLiteral CHART_UNONAME_NUMFMT
constexpr OUStringLiteral CHART_UNONAME_CUSTOM_LABEL_FIELDS
constexpr OUStringLiteral CHART_UNONAME_LABEL