1*cde9e8dcSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*cde9e8dcSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*cde9e8dcSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*cde9e8dcSAndrew Rist  * distributed with this work for additional information
6*cde9e8dcSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*cde9e8dcSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*cde9e8dcSAndrew Rist  * "License"); you may not use this file except in compliance
9*cde9e8dcSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*cde9e8dcSAndrew Rist  *
11*cde9e8dcSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*cde9e8dcSAndrew Rist  *
13*cde9e8dcSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*cde9e8dcSAndrew Rist  * software distributed under the License is distributed on an
15*cde9e8dcSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*cde9e8dcSAndrew Rist  * KIND, either express or implied.  See the License for the
17*cde9e8dcSAndrew Rist  * specific language governing permissions and limitations
18*cde9e8dcSAndrew Rist  * under the License.
19*cde9e8dcSAndrew Rist  *
20*cde9e8dcSAndrew Rist  *************************************************************/
21*cde9e8dcSAndrew Rist 
22*cde9e8dcSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_chart2.hxx"
26cdf0e10cSrcweir #include "StatisticsHelper.hxx"
27cdf0e10cSrcweir #include "DataSeriesHelper.hxx"
28cdf0e10cSrcweir #include "ErrorBar.hxx"
29cdf0e10cSrcweir #include "macros.hxx"
30cdf0e10cSrcweir 
31cdf0e10cSrcweir #include <rtl/math.hxx>
32cdf0e10cSrcweir #include <rtl/ustrbuf.hxx>
33cdf0e10cSrcweir #include <comphelper/processfactory.hxx>
34cdf0e10cSrcweir 
35cdf0e10cSrcweir #include <com/sun/star/lang/XMultiServiceFactory.hpp>
36cdf0e10cSrcweir #include <com/sun/star/chart2/data/XLabeledDataSequence.hpp>
37cdf0e10cSrcweir #include <com/sun/star/chart2/data/XNumericalDataSequence.hpp>
38cdf0e10cSrcweir #include <com/sun/star/chart2/data/XDataSink.hpp>
39cdf0e10cSrcweir #include <com/sun/star/chart/ErrorBarStyle.hpp>
40cdf0e10cSrcweir 
41cdf0e10cSrcweir using ::com::sun::star::uno::Sequence;
42cdf0e10cSrcweir using ::com::sun::star::uno::Reference;
43cdf0e10cSrcweir using ::rtl::OUString;
44cdf0e10cSrcweir using ::rtl::OUStringBuffer;
45cdf0e10cSrcweir using namespace ::com::sun::star;
46cdf0e10cSrcweir 
47cdf0e10cSrcweir namespace
48cdf0e10cSrcweir {
49cdf0e10cSrcweir 
lcl_getVariance(const Sequence<double> & rData,sal_Int32 & rOutValidCount,bool bUnbiasedEstimator)50cdf0e10cSrcweir double lcl_getVariance( const Sequence< double > & rData, sal_Int32 & rOutValidCount,
51cdf0e10cSrcweir         bool bUnbiasedEstimator )
52cdf0e10cSrcweir {
53cdf0e10cSrcweir     const sal_Int32 nCount = rData.getLength();
54cdf0e10cSrcweir     rOutValidCount = nCount;
55cdf0e10cSrcweir 
56cdf0e10cSrcweir     double fSum = 0.0;
57cdf0e10cSrcweir     double fQuadSum = 0.0;
58cdf0e10cSrcweir 
59cdf0e10cSrcweir     for( sal_Int32 i = 0; i < nCount; ++i )
60cdf0e10cSrcweir     {
61cdf0e10cSrcweir         const double fData = rData[i];
62cdf0e10cSrcweir         if( ::rtl::math::isNan( fData ))
63cdf0e10cSrcweir             --rOutValidCount;
64cdf0e10cSrcweir         else
65cdf0e10cSrcweir         {
66cdf0e10cSrcweir             fSum     += fData;
67cdf0e10cSrcweir             fQuadSum += fData * fData;
68cdf0e10cSrcweir         }
69cdf0e10cSrcweir     }
70cdf0e10cSrcweir 
71cdf0e10cSrcweir     double fResult;
72cdf0e10cSrcweir     if( rOutValidCount == 0 )
73cdf0e10cSrcweir         ::rtl::math::setNan( & fResult );
74cdf0e10cSrcweir     else
75cdf0e10cSrcweir     {
76cdf0e10cSrcweir         const double fN = static_cast< double >( rOutValidCount );
77cdf0e10cSrcweir         if( bUnbiasedEstimator )
78cdf0e10cSrcweir             fResult = (fQuadSum - fSum*fSum/fN) / (fN - 1);
79cdf0e10cSrcweir         else
80cdf0e10cSrcweir             fResult = (fQuadSum - fSum*fSum/fN) / fN;
81cdf0e10cSrcweir     }
82cdf0e10cSrcweir 
83cdf0e10cSrcweir     return fResult;
84cdf0e10cSrcweir }
85cdf0e10cSrcweir 
lcl_getErrorBarLabeledSequence(const Reference<chart2::data::XDataSource> & xDataSource,bool bPositiveValue,bool bYError,OUString & rOutRoleNameUsed)86cdf0e10cSrcweir Reference< chart2::data::XLabeledDataSequence > lcl_getErrorBarLabeledSequence(
87cdf0e10cSrcweir     const Reference< chart2::data::XDataSource > & xDataSource,
88cdf0e10cSrcweir     bool bPositiveValue, bool bYError,
89cdf0e10cSrcweir     OUString & rOutRoleNameUsed )
90cdf0e10cSrcweir {
91cdf0e10cSrcweir     OUStringBuffer aRole( C2U("error-bars-"));
92cdf0e10cSrcweir     if( bYError )
93cdf0e10cSrcweir         aRole.append( sal_Unicode( 'y' ));
94cdf0e10cSrcweir     else
95cdf0e10cSrcweir         aRole.append( sal_Unicode( 'x' ));
96cdf0e10cSrcweir 
97cdf0e10cSrcweir     OUString aPlainRole = aRole.makeStringAndClear();
98cdf0e10cSrcweir     aRole.append( aPlainRole );
99cdf0e10cSrcweir     aRole.append( sal_Unicode( '-' ));
100cdf0e10cSrcweir 
101cdf0e10cSrcweir     if( bPositiveValue )
102cdf0e10cSrcweir         aRole = aRole.appendAscii( "positive" );
103cdf0e10cSrcweir     else
104cdf0e10cSrcweir         aRole = aRole.appendAscii( "negative" );
105cdf0e10cSrcweir 
106cdf0e10cSrcweir     OUString aLongRole = aRole.makeStringAndClear();
107cdf0e10cSrcweir     Reference< chart2::data::XLabeledDataSequence > xLSeq(
108cdf0e10cSrcweir         ::chart::DataSeriesHelper::getDataSequenceByRole( xDataSource, aLongRole ));
109cdf0e10cSrcweir     // try role without "-negative" or "-positive" postfix
110cdf0e10cSrcweir     if( xLSeq.is())
111cdf0e10cSrcweir         rOutRoleNameUsed = aLongRole;
112cdf0e10cSrcweir     else
113cdf0e10cSrcweir     {
114cdf0e10cSrcweir         xLSeq.set( ::chart::DataSeriesHelper::getDataSequenceByRole( xDataSource, aPlainRole ));
115cdf0e10cSrcweir         if( xLSeq.is())
116cdf0e10cSrcweir             rOutRoleNameUsed = aPlainRole;
117cdf0e10cSrcweir         else
118cdf0e10cSrcweir             rOutRoleNameUsed = aLongRole;
119cdf0e10cSrcweir     }
120cdf0e10cSrcweir 
121cdf0e10cSrcweir     return xLSeq;
122cdf0e10cSrcweir }
123cdf0e10cSrcweir 
lcl_setRole(const Reference<chart2::data::XDataSequence> & xNewSequence,const OUString & rRole)124cdf0e10cSrcweir void lcl_setRole(
125cdf0e10cSrcweir     const Reference< chart2::data::XDataSequence > & xNewSequence,
126cdf0e10cSrcweir     const OUString & rRole )
127cdf0e10cSrcweir {
128cdf0e10cSrcweir     Reference< beans::XPropertySet > xSeqProp( xNewSequence, uno::UNO_QUERY );
129cdf0e10cSrcweir     if( xSeqProp.is())
130cdf0e10cSrcweir         xSeqProp->setPropertyValue( C2U("Role"), uno::makeAny( rRole ));
131cdf0e10cSrcweir }
132cdf0e10cSrcweir 
lcl_addSequenceToDataSource(const Reference<chart2::data::XDataSource> & xDataSource,const Reference<chart2::data::XDataSequence> & xNewSequence,const OUString & rRole)133cdf0e10cSrcweir void lcl_addSequenceToDataSource(
134cdf0e10cSrcweir     const Reference< chart2::data::XDataSource > & xDataSource,
135cdf0e10cSrcweir     const Reference< chart2::data::XDataSequence > & xNewSequence,
136cdf0e10cSrcweir     const OUString & rRole )
137cdf0e10cSrcweir {
138cdf0e10cSrcweir     Reference< chart2::data::XDataSink > xSink( xDataSource, uno::UNO_QUERY );
139cdf0e10cSrcweir     Reference< lang::XMultiServiceFactory > xFact( comphelper::getProcessServiceFactory(), uno::UNO_QUERY_THROW );
140cdf0e10cSrcweir     if( ! ( xFact.is() && xSink.is() ))
141cdf0e10cSrcweir         return;
142cdf0e10cSrcweir 
143cdf0e10cSrcweir     Reference< chart2::data::XLabeledDataSequence > xLSeq(
144cdf0e10cSrcweir         xFact->createInstance( C2U("com.sun.star.chart2.data.LabeledDataSequence")), uno::UNO_QUERY );
145cdf0e10cSrcweir     if( xLSeq.is())
146cdf0e10cSrcweir     {
147cdf0e10cSrcweir         lcl_setRole( xNewSequence, rRole );
148cdf0e10cSrcweir         xLSeq->setValues( xNewSequence );
149cdf0e10cSrcweir         Sequence< Reference< chart2::data::XLabeledDataSequence > > aSequences(
150cdf0e10cSrcweir             xDataSource->getDataSequences());
151cdf0e10cSrcweir         aSequences.realloc( aSequences.getLength() + 1 );
152cdf0e10cSrcweir         aSequences[ aSequences.getLength() - 1 ] = xLSeq;
153cdf0e10cSrcweir         xSink->setData( aSequences );
154cdf0e10cSrcweir     }
155cdf0e10cSrcweir }
156cdf0e10cSrcweir 
lcl_setXMLRangePropertyAtDataSequence(const Reference<chart2::data::XDataSequence> & xDataSequence,const OUString & rXMLRange)157cdf0e10cSrcweir void lcl_setXMLRangePropertyAtDataSequence(
158cdf0e10cSrcweir     const Reference< chart2::data::XDataSequence > & xDataSequence,
159cdf0e10cSrcweir     const OUString & rXMLRange )
160cdf0e10cSrcweir {
161cdf0e10cSrcweir     try
162cdf0e10cSrcweir     {
163cdf0e10cSrcweir         const OUString aXMLRangePropName( C2U( "CachedXMLRange" ));
164cdf0e10cSrcweir         Reference< beans::XPropertySet > xProp( xDataSequence, uno::UNO_QUERY_THROW );
165cdf0e10cSrcweir         Reference< beans::XPropertySetInfo > xInfo( xProp->getPropertySetInfo());
166cdf0e10cSrcweir         if( xInfo.is() && xInfo->hasPropertyByName( aXMLRangePropName ))
167cdf0e10cSrcweir             xProp->setPropertyValue( aXMLRangePropName, uno::makeAny( rXMLRange ));
168cdf0e10cSrcweir     }
169cdf0e10cSrcweir     catch( const uno::Exception & ex )
170cdf0e10cSrcweir     {
171cdf0e10cSrcweir         ASSERT_EXCEPTION( ex );
172cdf0e10cSrcweir     }
173cdf0e10cSrcweir }
174cdf0e10cSrcweir 
175cdf0e10cSrcweir } // anonymous namespace
176cdf0e10cSrcweir 
177cdf0e10cSrcweir namespace chart
178cdf0e10cSrcweir {
179cdf0e10cSrcweir 
getVariance(const Sequence<double> & rData,bool bUnbiasedEstimator)180cdf0e10cSrcweir double StatisticsHelper::getVariance(
181cdf0e10cSrcweir     const Sequence< double > & rData,
182cdf0e10cSrcweir     bool bUnbiasedEstimator /* = false */ )
183cdf0e10cSrcweir {
184cdf0e10cSrcweir     sal_Int32 nValCount;
185cdf0e10cSrcweir     return lcl_getVariance( rData, nValCount, bUnbiasedEstimator );
186cdf0e10cSrcweir }
187cdf0e10cSrcweir 
getStandardDeviation(const Sequence<double> & rData)188cdf0e10cSrcweir double StatisticsHelper::getStandardDeviation( const Sequence< double > & rData )
189cdf0e10cSrcweir {
190cdf0e10cSrcweir     double fResult = getVariance( rData );
191cdf0e10cSrcweir     if( ! ::rtl::math::isNan( fResult ))
192cdf0e10cSrcweir         fResult = sqrt( fResult );
193cdf0e10cSrcweir 
194cdf0e10cSrcweir     return fResult;
195cdf0e10cSrcweir }
196cdf0e10cSrcweir 
getStandardError(const Sequence<double> & rData)197cdf0e10cSrcweir double StatisticsHelper::getStandardError( const Sequence< double > & rData )
198cdf0e10cSrcweir {
199cdf0e10cSrcweir     sal_Int32 nValCount;
200cdf0e10cSrcweir     double fVar = lcl_getVariance( rData, nValCount, false );
201cdf0e10cSrcweir     double fResult;
202cdf0e10cSrcweir 
203cdf0e10cSrcweir     if( nValCount == 0 ||
204cdf0e10cSrcweir         ::rtl::math::isNan( fVar ))
205cdf0e10cSrcweir     {
206cdf0e10cSrcweir         ::rtl::math::setNan( & fResult );
207cdf0e10cSrcweir     }
208cdf0e10cSrcweir     else
209cdf0e10cSrcweir     {
210cdf0e10cSrcweir         // standard-deviation / sqrt(n)
211cdf0e10cSrcweir         fResult = sqrt( fVar ) / sqrt( double(nValCount) );
212cdf0e10cSrcweir     }
213cdf0e10cSrcweir 
214cdf0e10cSrcweir     return fResult;
215cdf0e10cSrcweir }
216cdf0e10cSrcweir 
getErrorLabeledDataSequenceFromDataSource(const Reference<chart2::data::XDataSource> & xDataSource,bool bPositiveValue,bool bYError)217cdf0e10cSrcweir Reference< chart2::data::XLabeledDataSequence > StatisticsHelper::getErrorLabeledDataSequenceFromDataSource(
218cdf0e10cSrcweir     const Reference< chart2::data::XDataSource > & xDataSource,
219cdf0e10cSrcweir     bool bPositiveValue,
220cdf0e10cSrcweir     bool bYError /* = true */ )
221cdf0e10cSrcweir {
222cdf0e10cSrcweir     Reference< chart2::data::XLabeledDataSequence > xResult;
223cdf0e10cSrcweir     if( !xDataSource.is())
224cdf0e10cSrcweir         return xResult;
225cdf0e10cSrcweir 
226cdf0e10cSrcweir     OUString aRole;
227cdf0e10cSrcweir     Reference< chart2::data::XLabeledDataSequence > xLSeq(
228cdf0e10cSrcweir         lcl_getErrorBarLabeledSequence( xDataSource, bPositiveValue, bYError, aRole ));
229cdf0e10cSrcweir     if( xLSeq.is())
230cdf0e10cSrcweir         xResult.set( xLSeq );
231cdf0e10cSrcweir 
232cdf0e10cSrcweir     return xResult;
233cdf0e10cSrcweir }
234cdf0e10cSrcweir 
getErrorDataSequenceFromDataSource(const Reference<chart2::data::XDataSource> & xDataSource,bool bPositiveValue,bool bYError)235cdf0e10cSrcweir Reference< chart2::data::XDataSequence > StatisticsHelper::getErrorDataSequenceFromDataSource(
236cdf0e10cSrcweir     const Reference< chart2::data::XDataSource > & xDataSource,
237cdf0e10cSrcweir     bool bPositiveValue,
238cdf0e10cSrcweir     bool bYError /* = true */ )
239cdf0e10cSrcweir {
240cdf0e10cSrcweir     Reference< chart2::data::XLabeledDataSequence > xLSeq(
241cdf0e10cSrcweir         StatisticsHelper::getErrorLabeledDataSequenceFromDataSource(
242cdf0e10cSrcweir             xDataSource, bPositiveValue,
243cdf0e10cSrcweir             bYError ));
244cdf0e10cSrcweir     if( !xLSeq.is())
245cdf0e10cSrcweir         return Reference< chart2::data::XDataSequence >();
246cdf0e10cSrcweir 
247cdf0e10cSrcweir     return xLSeq->getValues();
248cdf0e10cSrcweir }
249cdf0e10cSrcweir 
getErrorFromDataSource(const Reference<chart2::data::XDataSource> & xDataSource,sal_Int32 nIndex,bool bPositiveValue,bool bYError)250cdf0e10cSrcweir double StatisticsHelper::getErrorFromDataSource(
251cdf0e10cSrcweir     const Reference< chart2::data::XDataSource > & xDataSource,
252cdf0e10cSrcweir     sal_Int32 nIndex,
253cdf0e10cSrcweir     bool bPositiveValue,
254cdf0e10cSrcweir     bool bYError /* = true */ )
255cdf0e10cSrcweir {
256cdf0e10cSrcweir     double fResult = 0.0;
257cdf0e10cSrcweir     ::rtl::math::setNan( & fResult );
258cdf0e10cSrcweir 
259cdf0e10cSrcweir     Reference< chart2::data::XDataSequence > xValues(
260cdf0e10cSrcweir         StatisticsHelper::getErrorDataSequenceFromDataSource( xDataSource, bPositiveValue, bYError ));
261cdf0e10cSrcweir 
262cdf0e10cSrcweir     Reference< chart2::data::XNumericalDataSequence > xNumValues( xValues, uno::UNO_QUERY );
263cdf0e10cSrcweir     if( xNumValues.is())
264cdf0e10cSrcweir     {
265cdf0e10cSrcweir         Sequence< double > aData( xNumValues->getNumericalData());
266cdf0e10cSrcweir         if( nIndex < aData.getLength())
267cdf0e10cSrcweir             fResult = aData[nIndex];
268cdf0e10cSrcweir     }
269cdf0e10cSrcweir     else if( xValues.is())
270cdf0e10cSrcweir     {
271cdf0e10cSrcweir         Sequence< uno::Any > aData( xValues->getData());
272cdf0e10cSrcweir         if( nIndex < aData.getLength())
273cdf0e10cSrcweir             aData[nIndex] >>= fResult;
274cdf0e10cSrcweir     }
275cdf0e10cSrcweir 
276cdf0e10cSrcweir     return fResult;
277cdf0e10cSrcweir }
278cdf0e10cSrcweir 
setErrorDataSequence(const Reference<chart2::data::XDataSource> & xDataSource,const Reference<chart2::data::XDataProvider> & xDataProvider,const OUString & rNewRange,bool bPositiveValue,bool bYError,OUString * pXMLRange)279cdf0e10cSrcweir void StatisticsHelper::setErrorDataSequence(
280cdf0e10cSrcweir     const Reference< chart2::data::XDataSource > & xDataSource,
281cdf0e10cSrcweir     const Reference< chart2::data::XDataProvider > & xDataProvider,
282cdf0e10cSrcweir     const OUString & rNewRange,
283cdf0e10cSrcweir     bool bPositiveValue,
284cdf0e10cSrcweir     bool bYError /* = true */,
285cdf0e10cSrcweir     OUString * pXMLRange /* = 0 */ )
286cdf0e10cSrcweir {
287cdf0e10cSrcweir     Reference< chart2::data::XDataSink > xDataSink( xDataSource, uno::UNO_QUERY );
288cdf0e10cSrcweir     if( ! ( xDataSink.is() && xDataProvider.is()))
289cdf0e10cSrcweir         return;
290cdf0e10cSrcweir 
291cdf0e10cSrcweir     OUString aRole;
292cdf0e10cSrcweir     Reference< chart2::data::XLabeledDataSequence > xLSeq(
293cdf0e10cSrcweir         lcl_getErrorBarLabeledSequence( xDataSource, bPositiveValue, bYError, aRole ));
294cdf0e10cSrcweir     Reference< chart2::data::XDataSequence > xNewSequence(
295cdf0e10cSrcweir         xDataProvider->createDataSequenceByRangeRepresentation( rNewRange ));
296cdf0e10cSrcweir     if( xNewSequence.is())
297cdf0e10cSrcweir     {
298cdf0e10cSrcweir         if( pXMLRange )
299cdf0e10cSrcweir             lcl_setXMLRangePropertyAtDataSequence( xNewSequence, *pXMLRange );
300cdf0e10cSrcweir         if( xLSeq.is())
301cdf0e10cSrcweir         {
302cdf0e10cSrcweir             lcl_setRole( xNewSequence, aRole );
303cdf0e10cSrcweir             xLSeq->setValues( xNewSequence );
304cdf0e10cSrcweir         }
305cdf0e10cSrcweir         else
306cdf0e10cSrcweir             lcl_addSequenceToDataSource( xDataSource, xNewSequence, aRole );
307cdf0e10cSrcweir     }
308cdf0e10cSrcweir }
309cdf0e10cSrcweir 
addErrorBars(const Reference<chart2::XDataSeries> & xDataSeries,const Reference<uno::XComponentContext> & xContext,sal_Int32 nStyle,bool bYError)310cdf0e10cSrcweir Reference< beans::XPropertySet > StatisticsHelper::addErrorBars(
311cdf0e10cSrcweir     const Reference< chart2::XDataSeries > & xDataSeries,
312cdf0e10cSrcweir     const Reference< uno::XComponentContext > & xContext,
313cdf0e10cSrcweir     sal_Int32 nStyle,
314cdf0e10cSrcweir     bool bYError /* = true */ )
315cdf0e10cSrcweir {
316cdf0e10cSrcweir     Reference< beans::XPropertySet > xErrorBar;
317cdf0e10cSrcweir     Reference< beans::XPropertySet > xSeriesProp( xDataSeries, uno::UNO_QUERY );
318cdf0e10cSrcweir     if( !xSeriesProp.is())
319cdf0e10cSrcweir         return xErrorBar;
320cdf0e10cSrcweir 
321cdf0e10cSrcweir     const OUString aPropName( bYError ? C2U("ErrorBarY") : C2U("ErrorBarX"));
322cdf0e10cSrcweir     if( !( xSeriesProp->getPropertyValue( aPropName ) >>= xErrorBar ) ||
323cdf0e10cSrcweir         !xErrorBar.is())
324cdf0e10cSrcweir     {
325cdf0e10cSrcweir         xErrorBar.set( createErrorBar( xContext ));
326cdf0e10cSrcweir     }
327cdf0e10cSrcweir 
328cdf0e10cSrcweir     OSL_ASSERT( xErrorBar.is());
329cdf0e10cSrcweir     if( xErrorBar.is())
330cdf0e10cSrcweir     {
331cdf0e10cSrcweir         xErrorBar->setPropertyValue( C2U("ErrorBarStyle"), uno::makeAny( nStyle ));
332cdf0e10cSrcweir     }
333cdf0e10cSrcweir 
334cdf0e10cSrcweir     xSeriesProp->setPropertyValue( aPropName, uno::makeAny( xErrorBar ));
335cdf0e10cSrcweir 
336cdf0e10cSrcweir     return xErrorBar;
337cdf0e10cSrcweir }
338cdf0e10cSrcweir 
getErrorBars(const Reference<chart2::XDataSeries> & xDataSeries,bool bYError)339cdf0e10cSrcweir Reference< beans::XPropertySet > StatisticsHelper::getErrorBars(
340cdf0e10cSrcweir     const Reference< chart2::XDataSeries > & xDataSeries,
341cdf0e10cSrcweir     bool bYError /* = true */ )
342cdf0e10cSrcweir {
343cdf0e10cSrcweir     Reference< beans::XPropertySet > xSeriesProp( xDataSeries, uno::UNO_QUERY );
344cdf0e10cSrcweir     Reference< beans::XPropertySet > xErrorBar;
345cdf0e10cSrcweir     const OUString aPropName( bYError ? C2U("ErrorBarY") : C2U("ErrorBarX"));
346cdf0e10cSrcweir 
347cdf0e10cSrcweir     if ( xSeriesProp.is())
348cdf0e10cSrcweir         xSeriesProp->getPropertyValue( aPropName ) >>= xErrorBar;
349cdf0e10cSrcweir 
350cdf0e10cSrcweir     return xErrorBar;
351cdf0e10cSrcweir }
352cdf0e10cSrcweir 
hasErrorBars(const Reference<chart2::XDataSeries> & xDataSeries,bool bYError)353cdf0e10cSrcweir bool StatisticsHelper::hasErrorBars(
354cdf0e10cSrcweir     const Reference< chart2::XDataSeries > & xDataSeries,
355cdf0e10cSrcweir     bool bYError /* = true */ )
356cdf0e10cSrcweir {
357cdf0e10cSrcweir     Reference< beans::XPropertySet > xErrorBar( getErrorBars( xDataSeries, bYError ));
358cdf0e10cSrcweir     sal_Int32 nStyle = ::com::sun::star::chart::ErrorBarStyle::NONE;
359cdf0e10cSrcweir 
360cdf0e10cSrcweir     return ( xErrorBar.is() &&
361cdf0e10cSrcweir              ( xErrorBar->getPropertyValue( C2U("ErrorBarStyle")) >>= nStyle ) &&
362cdf0e10cSrcweir              nStyle != ::com::sun::star::chart::ErrorBarStyle::NONE );
363cdf0e10cSrcweir }
364cdf0e10cSrcweir 
removeErrorBars(const Reference<chart2::XDataSeries> & xDataSeries,bool bYError)365cdf0e10cSrcweir void StatisticsHelper::removeErrorBars(
366cdf0e10cSrcweir     const Reference< chart2::XDataSeries > & xDataSeries,
367cdf0e10cSrcweir     bool bYError /* = true  */ )
368cdf0e10cSrcweir {
369cdf0e10cSrcweir     Reference< beans::XPropertySet > xErrorBar( getErrorBars( xDataSeries, bYError ));
370cdf0e10cSrcweir     if ( xErrorBar.is())
371cdf0e10cSrcweir         xErrorBar->setPropertyValue( C2U("ErrorBarStyle"), uno::makeAny(
372cdf0e10cSrcweir                                          ::com::sun::star::chart::ErrorBarStyle::NONE ));
373cdf0e10cSrcweir }
374cdf0e10cSrcweir 
usesErrorBarRanges(const Reference<chart2::XDataSeries> & xDataSeries,bool bYError)375cdf0e10cSrcweir bool StatisticsHelper::usesErrorBarRanges(
376cdf0e10cSrcweir     const Reference< chart2::XDataSeries > & xDataSeries,
377cdf0e10cSrcweir     bool bYError /* = true */ )
378cdf0e10cSrcweir {
379cdf0e10cSrcweir     Reference< beans::XPropertySet > xErrorBar( getErrorBars( xDataSeries, bYError ));
380cdf0e10cSrcweir     sal_Int32 nStyle = ::com::sun::star::chart::ErrorBarStyle::NONE;
381cdf0e10cSrcweir 
382cdf0e10cSrcweir     return ( xErrorBar.is() &&
383cdf0e10cSrcweir              ( xErrorBar->getPropertyValue( C2U("ErrorBarStyle")) >>= nStyle ) &&
384cdf0e10cSrcweir              nStyle == ::com::sun::star::chart::ErrorBarStyle::FROM_DATA );
385cdf0e10cSrcweir }
386cdf0e10cSrcweir 
387cdf0e10cSrcweir } //  namespace chart
388