25#include <com/sun/star/beans/XPropertySet.hpp>
35using ::com::sun::star::uno::Reference;
36using ::com::sun::star::uno::Sequence;
38#ifdef DEBUG_CHART2_TEMPLATE
41void lcl_ShowDataSource(
const Reference< data::XDataSource > & xSource );
63#ifdef DEBUG_CHART2_TEMPLATE
64 lcl_ShowDataSource( xSource );
67 std::vector< uno::Reference< chart2::data::XLabeledDataSequence > >
aData =
getDataSequences(xSource);
70 std::vector< uno::Reference< chart2::data::XLabeledDataSequence > > aSequencesVec;
77 bool bCategoriesUsed =
false;
82 if( bHasCategories && ! bCategoriesUsed )
84 xCategories = labeledData;
86 SetRole( xCategories->getValues(),
"categories");
87 bCategoriesUsed =
true;
91 aSequencesVec.push_back( labeledData );
93 SetRole( labeledData->getValues(),
"values-y");
96 catch(
const uno::Exception & )
103 std::size_t nSeriesIndex = 0;
104 std::vector< rtl::Reference< DataSeries > > aSeriesVec;
105 aSeriesVec.reserve( aSequencesVec.size());
107 for (
auto const& elem : aSequencesVec)
109 std::vector< uno::Reference< chart2::data::XLabeledDataSequence > > aNewData { elem };
111 if( nSeriesIndex < aSeriesToReUse.size())
112 xSeries = aSeriesToReUse[nSeriesIndex];
115 assert( xSeries.is() );
116 xSeries->setData( aNewData );
118 aSeriesVec.push_back( xSeries );
122 return { { aSeriesVec }, xCategories };
132 const sal_Int32
nCount = aSeries.size();
137 std::vector< uno::Reference< data::XLabeledDataSequence > > aNewSequences;
148 SetRole( xValuesY->getValues(),
"values-y");
152 aNewSequences = { xValuesY };
155 const std::vector< uno::Reference< data::XLabeledDataSequence > > & aSeqs = aSeries[
i]->getDataSequences2();
156 if( aSeqs.size() != aNewSequences.size() )
158#ifdef DEBUG_CHART2_TEMPLATE
160 for( ; j<aSeqs.(); ++j )
162 assert( aSeqs[j] == xValuesY &&
"All sequences should be used" );
165 aSeries[
i]->setData( aNewSequences );
168 catch(
const uno::Exception & )
181 const std::vector< rtl::Reference< DataSeries > > aSeries(
FlattenSequence( aInterpretedData.
Series ));
186 if(
i->getDataSequences2().size() != 1 )
189 catch(
const uno::Exception & )
201struct lcl_LabeledSequenceEquals
207 if( !xLSeqToCmp.is())
217 xSeq.set( xLSeqToCmp->getLabel());
225 bool operator() (
const Reference< data::XLabeledDataSequence > & xSeq )
230 Reference< data::XDataSequence > xSeqValues( xSeq->getValues() );
231 Reference< data::XDataSequence > xSeqLabels( xSeq->getLabel() );
232 bool bHasValues = xSeqValues.is();
233 bool bHasLabels = xSeqLabels.is();
236 (!bHasValues ||
m_aValuesRangeRep == xSeqValues->getSourceRangeRepresentation()) ) &&
238 (!bHasLabels ||
m_aLabelRangeRep == xSeqLabels->getSourceRangeRepresentation()) )
254 std::vector< Reference< data::XLabeledDataSequence > > aResultVec;
255 aResultVec.reserve( aInterpretedData.
Series.size() +
260 aResultVec.push_back( aInterpretedData.
Categories );
262 const std::vector< rtl::Reference< DataSeries > > aSeries =
FlattenSequence( aInterpretedData.
Series );
271 if( none_of( aResultVec.begin(), aResultVec.end(),
272 lcl_LabeledSequenceEquals( xAdd )) )
274 aResultVec.push_back( xAdd );
278 catch(
const uno::Exception & )
304 xProp->getPropertyValue(
"Role") >>= aResult;
306 catch(
const uno::Exception & )
320 xProp->setPropertyValue(
"Role",
uno::Any( rRole ));
322 catch(
const uno::Exception & )
330 std::u16string_view rName )
344 bool bHasCategories =
false;
346 if( rArguments.hasElements() )
347 GetProperty( rArguments,
u"HasCategories" ) >>= bHasCategories;
349 for( std::size_t nLSeqIdx=0; ! bHasCategories && nLSeqIdx<rData.size(); ++nLSeqIdx )
350 bHasCategories = ( rData[nLSeqIdx].is() &&
GetRole( rData[nLSeqIdx]->getValues() ) ==
"categories");
352 return bHasCategories;
357 bool bUseCategoriesAsX =
true;
358 if( rArguments.hasElements() )
359 GetProperty( rArguments,
u"UseCategoriesAsX" ) >>= bUseCategoriesAsX;
360 return bUseCategoriesAsX;
365 return "com.sun.star.comp.chart2.DataInterpreter";
375 return {
"com.sun.star.chart2.DataInterpreter" };
379 const css::uno::Reference< css::chart2::data::XDataSource >& xSource)
381 std::vector< uno::Reference< chart2::data::XLabeledDataSequence > >
aData;
384 aData.push_back(rLDS);
391#ifdef DEBUG_CHART2_TEMPLATE
395void lcl_ShowDataSource(
const Reference< data::XDataSource > & xSource )
400 SAL_INFO(
"chart2",
"DataSource in DataInterpreter:" );
401 Sequence< Reference< data::XLabeledDataSequence > > aSequences( xSource->getDataSequences());
402 Reference< beans::XPropertySet > xProp;
404 const sal_Int32 nMax = aSequences.getLength();
405 for( sal_Int32 k = 0; k < nMax; ++k )
407 if( aSequences[k].is())
409 OUString aSourceRepr(
"<none>");
410 if( aSequences[k]->getValues().is())
411 aSourceRepr = aSequences[k]->getValues()->getSourceRangeRepresentation();
412 xProp.set( aSequences[k]->getValues(), uno::UNO_QUERY );
414 ( xProp->getPropertyValue(
"Role") >>= aId ))
416 SAL_INFO(
"chart2",
" <data sequence " << k <<
"> Role: " << aId <<
", Source: "<< aSourceRepr);
420 SAL_INFO(
"chart2",
" <data sequence " << k <<
"> unknown Role, Source: " << aSourceRepr );
423 aSourceRepr =
"<none>";
424 if( aSequences[k]->getLabel().is())
425 aSourceRepr = aSequences[k]->getLabel()->getSourceRangeRepresentation();
426 xProp.set( aSequences[k]->getLabel(), uno::UNO_QUERY );
428 ( xProp->getPropertyValue(
"Role") >>= aId ))
430 SAL_INFO(
"chart2",
" <data sequence label " << k <<
"> Role: " << aId
431 <<
", Source: " << aSourceRepr );
435 SAL_INFO(
"chart2",
" <data sequence label " << k <<
"> unknown Role, Source: " << aSourceRepr );
OUString m_aLabelRangeRep
OUString m_aValuesRangeRep
static bool HasCategories(const css::uno::Sequence< css::beans::PropertyValue > &rArguments, const std::vector< css::uno::Reference< css::chart2::data::XLabeledDataSequence > > &rData)
static OUString GetRole(const css::uno::Reference< css::chart2::data::XDataSequence > &xSeq)
virtual css::uno::Any getChartTypeSpecificData(const OUString &sKey)
Get chart information that is specific to a particular chart type, by key.
static rtl::Reference< ::chart::DataSource > mergeInterpretedData(const InterpretedData &aInterpretedData)
Try to reverse the operation done in interpretDataSource().
virtual ~DataInterpreter() override
virtual OUString SAL_CALL getImplementationName() override
XServiceInfo declarations.
virtual InterpretedData reinterpretDataSeries(const InterpretedData &aInterpretedData)
Re-interprets the data given in aInterpretedData while keeping the number of data series and the cate...
static std::vector< css::uno::Reference< css::chart2::data::XLabeledDataSequence > > getDataSequences(const css::uno::Reference< css::chart2::data::XDataSource > &xSource)
static void SetRole(const css::uno::Reference< css::chart2::data::XDataSequence > &xSeq, const OUString &rRole)
static css::uno::Any GetProperty(const css::uno::Sequence< css::beans::PropertyValue > &aArguments, std::u16string_view rName)
virtual bool isDataCompatible(const InterpretedData &aInterpretedData)
parses the given data and states, if a reinterpretDataSeries() call can be done without data loss.
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
static bool UseCategoriesAsX(const css::uno::Sequence< css::beans::PropertyValue > &rArguments)
virtual InterpretedData interpretDataSource(const css::uno::Reference< css::chart2::data::XDataSource > &xSource, const css::uno::Sequence< css::beans::PropertyValue > &aArguments, const std::vector< rtl::Reference< ::chart::DataSeries > > &aSeriesToReUse)
Interprets the given data.
virtual sal_Bool SAL_CALL supportsService(const OUString &ServiceName) override
#define DBG_UNHANDLED_EXCEPTION(...)
Sequence< PropertyValue > aArguments
#define SAL_INFO(area, stream)
constexpr OUStringLiteral aData
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.
std::vector< T > FlattenSequence(const std::vector< std::vector< T > > &aSeqSeq)
std::vector< std::vector< T > > -> std::vector< T >
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
offers tooling to interpret different data sources in a structural and chart-type-dependent way.
std::vector< std::vector< rtl::Reference<::chart::DataSeries > > > Series
css::uno::Reference< css::chart2::data::XLabeledDataSequence > Categories