LCOV - code coverage report
Current view: top level - chart2/source/tools - RegressionCurveCalculator.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 51 61 83.6 %
Date: 2014-11-03 Functions: 8 11 72.7 %
Legend: Lines: hit not hit

          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             : #include "RegressionCurveCalculator.hxx"
      21             : #include "RegressionCalculationHelper.hxx"
      22             : #include "servicenames_coosystems.hxx"
      23             : 
      24             : #include <comphelper/processfactory.hxx>
      25             : #include <rtl/math.hxx>
      26             : 
      27             : #include <com/sun/star/lang/XServiceName.hpp>
      28             : #include <com/sun/star/util/NumberFormatter.hpp>
      29             : 
      30             : using namespace ::com::sun::star;
      31             : 
      32             : using ::com::sun::star::uno::Reference;
      33             : using ::com::sun::star::uno::Sequence;
      34             : 
      35             : namespace chart
      36             : {
      37             : 
      38          94 : RegressionCurveCalculator::RegressionCurveCalculator() :
      39             :         m_fCorrelationCoeffitient(0.0),
      40             :         mDegree(2),
      41             :         mForceIntercept(false),
      42             :         mInterceptValue(0.0),
      43          94 :         mPeriod(2)
      44             : {
      45          94 :     rtl::math::setNan( &m_fCorrelationCoeffitient );
      46          94 :     rtl::math::setNan( &mInterceptValue );
      47          94 : }
      48             : 
      49          94 : RegressionCurveCalculator::~RegressionCurveCalculator()
      50          94 : {}
      51             : 
      52          28 : bool RegressionCurveCalculator::isLinearScaling(
      53             :     const Reference< chart2::XScaling > & xScaling )
      54             : {
      55             :     // no scaling means linear
      56          28 :     if( !xScaling.is())
      57           0 :         return true;
      58          28 :     static OUString aLinScalingServiceName( "com.sun.star.chart2.LinearScaling" );
      59          28 :     uno::Reference< lang::XServiceName > xServiceName( xScaling, uno::UNO_QUERY );
      60          28 :     return (xServiceName.is() && xServiceName->getServiceName().equals( aLinScalingServiceName ));
      61             : }
      62             : 
      63           0 : bool RegressionCurveCalculator::isLogarithmicScaling(
      64             :     const Reference< chart2::XScaling > & xScaling )
      65             : {
      66           0 :     static OUString aLogScalingServiceName( "com.sun.star.chart2.LogarithmicScaling" );
      67           0 :     uno::Reference< lang::XServiceName > xServiceName( xScaling, uno::UNO_QUERY );
      68           0 :     return (xServiceName.is() && xServiceName->getServiceName().equals( aLogScalingServiceName ));
      69             : }
      70             : 
      71          94 : void RegressionCurveCalculator::setRegressionProperties(
      72             :     sal_Int32   aDegree,
      73             :     sal_Bool    aForceIntercept,
      74             :     double      aInterceptValue,
      75             :     sal_Int32   aPeriod )
      76             :         throw (uno::RuntimeException, std::exception)
      77             : {
      78          94 :     mDegree = aDegree;
      79          94 :     mForceIntercept = aForceIntercept;
      80          94 :     mInterceptValue = aInterceptValue;
      81          94 :     mPeriod  = aPeriod;
      82          94 : }
      83             : 
      84          84 : OUString RegressionCurveCalculator::getFormattedString(
      85             :     const Reference< util::XNumberFormatter >& xNumFormatter,
      86             :     sal_Int32 nNumberFormatKey,
      87             :     double fNumber ) const
      88             : {
      89          84 :     OUString aResult;
      90             : 
      91          84 :     if( xNumFormatter.is())
      92          84 :         aResult = xNumFormatter->convertNumberToString( nNumberFormatKey, fNumber );
      93             :     else
      94           0 :         aResult = NUMBER_TO_STR( fNumber );
      95             : 
      96          84 :     return aResult;
      97             : }
      98             : 
      99          14 : Sequence< geometry::RealPoint2D > SAL_CALL RegressionCurveCalculator::getCurveValues(
     100             :     double min, double max, ::sal_Int32 nPointCount,
     101             :     const Reference< chart2::XScaling >& xScalingX,
     102             :     const Reference< chart2::XScaling >& /* xScalingY */,
     103             :     sal_Bool /* bMaySkipPointsInCalculation */ )
     104             :         throw (lang::IllegalArgumentException, uno::RuntimeException, std::exception)
     105             : {
     106          14 :     if( nPointCount < 2 )
     107           0 :         throw lang::IllegalArgumentException();
     108             : 
     109             :     // determine if scaling and inverse scaling for x-values work
     110          14 :     bool bDoXScaling( xScalingX.is());
     111          14 :     uno::Reference< chart2::XScaling > xInverseScaling;
     112          14 :     if( bDoXScaling )
     113          14 :         xInverseScaling.set( xScalingX->getInverseScaling());
     114          14 :     bDoXScaling = bDoXScaling && xInverseScaling.is();
     115             : 
     116          14 :     Sequence< geometry::RealPoint2D > aResult( nPointCount );
     117             : 
     118          14 :     double fMin( min );
     119          14 :     double fFact = (max - min) / double(nPointCount-1);
     120             : 
     121          14 :     if( bDoXScaling )
     122             :     {
     123          14 :         fMin = xScalingX->doScaling( min );
     124          14 :         fFact = (xScalingX->doScaling( max ) - fMin) / double(nPointCount-1);
     125             :     }
     126             : 
     127        1064 :     for(sal_Int32 nP=0; nP<nPointCount; nP++)
     128             :     {
     129        1050 :         double x = fMin + nP * fFact;
     130        1050 :         if( bDoXScaling )
     131        1050 :             x = xInverseScaling->doScaling( x );
     132        1050 :         aResult[nP].X = x;
     133        1050 :         aResult[nP].Y = this->getCurveValue( x );
     134             :     }
     135             : 
     136          14 :     return aResult;
     137             : }
     138             : 
     139          14 : double SAL_CALL RegressionCurveCalculator::getCorrelationCoefficient()
     140             :     throw (uno::RuntimeException, std::exception)
     141             : {
     142          14 :     return m_fCorrelationCoeffitient;
     143             : }
     144             : 
     145           0 : OUString SAL_CALL RegressionCurveCalculator::getRepresentation()
     146             :     throw (uno::RuntimeException, std::exception)
     147             : {
     148           0 :     return ImplGetRepresentation( Reference< util::XNumberFormatter >(), 0 );
     149             : }
     150             : 
     151          28 : OUString SAL_CALL RegressionCurveCalculator::getFormattedRepresentation(
     152             :     const Reference< util::XNumberFormatsSupplier > & xNumFmtSupplier,
     153             :     sal_Int32 nNumberFormatKey )
     154             :     throw (uno::RuntimeException, std::exception)
     155             : {
     156             :     // create and prepare a number formatter
     157          28 :     if( !xNumFmtSupplier.is())
     158           0 :         return getRepresentation();
     159          28 :     Reference< uno::XComponentContext > xContext( comphelper::getProcessComponentContext(), uno::UNO_QUERY_THROW );
     160          56 :     Reference< util::XNumberFormatter > xNumFormatter( util::NumberFormatter::create(xContext), uno::UNO_QUERY_THROW );
     161          28 :     xNumFormatter->attachNumberFormatsSupplier( xNumFmtSupplier );
     162             : 
     163          56 :     return ImplGetRepresentation( xNumFormatter, nNumberFormatKey );
     164             : }
     165             : 
     166             : } //  namespace chart
     167             : 
     168             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10