25#include <com/sun/star/chart2/AxisType.hpp>
26#include <com/sun/star/chart2/XAxis.hpp>
27#include <com/sun/star/chart/ChartAxisType.hpp>
30#include <osl/diagnose.h>
33using ::com::sun::star::uno::Any;
35using ::com::sun::star::uno::Reference;
36using ::com::sun::star::uno::Sequence;
37using ::com::sun::star::chart::TimeIncrement;
43 , std::shared_ptr<Chart2ModelContact> spChart2ModelContact)
46 , m_eScaleProperty( eScaleProperty )
99 OSL_FAIL(
"unknown scale property");
109 ,
const std::shared_ptr< Chart2ModelContact >& spChart2ModelContact )
143 Reference< chart2::XAxis > xAxis( xInnerPropertySet, uno::UNO_QUERY );
144 OSL_ENSURE(xAxis.is(),
"need an XAxis");
148 bool bSetScaleData =
false;
150 chart2::ScaleData aScaleData( xAxis->getScaleData() );
153 switch( eScaleProperty )
157 aScaleData.Maximum = rOuterValue;
158 bSetScaleData =
true;
163 aScaleData.Minimum = rOuterValue;
164 bSetScaleData =
true;
169 aScaleData.IncrementData.Distance = rOuterValue;
170 bSetScaleData =
true;
175 Sequence< chart2::SubIncrement >& rSubIncrements( aScaleData.IncrementData.SubIncrements );
176 if( !rSubIncrements.hasElements() )
177 rSubIncrements.realloc( 1 );
178 auto pSubIncrements = rSubIncrements.getArray();
180 double fStepHelp = 0;
181 if( rOuterValue >>= fStepHelp )
183 double fStepMain = 0;
186 sal_Int32 nIntervalCount =
static_cast< sal_Int32
>(fStepHelp);
187 pSubIncrements[ 0 ].IntervalCount <<= nIntervalCount;
189 else if( (fStepHelp != 0.0) &&
190 (aScaleData.IncrementData.Distance >>= fStepMain) )
193 sal_Int32 nIntervalCount =
static_cast< sal_Int32
>(fStepMain / fStepHelp);
194 pSubIncrements[ 0 ].IntervalCount <<= nIntervalCount;
197 bSetScaleData =
true;
202 Sequence< chart2::SubIncrement >& rSubIncrements( aScaleData.IncrementData.SubIncrements );
203 if( !rSubIncrements.hasElements() )
204 rSubIncrements.realloc( 1 );
205 auto pSubIncrements = rSubIncrements.getArray();
206 sal_Int32 nIntervalCount=0;
207 if( rOuterValue>>=nIntervalCount )
208 pSubIncrements[ 0 ].IntervalCount <<= nIntervalCount;
210 pSubIncrements[ 0 ].IntervalCount =
Any();
211 bSetScaleData =
true;
216 if( (rOuterValue >>= bBool) && bBool )
217 aScaleData.Maximum =
Any();
220 bSetScaleData =
true;
225 if( (rOuterValue >>= bBool) && bBool )
226 aScaleData.Minimum =
Any();
229 bSetScaleData =
true;
234 if( (rOuterValue >>= bBool) && bBool )
235 aScaleData.IncrementData.Distance =
Any();
238 bSetScaleData =
true;
243 Sequence< chart2::SubIncrement >& rSubIncrements( aScaleData.IncrementData.SubIncrements );
244 if( !rSubIncrements.hasElements() )
245 rSubIncrements.realloc( 1 );
246 auto pSubIncrements = rSubIncrements.getArray();
248 if( (rOuterValue >>= bBool) && bBool )
249 pSubIncrements[ 0 ].IntervalCount =
Any();
252 bSetScaleData =
true;
257 aScaleData.Origin = rOuterValue;
258 bSetScaleData =
true;
263 if( (rOuterValue >>= bBool) && bBool )
264 aScaleData.Origin =
Any();
267 bSetScaleData =
true;
273 if( rOuterValue >>= nType )
275 if( nType == css::chart::ChartAxisType::AUTOMATIC )
277 aScaleData.AutoDateAxis =
true;
278 if( aScaleData.AxisType == AxisType::DATE )
279 aScaleData.AxisType = AxisType::CATEGORY;
281 else if( nType == css::chart::ChartAxisType::CATEGORY )
283 aScaleData.AutoDateAxis =
false;
284 if( aScaleData.AxisType == AxisType::DATE )
285 aScaleData.AxisType = AxisType::CATEGORY;
287 else if( nType == css::chart::ChartAxisType::DATE )
289 if( aScaleData.AxisType == AxisType::CATEGORY )
290 aScaleData.AxisType = AxisType::DATE;
292 bSetScaleData =
true;
298 TimeIncrement aTimeIncrement;
299 rOuterValue >>= aTimeIncrement;
300 aScaleData.TimeIncrement = aTimeIncrement;
301 bSetScaleData =
true;
309 if( rOuterValue >>= bBool )
314 if( (!bBool) != (!bWasLogarithm) )
319 aScaleData.Scaling =
nullptr;
320 bSetScaleData =
true;
327 if( rOuterValue >>= bBool )
329 bool bWasReverse = ( aScaleData.Orientation == AxisOrientation_REVERSE );
330 if( (!bBool) != (!bWasReverse) )
332 aScaleData.Orientation = bBool ? AxisOrientation_REVERSE : AxisOrientation_MATHEMATICAL;
333 bSetScaleData =
true;
340 OSL_FAIL(
"unknown scale property");
346 xAxis->setScaleData( aScaleData );
354 OSL_ENSURE(xAxis.is(),
"need an XAxis");
358 chart2::ScaleData aScaleData( xAxis->getScaleData() );
360 ExplicitScaleData aExplicitScale;
361 ExplicitIncrementData aExplicitIncrement;
363 switch( eScaleProperty )
367 aRet = aScaleData.Maximum;
368 if( !aRet.hasValue() )
371 xAxis, aExplicitScale, aExplicitIncrement );
372 aRet <<= aExplicitScale.Maximum;
378 aRet = aScaleData.Minimum;
379 if( !aRet.hasValue() )
382 xAxis, aExplicitScale, aExplicitIncrement );
383 aRet <<= aExplicitScale.Minimum;
390 aRet = aScaleData.IncrementData.Distance;
391 if( !aRet.hasValue() )
394 xAxis, aExplicitScale, aExplicitIncrement );
395 aRet <<= aExplicitIncrement.Distance;
402 bool bNeedToCalculateExplicitValues =
true;
405 Sequence< chart2::SubIncrement >& rSubIncrements( aScaleData.IncrementData.SubIncrements );
408 if( rSubIncrements.hasElements() )
410 sal_Int32 nIntervalCount = 0;
411 rSubIncrements[ 0 ].IntervalCount >>= nIntervalCount;
412 aRet <<= double(nIntervalCount);
413 bNeedToCalculateExplicitValues =
false;
416 else if( aScaleData.IncrementData.Distance.hasValue() )
418 if( rSubIncrements.hasElements() )
420 double fStepMain = 0;
421 sal_Int32 nIntervalCount = 0;
422 if( (aScaleData.IncrementData.Distance >>= fStepMain) &&
423 (rSubIncrements[ 0 ].IntervalCount >>= nIntervalCount) &&
426 aRet <<= fStepMain /
static_cast< double >( nIntervalCount );
427 bNeedToCalculateExplicitValues =
false;
432 aRet = aScaleData.IncrementData.Distance;
433 bNeedToCalculateExplicitValues =
false;
437 if( bNeedToCalculateExplicitValues )
440 xAxis, aExplicitScale, aExplicitIncrement );
442 if( !aExplicitIncrement.SubIncrements.empty() &&
443 aExplicitIncrement.SubIncrements[ 0 ].IntervalCount > 0 )
447 if( rSubIncrements.hasElements() )
449 sal_Int32 nIntervalCount = aExplicitIncrement.SubIncrements[ 0 ].IntervalCount;
450 aRet <<= double(nIntervalCount);
454 aRet <<= aExplicitIncrement.Distance /
455 static_cast< double >(
456 aExplicitIncrement.SubIncrements[ 0 ].IntervalCount );
463 aRet <<= aExplicitIncrement.Distance;
470 sal_Int32 nIntervalCount = 0;
471 bool bNeedToCalculateExplicitValues =
true;
472 Sequence< chart2::SubIncrement >& rSubIncrements( aScaleData.IncrementData.SubIncrements );
473 if( rSubIncrements.hasElements() )
475 if( (rSubIncrements[ 0 ].IntervalCount >>= nIntervalCount) && (nIntervalCount > 0) )
476 bNeedToCalculateExplicitValues =
false;
478 if( bNeedToCalculateExplicitValues )
481 if( !aExplicitIncrement.SubIncrements.empty() )
482 nIntervalCount = aExplicitIncrement.SubIncrements[ 0 ].IntervalCount;
484 aRet <<= nIntervalCount;
489 aRet <<= !aScaleData.Maximum.hasValue();
494 aRet <<= !aScaleData.Minimum.hasValue();
499 aRet <<= !aScaleData.IncrementData.Distance.hasValue();
504 Sequence< chart2::SubIncrement >& rSubIncrements( aScaleData.IncrementData.SubIncrements );
505 if( rSubIncrements.hasElements() )
506 aRet <<= !rSubIncrements[ 0 ].IntervalCount.hasValue();
513 aRet = aScaleData.Origin;
514 if( !aRet.hasValue() )
517 xAxis, aExplicitScale, aExplicitIncrement );
518 aRet <<= aExplicitScale.Origin;
529 sal_Int32
nType = css::chart::ChartAxisType::AUTOMATIC;
530 if( aScaleData.AxisType == AxisType::DATE )
532 nType = css::chart::ChartAxisType::DATE;
534 else if( aScaleData.AxisType == AxisType::CATEGORY )
536 if( !aScaleData.AutoDateAxis )
537 nType = css::chart::ChartAxisType::CATEGORY;
544 if( aScaleData.AxisType == AxisType::DATE || aScaleData.AutoDateAxis )
545 aRet <<= aScaleData.TimeIncrement;
550 if( aScaleData.AxisType == AxisType::DATE || aScaleData.AutoDateAxis )
553 if( aExplicitScale.AxisType == AxisType::DATE )
555 TimeIncrement aTimeIncrement;
556 aTimeIncrement.MajorTimeInterval <<= aExplicitIncrement.MajorTimeInterval;
557 aTimeIncrement.MinorTimeInterval <<= aExplicitIncrement.MinorTimeInterval;
558 aTimeIncrement.TimeResolution <<= aExplicitScale.TimeResolution;
559 aRet <<= aTimeIncrement;
562 aRet <<= aScaleData.TimeIncrement;
574 aRet <<= aScaleData.Orientation == AxisOrientation_REVERSE;
579 OSL_FAIL(
"unknown scale property");
std::shared_ptr< Chart2ModelContact > m_spChart2ModelContact
static bool isLogarithmic(const css::uno::Reference< css::chart2::XScaling > &xScaling)
static css::uno::Reference< css::chart2::XScaling > createLogarithmicScaling(double fBase=10.0)
std::shared_ptr< Chart2ModelContact > m_spChart2ModelContact
virtual ~WrappedScaleProperty() override
static void addWrappedProperties(std::vector< std::unique_ptr< WrappedProperty > > &rList, const std::shared_ptr< Chart2ModelContact > &spChart2ModelContact)
css::uno::Any m_aOuterValue
tScaleProperty m_eScaleProperty
virtual void setPropertyValue(const css::uno::Any &rOuterValue, const css::uno::Reference< css::beans::XPropertySet > &xInnerPropertySet) const override
@ SCALE_PROP_EXPLICIT_DATE_INCREMENT
@ SCALE_PROP_AUTO_STEPMAIN
@ SCALE_PROP_AUTO_STEPHELP
@ SCALE_PROP_DATE_INCREMENT
@ SCALE_PROP_STEPHELP_COUNT
@ SCALE_PROP_REVERSEDIRECTION
WrappedScaleProperty(tScaleProperty eScaleProperty, std::shared_ptr< Chart2ModelContact > spChart2ModelContact)
virtual css::uno::Any getPropertyValue(const css::uno::Reference< css::beans::XPropertySet > &xInnerPropertySet) const override
OOO_DLLPUBLIC_CHARTTOOLS bool hasDoubleValue(const css::uno::Any &rAny)