LCOV - code coverage report
Current view: top level - chart2/source/tools - RegressionCurveCalculator.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 26 59 44.1 %
Date: 2012-08-25 Functions: 4 10 40.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 19 128 14.8 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*
       3                 :            :  * This file is part of the LibreOffice project.
       4                 :            :  *
       5                 :            :  * This Source Code Form is subject to the terms of the Mozilla Public
       6                 :            :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7                 :            :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8                 :            :  *
       9                 :            :  * This file incorporates work covered by the following license notice:
      10                 :            :  *
      11                 :            :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12                 :            :  *   contributor license agreements. See the NOTICE file distributed
      13                 :            :  *   with this work for additional information regarding copyright
      14                 :            :  *   ownership. The ASF licenses this file to you under the Apache
      15                 :            :  *   License, Version 2.0 (the "License"); you may not use this file
      16                 :            :  *   except in compliance with the License. You may obtain a copy of
      17                 :            :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18                 :            :  */
      19                 :            : 
      20                 :            : 
      21                 :            : #include "RegressionCurveCalculator.hxx"
      22                 :            : #include "RegressionCalculationHelper.hxx"
      23                 :            : #include "servicenames_coosystems.hxx"
      24                 :            : 
      25                 :            : #include <comphelper/processfactory.hxx>
      26                 :            : #include <rtl/math.hxx>
      27                 :            : 
      28                 :            : #include <com/sun/star/lang/XServiceName.hpp>
      29                 :            : 
      30                 :            : using namespace ::com::sun::star;
      31                 :            : 
      32                 :            : using ::com::sun::star::uno::Reference;
      33                 :            : using ::com::sun::star::uno::Sequence;
      34                 :            : using ::rtl::OUString;
      35                 :            : 
      36                 :            : namespace chart
      37                 :            : {
      38                 :            : 
      39                 :        108 : RegressionCurveCalculator::RegressionCurveCalculator() :
      40                 :        108 :         m_fCorrelationCoeffitient( 0.0 )
      41                 :            : {
      42                 :        108 :     ::rtl::math::setNan( & m_fCorrelationCoeffitient );
      43                 :        108 : }
      44                 :            : 
      45                 :        108 : RegressionCurveCalculator::~RegressionCurveCalculator()
      46         [ -  + ]:        108 : {}
      47                 :            : 
      48                 :          0 : bool RegressionCurveCalculator::isLinearScaling(
      49                 :            :     const Reference< chart2::XScaling > & xScaling )
      50                 :            : {
      51                 :            :     // no scaling means linear
      52         [ #  # ]:          0 :     if( !xScaling.is())
      53                 :          0 :         return true;
      54 [ #  # ][ #  # ]:          0 :     static OUString aLinScalingServiceName( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.chart2.LinearScaling" ));
         [ #  # ][ #  # ]
      55         [ #  # ]:          0 :     uno::Reference< lang::XServiceName > xServiceName( xScaling, uno::UNO_QUERY );
      56 [ #  # ][ #  # ]:          0 :     return (xServiceName.is() && xServiceName->getServiceName().equals( aLinScalingServiceName ));
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
      57                 :            : }
      58                 :            : 
      59                 :         32 : bool RegressionCurveCalculator::isLogarithmicScaling(
      60                 :            :     const Reference< chart2::XScaling > & xScaling )
      61                 :            : {
      62 [ +  + ][ +  - ]:         32 :     static OUString aLogScalingServiceName( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.chart2.LogarithmicScaling" ));
         [ +  - ][ #  # ]
      63         [ +  - ]:         32 :     uno::Reference< lang::XServiceName > xServiceName( xScaling, uno::UNO_QUERY );
      64 [ -  + ][ #  # ]:         32 :     return (xServiceName.is() && xServiceName->getServiceName().equals( aLogScalingServiceName ));
         [ #  # ][ #  # ]
         [ -  + ][ #  # ]
      65                 :            : }
      66                 :            : 
      67                 :            : 
      68                 :          0 : OUString RegressionCurveCalculator::getFormattedString(
      69                 :            :     const Reference< util::XNumberFormatter >& xNumFormatter,
      70                 :            :     ::sal_Int32 nNumberFormatKey,
      71                 :            :     double fNumber ) const
      72                 :            : {
      73                 :          0 :     OUString aResult;
      74                 :            : 
      75         [ #  # ]:          0 :     if( xNumFormatter.is())
      76 [ #  # ][ #  # ]:          0 :         aResult = xNumFormatter->convertNumberToString( nNumberFormatKey, fNumber );
      77                 :            :     else
      78         [ #  # ]:          0 :         aResult = NUMBER_TO_STR( fNumber );
      79                 :            : 
      80                 :          0 :     return aResult;
      81                 :            : }
      82                 :            : 
      83                 :         32 : Sequence< geometry::RealPoint2D > SAL_CALL RegressionCurveCalculator::getCurveValues(
      84                 :            :     double min, double max, ::sal_Int32 nPointCount,
      85                 :            :     const Reference< chart2::XScaling >& xScalingX,
      86                 :            :     const Reference< chart2::XScaling >& /* xScalingY */,
      87                 :            :     ::sal_Bool /* bMaySkipPointsInCalculation */ )
      88                 :            :     throw (lang::IllegalArgumentException,
      89                 :            :            uno::RuntimeException)
      90                 :            : {
      91         [ -  + ]:         32 :     if( nPointCount < 2 )
      92         [ #  # ]:          0 :         throw lang::IllegalArgumentException();
      93                 :            : 
      94                 :            :     // determine if scaling and inverse scaling for x-values work
      95                 :         32 :     bool bDoXScaling( xScalingX.is());
      96                 :         32 :     uno::Reference< chart2::XScaling > xInverseScaling;
      97         [ -  + ]:         32 :     if( bDoXScaling )
      98 [ #  # ][ #  # ]:          0 :         xInverseScaling.set( xScalingX->getInverseScaling());
                 [ #  # ]
      99 [ -  + ][ #  # ]:         32 :     bDoXScaling = bDoXScaling && xInverseScaling.is();
     100                 :            : 
     101         [ +  - ]:         32 :     Sequence< geometry::RealPoint2D > aResult( nPointCount );
     102                 :            : 
     103                 :         32 :     double fMin( min );
     104                 :         32 :     double fFact = (max - min) / double(nPointCount-1);
     105         [ -  + ]:         32 :     if( bDoXScaling )
     106                 :            :     {
     107 [ #  # ][ #  # ]:          0 :         fMin = xScalingX->doScaling( min );
     108 [ #  # ][ #  # ]:          0 :         fFact = (xScalingX->doScaling( max ) - fMin) / double(nPointCount-1);
     109                 :            :     }
     110                 :            : 
     111         [ +  + ]:       1632 :     for(sal_Int32 nP=0; nP<nPointCount; nP++)
     112                 :            :     {
     113                 :       1600 :         double x = fMin + nP * fFact;
     114         [ -  + ]:       1600 :         if( bDoXScaling )
     115 [ #  # ][ #  # ]:          0 :             x = xInverseScaling->doScaling( x );
     116         [ +  - ]:       1600 :         aResult[nP].X = x;
     117 [ +  - ][ +  - ]:       1600 :         aResult[nP].Y = this->getCurveValue( x );
     118                 :            :     }
     119                 :            : 
     120                 :         32 :     return aResult;
     121                 :            : }
     122                 :            : 
     123                 :          0 : double SAL_CALL RegressionCurveCalculator::getCorrelationCoefficient()
     124                 :            :     throw (uno::RuntimeException)
     125                 :            : {
     126                 :          0 :     return m_fCorrelationCoeffitient;
     127                 :            : }
     128                 :            : 
     129                 :          0 : OUString SAL_CALL RegressionCurveCalculator::getRepresentation()
     130                 :            :     throw (uno::RuntimeException)
     131                 :            : {
     132         [ #  # ]:          0 :     return ImplGetRepresentation( Reference< util::XNumberFormatter >(), 0 );
     133                 :            : }
     134                 :            : 
     135                 :          0 : OUString SAL_CALL RegressionCurveCalculator::getFormattedRepresentation(
     136                 :            :     const Reference< util::XNumberFormatsSupplier > & xNumFmtSupplier,
     137                 :            :     ::sal_Int32 nNumberFormatKey )
     138                 :            :     throw (uno::RuntimeException)
     139                 :            : {
     140                 :            :     // create and prepare a number formatter
     141         [ #  # ]:          0 :     if( !xNumFmtSupplier.is())
     142         [ #  # ]:          0 :         return getRepresentation();
     143                 :          0 :     Reference< util::XNumberFormatter > xNumFormatter;
     144 [ #  # ][ #  # ]:          0 :     Reference< lang::XMultiServiceFactory > xFact( comphelper::getProcessServiceFactory(), uno::UNO_QUERY );
     145         [ #  # ]:          0 :     if( xFact.is())
     146         [ #  # ]:          0 :         xNumFormatter.set( xFact->createInstance(
     147 [ #  # ][ #  # ]:          0 :                                OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.util.NumberFormatter"))), uno::UNO_QUERY );
                 [ #  # ]
     148         [ #  # ]:          0 :     if( !xNumFormatter.is())
     149         [ #  # ]:          0 :         return getRepresentation();
     150 [ #  # ][ #  # ]:          0 :     xNumFormatter->attachNumberFormatsSupplier( xNumFmtSupplier );
     151                 :            : 
     152         [ #  # ]:          0 :     return ImplGetRepresentation( xNumFormatter, nNumberFormatKey );
     153                 :            : }
     154                 :            : 
     155                 :            : 
     156                 :            : } //  namespace chart
     157                 :            : 
     158                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10