Kaydet (Commit) 428711f0 authored tarafından Laurent Balland-Poirier's avatar Laurent Balland-Poirier Kaydeden (comit) Laurent BP

Start tdf#100547 Trendline equation: customize X, Y names

Change trend line UI to add fields: X name and Y name
to change "x" and "f(x)" in equation representation

Next to be done: save it to ODF file

Change-Id: I0680ee1bbfbbb74016ecc858917e10d6790ac63a
Reviewed-on: https://gerrit.libreoffice.org/27069Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarLaurent BP <laurent.balland-poirier@laposte.net>
üst 84d9a364
...@@ -565,6 +565,7 @@ OUString ObjectNameProvider::getHelpText( const OUString& rObjectCID, const Refe ...@@ -565,6 +565,7 @@ OUString ObjectNameProvider::getHelpText( const OUString& rObjectCID, const Refe
sal_Int32 aPeriod = 2; sal_Int32 aPeriod = 2;
bool bForceIntercept = false; bool bForceIntercept = false;
double aInterceptValue = 0.0; double aInterceptValue = 0.0;
OUString aXName ("x"), aYName ("f(x)");
const LocaleDataWrapper& rLocaleDataWrapper = Application::GetSettings().GetLocaleDataWrapper(); const LocaleDataWrapper& rLocaleDataWrapper = Application::GetSettings().GetLocaleDataWrapper();
const OUString& aNumDecimalSep = rLocaleDataWrapper.getNumDecimalSep(); const OUString& aNumDecimalSep = rLocaleDataWrapper.getNumDecimalSep();
assert(aNumDecimalSep.getLength() > 0); assert(aNumDecimalSep.getLength() > 0);
...@@ -578,8 +579,17 @@ OUString ObjectNameProvider::getHelpText( const OUString& rObjectCID, const Refe ...@@ -578,8 +579,17 @@ OUString ObjectNameProvider::getHelpText( const OUString& rObjectCID, const Refe
xProperties->getPropertyValue( "ForceIntercept") >>= bForceIntercept; xProperties->getPropertyValue( "ForceIntercept") >>= bForceIntercept;
if (bForceIntercept) if (bForceIntercept)
xProperties->getPropertyValue( "InterceptValue") >>= aInterceptValue; xProperties->getPropertyValue( "InterceptValue") >>= aInterceptValue;
uno::Reference< beans::XPropertySet > xEqProp( xCurve->getEquationProperties());
if( xEqProp.is())
{
if ( !(xEqProp->getPropertyValue( "XName") >>= aXName) )
aXName = "x";
if ( !(xEqProp->getPropertyValue( "YName") >>= aYName) )
aYName = "f(x)";
}
} }
xCalculator->setRegressionProperties(aDegree, bForceIntercept, aInterceptValue, 2); xCalculator->setRegressionProperties(aDegree, bForceIntercept, aInterceptValue, 2);
xCalculator->setXYNames ( aXName, aYName );
RegressionCurveHelper::initializeCurveCalculator( xCalculator, xSeries, xChartModel ); RegressionCurveHelper::initializeCurveCalculator( xCalculator, xSeries, xChartModel );
// change text for Moving Average // change text for Moving Average
......
...@@ -60,6 +60,8 @@ TrendlineResources::TrendlineResources( vcl::Window * pParent, const SfxItemSet& ...@@ -60,6 +60,8 @@ TrendlineResources::TrendlineResources( vcl::Window * pParent, const SfxItemSet&
pTabPage->get(m_pCB_SetIntercept,"setIntercept"); pTabPage->get(m_pCB_SetIntercept,"setIntercept");
pTabPage->get(m_pFmtFld_InterceptValue,"interceptValue"); pTabPage->get(m_pFmtFld_InterceptValue,"interceptValue");
pTabPage->get(m_pCB_ShowEquation,"showEquation"); pTabPage->get(m_pCB_ShowEquation,"showEquation");
pTabPage->get(m_pEE_XName,"entry_Xname");
pTabPage->get(m_pEE_YName,"entry_Yname");
pTabPage->get(m_pCB_ShowCorrelationCoeff,"showCorrelationCoefficient"); pTabPage->get(m_pCB_ShowCorrelationCoeff,"showCorrelationCoefficient");
pTabPage->get(m_pFI_Linear,"imageLinear"); pTabPage->get(m_pFI_Linear,"imageLinear");
pTabPage->get(m_pFI_Logarithmic,"imageLogarithmic"); pTabPage->get(m_pFI_Logarithmic,"imageLogarithmic");
...@@ -82,6 +84,8 @@ TrendlineResources::TrendlineResources( vcl::Window * pParent, const SfxItemSet& ...@@ -82,6 +84,8 @@ TrendlineResources::TrendlineResources( vcl::Window * pParent, const SfxItemSet&
m_pNF_Period->SetModifyHdl( aLink2 ); m_pNF_Period->SetModifyHdl( aLink2 );
m_pFmtFld_InterceptValue->SetModifyHdl( aLink2 ); m_pFmtFld_InterceptValue->SetModifyHdl( aLink2 );
m_pCB_ShowEquation->SetToggleHdl( LINK(this, TrendlineResources, ShowEquation ) );
Reset( rInAttrs ); Reset( rInAttrs );
UpdateControlStates(); UpdateControlStates();
} }
...@@ -121,6 +125,24 @@ void TrendlineResources::Reset( const SfxItemSet& rInAttrs ) ...@@ -121,6 +125,24 @@ void TrendlineResources::Reset( const SfxItemSet& rInAttrs )
{ {
m_pEE_Name->SetText(""); m_pEE_Name->SetText("");
} }
if( rInAttrs.GetItemState( SCHATTR_REGRESSION_XNAME, true, &pPoolItem ) == SfxItemState::SET )
{
OUString aName = static_cast< const SfxStringItem* >(pPoolItem)->GetValue();
m_pEE_XName->SetText(aName);
}
else
{
m_pEE_XName->SetText("x");
}
if( rInAttrs.GetItemState( SCHATTR_REGRESSION_YNAME, true, &pPoolItem ) == SfxItemState::SET )
{
OUString aName = static_cast< const SfxStringItem* >(pPoolItem)->GetValue();
m_pEE_YName->SetText(aName);
}
else
{
m_pEE_YName->SetText("f(x)");
}
SfxItemState aState = rInAttrs.GetItemState( SCHATTR_REGRESSION_TYPE, true, &pPoolItem ); SfxItemState aState = rInAttrs.GetItemState( SCHATTR_REGRESSION_TYPE, true, &pPoolItem );
m_bTrendLineUnique = ( aState != SfxItemState::DONTCARE ); m_bTrendLineUnique = ( aState != SfxItemState::DONTCARE );
...@@ -254,6 +276,14 @@ bool TrendlineResources::FillItemSet(SfxItemSet* rOutAttrs) const ...@@ -254,6 +276,14 @@ bool TrendlineResources::FillItemSet(SfxItemSet* rOutAttrs) const
OUString aName = m_pEE_Name->GetText(); OUString aName = m_pEE_Name->GetText();
rOutAttrs->Put(SfxStringItem(SCHATTR_REGRESSION_CURVE_NAME, aName)); rOutAttrs->Put(SfxStringItem(SCHATTR_REGRESSION_CURVE_NAME, aName));
aName = m_pEE_XName->GetText();
if ( aName.isEmpty() )
aName = "x";
rOutAttrs->Put(SfxStringItem(SCHATTR_REGRESSION_XNAME, aName));
aName = m_pEE_YName->GetText();
if ( aName.isEmpty() )
aName = "f(x)";
rOutAttrs->Put(SfxStringItem(SCHATTR_REGRESSION_YNAME, aName));
sal_Int32 aDegree = m_pNF_Degree->GetValue(); sal_Int32 aDegree = m_pNF_Degree->GetValue();
rOutAttrs->Put(SfxInt32Item( SCHATTR_REGRESSION_DEGREE, aDegree ) ); rOutAttrs->Put(SfxInt32Item( SCHATTR_REGRESSION_DEGREE, aDegree ) );
...@@ -314,6 +344,8 @@ void TrendlineResources::UpdateControlStates() ...@@ -314,6 +344,8 @@ void TrendlineResources::UpdateControlStates()
} }
m_pCB_ShowEquation->Enable( !bMovingAverage ); m_pCB_ShowEquation->Enable( !bMovingAverage );
m_pCB_ShowCorrelationCoeff->Enable( !bMovingAverage ); m_pCB_ShowCorrelationCoeff->Enable( !bMovingAverage );
m_pEE_XName->Enable( !bMovingAverage && m_pCB_ShowEquation->IsChecked() );
m_pEE_YName->Enable( !bMovingAverage && m_pCB_ShowEquation->IsChecked() );
} }
IMPL_LINK_TYPED( TrendlineResources, ChangeValue, Edit&, rNumericField, void) IMPL_LINK_TYPED( TrendlineResources, ChangeValue, Edit&, rNumericField, void)
...@@ -356,6 +388,16 @@ void TrendlineResources::SetNbPoints( sal_Int32 nNbPoints ) ...@@ -356,6 +388,16 @@ void TrendlineResources::SetNbPoints( sal_Int32 nNbPoints )
UpdateControlStates(); UpdateControlStates();
} }
IMPL_LINK_TYPED( TrendlineResources, ShowEquation, CheckBox&, rCheckBox, void)
{
if( &rCheckBox == m_pCB_ShowEquation )
{
m_pEE_XName->Enable( m_pCB_ShowEquation->IsChecked() );
m_pEE_YName->Enable( m_pCB_ShowEquation->IsChecked() );
}
UpdateControlStates();
}
} // namespace chart } // namespace chart
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
...@@ -60,15 +60,17 @@ private: ...@@ -60,15 +60,17 @@ private:
VclPtr<FixedImage> m_pFI_Polynomial; VclPtr<FixedImage> m_pFI_Polynomial;
VclPtr<FixedImage> m_pFI_MovingAverage; VclPtr<FixedImage> m_pFI_MovingAverage;
VclPtr<NumericField> m_pNF_Degree; VclPtr<NumericField> m_pNF_Degree;
VclPtr<NumericField> m_pNF_Period; VclPtr<NumericField> m_pNF_Period;
VclPtr<Edit> m_pEE_Name; VclPtr<Edit> m_pEE_Name;
VclPtr<FormattedField> m_pFmtFld_ExtrapolateForward; VclPtr<FormattedField> m_pFmtFld_ExtrapolateForward;
VclPtr<FormattedField> m_pFmtFld_ExtrapolateBackward; VclPtr<FormattedField> m_pFmtFld_ExtrapolateBackward;
VclPtr<CheckBox> m_pCB_SetIntercept; VclPtr<CheckBox> m_pCB_SetIntercept;
VclPtr<FormattedField> m_pFmtFld_InterceptValue; VclPtr<FormattedField> m_pFmtFld_InterceptValue;
VclPtr<CheckBox> m_pCB_ShowEquation; VclPtr<CheckBox> m_pCB_ShowEquation;
VclPtr<CheckBox> m_pCB_ShowCorrelationCoeff; VclPtr<Edit> m_pEE_XName;
VclPtr<Edit> m_pEE_YName;
VclPtr<CheckBox> m_pCB_ShowCorrelationCoeff;
SvxChartRegress m_eTrendLineType; SvxChartRegress m_eTrendLineType;
...@@ -78,8 +80,9 @@ private: ...@@ -78,8 +80,9 @@ private:
sal_Int32 m_nNbPoints; sal_Int32 m_nNbPoints;
void UpdateControlStates(); void UpdateControlStates();
DECL_LINK_TYPED( SelectTrendLine, Button *, void ); DECL_LINK_TYPED( SelectTrendLine, Button*, void );
DECL_LINK_TYPED( ChangeValue, Edit&, void); DECL_LINK_TYPED( ChangeValue, Edit&, void);
DECL_LINK_TYPED( ShowEquation, CheckBox&, void);
}; };
} // namespace chart } // namespace chart
......
...@@ -230,6 +230,20 @@ bool RegressionCurveItemConverter::ApplySpecialItem( ...@@ -230,6 +230,20 @@ bool RegressionCurveItemConverter::ApplySpecialItem(
} }
break; break;
case SCHATTR_REGRESSION_XNAME:
{
uno::Reference< beans::XPropertySet > xEqProp( xCurve->getEquationProperties());
bChanged = lclConvertToPropertySet<OUString, SfxStringItem>(rItemSet, nWhichId, xEqProp, "XName");
}
break;
case SCHATTR_REGRESSION_YNAME:
{
uno::Reference< beans::XPropertySet > xEqProp( xCurve->getEquationProperties());
bChanged = lclConvertToPropertySet<OUString, SfxStringItem>(rItemSet, nWhichId, xEqProp, "YName");
}
break;
case SCHATTR_REGRESSION_SHOW_COEFF: case SCHATTR_REGRESSION_SHOW_COEFF:
{ {
uno::Reference< beans::XPropertySet > xEqProp( xCurve->getEquationProperties()); uno::Reference< beans::XPropertySet > xEqProp( xCurve->getEquationProperties());
...@@ -308,6 +322,18 @@ void RegressionCurveItemConverter::FillSpecialItem(sal_uInt16 nWhichId, SfxItemS ...@@ -308,6 +322,18 @@ void RegressionCurveItemConverter::FillSpecialItem(sal_uInt16 nWhichId, SfxItemS
} }
break; break;
case SCHATTR_REGRESSION_XNAME:
{
lclConvertToItemSet<OUString, SfxStringItem>(rOutItemSet, nWhichId, xCurve->getEquationProperties(), "XName");
}
break;
case SCHATTR_REGRESSION_YNAME:
{
lclConvertToItemSet<OUString, SfxStringItem>(rOutItemSet, nWhichId, xCurve->getEquationProperties(), "YName");
}
break;
case SCHATTR_REGRESSION_SHOW_COEFF: case SCHATTR_REGRESSION_SHOW_COEFF:
{ {
lclConvertToItemSet<bool, SfxBoolItem>(rOutItemSet, nWhichId, xCurve->getEquationProperties(), "ShowCorrelationCoefficient"); lclConvertToItemSet<bool, SfxBoolItem>(rOutItemSet, nWhichId, xCurve->getEquationProperties(), "ShowCorrelationCoefficient");
......
...@@ -507,6 +507,20 @@ bool StatisticsItemConverter::ApplySpecialItem( ...@@ -507,6 +507,20 @@ bool StatisticsItemConverter::ApplySpecialItem(
} }
break; break;
case SCHATTR_REGRESSION_XNAME:
{
uno::Reference< beans::XPropertySet > xEqProp( lcl_getEquationProperties( GetPropertySet(), &rItemSet ));
bChanged = lclConvertToPropertySet<OUString, SfxStringItem>(rItemSet, nWhichId, xEqProp, "XName");
}
break;
case SCHATTR_REGRESSION_YNAME:
{
uno::Reference< beans::XPropertySet > xEqProp( lcl_getEquationProperties( GetPropertySet(), &rItemSet ));
bChanged = lclConvertToPropertySet<OUString, SfxStringItem>(rItemSet, nWhichId, xEqProp, "YName");
}
break;
case SCHATTR_REGRESSION_SHOW_COEFF: case SCHATTR_REGRESSION_SHOW_COEFF:
{ {
uno::Reference< beans::XPropertySet > xEqProp( lcl_getEquationProperties( GetPropertySet(), &rItemSet )); uno::Reference< beans::XPropertySet > xEqProp( lcl_getEquationProperties( GetPropertySet(), &rItemSet ));
...@@ -776,6 +790,20 @@ void StatisticsItemConverter::FillSpecialItem( ...@@ -776,6 +790,20 @@ void StatisticsItemConverter::FillSpecialItem(
} }
break; break;
case SCHATTR_REGRESSION_XNAME:
{
uno::Reference< beans::XPropertySet > xEqProp( lcl_getEquationProperties( GetPropertySet(), nullptr ));
lclConvertToItemSet<OUString, SfxStringItem>(rOutItemSet, nWhichId, xEqProp, "XName");
}
break;
case SCHATTR_REGRESSION_YNAME:
{
uno::Reference< beans::XPropertySet > xEqProp( lcl_getEquationProperties( GetPropertySet(), nullptr ));
lclConvertToItemSet<OUString, SfxStringItem>(rOutItemSet, nWhichId, xEqProp, "YName");
}
break;
case SCHATTR_REGRESSION_SHOW_COEFF: case SCHATTR_REGRESSION_SHOW_COEFF:
{ {
uno::Reference< beans::XPropertySet > xEqProp( lcl_getEquationProperties( GetPropertySet(), nullptr )); uno::Reference< beans::XPropertySet > xEqProp( lcl_getEquationProperties( GetPropertySet(), nullptr ));
......
...@@ -536,6 +536,8 @@ void ChartController::executeDispatch_InsertTrendlineEquation( bool bInsertR2 ) ...@@ -536,6 +536,8 @@ void ChartController::executeDispatch_InsertTrendlineEquation( bool bInsertR2 )
ActionDescriptionProvider::INSERT, SCH_RESSTR( STR_OBJECT_CURVE_EQUATION )), ActionDescriptionProvider::INSERT, SCH_RESSTR( STR_OBJECT_CURVE_EQUATION )),
m_xUndoManager ); m_xUndoManager );
xEqProp->setPropertyValue( "ShowEquation", uno::makeAny( true )); xEqProp->setPropertyValue( "ShowEquation", uno::makeAny( true ));
xEqProp->setPropertyValue( "XName", uno::makeAny( OUString("x") ));
xEqProp->setPropertyValue( "YName", uno::makeAny( OUString("f(x)") ));
xEqProp->setPropertyValue( "ShowCorrelationCoefficient", uno::makeAny( bInsertR2 )); xEqProp->setPropertyValue( "ShowCorrelationCoefficient", uno::makeAny( bInsertR2 ));
aUndoGuard.commit(); aUndoGuard.commit();
} }
......
...@@ -709,6 +709,8 @@ bool ChartController::executeDispatch_Delete() ...@@ -709,6 +709,8 @@ bool ChartController::executeDispatch_Delete()
{ {
ControllerLockGuardUNO aCtlLockGuard( xModel ); ControllerLockGuardUNO aCtlLockGuard( xModel );
xEqProp->setPropertyValue( "ShowEquation", uno::makeAny( false )); xEqProp->setPropertyValue( "ShowEquation", uno::makeAny( false ));
xEqProp->setPropertyValue( "XName", uno::makeAny( OUString("x") ));
xEqProp->setPropertyValue( "YName", uno::makeAny( OUString("f(x)") ));
xEqProp->setPropertyValue( "ShowCorrelationCoefficient", uno::makeAny( false )); xEqProp->setPropertyValue( "ShowCorrelationCoefficient", uno::makeAny( false ));
} }
bReturn = true; bReturn = true;
......
...@@ -60,6 +60,7 @@ protected: ...@@ -60,6 +60,7 @@ protected:
bool mForceIntercept; bool mForceIntercept;
double mInterceptValue; double mInterceptValue;
sal_Int32 mPeriod; sal_Int32 mPeriod;
OUString mXName, mYName;
// ____ XRegressionCurveCalculator ____ // ____ XRegressionCurveCalculator ____
virtual void SAL_CALL setRegressionProperties( virtual void SAL_CALL setRegressionProperties(
...@@ -98,6 +99,10 @@ protected: ...@@ -98,6 +99,10 @@ protected:
const css::uno::Reference< css::util::XNumberFormatsSupplier >& xNumFmtSupplier, const css::uno::Reference< css::util::XNumberFormatsSupplier >& xNumFmtSupplier,
sal_Int32 nNumberFormatKey, sal_Int32 nFormulaLength ) sal_Int32 nNumberFormatKey, sal_Int32 nFormulaLength )
throw (css::uno::RuntimeException, std::exception) override; throw (css::uno::RuntimeException, std::exception) override;
virtual void SAL_CALL setXYNames(
const OUString& aXName, const OUString& aYName )
throw (css::uno::RuntimeException, std::exception) override;
}; };
} // namespace chart } // namespace chart
......
...@@ -169,7 +169,9 @@ ...@@ -169,7 +169,9 @@
#define SCHATTR_REGRESSION_SET_INTERCEPT (SCHATTR_REGRESSION_START + 7) #define SCHATTR_REGRESSION_SET_INTERCEPT (SCHATTR_REGRESSION_START + 7)
#define SCHATTR_REGRESSION_INTERCEPT_VALUE (SCHATTR_REGRESSION_START + 8) #define SCHATTR_REGRESSION_INTERCEPT_VALUE (SCHATTR_REGRESSION_START + 8)
#define SCHATTR_REGRESSION_CURVE_NAME (SCHATTR_REGRESSION_START + 9) #define SCHATTR_REGRESSION_CURVE_NAME (SCHATTR_REGRESSION_START + 9)
#define SCHATTR_REGRESSION_END SCHATTR_REGRESSION_CURVE_NAME #define SCHATTR_REGRESSION_XNAME (SCHATTR_REGRESSION_START + 10)
#define SCHATTR_REGRESSION_YNAME (SCHATTR_REGRESSION_START + 11)
#define SCHATTR_REGRESSION_END SCHATTR_REGRESSION_YNAME
#define SCHATTR_END SCHATTR_REGRESSION_END #define SCHATTR_END SCHATTR_REGRESSION_END
......
...@@ -162,12 +162,12 @@ OUString ExponentialRegressionCurveCalculator::ImplGetRepresentation( ...@@ -162,12 +162,12 @@ OUString ExponentialRegressionCurveCalculator::ImplGetRepresentation(
bool bHasLogSlope = !rtl::math::approxEqual( fabs(m_fLogSlope), 1.0 ); bool bHasLogSlope = !rtl::math::approxEqual( fabs(m_fLogSlope), 1.0 );
bool bHasIntercept = !rtl::math::approxEqual( fIntercept, 1.0 ) && fIntercept != 0.0; bool bHasIntercept = !rtl::math::approxEqual( fIntercept, 1.0 ) && fIntercept != 0.0;
OUStringBuffer aBuf( "f(x) = " ); OUStringBuffer aBuf( mYName + " = " );
sal_Int32 nLineLength = aBuf.getLength(); sal_Int32 nLineLength = aBuf.getLength();
sal_Int32 nValueLength=0; sal_Int32 nValueLength=0;
if ( pFormulaMaxWidth && *pFormulaMaxWidth > 0 ) if ( pFormulaMaxWidth && *pFormulaMaxWidth > 0 )
{ // count characters different from coefficients { // count characters different from coefficients
sal_Int32 nCharMin = nLineLength + 11; // 11 = "exp( ", " x )" + 2 extra characters sal_Int32 nCharMin = nLineLength + 10 + mXName.getLength(); // 10 = "exp( ", " x )" + 2 extra characters
if ( m_fSign < 0.0 ) if ( m_fSign < 0.0 )
nCharMin += 2; nCharMin += 2;
if ( fIntercept == 0.0 || ( !bHasSlope && m_fLogIntercept != 0.0 ) ) if ( fIntercept == 0.0 || ( !bHasSlope && m_fLogIntercept != 0.0 ) )
...@@ -219,7 +219,7 @@ OUString ExponentialRegressionCurveCalculator::ImplGetRepresentation( ...@@ -219,7 +219,7 @@ OUString ExponentialRegressionCurveCalculator::ImplGetRepresentation(
aTmpBuf.append( aValueString + " " ); aTmpBuf.append( aValueString + " " );
} }
} }
aTmpBuf.append( "x )"); aTmpBuf.append( mXName + " )");
addStringToEquation( aBuf, nLineLength, aTmpBuf, pFormulaMaxWidth ); addStringToEquation( aBuf, nLineLength, aTmpBuf, pFormulaMaxWidth );
return aBuf.makeStringAndClear(); return aBuf.makeStringAndClear();
......
...@@ -134,12 +134,12 @@ OUString LogarithmicRegressionCurveCalculator::ImplGetRepresentation( ...@@ -134,12 +134,12 @@ OUString LogarithmicRegressionCurveCalculator::ImplGetRepresentation(
sal_Int32 nNumberFormatKey, sal_Int32* pFormulaMaxWidth /* = nullptr */ ) const sal_Int32 nNumberFormatKey, sal_Int32* pFormulaMaxWidth /* = nullptr */ ) const
{ {
bool bHasSlope = !rtl::math::approxEqual( fabs( m_fSlope ), 1.0 ); bool bHasSlope = !rtl::math::approxEqual( fabs( m_fSlope ), 1.0 );
OUStringBuffer aBuf( "f(x) = " ); OUStringBuffer aBuf( mYName + " = " );
sal_Int32 nLineLength = aBuf.getLength(); sal_Int32 nLineLength = aBuf.getLength();
sal_Int32 nValueLength=0; sal_Int32 nValueLength=0;
if ( pFormulaMaxWidth && *pFormulaMaxWidth > 0 ) // count nValueLength if ( pFormulaMaxWidth && *pFormulaMaxWidth > 0 ) // count nValueLength
{ {
sal_Int32 nCharMin = nLineLength + 7; // 7 = "ln(x)" + 2 extra characters sal_Int32 nCharMin = nLineLength + 6 + mXName.getLength(); // 6 = "ln(x)" + 2 extra characters
if( m_fSlope < 0.0 ) if( m_fSlope < 0.0 )
nCharMin += 2; // "- " nCharMin += 2; // "- "
if( m_fSlope != 0.0 && m_fIntercept != 0.0 ) if( m_fSlope != 0.0 && m_fIntercept != 0.0 )
...@@ -172,7 +172,7 @@ OUString LogarithmicRegressionCurveCalculator::ImplGetRepresentation( ...@@ -172,7 +172,7 @@ OUString LogarithmicRegressionCurveCalculator::ImplGetRepresentation(
aTmpBuf.append( aValueString + " " ); aTmpBuf.append( aValueString + " " );
} }
} }
aTmpBuf.append( "ln(x) " ); aTmpBuf.append( "ln(" + mXName + ") " );
addStringToEquation( aBuf, nLineLength, aTmpBuf, pFormulaMaxWidth ); addStringToEquation( aBuf, nLineLength, aTmpBuf, pFormulaMaxWidth );
aTmpBuf.truncate(); aTmpBuf.truncate();
...@@ -189,7 +189,7 @@ OUString LogarithmicRegressionCurveCalculator::ImplGetRepresentation( ...@@ -189,7 +189,7 @@ OUString LogarithmicRegressionCurveCalculator::ImplGetRepresentation(
addStringToEquation( aBuf, nLineLength, aTmpBuf, pFormulaMaxWidth ); addStringToEquation( aBuf, nLineLength, aTmpBuf, pFormulaMaxWidth );
} }
if ( aBuf.toString() == "f(x) = " ) if ( aBuf.toString().equals( OUString(mYName + " = ") ) )
aBuf.append( "0" ); aBuf.append( "0" );
return aBuf.makeStringAndClear(); return aBuf.makeStringAndClear();
......
...@@ -121,7 +121,7 @@ OUString MeanValueRegressionCurveCalculator::ImplGetRepresentation( ...@@ -121,7 +121,7 @@ OUString MeanValueRegressionCurveCalculator::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* pFormulaLength /* = nullptr */ ) const
{ {
OUString aBuf = "f(x) = "; OUString aBuf = OUString(mYName + " = ");
if ( pFormulaLength ) if ( pFormulaLength )
{ {
*pFormulaLength -= aBuf.getLength(); *pFormulaLength -= aBuf.getLength();
......
...@@ -225,7 +225,7 @@ OUString PolynomialRegressionCurveCalculator::ImplGetRepresentation( ...@@ -225,7 +225,7 @@ OUString PolynomialRegressionCurveCalculator::ImplGetRepresentation(
const uno::Reference< util::XNumberFormatter >& xNumFormatter, const uno::Reference< util::XNumberFormatter >& xNumFormatter,
sal_Int32 nNumberFormatKey, sal_Int32* pFormulaMaxWidth /* = nullptr */ ) const sal_Int32 nNumberFormatKey, sal_Int32* pFormulaMaxWidth /* = nullptr */ ) const
{ {
OUStringBuffer aBuf( "f(x) = " ); OUStringBuffer aBuf( mYName + " = " );
sal_Int32 nValueLength=0; sal_Int32 nValueLength=0;
sal_Int32 aLastIndex = mCoefficients.size() - 1; sal_Int32 aLastIndex = mCoefficients.size() - 1;
...@@ -252,7 +252,7 @@ OUString PolynomialRegressionCurveCalculator::ImplGetRepresentation( ...@@ -252,7 +252,7 @@ OUString PolynomialRegressionCurveCalculator::ImplGetRepresentation(
nCharMin += 3; // " + " nCharMin += 3; // " + "
if ( i > 0 ) if ( i > 0 )
{ {
nCharMin += 1; // "x" nCharMin += mXName.getLength(); // "x"
if ( i > 1 ) if ( i > 1 )
nCharMin +=1; // "^i" nCharMin +=1; // "^i"
if ( i >= 10 ) if ( i >= 10 )
...@@ -296,7 +296,7 @@ OUString PolynomialRegressionCurveCalculator::ImplGetRepresentation( ...@@ -296,7 +296,7 @@ OUString PolynomialRegressionCurveCalculator::ImplGetRepresentation(
if(i > 0) if(i > 0)
{ {
aTmpBuf.append( "x" ); aTmpBuf.append( mXName );
if (i > 1) if (i > 1)
{ {
if (i < 10) // simple case if only one digit if (i < 10) // simple case if only one digit
...@@ -314,7 +314,7 @@ OUString PolynomialRegressionCurveCalculator::ImplGetRepresentation( ...@@ -314,7 +314,7 @@ OUString PolynomialRegressionCurveCalculator::ImplGetRepresentation(
} }
addStringToEquation( aBuf, nLineLength, aTmpBuf, pFormulaMaxWidth ); addStringToEquation( aBuf, nLineLength, aTmpBuf, pFormulaMaxWidth );
} }
if ( aBuf.toString() == "f(x) = " ) if ( aBuf.toString().equals( OUString( mYName + " = ") ) )
aBuf.append( "0" ); aBuf.append( "0" );
return aBuf.makeStringAndClear(); return aBuf.makeStringAndClear();
......
...@@ -146,12 +146,12 @@ OUString PotentialRegressionCurveCalculator::ImplGetRepresentation( ...@@ -146,12 +146,12 @@ OUString PotentialRegressionCurveCalculator::ImplGetRepresentation(
sal_Int32 nNumberFormatKey, sal_Int32* pFormulaMaxWidth /* = nullptr */ ) const sal_Int32 nNumberFormatKey, sal_Int32* pFormulaMaxWidth /* = nullptr */ ) const
{ {
bool bHasIntercept = !rtl::math::approxEqual( fabs(m_fIntercept), 1.0 ); bool bHasIntercept = !rtl::math::approxEqual( fabs(m_fIntercept), 1.0 );
OUStringBuffer aBuf( "f(x) = "); OUStringBuffer aBuf( mYName + " = " );
sal_Int32 nLineLength = aBuf.getLength(); sal_Int32 nLineLength = aBuf.getLength();
sal_Int32 nValueLength=0; sal_Int32 nValueLength=0;
if ( pFormulaMaxWidth && *pFormulaMaxWidth > 0 ) // count nValueLength if ( pFormulaMaxWidth && *pFormulaMaxWidth > 0 ) // count nValueLength
{ {
sal_Int32 nCharMin = nLineLength + 4; // 4 = "x^" + 2 extra characters sal_Int32 nCharMin = nLineLength + mXName.getLength() + 3; // 3 = "^" + 2 extra characters
if ( m_fIntercept != 0.0 && m_fSlope != 0.0 ) if ( m_fIntercept != 0.0 && m_fSlope != 0.0 )
{ {
if ( m_fIntercept < 0.0 ) if ( m_fIntercept < 0.0 )
...@@ -187,7 +187,7 @@ OUString PotentialRegressionCurveCalculator::ImplGetRepresentation( ...@@ -187,7 +187,7 @@ OUString PotentialRegressionCurveCalculator::ImplGetRepresentation(
} }
if( m_fSlope != 0.0 ) // add slope value if( m_fSlope != 0.0 ) // add slope value
{ {
aTmpBuf.append( "x^" ); aTmpBuf.append( mXName + "^" );
aTmpBuf.append( getFormattedString( xNumFormatter, nNumberFormatKey, m_fSlope, pValueLength )); aTmpBuf.append( getFormattedString( xNumFormatter, nNumberFormatKey, m_fSlope, pValueLength ));
} }
addStringToEquation( aBuf, nLineLength, aTmpBuf, pFormulaMaxWidth ); addStringToEquation( aBuf, nLineLength, aTmpBuf, pFormulaMaxWidth );
......
...@@ -45,7 +45,8 @@ RegressionCurveCalculator::RegressionCurveCalculator() : ...@@ -45,7 +45,8 @@ RegressionCurveCalculator::RegressionCurveCalculator() :
mDegree(2), mDegree(2),
mForceIntercept(false), mForceIntercept(false),
mInterceptValue(0.0), mInterceptValue(0.0),
mPeriod(2) mPeriod(2),
mXName("x"), mYName("f(x)")
{ {
rtl::math::setNan( &m_fCorrelationCoeffitient ); rtl::math::setNan( &m_fCorrelationCoeffitient );
rtl::math::setNan( &mInterceptValue ); rtl::math::setNan( &mInterceptValue );
...@@ -211,6 +212,19 @@ void RegressionCurveCalculator::addStringToEquation( ...@@ -211,6 +212,19 @@ void RegressionCurveCalculator::addStringToEquation(
nLineLength += aAddString.getLength(); nLineLength += aAddString.getLength();
} }
void SAL_CALL RegressionCurveCalculator::setXYNames( const OUString& aXName, const OUString& aYName )
throw (uno::RuntimeException, std::exception)
{
if ( aXName.isEmpty() )
mXName = OUString ("x");
else
mXName = aXName;
if ( aYName.isEmpty() )
mYName = OUString ("f(x)");
else
mYName = aYName;
}
} // namespace chart } // namespace chart
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
...@@ -456,6 +456,8 @@ void RegressionCurveHelper::removeEquations( ...@@ -456,6 +456,8 @@ void RegressionCurveHelper::removeEquations(
if( xEqProp.is()) if( xEqProp.is())
{ {
xEqProp->setPropertyValue( "ShowEquation", uno::makeAny( false )); xEqProp->setPropertyValue( "ShowEquation", uno::makeAny( false ));
xEqProp->setPropertyValue( "XName", uno::makeAny( OUString("x") ));
xEqProp->setPropertyValue( "YName", uno::makeAny( OUString("f(x) ") ));
xEqProp->setPropertyValue( "ShowCorrelationCoefficient", uno::makeAny( false )); xEqProp->setPropertyValue( "ShowCorrelationCoefficient", uno::makeAny( false ));
} }
} }
......
...@@ -52,6 +52,8 @@ static const char lcl_aServiceName[] = "com.sun.star.chart2.RegressionEquation" ...@@ -52,6 +52,8 @@ static const char lcl_aServiceName[] = "com.sun.star.chart2.RegressionEquation"
enum enum
{ {
PROP_EQUATION_SHOW, PROP_EQUATION_SHOW,
PROP_EQUATION_XNAME,
PROP_EQUATION_YNAME,
PROP_EQUATION_SHOW_CORRELATION_COEFF, PROP_EQUATION_SHOW_CORRELATION_COEFF,
PROP_EQUATION_REF_PAGE_SIZE, PROP_EQUATION_REF_PAGE_SIZE,
PROP_EQUATION_REL_POS, PROP_EQUATION_REL_POS,
...@@ -68,6 +70,20 @@ void lcl_AddPropertiesToVector( ...@@ -68,6 +70,20 @@ void lcl_AddPropertiesToVector(
beans::PropertyAttribute::BOUND beans::PropertyAttribute::BOUND
| beans::PropertyAttribute::MAYBEDEFAULT )); | beans::PropertyAttribute::MAYBEDEFAULT ));
rOutProperties.push_back(
Property( "XName",
PROP_EQUATION_XNAME,
cppu::UnoType<OUString>::get(),
beans::PropertyAttribute::BOUND
| beans::PropertyAttribute::MAYBEDEFAULT ));
rOutProperties.push_back(
Property( "YName",
PROP_EQUATION_YNAME,
cppu::UnoType<OUString>::get(),
beans::PropertyAttribute::BOUND
| beans::PropertyAttribute::MAYBEDEFAULT ));
rOutProperties.push_back( rOutProperties.push_back(
Property( "ShowCorrelationCoefficient", Property( "ShowCorrelationCoefficient",
PROP_EQUATION_SHOW_CORRELATION_COEFF, PROP_EQUATION_SHOW_CORRELATION_COEFF,
...@@ -113,6 +129,8 @@ private: ...@@ -113,6 +129,8 @@ private:
::chart::CharacterProperties::AddDefaultsToMap( rOutMap ); ::chart::CharacterProperties::AddDefaultsToMap( rOutMap );
::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_EQUATION_SHOW, false ); ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_EQUATION_SHOW, false );
::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_EQUATION_XNAME, OUString("x") );
::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_EQUATION_YNAME, OUString("f(x)") );
::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_EQUATION_SHOW_CORRELATION_COEFF, false ); ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_EQUATION_SHOW_CORRELATION_COEFF, false );
//::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_EQUATION_SEPARATOR, OUString( '\n' )); //::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_EQUATION_SEPARATOR, OUString( '\n' ));
......
...@@ -1251,6 +1251,15 @@ void VSeriesPlotter::createRegressionCurveEquationShapes( ...@@ -1251,6 +1251,15 @@ void VSeriesPlotter::createRegressionCurveEquationShapes(
xEquationProperties->getPropertyValue(CHART_UNONAME_NUMFMT) >>= nNumberFormatKey; xEquationProperties->getPropertyValue(CHART_UNONAME_NUMFMT) >>= nNumberFormatKey;
bool bResizeEquation = true; bool bResizeEquation = true;
sal_Int32 nMaxIteration = 2; sal_Int32 nMaxIteration = 2;
if ( bShowEquation )
{
OUString aXName, aYName;
if ( !(xEquationProperties->getPropertyValue( "XName" ) >>= aXName) )
aXName = OUString( "x" );
if ( !(xEquationProperties->getPropertyValue( "YName" ) >>= aYName) )
aYName = OUString( "f(x)" );
xRegressionCurveCalculator->setXYNames( aXName, aYName );
}
for ( sal_Int32 nCountIteration = 0; bResizeEquation && nCountIteration < nMaxIteration ; nCountIteration++ ) for ( sal_Int32 nCountIteration = 0; bResizeEquation && nCountIteration < nMaxIteration ; nCountIteration++ )
{ {
......
...@@ -158,6 +158,8 @@ ChartItemPool::ChartItemPool(): ...@@ -158,6 +158,8 @@ ChartItemPool::ChartItemPool():
ppPoolDefaults[SCHATTR_REGRESSION_SET_INTERCEPT - SCHATTR_START] = new SfxBoolItem(SCHATTR_REGRESSION_SET_INTERCEPT, false); ppPoolDefaults[SCHATTR_REGRESSION_SET_INTERCEPT - SCHATTR_START] = new SfxBoolItem(SCHATTR_REGRESSION_SET_INTERCEPT, false);
ppPoolDefaults[SCHATTR_REGRESSION_INTERCEPT_VALUE - SCHATTR_START] = new SvxDoubleItem(0.0, SCHATTR_REGRESSION_INTERCEPT_VALUE); ppPoolDefaults[SCHATTR_REGRESSION_INTERCEPT_VALUE - SCHATTR_START] = new SvxDoubleItem(0.0, SCHATTR_REGRESSION_INTERCEPT_VALUE);
ppPoolDefaults[SCHATTR_REGRESSION_CURVE_NAME - SCHATTR_START] = new SfxStringItem(SCHATTR_REGRESSION_CURVE_NAME, OUString()); ppPoolDefaults[SCHATTR_REGRESSION_CURVE_NAME - SCHATTR_START] = new SfxStringItem(SCHATTR_REGRESSION_CURVE_NAME, OUString());
ppPoolDefaults[SCHATTR_REGRESSION_XNAME - SCHATTR_START] = new SfxStringItem(SCHATTR_REGRESSION_XNAME, OUString("x"));
ppPoolDefaults[SCHATTR_REGRESSION_YNAME - SCHATTR_START] = new SfxStringItem(SCHATTR_REGRESSION_YNAME, OUString("f(x)"));
/************************************************************************** /**************************************************************************
* ItemInfos * ItemInfos
......
...@@ -521,6 +521,64 @@ ...@@ -521,6 +521,64 @@
<property name="height">1</property> <property name="height">1</property>
</packing> </packing>
</child> </child>
<child>
<object class="GtkLabel" id="label6">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="xalign">0</property>
<property name="label" translatable="yes">X Variable Name</property>
<property name="use_underline">True</property>
<property name="mnemonic_widget">entry_Xname</property>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">5</property>
<property name="width">1</property>
<property name="height">1</property>
</packing>
</child>
<child>
<object class="GtkEntry" id="entry_Xname">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="invisible_char"></property>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">5</property>
<property name="width">1</property>
<property name="height">1</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="label9">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="xalign">0</property>
<property name="label" translatable="yes">Y Variable Name</property>
<property name="use_underline">True</property>
<property name="mnemonic_widget">entry_Yname</property>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">6</property>
<property name="width">1</property>
<property name="height">1</property>
</packing>
</child>
<child>
<object class="GtkEntry" id="entry_Yname">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="invisible_char"></property>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">6</property>
<property name="width">1</property>
<property name="height">1</property>
</packing>
</child>
</object> </object>
</child> </child>
</object> </object>
......
...@@ -42,6 +42,8 @@ service RegressionCurveEquation ...@@ -42,6 +42,8 @@ service RegressionCurveEquation
service ::com::sun::star::style::CharacterProperties; service ::com::sun::star::style::CharacterProperties;
[property] boolean ShowEquation; [property] boolean ShowEquation;
[property] string XName;
[property] string YName;
[property] boolean ShowCorrelationCoefficient; [property] boolean ShowCorrelationCoefficient;
[property, maybevoid] ::com::sun::star::chart2::RelativePosition RelativePosition; [property, maybevoid] ::com::sun::star::chart2::RelativePosition RelativePosition;
......
...@@ -162,6 +162,14 @@ interface XRegressionCurveCalculator : com::sun::star::uno::XInterface ...@@ -162,6 +162,14 @@ interface XRegressionCurveCalculator : com::sun::star::uno::XInterface
[in] long nNumberFormatKey, [in] long nNumberFormatKey,
[in] long nFormulaLength ); [in] long nFormulaLength );
/** Set the names of X and Y variables of the equation to replace "x" and "f(x)" in representation
@param aXName string of the name of X variable
@param aYName string of the name of Y variable
*/
void setXYNames( [in] string aXName,
[in] string aYName );
}; };
} ; // chart2 } ; // chart2
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment