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

Generated by: LCOV version 1.10