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

Generated by: LCOV version 1.10