summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLaurent Balland-Poirier <laurent.balland-poirier@laposte.net>2016-05-24 21:40:57 +0200
committerLaurent BP <laurent.balland-poirier@laposte.net>2016-06-19 07:28:16 +0000
commit23d389384950c7a558e6c436282a4da0ff4f9054 (patch)
treebba18002a422f36a545e06e7137fe7423292fec1
parentd1f56846a72697bf55f0330a7b5d0e385bf4a5cb (diff)
tdf#94004 Wrap Power trendline equation
Wrap equation trendline if it is longer than chart width Continue https://gerrit.libreoffice.org/18397/ Change-Id: If805f712a29c412a01209533842f9a6c797cbaf1 Reviewed-on: https://gerrit.libreoffice.org/25418 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: jan iversen <jani@documentfoundation.org> (cherry picked from commit e420a335f783bb4d2ee9d74d56f91e16d189566f) Reviewed-on: https://gerrit.libreoffice.org/26119 Reviewed-by: Laurent BP <laurent.balland-poirier@laposte.net>
-rw-r--r--chart2/qa/extras/chart2_trendcalculators.cxx2
-rw-r--r--chart2/source/tools/PotentialRegressionCurveCalculator.cxx49
2 files changed, 37 insertions, 14 deletions
diff --git a/chart2/qa/extras/chart2_trendcalculators.cxx b/chart2/qa/extras/chart2_trendcalculators.cxx
index 04af84869237..ca327f1e2c94 100644
--- a/chart2/qa/extras/chart2_trendcalculators.cxx
+++ b/chart2/qa/extras/chart2_trendcalculators.cxx
@@ -136,7 +136,7 @@ void Chart2TrendCalculators::testPotentialRegression2()
xValues[i] = d;
yValues[i] = -2.0 * pow ( d, 3 );
}
- checkCalculator( xValues, yValues, "f(x) = -2 x^3");
+ checkCalculator( xValues, yValues, "f(x) = "+ aMinusSign +" 2 x^3");
}
// test y = - 2 X - 5
diff --git a/chart2/source/tools/PotentialRegressionCurveCalculator.cxx b/chart2/source/tools/PotentialRegressionCurveCalculator.cxx
index 8ea92c1d8909..3c19a3e2804e 100644
--- a/chart2/source/tools/PotentialRegressionCurveCalculator.cxx
+++ b/chart2/source/tools/PotentialRegressionCurveCalculator.cxx
@@ -20,6 +20,7 @@
#include "PotentialRegressionCurveCalculator.hxx"
#include "macros.hxx"
#include "RegressionCalculationHelper.hxx"
+#include <SpecialUnicodes.hxx>
#include <rtl/math.hxx>
#include <rtl/ustrbuf.hxx>
@@ -142,32 +143,54 @@ uno::Sequence< geometry::RealPoint2D > SAL_CALL PotentialRegressionCurveCalculat
OUString PotentialRegressionCurveCalculator::ImplGetRepresentation(
const uno::Reference< util::XNumberFormatter >& xNumFormatter,
- sal_Int32 nNumberFormatKey, sal_Int32* /* pFormulaLength = nullptr */ ) const
+ sal_Int32 nNumberFormatKey, sal_Int32* pFormulaMaxWidth /* = nullptr */ ) const
{
+ bool bHasIntercept = !rtl::math::approxEqual( fabs(m_fIntercept), 1.0 );
OUStringBuffer aBuf( "f(x) = ");
+ sal_Int32 nLineLength = aBuf.getLength();
+ sal_Int32 nValueLength=0;
+ if ( pFormulaMaxWidth && *pFormulaMaxWidth > 0 ) // count nValueLength
+ {
+ sal_Int32 nCharMin = nLineLength + 4; // 4 = "x^" + 2 extra characters
+ if ( m_fIntercept != 0.0 && m_fSlope != 0.0 )
+ {
+ if ( m_fIntercept < 0.0 )
+ nCharMin += 2; // "- "
+ if ( bHasIntercept )
+ nValueLength = (*pFormulaMaxWidth - nCharMin) / 2;
+ }
+ if ( nValueLength == 0 ) // not yet calculated
+ nValueLength = *pFormulaMaxWidth - nCharMin;
+ if ( nValueLength <= 0 )
+ nValueLength = 1;
+ }
if( m_fIntercept == 0.0 )
{
aBuf.append( '0' );
}
- else if( m_fSlope == 0.0 )
- {
- aBuf.append( getFormattedString( xNumFormatter, nNumberFormatKey, m_fIntercept ));
- }
else
{
- if( ! rtl::math::approxEqual( fabs(m_fIntercept), 1.0 ) )
+ // temporary buffer
+ OUStringBuffer aTmpBuf("");
+ // if nValueLength not calculated then nullptr
+ sal_Int32* pValueLength = nValueLength ? &nValueLength : nullptr;
+ if ( m_fIntercept < 0.0 ) // add intercept value
+ aTmpBuf.append( aMinusSign+" " );
+ if( bHasIntercept )
{
- aBuf.append( getFormattedString( xNumFormatter, nNumberFormatKey, m_fIntercept ));
- aBuf.append( ' ');
+ OUString aValueString = getFormattedString( xNumFormatter, nNumberFormatKey, fabs(m_fIntercept), pValueLength );
+ if ( aValueString != "1" ) // aValueString may be rounded to 1 if nValueLength is small
+ {
+ aTmpBuf.append( aValueString + " " );
+ }
}
- else // skip intercept if its value is 1 (or near 1)
+ if( m_fSlope != 0.0 ) // add slope value
{
- if ( m_fIntercept < 0.0 )
- aBuf.append( "- " );
+ aTmpBuf.append( "x^" );
+ aTmpBuf.append( getFormattedString( xNumFormatter, nNumberFormatKey, m_fSlope, pValueLength ));
}
- aBuf.append( "x^" );
- aBuf.append( getFormattedString( xNumFormatter, nNumberFormatKey, m_fSlope ));
+ addStringToEquation( aBuf, nLineLength, aTmpBuf, pFormulaMaxWidth );
}
return aBuf.makeStringAndClear();