diff options
Diffstat (limited to 'chart2/source/tools/StatisticsHelper.cxx')
-rw-r--r-- | chart2/source/tools/StatisticsHelper.cxx | 95 |
1 files changed, 40 insertions, 55 deletions
diff --git a/chart2/source/tools/StatisticsHelper.cxx b/chart2/source/tools/StatisticsHelper.cxx index 02dab3b9bd89..5f3bbdf802d6 100644 --- a/chart2/source/tools/StatisticsHelper.cxx +++ b/chart2/source/tools/StatisticsHelper.cxx @@ -18,20 +18,22 @@ */ #include <StatisticsHelper.hxx> +#include <DataSeries.hxx> #include <DataSeriesHelper.hxx> #include <ErrorBar.hxx> #include <unonames.hxx> -#include <rtl/math.hxx> #include <rtl/ustrbuf.hxx> #include <comphelper/processfactory.hxx> -#include <com/sun/star/chart2/XDataSeries.hpp> #include <com/sun/star/chart2/data/LabeledDataSequence.hpp> #include <com/sun/star/chart2/data/XNumericalDataSequence.hpp> #include <com/sun/star/chart2/data/XDataProvider.hpp> #include <com/sun/star/chart2/data/XDataSink.hpp> #include <com/sun/star/chart/ErrorBarStyle.hpp> -#include <tools/diagnose_ex.h> +#include <comphelper/diagnose_ex.hxx> + +#include <cmath> +#include <limits> using ::com::sun::star::uno::Sequence; using ::com::sun::star::uno::Reference; @@ -60,19 +62,14 @@ double lcl_getVariance( const Sequence< double > & rData, sal_Int32 & rOutValidC } } - double fResult; if( rOutValidCount == 0 ) - ::rtl::math::setNan( & fResult ); - else - { - const double fN = static_cast< double >( rOutValidCount ); - fResult = (fQuadSum - fSum*fSum/fN) / fN; - } + return std::numeric_limits<double>::quiet_NaN(); - return fResult; + const double fN = static_cast< double >( rOutValidCount ); + return (fQuadSum - fSum*fSum/fN) / fN; } -Reference< chart2::data::XLabeledDataSequence > lcl_getErrorBarLabeledSequence( +uno::Reference< chart2::data::XLabeledDataSequence > lcl_getErrorBarLabeledSequence( const Reference< chart2::data::XDataSource > & xDataSource, bool bPositiveValue, bool bYError, OUString & rOutRoleNameUsed ) @@ -84,8 +81,7 @@ Reference< chart2::data::XLabeledDataSequence > lcl_getErrorBarLabeledSequence( aRole.append( 'x'); OUString aPlainRole = aRole.makeStringAndClear(); - aRole.append( aPlainRole ); - aRole.append( '-' ); + aRole.append( aPlainRole + "-" ); if( bPositiveValue ) aRole.append( "positive" ); @@ -93,14 +89,14 @@ Reference< chart2::data::XLabeledDataSequence > lcl_getErrorBarLabeledSequence( aRole.append( "negative" ); OUString aLongRole = aRole.makeStringAndClear(); - Reference< chart2::data::XLabeledDataSequence > xLSeq( - ::chart::DataSeriesHelper::getDataSequenceByRole( xDataSource, aLongRole )); + uno::Reference< chart2::data::XLabeledDataSequence > xLSeq = + ::chart::DataSeriesHelper::getDataSequenceByRole( xDataSource, aLongRole ); // try role without "-negative" or "-positive" postfix if( xLSeq.is()) rOutRoleNameUsed = aLongRole; else { - xLSeq.set( ::chart::DataSeriesHelper::getDataSequenceByRole( xDataSource, aPlainRole )); + xLSeq = ::chart::DataSeriesHelper::getDataSequenceByRole( xDataSource, aPlainRole ); if( xLSeq.is()) rOutRoleNameUsed = aPlainRole; else @@ -136,7 +132,8 @@ void lcl_addSequenceToDataSource( Sequence< Reference< chart2::data::XLabeledDataSequence > > aSequences( xDataSource->getDataSequences()); aSequences.realloc( aSequences.getLength() + 1 ); - aSequences[ aSequences.getLength() - 1 ] = xLSeq; + auto pSequences = aSequences.getArray(); + pSequences[ aSequences.getLength() - 1 ] = xLSeq; xSink->setData( aSequences ); } @@ -146,7 +143,7 @@ void lcl_setXMLRangePropertyAtDataSequence( { try { - const OUString aXMLRangePropName( "CachedXMLRange"); + static constexpr OUString aXMLRangePropName( u"CachedXMLRange"_ustr); Reference< beans::XPropertySet > xProp( xDataSequence, uno::UNO_QUERY_THROW ); Reference< beans::XPropertySetInfo > xInfo( xProp->getPropertySetInfo()); if( xInfo.is() && xInfo->hasPropertyByName( aXMLRangePropName )) @@ -183,36 +180,27 @@ double StatisticsHelper::getStandardError( const Sequence< double > & rData ) { sal_Int32 nValCount; double fVar = lcl_getVariance( rData, nValCount ); - double fResult; - - if( nValCount == 0 || - std::isnan( fVar )) - { - ::rtl::math::setNan( & fResult ); - } - else - { - // standard-deviation / sqrt(n) - fResult = sqrt( fVar ) / sqrt( double(nValCount) ); - } - return fResult; + if( nValCount == 0 || std::isnan( fVar )) + return std::numeric_limits<double>::quiet_NaN(); + // standard-deviation / sqrt(n) + return sqrt( fVar ) / sqrt( double(nValCount) ); } -Reference< chart2::data::XLabeledDataSequence > StatisticsHelper::getErrorLabeledDataSequenceFromDataSource( +uno::Reference< chart2::data::XLabeledDataSequence > StatisticsHelper::getErrorLabeledDataSequenceFromDataSource( const Reference< chart2::data::XDataSource > & xDataSource, bool bPositiveValue, bool bYError /* = true */ ) { - Reference< chart2::data::XLabeledDataSequence > xResult; + uno::Reference< chart2::data::XLabeledDataSequence > xResult; if( !xDataSource.is()) return xResult; OUString aRole; - Reference< chart2::data::XLabeledDataSequence > xLSeq( - lcl_getErrorBarLabeledSequence( xDataSource, bPositiveValue, bYError, aRole )); + uno::Reference< chart2::data::XLabeledDataSequence > xLSeq = + lcl_getErrorBarLabeledSequence( xDataSource, bPositiveValue, bYError, aRole ); if( xLSeq.is()) - xResult.set( xLSeq ); + xResult = xLSeq; return xResult; } @@ -222,10 +210,10 @@ Reference< chart2::data::XDataSequence > StatisticsHelper::getErrorDataSequenceF bool bPositiveValue, bool bYError /* = true */ ) { - Reference< chart2::data::XLabeledDataSequence > xLSeq( + uno::Reference< chart2::data::XLabeledDataSequence > xLSeq = StatisticsHelper::getErrorLabeledDataSequenceFromDataSource( xDataSource, bPositiveValue, - bYError )); + bYError ); if( !xLSeq.is()) return Reference< chart2::data::XDataSequence >(); @@ -238,8 +226,7 @@ double StatisticsHelper::getErrorFromDataSource( bool bPositiveValue, bool bYError /* = true */ ) { - double fResult = 0.0; - ::rtl::math::setNan( & fResult ); + double fResult = std::numeric_limits<double>::quiet_NaN(); Reference< chart2::data::XDataSequence > xValues( StatisticsHelper::getErrorDataSequenceFromDataSource( xDataSource, bPositiveValue, bYError )); @@ -293,18 +280,17 @@ void StatisticsHelper::setErrorDataSequence( } Reference< beans::XPropertySet > StatisticsHelper::addErrorBars( - const Reference< chart2::XDataSeries > & xDataSeries, + const rtl::Reference< DataSeries > & xDataSeries, sal_Int32 nStyle, bool bYError /* = true */ ) { Reference< beans::XPropertySet > xErrorBar; - Reference< beans::XPropertySet > xSeriesProp( xDataSeries, uno::UNO_QUERY ); - if( !xSeriesProp.is()) + if( !xDataSeries.is()) return xErrorBar; const OUString aPropName( - bYError ? OUString(CHART_UNONAME_ERRORBAR_Y) : OUString(CHART_UNONAME_ERRORBAR_X)); - if( !( xSeriesProp->getPropertyValue( aPropName ) >>= xErrorBar ) || + bYError ? CHART_UNONAME_ERRORBAR_Y : CHART_UNONAME_ERRORBAR_X); + if( !( xDataSeries->getPropertyValue( aPropName ) >>= xErrorBar ) || !xErrorBar.is()) { xErrorBar.set( new ErrorBar ); @@ -316,28 +302,27 @@ Reference< beans::XPropertySet > StatisticsHelper::addErrorBars( xErrorBar->setPropertyValue( "ErrorBarStyle", uno::Any( nStyle )); } - xSeriesProp->setPropertyValue( aPropName, uno::Any( xErrorBar )); + xDataSeries->setPropertyValue( aPropName, uno::Any( xErrorBar )); return xErrorBar; } Reference< beans::XPropertySet > StatisticsHelper::getErrorBars( - const Reference< chart2::XDataSeries > & xDataSeries, + const rtl::Reference< DataSeries > & xDataSeries, bool bYError /* = true */ ) { - Reference< beans::XPropertySet > xSeriesProp( xDataSeries, uno::UNO_QUERY ); Reference< beans::XPropertySet > xErrorBar; const OUString aPropName( - bYError ? OUString(CHART_UNONAME_ERRORBAR_Y) : OUString(CHART_UNONAME_ERRORBAR_X)); + bYError ? CHART_UNONAME_ERRORBAR_Y : CHART_UNONAME_ERRORBAR_X); - if ( xSeriesProp.is()) - xSeriesProp->getPropertyValue( aPropName ) >>= xErrorBar; + if ( xDataSeries.is()) + xDataSeries->getPropertyValue( aPropName ) >>= xErrorBar; return xErrorBar; } bool StatisticsHelper::hasErrorBars( - const Reference< chart2::XDataSeries > & xDataSeries, + const rtl::Reference< DataSeries > & xDataSeries, bool bYError /* = true */ ) { Reference< beans::XPropertySet > xErrorBar( getErrorBars( xDataSeries, bYError )); @@ -349,7 +334,7 @@ bool StatisticsHelper::hasErrorBars( } void StatisticsHelper::removeErrorBars( - const Reference< chart2::XDataSeries > & xDataSeries, + const rtl::Reference< DataSeries > & xDataSeries, bool bYError /* = true */ ) { Reference< beans::XPropertySet > xErrorBar( getErrorBars( xDataSeries, bYError )); @@ -359,7 +344,7 @@ void StatisticsHelper::removeErrorBars( } bool StatisticsHelper::usesErrorBarRanges( - const Reference< chart2::XDataSeries > & xDataSeries, + const rtl::Reference< DataSeries > & xDataSeries, bool bYError /* = true */ ) { Reference< beans::XPropertySet > xErrorBar( getErrorBars( xDataSeries, bYError )); |