diff options
author | Vladimir Glazounov <vg@openoffice.org> | 2007-05-22 17:57:32 +0000 |
---|---|---|
committer | Vladimir Glazounov <vg@openoffice.org> | 2007-05-22 17:57:32 +0000 |
commit | 98429e54189c6e5aeb5201364ac42f75dc78abcb (patch) | |
tree | 81d7dd178bd8b9e183659ba3f963ccfd449a45f8 | |
parent | 173013b5e4d0691e23025f266746e09bcc1ab24a (diff) |
INTEGRATION: CWS chart2mst3 (1.1.4); FILE MERGED
2007/03/06 14:09:24 bm 1.1.4.34: lcl_findLSequenceWithOnlyLabel: make more safe if labeled sequence is empty
2007/02/24 10:38:28 iha 1.1.4.33: #i74648# also change attributed data points
2007/02/23 18:07:52 iha 1.1.4.32: #i74655# symbols lost when switching smooth lines
2007/02/09 12:39:03 bm 1.1.4.31: #i72841# temporary did not work on Linux
2007/02/09 12:29:58 bm 1.1.4.30: #i72841# move deleteSeries functionality here from source/controller/dialog/DialogModel.cxx
2006/12/11 17:31:54 bm 1.1.4.29: #i72308# allow to set the label before the values of a series
2006/10/18 17:16:03 bm 1.1.4.28: RESYNC: (1.2-1.3); FILE MERGED
2006/08/02 11:16:27 bm 1.1.4.27: #i27352# implement quick help
2006/07/25 16:46:03 bm 1.1.4.26: #i64824# handle number formats in the data browser
2006/07/19 08:46:04 bm 1.1.4.25: getLabelForLabeledDataSequence: some comments added
2006/04/11 10:53:38 bm 1.1.4.24: getAttachedAxisIndex: return a value
2006/04/10 12:25:15 iha 1.1.4.23: api restructure axis, grids, scales and increments
2006/03/10 12:45:34 bm 1.1.4.22: #i63011# explicit qualification in declaration, function names were qualified with namespace (was a class in the past)
2005/12/21 21:29:26 iha 1.1.4.21: remove identifiers from model objects and create an index based CID protocol instead for selection purposes
2005/11/02 19:19:16 iha 1.1.4.20: added helping method SetRole()
2005/11/01 13:08:08 iha 1.1.4.19: support sequence mapping
2005/10/29 18:50:11 iha 1.1.4.18: make more failsave
2005/10/27 17:43:54 iha 1.1.4.17: support autogenerated label
2005/10/25 16:28:30 iha 1.1.4.16: corrected getDataSeriesLabel
2005/10/24 11:06:55 iha 1.1.4.15: coordinate system restructure
2005/10/13 17:39:08 iha 1.1.4.14: renamed BoundedCoordinateSystem to CoordinateSystem
2005/10/07 12:07:38 bm 1.1.4.13: RESYNC: (1.1-1.2); FILE MERGED
2005/09/16 16:50:15 iha 1.1.4.12: no creation of dummy categories in model - instead trigger generation of missing labels and categories in view
2005/09/08 18:17:42 iha 1.1.4.11: use generated labels for series names
2005/08/03 16:36:27 bm 1.1.4.10: algohelper.hxx split up into CommonFunctors.hxx ContainerHelper.hxx CloneHelper.hxx
2005/05/09 13:01:22 bm 1.1.4.9: data namespace forgotten
2005/05/09 09:51:32 bm 1.1.4.8: moved parts of API to data namespace
2004/09/17 10:52:50 bm 1.1.4.7: API simplification
2004/09/15 11:48:26 bm 1.1.4.6: API simplification
2004/05/07 15:36:50 bm 1.1.4.5: legend-entries: use TextualDataSequence if available
2004/04/27 13:42:02 bm 1.1.4.4: +createUniqueSeriesId that calculates a yet unused id
+getDataSeriesIdentifier convenience to get the Identifier property of a series
2004/03/19 14:33:01 bm 1.1.4.3: XDataSource now contains XLabeledDataSources
2004/02/16 09:03:06 bm 1.1.4.2: operator lcl_MatchesRole needs const operator()
2004/02/13 16:51:50 bm 1.1.4.1: join from changes on branch bm_post_chart01
-rw-r--r-- | chart2/source/tools/DataSeriesHelper.cxx | 608 |
1 files changed, 592 insertions, 16 deletions
diff --git a/chart2/source/tools/DataSeriesHelper.cxx b/chart2/source/tools/DataSeriesHelper.cxx index e9f3555273a4..30ece8f61581 100644 --- a/chart2/source/tools/DataSeriesHelper.cxx +++ b/chart2/source/tools/DataSeriesHelper.cxx @@ -4,9 +4,9 @@ * * $RCSfile: DataSeriesHelper.cxx,v $ * - * $Revision: 1.3 $ + * $Revision: 1.4 $ * - * last change: $Author: obo $ $Date: 2006-09-17 13:23:19 $ + * last change: $Author: vg $ $Date: 2007-05-22 18:57:32 $ * * The Contents of this file are made available subject to * the terms of GNU Lesser General Public License Version 2.1. @@ -36,35 +36,84 @@ // MARKER(update_precomp.py): autogen include statement, do not remove #include "precompiled_chart2.hxx" #include "DataSeriesHelper.hxx" +#include "DiagramHelper.hxx" +#include "DataSource.hxx" +#include "macros.hxx" +#include "ContainerHelper.hxx" #ifndef _COM_SUN_STAR_BEANS_XPROPERTYSET_HPP_ #include <com/sun/star/beans/XPropertySet.hpp> #endif +#ifndef _COM_SUN_STAR_CHART2_DATA_XTEXTUALDATASEQUENCE_HPP_ +#include <com/sun/star/chart2/data/XTextualDataSequence.hpp> +#endif +#ifndef _COM_SUN_STAR_CHART2_STACKINGDIRECTION_HPP_ +#include <com/sun/star/chart2/StackingDirection.hpp> +#endif +#ifndef _COM_SUN_STAR_CHART2_DATA_LABELORIGIN_HPP_ +#include <com/sun/star/chart2/data/LabelOrigin.hpp> +#endif +#ifndef _COM_SUN_STAR_CHART2_AXISTYPE_HPP_ +#include <com/sun/star/chart2/AxisType.hpp> +#endif + +#ifndef _COM_SUN_STAR_CHART2_SYMBOLSTYLE_HPP_ +#include <com/sun/star/chart2/SymbolStyle.hpp> +#endif +#ifndef _COM_SUN_STAR_CHART2_SYMBOL_HPP_ +#include <com/sun/star/chart2/Symbol.hpp> +#endif +#ifndef _COM_SUN_STAR_DRAWING_LINESTYLE_HPP_ +#include <com/sun/star/drawing/LineStyle.hpp> +#endif + + +#include <com/sun/star/chart2/XCoordinateSystemContainer.hpp> +#include <com/sun/star/chart2/XChartTypeContainer.hpp> +#include <com/sun/star/chart2/XDataSeriesContainer.hpp> + +#ifndef _RTL_USTRBUF_HXX_ +#include <rtl/ustrbuf.hxx> +#endif #include <functional> #include <algorithm> +#include <iterator> +#include <vector> +#include <set> using namespace ::com::sun::star; using ::com::sun::star::uno::Reference; using ::com::sun::star::uno::Sequence; using ::rtl::OUString; +using ::rtl::OUStringBuffer; // ---------------------------------------- namespace { -class lcl_MatchesRole : public ::std::unary_function< bool, Reference< chart2::XDataSequence > > +class lcl_MatchesRole : public ::std::unary_function< Reference< chart2::data::XLabeledDataSequence >, bool > { public: - lcl_MatchesRole( const OUString & aRole ) : - m_aRole( aRole ) + explicit lcl_MatchesRole( const OUString & aRole, bool bMatchPrefix ) : + m_aRole( aRole ), + m_bMatchPrefix( bMatchPrefix ) {} - bool operator () ( const Reference< chart2::XDataSequence > & xSeq ) + bool operator () ( const Reference< chart2::data::XLabeledDataSequence > & xSeq ) const { - Reference< beans::XPropertySet > xProp( xSeq, uno::UNO_QUERY ); + if(!xSeq.is()) + return false; + Reference< beans::XPropertySet > xProp( xSeq->getValues(), uno::UNO_QUERY ); OUString aRole; + + if( m_bMatchPrefix ) + return ( xProp.is() && + (xProp->getPropertyValue( + OUString( RTL_CONSTASCII_USTRINGPARAM( "Role" )) ) >>= aRole ) && + aRole.match( m_aRole )); + return ( xProp.is() && (xProp->getPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "Role" )) ) >>= aRole ) && @@ -73,8 +122,65 @@ public: private: OUString m_aRole; + bool m_bMatchPrefix; }; +Reference< chart2::data::XLabeledDataSequence > lcl_findLSequenceWithOnlyLabel( + const Reference< chart2::data::XDataSource > & xDataSource ) +{ + Reference< chart2::data::XLabeledDataSequence > xResult; + Sequence< Reference< chart2::data::XLabeledDataSequence > > aSequences( xDataSource->getDataSequences()); + + for( sal_Int32 i=0; i<aSequences.getLength(); ++i ) + { + OSL_ENSURE( aSequences[i].is(), "empty LabeledDataSequence" ); + // no values are set but a label exists + if( aSequences[i].is() && + ( ! aSequences[i]->getValues().is() && + aSequences[i]->getLabel().is())) + { + xResult.set( aSequences[i] ); + break; + } + } + + return xResult; +} + +void lcl_getCooSysAndChartTypeOfSeries( + const Reference< chart2::XDataSeries > & xSeries, + const Reference< chart2::XDiagram > & xDiagram, + Reference< chart2::XCoordinateSystem > & xOutCooSys, + Reference< chart2::XChartType > & xOutChartType ) +{ + Reference< chart2::XCoordinateSystemContainer > xCooSysCnt( xDiagram, uno::UNO_QUERY ); + if( xCooSysCnt.is()) + { + Sequence< Reference< chart2::XCoordinateSystem > > aCooSysSeq( xCooSysCnt->getCoordinateSystems()); + for( sal_Int32 nCooSysIdx=0; nCooSysIdx<aCooSysSeq.getLength(); ++nCooSysIdx ) + { + Reference< chart2::XChartTypeContainer > xCTCnt( aCooSysSeq[nCooSysIdx], uno::UNO_QUERY_THROW ); + Sequence< Reference< chart2::XChartType > > aChartTypes( xCTCnt->getChartTypes()); + for( sal_Int32 nCTIdx=0; nCTIdx<aChartTypes.getLength(); ++nCTIdx ) + { + Reference< chart2::XDataSeriesContainer > xSeriesCnt( aChartTypes[nCTIdx], uno::UNO_QUERY ); + if( xSeriesCnt.is()) + { + Sequence< Reference< chart2::XDataSeries > > aSeries( xSeriesCnt->getDataSeries()); + for( sal_Int32 nSeriesIdx=0; nSeriesIdx<aSeries.getLength(); ++nSeriesIdx ) + { + if( aSeries[nSeriesIdx] == xSeries ) + { + xOutCooSys.set( aCooSysSeq[nCooSysIdx] ); + xOutChartType.set( aChartTypes[nCTIdx] ); + } + } + } + } + } + } +} + } // anonymous namespace // ---------------------------------------- @@ -84,20 +190,43 @@ namespace chart namespace DataSeriesHelper { -Reference< chart2::XDataSequence > +OUString GetRole( const uno::Reference< chart2::data::XLabeledDataSequence >& xLabeledDataSequence ) +{ + OUString aRet; + if( xLabeledDataSequence.is() ) + { + Reference< beans::XPropertySet > xProp( xLabeledDataSequence->getValues(), uno::UNO_QUERY ); + if( xProp.is() ) + xProp->getPropertyValue( C2U("Role") ) >>= aRet; + } + return aRet; +} + +void SetRole( const uno::Reference< chart2::data::XLabeledDataSequence >& xLabeledDataSequence, + const ::rtl::OUString& rRole ) +{ + if( xLabeledDataSequence.is() ) + { + Reference< beans::XPropertySet > xProp( xLabeledDataSequence->getValues(), uno::UNO_QUERY ); + if( xProp.is() ) + xProp->setPropertyValue( C2U("Role"), uno::makeAny(rRole) ) ; + } +} + +Reference< chart2::data::XLabeledDataSequence > getDataSequenceByRole( - const Reference< chart2::XDataSource > & xSource, OUString aRole ) + const Reference< chart2::data::XDataSource > & xSource, OUString aRole, + bool bMatchPrefix /* = false */ ) { - Reference< chart2::XDataSequence > aNoResult; + Reference< chart2::data::XLabeledDataSequence > aNoResult; if( ! xSource.is()) return aNoResult; + Sequence< Reference< chart2::data::XLabeledDataSequence > > aLabeledSeq( xSource->getDataSequences()); - Sequence< Reference< chart2::XDataSequence > > aSeq( xSource->getDataSequences()); - - const Reference< chart2::XDataSequence > * pBegin = aSeq.getConstArray(); - const Reference< chart2::XDataSequence > * pEnd = pBegin + aSeq.getLength(); - const Reference< chart2::XDataSequence > * pMatch = - ::std::find_if( pBegin, pEnd, lcl_MatchesRole( aRole )); + const Reference< chart2::data::XLabeledDataSequence > * pBegin = aLabeledSeq.getConstArray(); + const Reference< chart2::data::XLabeledDataSequence > * pEnd = pBegin + aLabeledSeq.getLength(); + const Reference< chart2::data::XLabeledDataSequence > * pMatch = + ::std::find_if( pBegin, pEnd, lcl_MatchesRole( aRole, bMatchPrefix )); if( pMatch != pEnd ) return *pMatch; @@ -105,5 +234,452 @@ Reference< chart2::XDataSequence > return aNoResult; } +::std::vector< Reference< chart2::data::XLabeledDataSequence > > + getAllDataSequencesByRole( const Sequence< Reference< chart2::data::XLabeledDataSequence > > & aDataSequences, + OUString aRole, bool bMatchPrefix /* = false */ ) +{ + ::std::vector< Reference< chart2::data::XLabeledDataSequence > > aResultVec; + ::std::remove_copy_if( aDataSequences.getConstArray(), aDataSequences.getConstArray() + aDataSequences.getLength(), + ::std::back_inserter( aResultVec ), + ::std::not1( lcl_MatchesRole( aRole, bMatchPrefix ))); + return aResultVec; +} + +Reference< chart2::data::XDataSource > + getDataSource( const Sequence< Reference< chart2::XDataSeries > > & aSeries ) +{ + ::std::vector< Reference< chart2::data::XLabeledDataSequence > > aSeqVec; + + for( sal_Int32 i = 0; i < aSeries.getLength(); ++i ) + { + Reference< chart2::data::XDataSource > xSource( aSeries[ i ], uno::UNO_QUERY ); + if( xSource.is()) + { + Sequence< Reference< chart2::data::XLabeledDataSequence > > aSeq( xSource->getDataSequences()); + ::std::copy( aSeq.getConstArray(), aSeq.getConstArray() + aSeq.getLength(), + ::std::back_inserter( aSeqVec )); + } + } + + return Reference< chart2::data::XDataSource >( + new DataSource( ContainerHelper::ContainerToSequence( aSeqVec ))); +} + +namespace +{ +OUString lcl_getDataSequenceLabel( const Reference< chart2::data::XDataSequence > & xSequence ) +{ + OUString aResult; + + Reference< chart2::data::XTextualDataSequence > xTextSeq( xSequence, uno::UNO_QUERY ); + if( xTextSeq.is()) + { + Sequence< OUString > aSeq( xTextSeq->getTextualData()); + + const sal_Int32 nMax = aSeq.getLength() - 1; + OUString aVal; + OUStringBuffer aBuf; + + for( sal_Int32 i = 0; i <= nMax; ++i ) + { + aBuf.append( aSeq[i] ); + if( i < nMax ) + aBuf.append( sal_Unicode( ' ' )); + } + aResult = aBuf.makeStringAndClear(); + } + else if( xSequence.is()) + { + Sequence< uno::Any > aSeq( xSequence->getData()); + + const sal_Int32 nMax = aSeq.getLength() - 1; + OUString aVal; + OUStringBuffer aBuf; + double fNum; + + for( sal_Int32 i = 0; i <= nMax; ++i ) + { + if( aSeq[i] >>= aVal ) + { + aBuf.append( aVal ); + if( i < nMax ) + aBuf.append( sal_Unicode( ' ' )); + } + else if( aSeq[ i ] >>= fNum ) + { + aBuf.append( fNum ); + if( i < nMax ) + aBuf.append( sal_Unicode( ' ' )); + } + } + aResult = aBuf.makeStringAndClear(); + } + + return aResult; +} +} + +OUString getLabelForLabeledDataSequence( + const Reference< chart2::data::XLabeledDataSequence > & xLabeledSeq ) +{ + OUString aResult; + if( xLabeledSeq.is()) + { + Reference< chart2::data::XDataSequence > xSeq( xLabeledSeq->getLabel()); + if( xSeq.is() ) + aResult = lcl_getDataSequenceLabel( xSeq ); + if( !xSeq.is() || !aResult.getLength() ) + { + // no label set or label content is empty -> use auto-generated one + Reference< chart2::data::XDataSequence > xValueSeq( xLabeledSeq->getValues() ); + if( xValueSeq.is() ) + { + Sequence< OUString > aLabels( xValueSeq->generateLabel( + chart2::data::LabelOrigin_SHORT_SIDE ) ); + // no labels returned is interpreted as: auto-generation not + // supported by sequence + if( aLabels.getLength() ) + aResult=aLabels[0]; + else + { + //todo?: maybe use the index of the series as name + //but as the index may change it would be better to have such a name persistent + //what is not possible at the moment + //--> maybe use the identifier as part of the name ... + aResult = lcl_getDataSequenceLabel( xValueSeq ); + } + } + } + } + return aResult; +} + +OUString getDataSeriesLabel( + const Reference< chart2::XDataSeries > & xSeries, + const OUString & rLabelSequenceRole ) +{ + OUString aResult; + + Reference< chart2::data::XDataSource > xSource( xSeries, uno::UNO_QUERY ); + if( xSource.is()) + { + Reference< chart2::data::XLabeledDataSequence > xLabeledSeq( + ::chart::DataSeriesHelper::getDataSequenceByRole( xSource, rLabelSequenceRole )); + if( xLabeledSeq.is()) + aResult = getLabelForLabeledDataSequence( xLabeledSeq ); + else + { + // special case: labeled data series with only a label and no values may + // serve as label + xLabeledSeq.set( lcl_findLSequenceWithOnlyLabel( xSource )); + if( xLabeledSeq.is()) + { + Reference< chart2::data::XDataSequence > xSeq( xLabeledSeq->getLabel()); + if( xSeq.is()) + aResult = lcl_getDataSequenceLabel( xSeq ); + } + } + + } + + return aResult; +} + +StackMode getStackModeFromSeries( + const Sequence< Reference< chart2::XDataSeries > > & aSeries, + const Reference< chart2::XCoordinateSystem > & xCorrespondingCoordinateSystem ) +{ + StackMode eStackMode = StackMode_NONE; + + try + { + chart2::StackingDirection eCommonDirection = chart2::StackingDirection_NO_STACKING; + bool bDirectionInitialized = false; + + // first series is irrelvant for stacking, start with second, unless + // there is only one series + const sal_Int32 nSeriesCount = aSeries.getLength(); + sal_Int32 i = (nSeriesCount == 1) ? 0: 1; + for( ; i<nSeriesCount; ++i ) + { + Reference< beans::XPropertySet > xProp( aSeries[i], uno::UNO_QUERY_THROW ); + chart2::StackingDirection eCurrentDirection = eCommonDirection; + // property is not MAYBEVOID + bool bSuccess = ( xProp->getPropertyValue( C2U("StackingDirection") ) >>= eCurrentDirection ); + OSL_ASSERT( bSuccess ); + if( ! bDirectionInitialized ) + { + eCommonDirection = eCurrentDirection; + bDirectionInitialized = true; + } + else + { + if( eCommonDirection != eCurrentDirection ) + { + eStackMode = StackMode_AMBIGUOUS; + break; + } + } + } + + if( eStackMode != StackMode_AMBIGUOUS ) + { + if( eCommonDirection == chart2::StackingDirection_Z_STACKING ) + eStackMode = StackMode_Z_STACKED; + else if( eCommonDirection == chart2::StackingDirection_Y_STACKING ) + { + eStackMode = StackMode_Y_STACKED; + + // percent stacking + if( xCorrespondingCoordinateSystem.is() ) + { + if( 1 < xCorrespondingCoordinateSystem->getDimension() ) + { + sal_Int32 nAxisIndex = 0; + if( nSeriesCount ) + nAxisIndex = getAttachedAxisIndex(aSeries[0]); + + Reference< chart2::XAxis > xAxis( + xCorrespondingCoordinateSystem->getAxisByDimension( 1,nAxisIndex )); + if( xAxis.is()) + { + chart2::ScaleData aScaleData = xAxis->getScaleData(); + if( aScaleData.AxisType==chart2::AxisType::PERCENT ) + eStackMode = StackMode_Y_STACKED_PERCENT; + } + } + } + } + } + } + catch( uno::Exception & ex ) + { + ASSERT_EXCEPTION( ex ); + } + + return eStackMode; +} + +void setStackModeAtSeries( + const Sequence< Reference< chart2::XDataSeries > > & aSeries, + const Reference< chart2::XCoordinateSystem > & xCorrespondingCoordinateSystem, + StackMode eStackMode ) +{ + if( eStackMode == StackMode_AMBIGUOUS ) + return; + + const OUString aPropName( RTL_CONSTASCII_USTRINGPARAM( "StackingDirection" )); + const uno::Any aPropValue = uno::makeAny( + ( (eStackMode == StackMode_Y_STACKED) || + (eStackMode == StackMode_Y_STACKED_PERCENT) ) + ? chart2::StackingDirection_Y_STACKING + : (eStackMode == StackMode_Z_STACKED ) + ? chart2::StackingDirection_Z_STACKING + : chart2::StackingDirection_NO_STACKING ); + + std::set< sal_Int32 > aAxisIndexSet; + for( sal_Int32 i=0; i<aSeries.getLength(); ++i ) + { + try + { + Reference< beans::XPropertySet > xProp( aSeries[i], uno::UNO_QUERY ); + if( xProp.is() ) + { + xProp->setPropertyValue( aPropName, aPropValue ); + + sal_Int32 nAxisIndex; + xProp->getPropertyValue( C2U("AttachedAxisIndex") ) >>= nAxisIndex; + aAxisIndexSet.insert(nAxisIndex); + } + } + catch( uno::Exception & ex ) + { + ASSERT_EXCEPTION( ex ); + } + } + + if( xCorrespondingCoordinateSystem.is() && + 1 < xCorrespondingCoordinateSystem->getDimension() ) + { + sal_Int32 nAxisIndexCount = aAxisIndexSet.size(); + if( !nAxisIndexCount ) + { + aAxisIndexSet.insert(0); + nAxisIndexCount = aAxisIndexSet.size(); + } + + for( ::std::set< sal_Int32 >::const_iterator aIt = aAxisIndexSet.begin(); + aIt != aAxisIndexSet.end(); ++aIt ) + { + sal_Int32 nAxisIndex = *aIt; + Reference< chart2::XAxis > xAxis( + xCorrespondingCoordinateSystem->getAxisByDimension( 1, nAxisIndex )); + if( xAxis.is()) + { + sal_Bool bPercent = (eStackMode == StackMode_Y_STACKED_PERCENT); + chart2::ScaleData aScaleData = xAxis->getScaleData(); + + if( bPercent != (aScaleData.AxisType==chart2::AxisType::PERCENT) ) + { + if( bPercent ) + aScaleData.AxisType = chart2::AxisType::PERCENT; + else + aScaleData.AxisType = chart2::AxisType::REALNUMBER; + xAxis->setScaleData( aScaleData ); + } + } + } + } +} + +sal_Int32 getAttachedAxisIndex( const Reference< chart2::XDataSeries > & xSeries ) +{ + sal_Int32 nRet = 0; + try + { + Reference< beans::XPropertySet > xProp( xSeries, uno::UNO_QUERY ); + if( xProp.is() ) + { + xProp->getPropertyValue( C2U("AttachedAxisIndex") ) >>= nRet; + } + } + catch( uno::Exception & ex ) + { + ASSERT_EXCEPTION( ex ); + } + return nRet; +} + +sal_Int32 getNumberFormatKeyFromAxis( + const Reference< chart2::XDataSeries > & xSeries, + const Reference< chart2::XCoordinateSystem > & xCorrespondingCoordinateSystem, + sal_Int32 nDimensionIndex, + sal_Int32 nAxisIndex /* = -1 */ ) +{ + sal_Int32 nResult = 0; + if( nAxisIndex == -1 ) + nAxisIndex = getAttachedAxisIndex( xSeries ); + try + { + Reference< beans::XPropertySet > xAxisProp( + xCorrespondingCoordinateSystem->getAxisByDimension( nDimensionIndex, nAxisIndex ), uno::UNO_QUERY ); + if( xAxisProp.is()) + xAxisProp->getPropertyValue( C2U("NumberFormat")) >>= nResult; + } + catch( const uno::Exception & ex ) + { + ASSERT_EXCEPTION( ex ); + } + + return nResult; +} + +Reference< chart2::XCoordinateSystem > getCoordinateSystemOfSeries( + const Reference< chart2::XDataSeries > & xSeries, + const Reference< chart2::XDiagram > & xDiagram ) +{ + Reference< chart2::XCoordinateSystem > xResult; + Reference< chart2::XChartType > xDummy; + lcl_getCooSysAndChartTypeOfSeries( xSeries, xDiagram, xResult, xDummy ); + + return xResult; +} + +Reference< chart2::XChartType > getChartTypeOfSeries( + const Reference< chart2::XDataSeries > & xSeries, + const Reference< chart2::XDiagram > & xDiagram ) +{ + Reference< chart2::XChartType > xResult; + Reference< chart2::XCoordinateSystem > xDummy; + lcl_getCooSysAndChartTypeOfSeries( xSeries, xDiagram, xDummy, xResult ); + + return xResult; +} + +void deleteSeries( + const Reference< chart2::XDataSeries > & xSeries, + const Reference< chart2::XChartType > & xChartType ) +{ + try + { + Reference< chart2::XDataSeriesContainer > xSeriesCnt( xChartType, uno::UNO_QUERY_THROW ); + ::std::vector< Reference< chart2::XDataSeries > > aSeries( + ContainerHelper::SequenceToVector( xSeriesCnt->getDataSeries())); + ::std::vector< Reference< chart2::XDataSeries > >::iterator aIt = + ::std::find( aSeries.begin(), aSeries.end(), xSeries ); + if( aIt != aSeries.end()) + { + aSeries.erase( aIt ); + xSeriesCnt->setDataSeries( ContainerHelper::ContainerToSequence( aSeries )); + } + } + catch( uno::Exception & ex ) + { + ASSERT_EXCEPTION( ex ); + } +} + +void switchSymbolsOnOrOff( const Reference< beans::XPropertySet > & xSeriesProperties, + bool bSymbolsOn, sal_Int32 nSeriesIndex ) +{ + if( !xSeriesProperties.is() ) + return; + + chart2::Symbol aSymbProp; + if( (xSeriesProperties->getPropertyValue( C2U( "Symbol" )) >>= aSymbProp ) ) + { + if( !bSymbolsOn ) + aSymbProp.Style = chart2::SymbolStyle_NONE; + else if( aSymbProp.Style == chart2::SymbolStyle_NONE ) + { + aSymbProp.Style = chart2::SymbolStyle_STANDARD; + aSymbProp.StandardSymbol = nSeriesIndex; + } + xSeriesProperties->setPropertyValue( C2U( "Symbol" ), uno::makeAny( aSymbProp )); + } + //todo: check attributed data points +} + +void switchLinesOnOrOff( const Reference< beans::XPropertySet > & xSeriesProperties, bool bLinesOn ) +{ + if( !xSeriesProperties.is() ) + return; + + if( bLinesOn ) + { + // keep line-styles that are not NONE + drawing::LineStyle eLineStyle; + if( (xSeriesProperties->getPropertyValue( C2U( "LineStyle" )) >>= eLineStyle ) && + eLineStyle == drawing::LineStyle_NONE ) + { + xSeriesProperties->setPropertyValue( C2U( "LineStyle" ), uno::makeAny( drawing::LineStyle_SOLID ) ); + } + } + else + xSeriesProperties->setPropertyValue( C2U( "LineStyle" ), uno::makeAny( drawing::LineStyle_NONE ) ); +} + +void setPropertyAlsoToAllAttributedDataPoints( const Reference< chart2::XDataSeries >& xSeries, + const OUString& rPropertyName, const uno::Any& rPropertyValue ) +{ + Reference< beans::XPropertySet > xSeriesProperties( xSeries, uno::UNO_QUERY ); + if( !xSeriesProperties.is() ) + return; + + xSeriesProperties->setPropertyValue( rPropertyName, rPropertyValue ); + uno::Sequence< sal_Int32 > aAttributedDataPointIndexList; + if( xSeriesProperties->getPropertyValue( C2U( "AttributedDataPoints" ) ) >>= aAttributedDataPointIndexList ) + { + for(sal_Int32 nN=aAttributedDataPointIndexList.getLength();nN--;) + { + Reference< beans::XPropertySet > xPointProp( xSeries->getDataPointByIndex(nN) ); + if(!xPointProp.is()) + continue; + xPointProp->setPropertyValue( rPropertyName, rPropertyValue ); + } + } +} + + } // namespace DataSeriesHelper } // namespace chart |