LCOV - code coverage report
Current view: top level - chart2/source/tools - RegressionCurveCalculator.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 51 61 83.6 %
Date: 2014-04-11 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          53 : RegressionCurveCalculator::RegressionCurveCalculator() :
      39             :         m_fCorrelationCoeffitient(0.0),
      40             :         mDegree(2),
      41             :         mForceIntercept(false),
      42             :         mInterceptValue(0.0),
      43          53 :         mPeriod(2)
      44             : {
      45          53 :     rtl::math::setNan( &m_fCorrelationCoeffitient );
      46          53 :     rtl::math::setNan( &mInterceptValue );
      47          53 : }
      48             : 
      49          53 : RegressionCurveCalculator::~RegressionCurveCalculator()
      50          53 : {}
      51             : 
      52          14 : bool RegressionCurveCalculator::isLinearScaling(
      53             :     const Reference< chart2::XScaling > & xScaling )
      54             : {
      55             :     // no scaling means linear
      56          14 :     if( !xScaling.is())
      57           0 :         return true;
      58          14 :     static OUString aLinScalingServiceName( "com.sun.star.chart2.LinearScaling" );
      59          14 :     uno::Reference< lang::XServiceName > xServiceName( xScaling, uno::UNO_QUERY );
      60          14 :     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          53 : 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          53 :     mDegree = aDegree;
      79          53 :     mForceIntercept = aForceIntercept;
      80          53 :     mInterceptValue = aInterceptValue;
      81          53 :     mPeriod  = aPeriod;
      82          53 : }
      83             : 
      84          42 : OUString RegressionCurveCalculator::getFormattedString(
      85             :     const Reference< util::XNumberFormatter >& xNumFormatter,
      86             :     sal_Int32 nNumberFormatKey,
      87             :     double fNumber ) const
      88             : {
      89          42 :     OUString aResult;
      90             : 
      91          42 :     if( xNumFormatter.is())
      92          42 :         aResult = xNumFormatter->convertNumberToString( nNumberFormatKey, fNumber );
      93             :     else
      94           0 :         aResult = NUMBER_TO_STR( fNumber );
      95             : 
      96          42 :     return aResult;
      97             : }
      98             : 
      99           7 : 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           7 :     if( nPointCount < 2 )
     107           0 :         throw lang::IllegalArgumentException();
     108             : 
     109             :     // determine if scaling and inverse scaling for x-values work
     110           7 :     bool bDoXScaling( xScalingX.is());
     111           7 :     uno::Reference< chart2::XScaling > xInverseScaling;
     112           7 :     if( bDoXScaling )
     113           7 :         xInverseScaling.set( xScalingX->getInverseScaling());
     114           7 :     bDoXScaling = bDoXScaling && xInverseScaling.is();
     115             : 
     116           7 :     Sequence< geometry::RealPoint2D > aResult( nPointCount );
     117             : 
     118           7 :     double fMin( min );
     119           7 :     double fFact = (max - min) / double(nPointCount-1);
     120             : 
     121           7 :     if( bDoXScaling )
     122             :     {
     123           7 :         fMin = xScalingX->doScaling( min );
     124           7 :         fFact = (xScalingX->doScaling( max ) - fMin) / double(nPointCount-1);
     125             :     }
     126             : 
     127         532 :     for(sal_Int32 nP=0; nP<nPointCount; nP++)
     128             :     {
     129         525 :         double x = fMin + nP * fFact;
     130         525 :         if( bDoXScaling )
     131         525 :             x = xInverseScaling->doScaling( x );
     132         525 :         aResult[nP].X = x;
     133         525 :         aResult[nP].Y = this->getCurveValue( x );
     134             :     }
     135             : 
     136           7 :     return aResult;
     137             : }
     138             : 
     139           7 : double SAL_CALL RegressionCurveCalculator::getCorrelationCoefficient()
     140             :     throw (uno::RuntimeException, std::exception)
     141             : {
     142           7 :     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          14 : 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          14 :     if( !xNumFmtSupplier.is())
     158           0 :         return getRepresentation();
     159          14 :     Reference< uno::XComponentContext > xContext( comphelper::getProcessComponentContext(), uno::UNO_QUERY_THROW );
     160          28 :     Reference< util::XNumberFormatter > xNumFormatter( util::NumberFormatter::create(xContext), uno::UNO_QUERY_THROW );
     161          14 :     xNumFormatter->attachNumberFormatsSupplier( xNumFmtSupplier );
     162             : 
     163          28 :     return ImplGetRepresentation( xNumFormatter, nNumberFormatKey );
     164             : }
     165             : 
     166             : } //  namespace chart
     167             : 
     168             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10