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

Generated by: LCOV version 1.10