diff options
author | Laurent Balland-Poirier <laurent.balland-poirier@laposte.net> | 2016-03-31 23:15:28 +0200 |
---|---|---|
committer | Markus Mohrhard <markus.mohrhard@googlemail.com> | 2016-04-02 18:56:19 +0000 |
commit | a0b1a10ddcf5e17116055a0c82200231bf5cd55f (patch) | |
tree | 22556660e96dcc13ce19df82b803e614bc807a21 /chart2 | |
parent | 0b5a02eeaa50ffe77d18374162b984a36e69c6cf (diff) |
Chart: Improve polynomial trendline equation rendering
Convert power figures in supersript figures
Replace minus sign
Change-Id: Ia0e77b5de3b6f2368efd1315576f9709d7b1b2d9
Reviewed-on: https://gerrit.libreoffice.org/23714
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Markus Mohrhard <markus.mohrhard@googlemail.com>
Diffstat (limited to 'chart2')
-rw-r--r-- | chart2/inc/SpecialUnicodes.hxx | 18 | ||||
-rw-r--r-- | chart2/qa/extras/chart2_trendcalculators.cxx | 7 | ||||
-rw-r--r-- | chart2/source/tools/PolynomialRegressionCurveCalculator.cxx | 33 |
3 files changed, 46 insertions, 12 deletions
diff --git a/chart2/inc/SpecialUnicodes.hxx b/chart2/inc/SpecialUnicodes.hxx new file mode 100644 index 000000000000..6b3398daf840 --- /dev/null +++ b/chart2/inc/SpecialUnicodes.hxx @@ -0,0 +1,18 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#ifndef INCLUDED_CHART2_INC_SPECIALUNICODES_HXX +#define INCLUDED_CHART2_INC_SPECIALUNICODES_HXX + +const OUString aMinusSign ( sal_Unicode (0x2212) ); +const sal_Unicode aSuperscriptFigures[10]={ 0x2070, 0x00B9, 0x00B2, 0x00B3, 0x2074, 0x2075, 0x2076, 0x2077, 0x2078, 0x2079 }; + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/chart2/qa/extras/chart2_trendcalculators.cxx b/chart2/qa/extras/chart2_trendcalculators.cxx index 0fd3c1d27fb7..0c3b972c3031 100644 --- a/chart2/qa/extras/chart2_trendcalculators.cxx +++ b/chart2/qa/extras/chart2_trendcalculators.cxx @@ -10,6 +10,8 @@ #include "charttest.hxx" #include <com/sun/star/chart2/XRegressionCurveContainer.hpp> #include <com/sun/star/chart2/XRegressionCurveCalculator.hpp> +#include <SpecialUnicodes.hxx> + // Define the index of sheets in the test document #define SHEET_POTENTIAL1 0 @@ -150,7 +152,7 @@ void Chart2TrendCalculators::testLinearRegression1() xValues[i] = d; yValues[i] = - 2.0 * d - 5.0 ; } - checkCalculator( xValues, yValues, "f(x) = - 2x - 5"); + checkCalculator( xValues, yValues, "f(x) = "+ aMinusSign +" 2x "+ aMinusSign +" 5"); } // test y = A x ^ B @@ -166,7 +168,8 @@ void Chart2TrendCalculators::testPolynomialRegression1() xValues[i] = d; yValues[i] = - 2.0 * d * d + 4 * d - 5; } - checkCalculator( xValues, yValues, "f(x) = - 2x^2 + 4x - 5"); + OUString sExpectedFormula( "f(x) = "+ aMinusSign +" 2x" + OUString( aSuperscriptFigures[2] ) + " + 4x "+ aMinusSign +" 5" ); + checkCalculator( xValues, yValues, sExpectedFormula ); } void Chart2TrendCalculators::testExponentialRegression1() diff --git a/chart2/source/tools/PolynomialRegressionCurveCalculator.cxx b/chart2/source/tools/PolynomialRegressionCurveCalculator.cxx index 1d26611c865a..6dba3a26fa27 100644 --- a/chart2/source/tools/PolynomialRegressionCurveCalculator.cxx +++ b/chart2/source/tools/PolynomialRegressionCurveCalculator.cxx @@ -25,6 +25,9 @@ #include <rtl/math.hxx> #include <rtl/ustrbuf.hxx> +#include <SpecialUnicodes.hxx> + + using namespace com::sun::star; namespace chart @@ -235,7 +238,7 @@ OUString PolynomialRegressionCurveCalculator::ImplGetRepresentation( const uno::Reference< util::XNumberFormatter >& xNumFormatter, sal_Int32 nNumberFormatKey ) const { - OUStringBuffer aBuf( "f(x) = "); + OUStringBuffer aBuf( "f(x) = " ); sal_Int32 aLastIndex = mCoefficients.size() - 1; bool bFindValue = false; @@ -248,12 +251,14 @@ OUString PolynomialRegressionCurveCalculator::ImplGetRepresentation( } else if (aValue < 0.0) { - aBuf.append( " - " ); + if ( bFindValue ) // if it is not the first aValue + aBuf.append( " " ); + aBuf.append( aMinusSign + " "); aValue = - aValue; } else { - if ( bFindValue ) + if ( bFindValue ) // if it is not the first aValue aBuf.append( " + " ); } bFindValue = true; @@ -263,17 +268,25 @@ OUString PolynomialRegressionCurveCalculator::ImplGetRepresentation( if(i > 0) { - if (i == 1) - { - aBuf.append( "x" ); - } - else + aBuf.append( "x" ); + if (i > 1) { - aBuf.append( "x^" ); - aBuf.append(i); + if (i < 10) // simple case if only one digit + aBuf.append( aSuperscriptFigures[ i ] ); + else + { + OUString aValueOfi = OUString::number( i ); + for ( sal_Int32 n = 0; n < aValueOfi.getLength() ; n++ ) + { + sal_Int32 nIndex = aValueOfi[n] - sal_Unicode ( '0' ); + aBuf.append( aSuperscriptFigures[ nIndex ] ); + } + } } } } + if ( aBuf.toString() == "f(x) = " ) + aBuf.append( "0" ); return aBuf.makeStringAndClear(); } |