summaryrefslogtreecommitdiffstats
path: root/chart2
diff options
context:
space:
mode:
authorLaurent Balland-Poirier <laurent.balland-poirier@laposte.net>2016-06-28 23:34:34 +0200
committerLaurent BP <laurent.balland-poirier@laposte.net>2016-08-16 20:54:54 +0000
commit428711f03c31802e339e57384b9f925a0e4dcc12 (patch)
treea7c5d08b20a56890943df67bd82e12021aaee4ee /chart2
parentGSoC - fix build of fasttokenhandler (diff)
downloadcore-428711f03c31802e339e57384b9f925a0e4dcc12.tar.gz
core-428711f03c31802e339e57384b9f925a0e4dcc12.zip
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/27069 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Laurent BP <laurent.balland-poirier@laposte.net>
Diffstat (limited to 'chart2')
-rw-r--r--chart2/source/controller/dialogs/ObjectNameProvider.cxx10
-rw-r--r--chart2/source/controller/dialogs/res_Trendline.cxx42
-rw-r--r--chart2/source/controller/dialogs/res_Trendline.hxx23
-rw-r--r--chart2/source/controller/itemsetwrapper/RegressionCurveItemConverter.cxx26
-rw-r--r--chart2/source/controller/itemsetwrapper/StatisticsItemConverter.cxx28
-rw-r--r--chart2/source/controller/main/ChartController_Insert.cxx2
-rw-r--r--chart2/source/controller/main/ChartController_Tools.cxx2
-rw-r--r--chart2/source/inc/RegressionCurveCalculator.hxx5
-rw-r--r--chart2/source/inc/chartview/ChartSfxItemIds.hxx4
-rw-r--r--chart2/source/tools/ExponentialRegressionCurveCalculator.cxx6
-rw-r--r--chart2/source/tools/LogarithmicRegressionCurveCalculator.cxx8
-rw-r--r--chart2/source/tools/MeanValueRegressionCurveCalculator.cxx2
-rw-r--r--chart2/source/tools/PolynomialRegressionCurveCalculator.cxx8
-rw-r--r--chart2/source/tools/PotentialRegressionCurveCalculator.cxx6
-rw-r--r--chart2/source/tools/RegressionCurveCalculator.cxx16
-rw-r--r--chart2/source/tools/RegressionCurveHelper.cxx2
-rw-r--r--chart2/source/tools/RegressionEquation.cxx18
-rw-r--r--chart2/source/view/charttypes/VSeriesPlotter.cxx9
-rw-r--r--chart2/source/view/main/ChartItemPool.cxx2
-rw-r--r--chart2/uiconfig/ui/tp_Trendline.ui58
20 files changed, 250 insertions, 27 deletions
diff --git a/chart2/source/controller/dialogs/ObjectNameProvider.cxx b/chart2/source/controller/dialogs/ObjectNameProvider.cxx
index 3eccea94c068..6e112ae9fa5c 100644
--- a/chart2/source/controller/dialogs/ObjectNameProvider.cxx
+++ b/chart2/source/controller/dialogs/ObjectNameProvider.cxx
@@ -565,6 +565,7 @@ OUString ObjectNameProvider::getHelpText( const OUString& rObjectCID, const Refe
sal_Int32 aPeriod = 2;
bool bForceIntercept = false;
double aInterceptValue = 0.0;
+ OUString aXName ("x"), aYName ("f(x)");
const LocaleDataWrapper& rLocaleDataWrapper = Application::GetSettings().GetLocaleDataWrapper();
const OUString& aNumDecimalSep = rLocaleDataWrapper.getNumDecimalSep();
assert(aNumDecimalSep.getLength() > 0);
@@ -578,8 +579,17 @@ OUString ObjectNameProvider::getHelpText( const OUString& rObjectCID, const Refe
xProperties->getPropertyValue( "ForceIntercept") >>= bForceIntercept;
if (bForceIntercept)
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->setXYNames ( aXName, aYName );
RegressionCurveHelper::initializeCurveCalculator( xCalculator, xSeries, xChartModel );
// change text for Moving Average
diff --git a/chart2/source/controller/dialogs/res_Trendline.cxx b/chart2/source/controller/dialogs/res_Trendline.cxx
index 2ce1262110ff..dbd77e690548 100644
--- a/chart2/source/controller/dialogs/res_Trendline.cxx
+++ b/chart2/source/controller/dialogs/res_Trendline.cxx
@@ -60,6 +60,8 @@ TrendlineResources::TrendlineResources( vcl::Window * pParent, const SfxItemSet&
pTabPage->get(m_pCB_SetIntercept,"setIntercept");
pTabPage->get(m_pFmtFld_InterceptValue,"interceptValue");
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_pFI_Linear,"imageLinear");
pTabPage->get(m_pFI_Logarithmic,"imageLogarithmic");
@@ -82,6 +84,8 @@ TrendlineResources::TrendlineResources( vcl::Window * pParent, const SfxItemSet&
m_pNF_Period->SetModifyHdl( aLink2 );
m_pFmtFld_InterceptValue->SetModifyHdl( aLink2 );
+ m_pCB_ShowEquation->SetToggleHdl( LINK(this, TrendlineResources, ShowEquation ) );
+
Reset( rInAttrs );
UpdateControlStates();
}
@@ -121,6 +125,24 @@ void TrendlineResources::Reset( const SfxItemSet& rInAttrs )
{
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 );
m_bTrendLineUnique = ( aState != SfxItemState::DONTCARE );
@@ -254,6 +276,14 @@ bool TrendlineResources::FillItemSet(SfxItemSet* rOutAttrs) const
OUString aName = m_pEE_Name->GetText();
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();
rOutAttrs->Put(SfxInt32Item( SCHATTR_REGRESSION_DEGREE, aDegree ) );
@@ -314,6 +344,8 @@ void TrendlineResources::UpdateControlStates()
}
m_pCB_ShowEquation->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)
@@ -356,6 +388,16 @@ void TrendlineResources::SetNbPoints( sal_Int32 nNbPoints )
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
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/chart2/source/controller/dialogs/res_Trendline.hxx b/chart2/source/controller/dialogs/res_Trendline.hxx
index 9fe50e672023..69ca98e2e4ab 100644
--- a/chart2/source/controller/dialogs/res_Trendline.hxx
+++ b/chart2/source/controller/dialogs/res_Trendline.hxx
@@ -60,15 +60,17 @@ private:
VclPtr<FixedImage> m_pFI_Polynomial;
VclPtr<FixedImage> m_pFI_MovingAverage;
- VclPtr<NumericField> m_pNF_Degree;
- VclPtr<NumericField> m_pNF_Period;
- VclPtr<Edit> m_pEE_Name;
- VclPtr<FormattedField> m_pFmtFld_ExtrapolateForward;
- VclPtr<FormattedField> m_pFmtFld_ExtrapolateBackward;
- VclPtr<CheckBox> m_pCB_SetIntercept;
- VclPtr<FormattedField> m_pFmtFld_InterceptValue;
- VclPtr<CheckBox> m_pCB_ShowEquation;
- VclPtr<CheckBox> m_pCB_ShowCorrelationCoeff;
+ VclPtr<NumericField> m_pNF_Degree;
+ VclPtr<NumericField> m_pNF_Period;
+ VclPtr<Edit> m_pEE_Name;
+ VclPtr<FormattedField> m_pFmtFld_ExtrapolateForward;
+ VclPtr<FormattedField> m_pFmtFld_ExtrapolateBackward;
+ VclPtr<CheckBox> m_pCB_SetIntercept;
+ VclPtr<FormattedField> m_pFmtFld_InterceptValue;
+ VclPtr<CheckBox> m_pCB_ShowEquation;
+ VclPtr<Edit> m_pEE_XName;
+ VclPtr<Edit> m_pEE_YName;
+ VclPtr<CheckBox> m_pCB_ShowCorrelationCoeff;
SvxChartRegress m_eTrendLineType;
@@ -78,8 +80,9 @@ private:
sal_Int32 m_nNbPoints;
void UpdateControlStates();
- DECL_LINK_TYPED( SelectTrendLine, Button *, void );
+ DECL_LINK_TYPED( SelectTrendLine, Button*, void );
DECL_LINK_TYPED( ChangeValue, Edit&, void);
+ DECL_LINK_TYPED( ShowEquation, CheckBox&, void);
};
} // namespace chart
diff --git a/chart2/source/controller/itemsetwrapper/RegressionCurveItemConverter.cxx b/chart2/source/controller/itemsetwrapper/RegressionCurveItemConverter.cxx
index 0e66927751a4..e4ac94260d0b 100644
--- a/chart2/source/controller/itemsetwrapper/RegressionCurveItemConverter.cxx
+++ b/chart2/source/controller/itemsetwrapper/RegressionCurveItemConverter.cxx
@@ -230,6 +230,20 @@ bool RegressionCurveItemConverter::ApplySpecialItem(
}
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:
{
uno::Reference< beans::XPropertySet > xEqProp( xCurve->getEquationProperties());
@@ -308,6 +322,18 @@ void RegressionCurveItemConverter::FillSpecialItem(sal_uInt16 nWhichId, SfxItemS
}
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:
{
lclConvertToItemSet<bool, SfxBoolItem>(rOutItemSet, nWhichId, xCurve->getEquationProperties(), "ShowCorrelationCoefficient");
diff --git a/chart2/source/controller/itemsetwrapper/StatisticsItemConverter.cxx b/chart2/source/controller/itemsetwrapper/StatisticsItemConverter.cxx
index 9e1f0cc21d1c..b99d19afa9bd 100644
--- a/chart2/source/controller/itemsetwrapper/StatisticsItemConverter.cxx
+++ b/chart2/source/controller/itemsetwrapper/StatisticsItemConverter.cxx
@@ -507,6 +507,20 @@ bool StatisticsItemConverter::ApplySpecialItem(
}
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:
{
uno::Reference< beans::XPropertySet > xEqProp( lcl_getEquationProperties( GetPropertySet(), &rItemSet ));
@@ -776,6 +790,20 @@ void StatisticsItemConverter::FillSpecialItem(
}
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:
{
uno::Reference< beans::XPropertySet > xEqProp( lcl_getEquationProperties( GetPropertySet(), nullptr ));
diff --git a/chart2/source/controller/main/ChartController_Insert.cxx b/chart2/source/controller/main/ChartController_Insert.cxx
index fd0cda101014..38819c7596b1 100644
--- a/chart2/source/controller/main/ChartController_Insert.cxx
+++ b/chart2/source/controller/main/ChartController_Insert.cxx
@@ -536,6 +536,8 @@ void ChartController::executeDispatch_InsertTrendlineEquation( bool bInsertR2 )
ActionDescriptionProvider::INSERT, SCH_RESSTR( STR_OBJECT_CURVE_EQUATION )),
m_xUndoManager );
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 ));
aUndoGuard.commit();
}
diff --git a/chart2/source/controller/main/ChartController_Tools.cxx b/chart2/source/controller/main/ChartController_Tools.cxx
index 3cc97afd6c9d..8eb20b561889 100644
--- a/chart2/source/controller/main/ChartController_Tools.cxx
+++ b/chart2/source/controller/main/ChartController_Tools.cxx
@@ -709,6 +709,8 @@ bool ChartController::executeDispatch_Delete()
{
ControllerLockGuardUNO aCtlLockGuard( xModel );
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 ));
}
bReturn = true;
diff --git a/chart2/source/inc/RegressionCurveCalculator.hxx b/chart2/source/inc/RegressionCurveCalculator.hxx
index 4f8e2604f87f..422c39b3ed55 100644
--- a/chart2/source/inc/RegressionCurveCalculator.hxx
+++ b/chart2/source/inc/RegressionCurveCalculator.hxx
@@ -60,6 +60,7 @@ protected:
bool mForceIntercept;
double mInterceptValue;
sal_Int32 mPeriod;
+ OUString mXName, mYName;
// ____ XRegressionCurveCalculator ____
virtual void SAL_CALL setRegressionProperties(
@@ -98,6 +99,10 @@ protected:
const css::uno::Reference< css::util::XNumberFormatsSupplier >& xNumFmtSupplier,
sal_Int32 nNumberFormatKey, sal_Int32 nFormulaLength )
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
diff --git a/chart2/source/inc/chartview/ChartSfxItemIds.hxx b/chart2/source/inc/chartview/ChartSfxItemIds.hxx
index 3bce731ebdce..d2b873cf80a0 100644
--- a/chart2/source/inc/chartview/ChartSfxItemIds.hxx
+++ b/chart2/source/inc/chartview/ChartSfxItemIds.hxx
@@ -169,7 +169,9 @@
#define SCHATTR_REGRESSION_SET_INTERCEPT (SCHATTR_REGRESSION_START + 7)
#define SCHATTR_REGRESSION_INTERCEPT_VALUE (SCHATTR_REGRESSION_START + 8)
#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
diff --git a/chart2/source/tools/ExponentialRegressionCurveCalculator.cxx b/chart2/source/tools/ExponentialRegressionCurveCalculator.cxx
index f6a75716eb80..9d3f105d9b54 100644
--- a/chart2/source/tools/ExponentialRegressionCurveCalculator.cxx
+++ b/chart2/source/tools/ExponentialRegressionCurveCalculator.cxx
@@ -162,12 +162,12 @@ OUString ExponentialRegressionCurveCalculator::ImplGetRepresentation(
bool bHasLogSlope = !rtl::math::approxEqual( fabs(m_fLogSlope), 1.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 nValueLength=0;
if ( pFormulaMaxWidth && *pFormulaMaxWidth > 0 )
{ // 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 )
nCharMin += 2;
if ( fIntercept == 0.0 || ( !bHasSlope && m_fLogIntercept != 0.0 ) )
@@ -219,7 +219,7 @@ OUString ExponentialRegressionCurveCalculator::ImplGetRepresentation(
aTmpBuf.append( aValueString + " " );
}
}
- aTmpBuf.append( "x )");
+ aTmpBuf.append( mXName + " )");
addStringToEquation( aBuf, nLineLength, aTmpBuf, pFormulaMaxWidth );
return aBuf.makeStringAndClear();
diff --git a/chart2/source/tools/LogarithmicRegressionCurveCalculator.cxx b/chart2/source/tools/LogarithmicRegressionCurveCalculator.cxx
index 97f0b8524637..b3d5e8f018af 100644
--- a/chart2/source/tools/LogarithmicRegressionCurveCalculator.cxx
+++ b/chart2/source/tools/LogarithmicRegressionCurveCalculator.cxx
@@ -134,12 +134,12 @@ OUString LogarithmicRegressionCurveCalculator::ImplGetRepresentation(
sal_Int32 nNumberFormatKey, sal_Int32* pFormulaMaxWidth /* = nullptr */ ) const
{
bool bHasSlope = !rtl::math::approxEqual( fabs( m_fSlope ), 1.0 );
- OUStringBuffer aBuf( "f(x) = " );
+ OUStringBuffer aBuf( mYName + " = " );
sal_Int32 nLineLength = aBuf.getLength();
sal_Int32 nValueLength=0;
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 )
nCharMin += 2; // "- "
if( m_fSlope != 0.0 && m_fIntercept != 0.0 )
@@ -172,7 +172,7 @@ OUString LogarithmicRegressionCurveCalculator::ImplGetRepresentation(
aTmpBuf.append( aValueString + " " );
}
}
- aTmpBuf.append( "ln(x) " );
+ aTmpBuf.append( "ln(" + mXName + ") " );
addStringToEquation( aBuf, nLineLength, aTmpBuf, pFormulaMaxWidth );
aTmpBuf.truncate();
@@ -189,7 +189,7 @@ OUString LogarithmicRegressionCurveCalculator::ImplGetRepresentation(
addStringToEquation( aBuf, nLineLength, aTmpBuf, pFormulaMaxWidth );
}
- if ( aBuf.toString() == "f(x) = " )
+ if ( aBuf.toString().equals( OUString(mYName + " = ") ) )
aBuf.append( "0" );
return aBuf.makeStringAndClear();
diff --git a/chart2/source/tools/MeanValueRegressionCurveCalculator.cxx b/chart2/source/tools/MeanValueRegressionCurveCalculator.cxx
index 4703fe4f8af2..3835a46ccbef 100644
--- a/chart2/source/tools/MeanValueRegressionCurveCalculator.cxx
+++ b/chart2/source/tools/MeanValueRegressionCurveCalculator.cxx
@@ -121,7 +121,7 @@ OUString MeanValueRegressionCurveCalculator::ImplGetRepresentation(
const uno::Reference< util::XNumberFormatter >& xNumFormatter,
sal_Int32 nNumberFormatKey, sal_Int32* pFormulaLength /* = nullptr */ ) const
{
- OUString aBuf = "f(x) = ";
+ OUString aBuf = OUString(mYName + " = ");
if ( pFormulaLength )
{
*pFormulaLength -= aBuf.getLength();
diff --git a/chart2/source/tools/PolynomialRegressionCurveCalculator.cxx b/chart2/source/tools/PolynomialRegressionCurveCalculator.cxx
index 2134b4fb6b75..c4976a54efa7 100644
--- a/chart2/source/tools/PolynomialRegressionCurveCalculator.cxx
+++ b/chart2/source/tools/PolynomialRegressionCurveCalculator.cxx
@@ -225,7 +225,7 @@ OUString PolynomialRegressionCurveCalculator::ImplGetRepresentation(
const uno::Reference< util::XNumberFormatter >& xNumFormatter,
sal_Int32 nNumberFormatKey, sal_Int32* pFormulaMaxWidth /* = nullptr */ ) const
{
- OUStringBuffer aBuf( "f(x) = " );
+ OUStringBuffer aBuf( mYName + " = " );
sal_Int32 nValueLength=0;
sal_Int32 aLastIndex = mCoefficients.size() - 1;
@@ -252,7 +252,7 @@ OUString PolynomialRegressionCurveCalculator::ImplGetRepresentation(
nCharMin += 3; // " + "
if ( i > 0 )
{
- nCharMin += 1; // "x"
+ nCharMin += mXName.getLength(); // "x"
if ( i > 1 )
nCharMin +=1; // "^i"
if ( i >= 10 )
@@ -296,7 +296,7 @@ OUString PolynomialRegressionCurveCalculator::ImplGetRepresentation(
if(i > 0)
{
- aTmpBuf.append( "x" );
+ aTmpBuf.append( mXName );
if (i > 1)
{
if (i < 10) // simple case if only one digit
@@ -314,7 +314,7 @@ OUString PolynomialRegressionCurveCalculator::ImplGetRepresentation(
}
addStringToEquation( aBuf, nLineLength, aTmpBuf, pFormulaMaxWidth );
}
- if ( aBuf.toString() == "f(x) = " )
+ if ( aBuf.toString().equals( OUString( mYName + " = ") ) )
aBuf.append( "0" );
return aBuf.makeStringAndClear();
diff --git a/chart2/source/tools/PotentialRegressionCurveCalculator.cxx b/chart2/source/tools/PotentialRegressionCurveCalculator.cxx
index 3282f2dc1abc..aea4e68ad0ac 100644
--- a/chart2/source/tools/PotentialRegressionCurveCalculator.cxx
+++ b/chart2/source/tools/PotentialRegressionCurveCalculator.cxx
@@ -146,12 +146,12 @@ OUString PotentialRegressionCurveCalculator::ImplGetRepresentation(
sal_Int32 nNumberFormatKey, sal_Int32* pFormulaMaxWidth /* = nullptr */ ) const
{
bool bHasIntercept = !rtl::math::approxEqual( fabs(m_fIntercept), 1.0 );
- OUStringBuffer aBuf( "f(x) = ");
+ OUStringBuffer aBuf( mYName + " = " );
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
+ 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 )
@@ -187,7 +187,7 @@ OUString PotentialRegressionCurveCalculator::ImplGetRepresentation(
}
if( m_fSlope != 0.0 ) // add slope value
{
- aTmpBuf.append( "x^" );
+ aTmpBuf.append( mXName + "^" );
aTmpBuf.append( getFormattedString( xNumFormatter, nNumberFormatKey, m_fSlope, pValueLength ));
}
addStringToEquation( aBuf, nLineLength, aTmpBuf, pFormulaMaxWidth );
diff --git a/chart2/source/tools/RegressionCurveCalculator.cxx b/chart2/source/tools/RegressionCurveCalculator.cxx
index 09f03cc1d00c..429eeb002121 100644
--- a/chart2/source/tools/RegressionCurveCalculator.cxx
+++ b/chart2/source/tools/RegressionCurveCalculator.cxx
@@ -45,7 +45,8 @@ RegressionCurveCalculator::RegressionCurveCalculator() :
mDegree(2),
mForceIntercept(false),
mInterceptValue(0.0),
- mPeriod(2)
+ mPeriod(2),
+ mXName("x"), mYName("f(x)")
{
rtl::math::setNan( &m_fCorrelationCoeffitient );
rtl::math::setNan( &mInterceptValue );
@@ -211,6 +212,19 @@ void RegressionCurveCalculator::addStringToEquation(
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
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/chart2/source/tools/RegressionCurveHelper.cxx b/chart2/source/tools/RegressionCurveHelper.cxx
index 4681a7cfad61..4cc6d69dc427 100644
--- a/chart2/source/tools/RegressionCurveHelper.cxx
+++ b/chart2/source/tools/RegressionCurveHelper.cxx
@@ -456,6 +456,8 @@ void RegressionCurveHelper::removeEquations(
if( xEqProp.is())
{
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 ));
}
}
diff --git a/chart2/source/tools/RegressionEquation.cxx b/chart2/source/tools/RegressionEquation.cxx
index a544fe2a504b..692576f3c3b9 100644
--- a/chart2/source/tools/RegressionEquation.cxx
+++ b/chart2/source/tools/RegressionEquation.cxx
@@ -52,6 +52,8 @@ static const char lcl_aServiceName[] = "com.sun.star.chart2.RegressionEquation"
enum
{
PROP_EQUATION_SHOW,
+ PROP_EQUATION_XNAME,
+ PROP_EQUATION_YNAME,
PROP_EQUATION_SHOW_CORRELATION_COEFF,
PROP_EQUATION_REF_PAGE_SIZE,
PROP_EQUATION_REL_POS,
@@ -69,6 +71,20 @@ void lcl_AddPropertiesToVector(
| 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(
Property( "ShowCorrelationCoefficient",
PROP_EQUATION_SHOW_CORRELATION_COEFF,
cppu::UnoType<bool>::get(),
@@ -113,6 +129,8 @@ private:
::chart::CharacterProperties::AddDefaultsToMap( rOutMap );
::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_SEPARATOR, OUString( '\n' ));
diff --git a/chart2/source/view/charttypes/VSeriesPlotter.cxx b/chart2/source/view/charttypes/VSeriesPlotter.cxx
index eebc5969e2f2..7402bdf5b4ed 100644
--- a/chart2/source/view/charttypes/VSeriesPlotter.cxx
+++ b/chart2/source/view/charttypes/VSeriesPlotter.cxx
@@ -1251,6 +1251,15 @@ void VSeriesPlotter::createRegressionCurveEquationShapes(
xEquationProperties->getPropertyValue(CHART_UNONAME_NUMFMT) >>= nNumberFormatKey;
bool bResizeEquation = true;
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++ )
{
diff --git a/chart2/source/view/main/ChartItemPool.cxx b/chart2/source/view/main/ChartItemPool.cxx
index 1587ac704d7e..6e089e0726b2 100644
--- a/chart2/source/view/main/ChartItemPool.cxx
+++ b/chart2/source/view/main/ChartItemPool.cxx
@@ -158,6 +158,8 @@ ChartItemPool::ChartItemPool():
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_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
diff --git a/chart2/uiconfig/ui/tp_Trendline.ui b/chart2/uiconfig/ui/tp_Trendline.ui
index 7060c9931683..e2a05d7ba691 100644
--- a/chart2/uiconfig/ui/tp_Trendline.ui
+++ b/chart2/uiconfig/ui/tp_Trendline.ui
@@ -521,6 +521,64 @@
<property name="height">1</property>
</packing>
</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>
</child>
</object>