21#include <com/sun/star/chart/TimeUnit.hpp>
22#include <rtl/math.hxx>
30constexpr OUStringLiteral lcl_aServiceName_DateScaling =
u"com.sun.star.chart2.DateScaling";
31constexpr OUStringLiteral lcl_aServiceName_InverseDateScaling
32 =
u"com.sun.star.chart2.InverseDateScaling";
34const double lcl_fNumberOfMonths = 12.0;
41using ::com::sun::star::chart::TimeUnit::DAY;
42using ::com::sun::star::chart::TimeUnit::MONTH;
43using ::com::sun::star::chart::TimeUnit::YEAR;
46 : m_aNullDate( rNullDate )
47 , m_nTimeUnit( nTimeUnit )
48 , m_bShifted( bShifted )
58 double fResult(
value);
59 if( std::isnan(
value ) || std::isinf(
value ) )
60 return std::numeric_limits<double>::quiet_NaN();
75 fResult *= lcl_fNumberOfMonths;
78 double fDayOfMonth = aDate.
GetDay();
81 fResult += fDayOfMonth/fDaysInMonth;
85 fResult += 0.5*lcl_fNumberOfMonths;
102 return lcl_aServiceName_DateScaling;
107 return lcl_aServiceName_DateScaling;
117 return { lcl_aServiceName_DateScaling };
121 : m_aNullDate( rNullDate )
122 , m_nTimeUnit( nTimeUnit )
123 , m_bShifted( bShifted )
133 double fResult(
value);
134 if( std::isnan(
value ) || std::isinf(
value ) )
135 return std::numeric_limits<double>::quiet_NaN();
152 value -= 0.5*lcl_fNumberOfMonths;
157 double fYear = ::rtl::math::approxFloor(
value/lcl_fNumberOfMonths);
158 double fMonth = ::rtl::math::approxFloor(
value-(fYear*lcl_fNumberOfMonths));
164 aDate.
SetYear(
static_cast<sal_uInt16
>(fYear) );
165 aDate.
SetMonth(
static_cast<sal_uInt16
>(fMonth) );
167 double fMonthCount = (fYear*lcl_fNumberOfMonths)+fMonth;
170 aDate.
SetDay(
static_cast<sal_uInt16
>(::rtl::math::round(fDay)) );
185 return lcl_aServiceName_InverseDateScaling;
190 return lcl_aServiceName_InverseDateScaling;
200 return { lcl_aServiceName_InverseDateScaling };
void AddDays(sal_Int32 nAddDays)
sal_Int16 GetYear() const
sal_uInt16 GetDay() const
sal_uInt16 GetDaysInMonth() const
void SetMonth(sal_uInt16 nNewMonth)
void SetYear(sal_Int16 nNewYear)
void SetDay(sal_uInt16 nNewDay)
sal_uInt16 GetMonth() const
virtual css::uno::Reference< css::chart2::XScaling > SAL_CALL getInverseScaling() override
virtual double SAL_CALL doScaling(double value) override
virtual ~DateScaling() override
virtual OUString SAL_CALL getServiceName() override
DateScaling(const Date &rNullDate, sal_Int32 nTimeUnit, bool bShifted)
virtual sal_Bool SAL_CALL supportsService(const OUString &ServiceName) override
virtual OUString SAL_CALL getImplementationName() override
declare XServiceInfo methods
const sal_Int32 m_nTimeUnit
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
const sal_Int32 m_nTimeUnit
virtual ~InverseDateScaling() override
virtual OUString SAL_CALL getImplementationName() override
declare XServiceInfo methods
InverseDateScaling(const Date &rNullDate, sal_Int32 nTimeUnit, bool bShifted)
virtual double SAL_CALL doScaling(double value) override
virtual css::uno::Reference< css::chart2::XScaling > SAL_CALL getInverseScaling() override
virtual OUString SAL_CALL getServiceName() override
virtual sal_Bool SAL_CALL supportsService(const OUString &ServiceName) override
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)