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/source/tools | |
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/source/tools')
-rw-r--r-- | chart2/source/tools/PolynomialRegressionCurveCalculator.cxx | 33 |
1 files changed, 23 insertions, 10 deletions
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(); } |