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>
This commit is contained in:
committed by
jan iversen
parent
0159ef4fbf
commit
e420a335f7
@@ -136,7 +136,7 @@ void Chart2TrendCalculators::testPotentialRegression2()
|
|||||||
xValues[i] = d;
|
xValues[i] = d;
|
||||||
yValues[i] = -2.0 * pow ( d, 3 );
|
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
|
// test y = - 2 X - 5
|
||||||
|
@@ -20,6 +20,7 @@
|
|||||||
#include "PotentialRegressionCurveCalculator.hxx"
|
#include "PotentialRegressionCurveCalculator.hxx"
|
||||||
#include "macros.hxx"
|
#include "macros.hxx"
|
||||||
#include "RegressionCalculationHelper.hxx"
|
#include "RegressionCalculationHelper.hxx"
|
||||||
|
#include <SpecialUnicodes.hxx>
|
||||||
|
|
||||||
#include <rtl/math.hxx>
|
#include <rtl/math.hxx>
|
||||||
#include <rtl/ustrbuf.hxx>
|
#include <rtl/ustrbuf.hxx>
|
||||||
@@ -142,32 +143,54 @@ uno::Sequence< geometry::RealPoint2D > SAL_CALL PotentialRegressionCurveCalculat
|
|||||||
|
|
||||||
OUString PotentialRegressionCurveCalculator::ImplGetRepresentation(
|
OUString PotentialRegressionCurveCalculator::ImplGetRepresentation(
|
||||||
const uno::Reference< util::XNumberFormatter >& xNumFormatter,
|
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) = ");
|
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 )
|
if( m_fIntercept == 0.0 )
|
||||||
{
|
{
|
||||||
aBuf.append( '0' );
|
aBuf.append( '0' );
|
||||||
}
|
}
|
||||||
else if( m_fSlope == 0.0 )
|
|
||||||
{
|
|
||||||
aBuf.append( getFormattedString( xNumFormatter, nNumberFormatKey, m_fIntercept ));
|
|
||||||
}
|
|
||||||
else
|
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 ));
|
OUString aValueString = getFormattedString( xNumFormatter, nNumberFormatKey, fabs(m_fIntercept), pValueLength );
|
||||||
aBuf.append( ' ');
|
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 )
|
aTmpBuf.append( "x^" );
|
||||||
aBuf.append( "- " );
|
aTmpBuf.append( getFormattedString( xNumFormatter, nNumberFormatKey, m_fSlope, pValueLength ));
|
||||||
}
|
}
|
||||||
aBuf.append( "x^" );
|
addStringToEquation( aBuf, nLineLength, aTmpBuf, pFormulaMaxWidth );
|
||||||
aBuf.append( getFormattedString( xNumFormatter, nNumberFormatKey, m_fSlope ));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return aBuf.makeStringAndClear();
|
return aBuf.makeStringAndClear();
|
||||||
|
Reference in New Issue
Block a user