diff options
Diffstat (limited to 'chart2/source/tools')
-rw-r--r-- | chart2/source/tools/DataSeriesHelper.cxx | 182 | ||||
-rw-r--r-- | chart2/source/tools/LegendHelper.cxx | 48 | ||||
-rw-r--r-- | chart2/source/tools/RegressionCurveHelper.cxx | 51 |
3 files changed, 281 insertions, 0 deletions
diff --git a/chart2/source/tools/DataSeriesHelper.cxx b/chart2/source/tools/DataSeriesHelper.cxx index 61fecf18b5e7..7203f9ad6e63 100644 --- a/chart2/source/tools/DataSeriesHelper.cxx +++ b/chart2/source/tools/DataSeriesHelper.cxx @@ -36,6 +36,7 @@ #include "macros.hxx" #include "ContainerHelper.hxx" #include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/chart2/DataPointLabel.hpp> #include <com/sun/star/chart2/data/XTextualDataSequence.hpp> #include <com/sun/star/chart2/StackingDirection.hpp> #include <com/sun/star/chart2/data/LabelOrigin.hpp> @@ -57,6 +58,7 @@ #include <set> using namespace ::com::sun::star; +using namespace ::com::sun::star::chart2; using ::com::sun::star::uno::Reference; using ::com::sun::star::uno::Sequence; @@ -155,6 +157,50 @@ void lcl_getCooSysAndChartTypeOfSeries( } } +void lcl_insertOrDeleteDataLabelsToSeriesAndAllPoints( const Reference< chart2::XDataSeries >& xSeries, bool bInsert ) +{ + try + { + Reference< beans::XPropertySet > xSeriesProperties( xSeries, uno::UNO_QUERY ); + if( xSeriesProperties.is() ) + { + DataPointLabel aLabelAtSeries; + xSeriesProperties->getPropertyValue( C2U( "Label" ) ) >>= aLabelAtSeries; + aLabelAtSeries.ShowNumber = bInsert; + if( !bInsert ) + { + aLabelAtSeries.ShowNumberInPercent = false; + aLabelAtSeries.ShowCategoryName = false; + } + xSeriesProperties->setPropertyValue( C2U( "Label" ), uno::makeAny( aLabelAtSeries ) ); + uno::Sequence< sal_Int32 > aAttributedDataPointIndexList; + if( xSeriesProperties->getPropertyValue( C2U( "AttributedDataPoints" ) ) >>= aAttributedDataPointIndexList ) + { + for(sal_Int32 nN=aAttributedDataPointIndexList.getLength();nN--;) + { + Reference< beans::XPropertySet > xPointProp( xSeries->getDataPointByIndex(aAttributedDataPointIndexList[nN]) ); + if( xPointProp.is() ) + { + DataPointLabel aLabel; + xPointProp->getPropertyValue( C2U( "Label" ) ) >>= aLabel; + aLabel.ShowNumber = bInsert; + if( !bInsert ) + { + aLabel.ShowNumberInPercent = false; + aLabel.ShowCategoryName = false; + } + xPointProp->setPropertyValue( C2U( "Label" ), uno::makeAny( aLabel ) ); + } + } + } + } + } + catch( uno::Exception &e) + { + ASSERT_EXCEPTION( e ); + } +} + } // anonymous namespace // ---------------------------------------- @@ -735,5 +781,141 @@ sal_Int32 translateIndexFromHiddenToFullSequence( sal_Int32 nIndex, const Refere return nIndex; } +bool hasDataLabelsAtSeries( const Reference< chart2::XDataSeries >& xSeries ) +{ + bool bRet = false; + try + { + Reference< beans::XPropertySet > xProp( xSeries, uno::UNO_QUERY ); + if( xProp.is() ) + { + DataPointLabel aLabel; + if( (xProp->getPropertyValue( C2U( "Label" ) ) >>= aLabel) ) + bRet = aLabel.ShowNumber || aLabel.ShowNumberInPercent || aLabel.ShowCategoryName; + } + } + catch( uno::Exception &e) + { + ASSERT_EXCEPTION( e ); + } + return bRet; +} + +bool hasDataLabelsAtPoints( const Reference< chart2::XDataSeries >& xSeries ) +{ + bool bRet = false; + try + { + Reference< beans::XPropertySet > xSeriesProperties( xSeries, uno::UNO_QUERY ); + if( xSeriesProperties.is() ) + { + uno::Sequence< sal_Int32 > aAttributedDataPointIndexList; + if( xSeriesProperties->getPropertyValue( C2U( "AttributedDataPoints" ) ) >>= aAttributedDataPointIndexList ) + { + for(sal_Int32 nN=aAttributedDataPointIndexList.getLength();nN--;) + { + Reference< beans::XPropertySet > xPointProp( xSeries->getDataPointByIndex(aAttributedDataPointIndexList[nN]) ); + if( xPointProp.is() ) + { + DataPointLabel aLabel; + if( (xPointProp->getPropertyValue( C2U( "Label" ) ) >>= aLabel) ) + bRet = aLabel.ShowNumber || aLabel.ShowNumberInPercent || aLabel.ShowCategoryName; + if( bRet ) + break; + } + } + } + } + } + catch( uno::Exception &e) + { + ASSERT_EXCEPTION( e ); + } + return bRet; +} + +bool hasDataLabelAtPoint( const Reference< chart2::XDataSeries >& xSeries, sal_Int32 nPointIndex ) +{ + bool bRet = false; + try + { + Reference< beans::XPropertySet > xProp; + Reference< beans::XPropertySet > xSeriesProperties( xSeries, uno::UNO_QUERY ); + if( xSeriesProperties.is() ) + { + uno::Sequence< sal_Int32 > aAttributedDataPointIndexList; + if( xSeriesProperties->getPropertyValue( C2U( "AttributedDataPoints" ) ) >>= aAttributedDataPointIndexList ) + { + ::std::vector< sal_Int32 > aIndices( ContainerHelper::SequenceToVector( aAttributedDataPointIndexList ) ); + ::std::vector< sal_Int32 >::iterator aIt = ::std::find( aIndices.begin(), aIndices.end(), nPointIndex ); + if( aIt != aIndices.end()) + xProp = xSeries->getDataPointByIndex(nPointIndex); + else + xProp = xSeriesProperties; + } + if( xProp.is() ) + { + DataPointLabel aLabel; + if( (xProp->getPropertyValue( C2U( "Label" ) ) >>= aLabel) ) + bRet = aLabel.ShowNumber || aLabel.ShowNumberInPercent || aLabel.ShowCategoryName; + } + } + } + catch( uno::Exception &e) + { + ASSERT_EXCEPTION( e ); + } + return bRet; +} + +void insertDataLabelsToSeriesAndAllPoints( const Reference< chart2::XDataSeries >& xSeries ) +{ + lcl_insertOrDeleteDataLabelsToSeriesAndAllPoints( xSeries, true /*bInsert*/ ); +} + +void deleteDataLabelsFromSeriesAndAllPoints( const Reference< chart2::XDataSeries >& xSeries ) +{ + lcl_insertOrDeleteDataLabelsToSeriesAndAllPoints( xSeries, false /*bInsert*/ ); +} + + +void insertDataLabelToPoint( const Reference< beans::XPropertySet >& xPointProp ) +{ + try + { + if( xPointProp.is() ) + { + DataPointLabel aLabel; + xPointProp->getPropertyValue( C2U( "Label" ) ) >>= aLabel; + aLabel.ShowNumber = true; + xPointProp->setPropertyValue( C2U( "Label" ), uno::makeAny( aLabel ) ); + } + } + catch( uno::Exception &e) + { + ASSERT_EXCEPTION( e ); + } +} + +void deleteDataLabelsFromPoint( const Reference< beans::XPropertySet >& xPointProp ) +{ + try + { + if( xPointProp.is() ) + { + DataPointLabel aLabel; + xPointProp->getPropertyValue( C2U( "Label" ) ) >>= aLabel; + aLabel.ShowNumber = false; + aLabel.ShowNumberInPercent = false; + aLabel.ShowCategoryName = false; + xPointProp->setPropertyValue( C2U( "Label" ), uno::makeAny( aLabel ) ); + } + } + catch( uno::Exception &e) + { + ASSERT_EXCEPTION( e ); + } +} + } // namespace DataSeriesHelper } // namespace chart diff --git a/chart2/source/tools/LegendHelper.cxx b/chart2/source/tools/LegendHelper.cxx index 6d21d13f0dc7..60da06f2b638 100644 --- a/chart2/source/tools/LegendHelper.cxx +++ b/chart2/source/tools/LegendHelper.cxx @@ -32,18 +32,66 @@ #include "precompiled_chart2.hxx" #include "LegendHelper.hxx" #include "macros.hxx" +#include <com/sun/star/chart2/LegendExpansion.hpp> +#include <com/sun/star/chart2/LegendPosition.hpp> +#include <com/sun/star/chart2/RelativePosition.hpp> #include <com/sun/star/chart2/XChartDocument.hpp> #include <com/sun/star/chart2/XLegend.hpp> #include <com/sun/star/lang/XServiceInfo.hpp> #include <tools/debug.hxx> using namespace ::com::sun::star; +using ::com::sun::star::uno::Reference; //............................................................................. namespace chart { //............................................................................. + +//static +Reference< chart2::XLegend > LegendHelper::showLegend( const Reference< frame::XModel >& xModel + , const uno::Reference< uno::XComponentContext >& xContext ) +{ + uno::Reference< chart2::XLegend > xLegend = LegendHelper::getLegend( xModel, xContext, true ); + uno::Reference< beans::XPropertySet > xProp( xLegend, uno::UNO_QUERY ); + if( xProp.is()) + { + xProp->setPropertyValue( C2U("Show"), uno::makeAny(sal_True) ); + + chart2::RelativePosition aRelativePosition; + if( !(xProp->getPropertyValue( C2U( "RelativePosition" )) >>= aRelativePosition) ) + { + chart2::LegendPosition ePos = chart2::LegendPosition_LINE_END; + if( !(xProp->getPropertyValue( C2U( "AnchorPosition" )) >>= ePos ) ) + xProp->setPropertyValue( C2U( "AnchorPosition" ), uno::makeAny( ePos )); + + chart2::LegendExpansion eExpansion = + ( ePos == chart2::LegendPosition_LINE_END || + ePos == chart2::LegendPosition_LINE_START ) + ? chart2::LegendExpansion_HIGH + : chart2::LegendExpansion_WIDE; + if( !(xProp->getPropertyValue( C2U( "Expansion" )) >>= eExpansion ) ) + xProp->setPropertyValue( C2U( "Expansion" ), uno::makeAny( eExpansion )); + + xProp->setPropertyValue( C2U( "RelativePosition" ), uno::Any()); + } + + } + return xLegend; +} + +//static +void LegendHelper::hideLegend( const Reference< frame::XModel >& xModel ) +{ + uno::Reference< chart2::XLegend > xLegend = LegendHelper::getLegend( xModel, 0, false ); + uno::Reference< beans::XPropertySet > xProp( xLegend, uno::UNO_QUERY ); + if( xProp.is()) + { + xProp->setPropertyValue( C2U("Show"), uno::makeAny(sal_False) ); + } +} + // static uno::Reference< chart2::XLegend > LegendHelper::getLegend( const uno::Reference< frame::XModel >& xModel diff --git a/chart2/source/tools/RegressionCurveHelper.cxx b/chart2/source/tools/RegressionCurveHelper.cxx index 7686b2c7009d..8a4fd8ce4f7e 100644 --- a/chart2/source/tools/RegressionCurveHelper.cxx +++ b/chart2/source/tools/RegressionCurveHelper.cxx @@ -457,6 +457,39 @@ bool RegressionCurveHelper::removeAllExceptMeanValueLine( return bRemovedSomething; } +void RegressionCurveHelper::removeEquations( + uno::Reference< chart2::XRegressionCurveContainer > & xRegCnt ) +{ + if( xRegCnt.is()) + { + try + { + uno::Sequence< uno::Reference< chart2::XRegressionCurve > > aCurves( + xRegCnt->getRegressionCurves()); + for( sal_Int32 i = 0; i < aCurves.getLength(); ++i ) + { + if( !isMeanValueLine( aCurves[i] ) ) + { + uno::Reference< chart2::XRegressionCurve > xRegCurve( aCurves[ i ] ); + if( xRegCurve.is() ) + { + uno::Reference< beans::XPropertySet > xEqProp( xRegCurve->getEquationProperties() ) ; + if( xEqProp.is()) + { + xEqProp->setPropertyValue( C2U("ShowEquation"), uno::makeAny( false )); + xEqProp->setPropertyValue( C2U("ShowCorrelationCoefficient"), uno::makeAny( false )); + } + } + } + } + } + catch( uno::Exception & ex ) + { + ASSERT_EXCEPTION( ex ); + } + } +} + // static void RegressionCurveHelper::replaceOrAddCurveAndReduceToOne( tRegressionType eType, @@ -683,6 +716,24 @@ sal_Int32 RegressionCurveHelper::getRegressionCurveIndex( return -1; } +bool RegressionCurveHelper::hasEquation( const Reference< chart2::XRegressionCurve > & xCurve ) +{ + bool bHasEquation = false; + if( xCurve.is()) + { + uno::Reference< beans::XPropertySet > xEquationProp( xCurve->getEquationProperties()); + if( xEquationProp.is()) + { + bool bShowEquation = false; + bool bShowCoefficient = false; + xEquationProp->getPropertyValue( C2U("ShowEquation")) >>= bShowEquation; + xEquationProp->getPropertyValue( C2U("ShowCorrelationCoefficient")) >>= bShowCoefficient; + bHasEquation = bShowEquation || bShowCoefficient; + } + } + return bHasEquation; +} + //............................................................................. } //namespace chart //............................................................................. |