diff options
Diffstat (limited to 'chart2/source/view')
70 files changed, 3121 insertions, 1375 deletions
diff --git a/chart2/source/view/axes/DateHelper.cxx b/chart2/source/view/axes/DateHelper.cxx new file mode 100644 index 000000000000..45f958ab2898 --- /dev/null +++ b/chart2/source/view/axes/DateHelper.cxx @@ -0,0 +1,132 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_chart2.hxx" +#include "DateHelper.hxx" +#include "DateScaling.hxx" +#include <rtl/math.hxx> +#include <com/sun/star/chart/TimeUnit.hpp> + +//............................................................................. +namespace chart +{ +//............................................................................. +using namespace ::com::sun::star; + +bool DateHelper::IsInSameYear( const Date& rD1, const Date& rD2 ) +{ + return rD1.GetYear() == rD2.GetYear(); +} +bool DateHelper::IsInSameMonth( const Date& rD1, const Date& rD2 ) +{ + return (rD1.GetYear() == rD2.GetYear()) + && (rD1.GetMonth() == rD2.GetMonth()); +} +long DateHelper::GetMonthsBetweenDates( Date aD1, Date aD2 ) +{ + Date aHelp = aD1; + long nSign = 1; + if( aD1 < aD2 ) + { + aD1 = aD2; + aD2 = aHelp; + nSign = -1; + } + + return nSign*( ( aD1.GetMonth() - aD2.GetMonth() ) + + ( aD1.GetYear() - aD2.GetYear() )*12 ); +} + +Date DateHelper::GetDateSomeMonthsAway( const Date& rD, long nMonthDistance ) +{ + Date aRet(rD); + long nMonth = rD.GetMonth()+nMonthDistance; + long nNewMonth = nMonth%12; + long nNewYear = rD.GetYear() + nMonth/12; + if( nMonth <= 0 || !nNewMonth ) + nNewYear--; + if( nNewMonth <= 0 ) + nNewMonth += 12; + aRet.SetMonth( USHORT(nNewMonth) ); + aRet.SetYear( USHORT(nNewYear) ); + while(!aRet.IsValid()) + aRet--; + return aRet; +} + +Date DateHelper::GetDateSomeYearsAway( const Date& rD, long nYearDistance ) +{ + Date aRet(rD); + aRet.SetYear( static_cast<USHORT>(rD.GetYear()+nYearDistance) ); + while(!aRet.IsValid()) + aRet--; + return aRet; +} + +bool DateHelper::IsLessThanOneMonthAway( const Date& rD1, const Date& rD2 ) +{ + Date aDMin( DateHelper::GetDateSomeMonthsAway( rD1, -1 ) ); + Date aDMax( DateHelper::GetDateSomeMonthsAway( rD1, 1 ) ); + + if( rD2 > aDMin && rD2 < aDMax ) + return true; + return false; +} + +bool DateHelper::IsLessThanOneYearAway( const Date& rD1, const Date& rD2 ) +{ + Date aDMin( DateHelper::GetDateSomeYearsAway( rD1, -1 ) ); + Date aDMax( DateHelper::GetDateSomeYearsAway( rD1, 1 ) ); + + if( rD2 > aDMin && rD2 < aDMax ) + return true; + return false; +} + +double DateHelper::RasterizeDateValue( double fValue, const Date& rNullDate, long TimeResolution ) +{ + Date aDate(rNullDate); aDate += static_cast<long>(::rtl::math::approxFloor(fValue)); + switch(TimeResolution) + { + case ::com::sun::star::chart::TimeUnit::DAY: + break; + case ::com::sun::star::chart::TimeUnit::YEAR: + aDate.SetMonth(1); + aDate.SetDay(1); + break; + case ::com::sun::star::chart::TimeUnit::MONTH: + default: + aDate.SetDay(1); + break; + } + return aDate - rNullDate; +} + +//............................................................................. +} //namespace chart +//............................................................................. diff --git a/chart2/source/view/axes/DateScaling.cxx b/chart2/source/view/axes/DateScaling.cxx new file mode 100644 index 000000000000..6802fba67bd2 --- /dev/null +++ b/chart2/source/view/axes/DateScaling.cxx @@ -0,0 +1,216 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_chart2.hxx" +#include "DateScaling.hxx" +#include <com/sun/star/chart/TimeUnit.hpp> +#include <rtl/math.hxx> +#include "com/sun/star/uno/RuntimeException.hpp" + +namespace +{ + +static const ::rtl::OUString lcl_aServiceName_DateScaling( + RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.chart2.DateScaling" )); +static const ::rtl::OUString lcl_aServiceName_InverseDateScaling( + RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.chart2.InverseDateScaling" )); + +static const ::rtl::OUString lcl_aImplementationName_DateScaling( + RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.chart2.DateScaling" )); +static const ::rtl::OUString lcl_aImplementationName_InverseDateScaling( + RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.chart2.InverseDateScaling" )); + +static const double lcl_fNumberOfMonths = 12.0;//todo: this needs to be offered by basic tools Date class if it should be more generic +} + +//............................................................................. +namespace chart +{ +//............................................................................. +using namespace ::com::sun::star; +using namespace ::com::sun::star::chart2; +using ::com::sun::star::chart::TimeUnit::DAY; +using ::com::sun::star::chart::TimeUnit::MONTH; +using ::com::sun::star::chart::TimeUnit::YEAR; + +DateScaling::DateScaling( const Date& rNullDate, sal_Int32 nTimeUnit, bool bShifted ) + : m_aNullDate( rNullDate ) + , m_nTimeUnit( nTimeUnit ) + , m_bShifted( bShifted ) +{ +} + +DateScaling::~DateScaling() +{ +} + +double SAL_CALL DateScaling::doScaling( double value ) + throw (uno::RuntimeException) +{ + double fResult(value); + if( ::rtl::math::isNan( value ) || ::rtl::math::isInf( value ) ) + ::rtl::math::setNan( & fResult ); + else + { + Date aDate(m_aNullDate); + aDate += static_cast<long>(::rtl::math::approxFloor(value)); + switch( m_nTimeUnit ) + { + case DAY: + fResult = value; + if(m_bShifted) + fResult+=0.5; + break; + case YEAR: + case MONTH: + default: + fResult = aDate.GetYear(); + fResult *= lcl_fNumberOfMonths;//asssuming equal count of months in each year + fResult += aDate.GetMonth(); + + double fDayOfMonth = aDate.GetDay(); + fDayOfMonth -= 1.0; + double fDaysInMonth = aDate.GetDaysInMonth(); + fResult += fDayOfMonth/fDaysInMonth; + if(m_bShifted) + { + if( YEAR==m_nTimeUnit ) + fResult += 0.5*lcl_fNumberOfMonths; + else + fResult += 0.5; + } + break; + } + } + return fResult; +} + +uno::Reference< XScaling > SAL_CALL DateScaling::getInverseScaling() + throw (uno::RuntimeException) +{ + return new InverseDateScaling( m_aNullDate, m_nTimeUnit, m_bShifted ); +} + +::rtl::OUString SAL_CALL DateScaling::getServiceName() + throw (uno::RuntimeException) +{ + return lcl_aServiceName_DateScaling; +} + +uno::Sequence< ::rtl::OUString > DateScaling::getSupportedServiceNames_Static() +{ + return uno::Sequence< ::rtl::OUString >( & lcl_aServiceName_DateScaling, 1 ); +} + +// implement XServiceInfo methods basing upon getSupportedServiceNames_Static +APPHELPER_XSERVICEINFO_IMPL( DateScaling, lcl_aServiceName_DateScaling ) + +// ---------------------------------------- + +InverseDateScaling::InverseDateScaling( const Date& rNullDate, sal_Int32 nTimeUnit, bool bShifted ) + : m_aNullDate( rNullDate ) + , m_nTimeUnit( nTimeUnit ) + , m_bShifted( bShifted ) +{ +} + +InverseDateScaling::~InverseDateScaling() +{ +} + +double SAL_CALL InverseDateScaling::doScaling( double value ) + throw (uno::RuntimeException) +{ + double fResult(value); + if( ::rtl::math::isNan( value ) || ::rtl::math::isInf( value ) ) + ::rtl::math::setNan( & fResult ); + else + { + switch( m_nTimeUnit ) + { + case DAY: + if(m_bShifted) + value -= 0.5; + fResult = value; + break; + case YEAR: + case MONTH: + default: + //Date aDate(m_aNullDate); + if(m_bShifted) + { + if( YEAR==m_nTimeUnit ) + value -= 0.5*lcl_fNumberOfMonths; + else + value -= 0.5; + } + Date aDate; + double fYear = ::rtl::math::approxFloor(value/lcl_fNumberOfMonths); + double fMonth = ::rtl::math::approxFloor(value-(fYear*lcl_fNumberOfMonths)); + if( fMonth==0.0 ) + { + fYear--; + fMonth=12.0; + } + aDate.SetYear( static_cast<USHORT>(fYear) ); + aDate.SetMonth( static_cast<USHORT>(fMonth) ); + aDate.SetDay( 1 ); + double fMonthCount = (fYear*lcl_fNumberOfMonths)+fMonth; + double fDay = (value-fMonthCount)*aDate.GetDaysInMonth(); + fDay += 1.0; + aDate.SetDay( static_cast<USHORT>(::rtl::math::round(fDay)) ); + fResult = aDate - m_aNullDate; + break; + } + } + return fResult; +} + +uno::Reference< XScaling > SAL_CALL InverseDateScaling::getInverseScaling() + throw (uno::RuntimeException) +{ + return new DateScaling( m_aNullDate, m_nTimeUnit, m_bShifted ); +} + +::rtl::OUString SAL_CALL InverseDateScaling::getServiceName() + throw (uno::RuntimeException) +{ + return lcl_aServiceName_InverseDateScaling; +} + +uno::Sequence< ::rtl::OUString > InverseDateScaling::getSupportedServiceNames_Static() +{ + return uno::Sequence< ::rtl::OUString >( & lcl_aServiceName_InverseDateScaling, 1 ); +} + +// implement XServiceInfo methods basing upon getSupportedServiceNames_Static +APPHELPER_XSERVICEINFO_IMPL( InverseDateScaling, lcl_aServiceName_InverseDateScaling ) + +//............................................................................. +} //namespace chart +//............................................................................. diff --git a/chart2/source/view/axes/DateScaling.hxx b/chart2/source/view/axes/DateScaling.hxx new file mode 100644 index 000000000000..5e550604a957 --- /dev/null +++ b/chart2/source/view/axes/DateScaling.hxx @@ -0,0 +1,114 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef _CHART2_DATESCALING_HXX +#define _CHART2_DATESCALING_HXX +#include "ServiceMacros.hxx" +#include <com/sun/star/chart2/XScaling.hpp> +#include <com/sun/star/lang/XServiceInfo.hpp> +#include <com/sun/star/lang/XServiceName.hpp> +#include <com/sun/star/uno/XComponentContext.hpp> +#include <cppuhelper/implbase3.hxx> +#include <tools/date.hxx> + +//............................................................................. +namespace chart +{ +//............................................................................. + +//----------------------------------------------------------------------------- +/** +*/ + +class DateScaling : + public ::cppu::WeakImplHelper3 < + ::com::sun::star::chart2::XScaling, + ::com::sun::star::lang::XServiceName, + ::com::sun::star::lang::XServiceInfo + > +{ +public: + DateScaling( const Date& rNullDate, sal_Int32 nTimeUnit, bool bShifted ); + virtual ~DateScaling(); + + /// declare XServiceInfo methods + APPHELPER_XSERVICEINFO_DECL() + + // ____ XScaling ____ + virtual double SAL_CALL doScaling( double value ) + throw (::com::sun::star::uno::RuntimeException); + + virtual ::com::sun::star::uno::Reference< + ::com::sun::star::chart2::XScaling > SAL_CALL + getInverseScaling() throw (::com::sun::star::uno::RuntimeException); + + // ____ XServiceName ____ + virtual ::rtl::OUString SAL_CALL getServiceName() + throw (::com::sun::star::uno::RuntimeException); + +private: + const Date m_aNullDate; + const sal_Int32 m_nTimeUnit; + const bool m_bShifted; +}; + +class InverseDateScaling : + public ::cppu::WeakImplHelper3 < + ::com::sun::star::chart2::XScaling, + ::com::sun::star::lang::XServiceName, + ::com::sun::star::lang::XServiceInfo + > +{ +public: + InverseDateScaling( const Date& rNullDate, sal_Int32 nTimeUnit, bool bShifted ); + virtual ~InverseDateScaling(); + + /// declare XServiceInfo methods + APPHELPER_XSERVICEINFO_DECL() + + // ____ XScaling ____ + virtual double SAL_CALL doScaling( double value ) + throw (::com::sun::star::uno::RuntimeException); + + virtual ::com::sun::star::uno::Reference< + ::com::sun::star::chart2::XScaling > SAL_CALL + getInverseScaling() throw (::com::sun::star::uno::RuntimeException); + + // ____ XServiceName ____ + virtual ::rtl::OUString SAL_CALL getServiceName() + throw (::com::sun::star::uno::RuntimeException); + +private: + const Date m_aNullDate; + const sal_Int32 m_nTimeUnit; + const bool m_bShifted; +}; + +//............................................................................. +} //namespace chart +//............................................................................. +#endif + diff --git a/chart2/source/view/axes/MinimumAndMaximumSupplier.cxx b/chart2/source/view/axes/MinimumAndMaximumSupplier.cxx index 88f99b493144..97523d38758f 100644 --- a/chart2/source/view/axes/MinimumAndMaximumSupplier.cxx +++ b/chart2/source/view/axes/MinimumAndMaximumSupplier.cxx @@ -29,6 +29,9 @@ #include "precompiled_chart2.hxx" #include "MinimumAndMaximumSupplier.hxx" + +#include <com/sun/star/chart/TimeUnit.hpp> + #include <rtl/math.hxx> #include <com/sun/star/awt/Size.hpp> @@ -196,6 +199,24 @@ void MergedMinimumAndMaximumSupplier::clearMinimumAndMaximumSupplierList() m_aMinimumAndMaximumSupplierList.clear(); } +long MergedMinimumAndMaximumSupplier::calculateTimeResolutionOnXAxis() +{ + long nRet = ::com::sun::star::chart::TimeUnit::YEAR; + for( MinimumAndMaximumSupplierSet::iterator aIt = begin(), aEnd = end(); aIt != aEnd; ++aIt ) + { + long nCurrent = (*aIt)->calculateTimeResolutionOnXAxis(); + if(nRet>nCurrent) + nRet=nCurrent; + } + return nRet; +} + +void MergedMinimumAndMaximumSupplier::setTimeResolutionOnXAxis( long nTimeResolution, const Date& rNullDate ) +{ + for( MinimumAndMaximumSupplierSet::iterator aIt = begin(), aEnd = end(); aIt != aEnd; ++aIt ) + (*aIt)->setTimeResolutionOnXAxis( nTimeResolution, rNullDate ); +} + //............................................................................. } //namespace chart //............................................................................. diff --git a/chart2/source/view/axes/ScaleAutomatism.cxx b/chart2/source/view/axes/ScaleAutomatism.cxx index 890bf87df96e..075ad16347c2 100644 --- a/chart2/source/view/axes/ScaleAutomatism.cxx +++ b/chart2/source/view/axes/ScaleAutomatism.cxx @@ -29,8 +29,12 @@ #include "precompiled_chart2.hxx" #include "ScaleAutomatism.hxx" #include "macros.hxx" -#include "TickmarkHelper.hxx" +#include "Tickmarks_Equidistant.hxx" +#include "DateHelper.hxx" +#include "DateScaling.hxx" #include "AxisHelper.hxx" +#include <com/sun/star/chart/TimeUnit.hpp> + #include <rtl/math.hxx> #include <tools/debug.hxx> @@ -40,6 +44,9 @@ namespace chart //............................................................................. using namespace ::com::sun::star; using namespace ::com::sun::star::chart2; +using ::com::sun::star::chart::TimeUnit::DAY; +using ::com::sun::star::chart::TimeUnit::MONTH; +using ::com::sun::star::chart::TimeUnit::YEAR; const sal_Int32 MAXIMUM_MANUAL_INCREMENT_COUNT = 500; const sal_Int32 MAXIMUM_AUTO_INCREMENT_COUNT = 10; @@ -56,7 +63,42 @@ void lcl_ensureMaximumSubIncrementCount( sal_Int32& rnSubIntervalCount ) }//end anonymous namespace -ScaleAutomatism::ScaleAutomatism( const ScaleData& rSourceScale ) + +//............................................................................. + +ExplicitScaleData::ExplicitScaleData() + : Minimum(0.0) + , Maximum(10.0) + , Origin(0.0) + , Orientation(::com::sun::star::chart2::AxisOrientation_MATHEMATICAL) + , Scaling() + , AxisType(::com::sun::star::chart2::AxisType::REALNUMBER) + , ShiftedCategoryPosition(false) + , TimeResolution(::com::sun::star::chart::TimeUnit::DAY) + , NullDate(30,12,1899) +{ +} + +ExplicitSubIncrement::ExplicitSubIncrement() + : IntervalCount(2) + , PostEquidistant(true) +{ +} + + +ExplicitIncrementData::ExplicitIncrementData() + : MajorTimeInterval(1,::com::sun::star::chart::TimeUnit::DAY) + , MinorTimeInterval(1,::com::sun::star::chart::TimeUnit::DAY) + , Distance(1.0) + , PostEquidistant(true) + , BaseValue(0.0) + , SubIncrements() +{ +} + +//............................................................................. + +ScaleAutomatism::ScaleAutomatism( const ScaleData& rSourceScale, const Date& rNullDate ) : m_aSourceScale( rSourceScale ) , m_fValueMinimum( 0.0 ) , m_fValueMaximum( 0.0 ) @@ -65,6 +107,8 @@ ScaleAutomatism::ScaleAutomatism( const ScaleData& rSourceScale ) , m_bExpandIfValuesCloseToBorder( false ) , m_bExpandWideValuesToZero( false ) , m_bExpandNarrowValuesTowardZero( false ) + , m_nTimeResolution(::com::sun::star::chart::TimeUnit::DAY) + , m_aNullDate(rNullDate) { ::rtl::math::setNan( &m_fValueMinimum ); ::rtl::math::setNan( &m_fValueMaximum ); @@ -111,14 +155,19 @@ void ScaleAutomatism::setMaximumAutoMainIncrementCount( sal_Int32 nMaximumAutoMa m_nMaximumAutoMainIncrementCount = nMaximumAutoMainIncrementCount; } +void ScaleAutomatism::setAutomaticTimeResolution( sal_Int32 nTimeResolution ) +{ + m_nTimeResolution = nTimeResolution; +} + void ScaleAutomatism::calculateExplicitScaleAndIncrement( ExplicitScaleData& rExplicitScale, ExplicitIncrementData& rExplicitIncrement ) const { // fill explicit scale rExplicitScale.Orientation = m_aSourceScale.Orientation; rExplicitScale.Scaling = m_aSourceScale.Scaling; - rExplicitScale.Breaks = m_aSourceScale.Breaks; rExplicitScale.AxisType = m_aSourceScale.AxisType; + rExplicitScale.NullDate = m_aNullDate; bool bAutoMinimum = !(m_aSourceScale.Minimum >>= rExplicitScale.Minimum); bool bAutoMaximum = !(m_aSourceScale.Maximum >>= rExplicitScale.Maximum); @@ -130,7 +179,12 @@ void ScaleAutomatism::calculateExplicitScaleAndIncrement( if( m_aSourceScale.AxisType==AxisType::PERCENT ) rExplicitScale.Minimum = 0.0; else if( ::rtl::math::isNan( m_fValueMinimum ) ) - rExplicitScale.Minimum = 0.0; //@todo get Minimum from scaling or from plotter???? + { + if( m_aSourceScale.AxisType==AxisType::DATE ) + rExplicitScale.Minimum = 36526.0; //1.1.2000 + else + rExplicitScale.Minimum = 0.0; //@todo get Minimum from scaling or from plotter???? + } else rExplicitScale.Minimum = m_fValueMinimum; } @@ -141,7 +195,12 @@ void ScaleAutomatism::calculateExplicitScaleAndIncrement( if( m_aSourceScale.AxisType==AxisType::PERCENT ) rExplicitScale.Maximum = 1.0; else if( ::rtl::math::isNan( m_fValueMaximum ) ) - rExplicitScale.Maximum = 10.0; //@todo get Maximum from scaling or from plotter???? + { + if( m_aSourceScale.AxisType==AxisType::DATE ) + rExplicitScale.Maximum = 40179.0; //1.1.2010 + else + rExplicitScale.Maximum = 10.0; //@todo get Maximum from scaling or from plotter???? + } else rExplicitScale.Maximum = m_fValueMaximum; } @@ -149,14 +208,14 @@ void ScaleAutomatism::calculateExplicitScaleAndIncrement( //--------------------------------------------------------------- //fill explicit increment - rExplicitIncrement.ShiftedPosition = (m_aSourceScale.AxisType==AxisType::SERIES) ? true : false; + rExplicitScale.ShiftedCategoryPosition = m_aSourceScale.ShiftedCategoryPosition; bool bIsLogarithm = false; //minimum and maximum of the ExplicitScaleData may be changed if allowed - if( m_aSourceScale.AxisType==AxisType::CATEGORY || m_aSourceScale.AxisType==AxisType::SERIES ) - { + if( m_aSourceScale.AxisType==AxisType::DATE ) + calculateExplicitIncrementAndScaleForDateTimeAxis( rExplicitScale, rExplicitIncrement, bAutoMinimum, bAutoMaximum ); + else if( m_aSourceScale.AxisType==AxisType::CATEGORY || m_aSourceScale.AxisType==AxisType::SERIES ) calculateExplicitIncrementAndScaleForCategory( rExplicitScale, rExplicitIncrement, bAutoMinimum, bAutoMaximum ); - } else { bIsLogarithm = AxisHelper::isLogarithmic( rExplicitScale.Scaling ); @@ -186,6 +245,11 @@ ScaleData ScaleAutomatism::getScale() const return m_aSourceScale; } +Date ScaleAutomatism::getNullDate() const +{ + return m_aNullDate; +} + // private -------------------------------------------------------------------- void ScaleAutomatism::calculateExplicitIncrementAndScaleForCategory( @@ -196,6 +260,9 @@ void ScaleAutomatism::calculateExplicitIncrementAndScaleForCategory( // no scaling for categories rExplicitScale.Scaling.clear(); + if( rExplicitScale.ShiftedCategoryPosition ) + rExplicitScale.Maximum += 1.0; + // ensure that at least one category is visible if( rExplicitScale.Maximum <= rExplicitScale.Minimum ) rExplicitScale.Maximum = rExplicitScale.Minimum + 1.0; @@ -207,9 +274,9 @@ void ScaleAutomatism::calculateExplicitIncrementAndScaleForCategory( // automatic minimum and maximum if( bAutoMinimum && m_bExpandBorderToIncrementRhythm ) - rExplicitScale.Minimum = TickmarkHelper::getMinimumAtIncrement( rExplicitScale.Minimum, rExplicitIncrement ); + rExplicitScale.Minimum = EquidistantTickFactory::getMinimumAtIncrement( rExplicitScale.Minimum, rExplicitIncrement ); if( bAutoMaximum && m_bExpandBorderToIncrementRhythm ) - rExplicitScale.Maximum = TickmarkHelper::getMaximumAtIncrement( rExplicitScale.Maximum, rExplicitIncrement ); + rExplicitScale.Maximum = EquidistantTickFactory::getMaximumAtIncrement( rExplicitScale.Maximum, rExplicitIncrement ); //prevent performace killover double fDistanceCount = ::rtl::math::approxFloor( (rExplicitScale.Maximum-rExplicitScale.Minimum) / rExplicitIncrement.Distance ); @@ -223,29 +290,28 @@ void ScaleAutomatism::calculateExplicitIncrementAndScaleForCategory( //--------------------------------------------------------------- //fill explicit sub increment sal_Int32 nSubCount = m_aSourceScale.IncrementData.SubIncrements.getLength(); - rExplicitIncrement.SubIncrements.realloc(nSubCount); for( sal_Int32 nN=0; nN<nSubCount; nN++ ) { - const SubIncrement& rSubIncrement = m_aSourceScale.IncrementData.SubIncrements[nN]; - ExplicitSubIncrement& rExplicitSubIncrement = rExplicitIncrement.SubIncrements[nN]; - - if(!(rSubIncrement.IntervalCount>>=rExplicitSubIncrement.IntervalCount)) + ExplicitSubIncrement aExplicitSubIncrement; + const SubIncrement& rSubIncrement= m_aSourceScale.IncrementData.SubIncrements[nN]; + if(!(rSubIncrement.IntervalCount>>=aExplicitSubIncrement.IntervalCount)) { //scaling dependent //@todo autocalculate IntervalCount dependent on MainIncrement and scaling - rExplicitSubIncrement.IntervalCount = 2; + aExplicitSubIncrement.IntervalCount = 2; } - lcl_ensureMaximumSubIncrementCount( rExplicitSubIncrement.IntervalCount ); - if(!(rSubIncrement.PostEquidistant>>=rExplicitSubIncrement.PostEquidistant)) + lcl_ensureMaximumSubIncrementCount( aExplicitSubIncrement.IntervalCount ); + if(!(rSubIncrement.PostEquidistant>>=aExplicitSubIncrement.PostEquidistant)) { //scaling dependent - rExplicitSubIncrement.PostEquidistant = sal_False; + aExplicitSubIncrement.PostEquidistant = sal_False; } + rExplicitIncrement.SubIncrements.push_back(aExplicitSubIncrement); } } -//@todo these method should become part of the scaling interface and implementation somehow -//@todo problem with outparamters at api +//----------------------------------------------------------------------------------------- + void ScaleAutomatism::calculateExplicitIncrementAndScaleForLogarithmic( ExplicitScaleData& rExplicitScale, ExplicitIncrementData& rExplicitIncrement, @@ -412,7 +478,7 @@ void ScaleAutomatism::calculateExplicitIncrementAndScaleForLogarithmic( // round to entire multiples of the distance and add additional space if( bAutoMinimum && m_bExpandBorderToIncrementRhythm ) { - fAxisMinimum = TickmarkHelper::getMinimumAtIncrement( fAxisMinimum, rExplicitIncrement ); + fAxisMinimum = EquidistantTickFactory::getMinimumAtIncrement( fAxisMinimum, rExplicitIncrement ); //ensure valid values after scaling #i100995# if( !bAutoDistance ) @@ -428,7 +494,7 @@ void ScaleAutomatism::calculateExplicitIncrementAndScaleForLogarithmic( } if( bAutoMaximum && m_bExpandBorderToIncrementRhythm ) { - fAxisMaximum = TickmarkHelper::getMaximumAtIncrement( fAxisMaximum, rExplicitIncrement ); + fAxisMaximum = EquidistantTickFactory::getMaximumAtIncrement( fAxisMaximum, rExplicitIncrement ); //ensure valid values after scaling #i100995# if( !bAutoDistance ) @@ -488,27 +554,210 @@ void ScaleAutomatism::calculateExplicitIncrementAndScaleForLogarithmic( //--------------------------------------------------------------- //fill explicit sub increment sal_Int32 nSubCount = m_aSourceScale.IncrementData.SubIncrements.getLength(); - rExplicitIncrement.SubIncrements.realloc(nSubCount); for( sal_Int32 nN=0; nN<nSubCount; nN++ ) { - const SubIncrement& rSubIncrement = m_aSourceScale.IncrementData.SubIncrements[nN]; - ExplicitSubIncrement& rExplicitSubIncrement = rExplicitIncrement.SubIncrements[nN]; - - if(!(rSubIncrement.IntervalCount>>=rExplicitSubIncrement.IntervalCount)) + ExplicitSubIncrement aExplicitSubIncrement; + const SubIncrement& rSubIncrement = m_aSourceScale.IncrementData.SubIncrements[nN]; + if(!(rSubIncrement.IntervalCount>>=aExplicitSubIncrement.IntervalCount)) { //scaling dependent //@todo autocalculate IntervalCount dependent on MainIncrement and scaling - rExplicitSubIncrement.IntervalCount = 9; + aExplicitSubIncrement.IntervalCount = 9; } - lcl_ensureMaximumSubIncrementCount( rExplicitSubIncrement.IntervalCount ); - if(!(rSubIncrement.PostEquidistant>>=rExplicitSubIncrement.PostEquidistant)) + lcl_ensureMaximumSubIncrementCount( aExplicitSubIncrement.IntervalCount ); + if(!(rSubIncrement.PostEquidistant>>=aExplicitSubIncrement.PostEquidistant)) { //scaling dependent - rExplicitSubIncrement.PostEquidistant = sal_False; + aExplicitSubIncrement.PostEquidistant = sal_False; } + rExplicitIncrement.SubIncrements.push_back(aExplicitSubIncrement); } } +//----------------------------------------------------------------------------------------- + +void ScaleAutomatism::calculateExplicitIncrementAndScaleForDateTimeAxis( + ExplicitScaleData& rExplicitScale, + ExplicitIncrementData& rExplicitIncrement, + bool bAutoMinimum, bool bAutoMaximum ) const +{ + Date aMinDate(m_aNullDate); aMinDate += static_cast<long>(::rtl::math::approxFloor(rExplicitScale.Minimum)); + Date aMaxDate(m_aNullDate); aMaxDate += static_cast<long>(::rtl::math::approxFloor(rExplicitScale.Maximum)); + rExplicitIncrement.PostEquidistant = sal_False; + + if( aMinDate > aMaxDate ) + { + std::swap(aMinDate,aMaxDate); + } + + if( !(m_aSourceScale.TimeIncrement.TimeResolution >>= rExplicitScale.TimeResolution) ) + rExplicitScale.TimeResolution = m_nTimeResolution; + + rExplicitScale.Scaling = new DateScaling(m_aNullDate,rExplicitScale.TimeResolution,false); + + // choose min and max suitable to time resolution + switch( rExplicitScale.TimeResolution ) + { + case DAY: + if( rExplicitScale.ShiftedCategoryPosition ) + aMaxDate++;//for explicit scales we need one interval more (maximum excluded) + break; + case MONTH: + aMinDate.SetDay(1); + aMaxDate.SetDay(1); + if( rExplicitScale.ShiftedCategoryPosition ) + aMaxDate = DateHelper::GetDateSomeMonthsAway(aMaxDate,1);//for explicit scales we need one interval more (maximum excluded) + if( DateHelper::IsLessThanOneMonthAway( aMinDate, aMaxDate ) ) + { + if( bAutoMaximum || !bAutoMinimum ) + aMaxDate = DateHelper::GetDateSomeMonthsAway(aMinDate,1); + else + aMinDate = DateHelper::GetDateSomeMonthsAway(aMaxDate,-1); + } + break; + case YEAR: + aMinDate.SetDay(1); + aMinDate.SetMonth(1); + aMaxDate.SetDay(1); + aMaxDate.SetMonth(1); + if( rExplicitScale.ShiftedCategoryPosition ) + aMaxDate = DateHelper::GetDateSomeYearsAway(aMaxDate,1);//for explicit scales we need one interval more (maximum excluded) + if( DateHelper::IsLessThanOneYearAway( aMinDate, aMaxDate ) ) + { + if( bAutoMaximum || !bAutoMinimum ) + aMaxDate = DateHelper::GetDateSomeYearsAway(aMinDate,1); + else + aMinDate = DateHelper::GetDateSomeYearsAway(aMaxDate,-1); + } + break; + } + + // set the resulting limits (swap back to negative range if needed) + rExplicitScale.Minimum = aMinDate - m_aNullDate; + rExplicitScale.Maximum = aMaxDate - m_aNullDate; + + bool bAutoMajor = !(m_aSourceScale.TimeIncrement.MajorTimeInterval >>= rExplicitIncrement.MajorTimeInterval); + bool bAutoMinor = !(m_aSourceScale.TimeIncrement.MinorTimeInterval >>= rExplicitIncrement.MinorTimeInterval); + + sal_Int32 nMaxMainIncrementCount = bAutoMajor ? + m_nMaximumAutoMainIncrementCount : MAXIMUM_MANUAL_INCREMENT_COUNT; + if( nMaxMainIncrementCount > 1 ) + nMaxMainIncrementCount--; + + + //choose major time interval: + long nDayCount = (aMaxDate-aMinDate); + long nMainIncrementCount = 1; + if( !bAutoMajor ) + { + long nIntervalDayCount = rExplicitIncrement.MajorTimeInterval.Number; + if( rExplicitIncrement.MajorTimeInterval.TimeUnit < rExplicitScale.TimeResolution ) + rExplicitIncrement.MajorTimeInterval.TimeUnit = rExplicitScale.TimeResolution; + switch( rExplicitIncrement.MajorTimeInterval.TimeUnit ) + { + case DAY: + break; + case MONTH: + nIntervalDayCount*=31;//todo: maybe different for other calendars... get localized calendar according to set number format at axis ... + break; + case YEAR: + nIntervalDayCount*=365;//todo: maybe different for other calendars... get localized calendar according to set number format at axis ... + break; + } + nMainIncrementCount = nDayCount/nIntervalDayCount; + if( nMainIncrementCount > nMaxMainIncrementCount ) + bAutoMajor = true; + } + if( bAutoMajor ) + { + long nNumer = 1; + long nIntervalDays = nDayCount / nMaxMainIncrementCount; + double nDaysPerInterval = 1.0; + if( nIntervalDays>365 || YEAR==rExplicitScale.TimeResolution ) + { + rExplicitIncrement.MajorTimeInterval.TimeUnit = YEAR; + nDaysPerInterval = 365.0;//todo: maybe different for other calendars... get localized calendar according to set number format at axis ... + } + else if( nIntervalDays>31 || MONTH==rExplicitScale.TimeResolution ) + { + rExplicitIncrement.MajorTimeInterval.TimeUnit = MONTH; + nDaysPerInterval = 31.0;//todo: maybe different for other calendars... get localized calendar according to set number format at axis ... + } + else + { + rExplicitIncrement.MajorTimeInterval.TimeUnit = DAY; + nDaysPerInterval = 1.0; + } + + nNumer = static_cast<sal_Int32>( rtl::math::approxCeil( nIntervalDays/nDaysPerInterval ) ); + if(nNumer<=0) + nNumer=1; + rExplicitIncrement.MajorTimeInterval.Number = nNumer; + nMainIncrementCount = nDayCount/(nNumer*nDaysPerInterval); + } + + //choose minor time interval: + if( !bAutoMinor ) + { + if( rExplicitIncrement.MinorTimeInterval.TimeUnit > rExplicitIncrement.MajorTimeInterval.TimeUnit ) + rExplicitIncrement.MinorTimeInterval.TimeUnit = rExplicitIncrement.MajorTimeInterval.TimeUnit; + long nIntervalDayCount = rExplicitIncrement.MinorTimeInterval.Number; + switch( rExplicitIncrement.MinorTimeInterval.TimeUnit ) + { + case DAY: + break; + case MONTH: + nIntervalDayCount*=31;//todo: maybe different for other calendars... get localized calendar according to set number format at axis ... + break; + case YEAR: + nIntervalDayCount*=365;//todo: maybe different for other calendars... get localized calendar according to set number format at axis ... + break; + } + if( nDayCount/nIntervalDayCount > nMaxMainIncrementCount ) + bAutoMinor = true; + } + if( bAutoMinor ) + { + rExplicitIncrement.MinorTimeInterval.TimeUnit = rExplicitIncrement.MajorTimeInterval.TimeUnit; + rExplicitIncrement.MinorTimeInterval.Number = 1; + if( nMainIncrementCount > 100 ) + rExplicitIncrement.MinorTimeInterval.Number = rExplicitIncrement.MajorTimeInterval.Number; + else + { + if( rExplicitIncrement.MajorTimeInterval.Number >= 2 ) + { + if( !(rExplicitIncrement.MajorTimeInterval.Number%2) ) + rExplicitIncrement.MinorTimeInterval.Number = rExplicitIncrement.MajorTimeInterval.Number/2; + else if( !(rExplicitIncrement.MajorTimeInterval.Number%3) ) + rExplicitIncrement.MinorTimeInterval.Number = rExplicitIncrement.MajorTimeInterval.Number/3; + else if( !(rExplicitIncrement.MajorTimeInterval.Number%5) ) + rExplicitIncrement.MinorTimeInterval.Number = rExplicitIncrement.MajorTimeInterval.Number/5; + else if( rExplicitIncrement.MajorTimeInterval.Number > 50 ) + rExplicitIncrement.MinorTimeInterval.Number = rExplicitIncrement.MajorTimeInterval.Number; + } + else + { + switch( rExplicitIncrement.MajorTimeInterval.TimeUnit ) + { + case DAY: + break; + case MONTH: + if( rExplicitScale.TimeResolution == DAY ) + rExplicitIncrement.MinorTimeInterval.TimeUnit = DAY; + break; + case YEAR: + if( rExplicitScale.TimeResolution <= MONTH ) + rExplicitIncrement.MinorTimeInterval.TimeUnit = MONTH; + break; + } + } + } + } + +} + +//----------------------------------------------------------------------------------------- + void ScaleAutomatism::calculateExplicitIncrementAndScaleForLinear( ExplicitScaleData& rExplicitScale, ExplicitIncrementData& rExplicitIncrement, @@ -692,7 +941,7 @@ void ScaleAutomatism::calculateExplicitIncrementAndScaleForLinear( { // round to entire multiples of the distance, based on the base value if( m_bExpandBorderToIncrementRhythm ) - fAxisMinimum = TickmarkHelper::getMinimumAtIncrement( fAxisMinimum, rExplicitIncrement ); + fAxisMinimum = EquidistantTickFactory::getMinimumAtIncrement( fAxisMinimum, rExplicitIncrement ); // additional space, if source minimum is to near at axis minimum if( m_bExpandIfValuesCloseToBorder ) if( (fAxisMinimum != 0.0) && ((fAxisMaximum - fSourceMinimum) / (fAxisMaximum - fAxisMinimum) > 20.0 / 21.0) ) @@ -702,7 +951,7 @@ void ScaleAutomatism::calculateExplicitIncrementAndScaleForLinear( { // round to entire multiples of the distance, based on the base value if( m_bExpandBorderToIncrementRhythm ) - fAxisMaximum = TickmarkHelper::getMaximumAtIncrement( fAxisMaximum, rExplicitIncrement ); + fAxisMaximum = EquidistantTickFactory::getMaximumAtIncrement( fAxisMaximum, rExplicitIncrement ); // additional space, if source maximum is to near at axis maximum if( m_bExpandIfValuesCloseToBorder ) if( (fAxisMaximum != 0.0) && ((fSourceMaximum - fAxisMinimum) / (fAxisMaximum - fAxisMinimum) > 20.0 / 21.0) ) @@ -734,24 +983,23 @@ void ScaleAutomatism::calculateExplicitIncrementAndScaleForLinear( //--------------------------------------------------------------- //fill explicit sub increment sal_Int32 nSubCount = m_aSourceScale.IncrementData.SubIncrements.getLength(); - rExplicitIncrement.SubIncrements.realloc(nSubCount); for( sal_Int32 nN=0; nN<nSubCount; nN++ ) { - const SubIncrement& rSubIncrement = m_aSourceScale.IncrementData.SubIncrements[nN]; - ExplicitSubIncrement& rExplicitSubIncrement = rExplicitIncrement.SubIncrements[nN]; - - if(!(rSubIncrement.IntervalCount>>=rExplicitSubIncrement.IntervalCount)) + ExplicitSubIncrement aExplicitSubIncrement; + const SubIncrement& rSubIncrement= m_aSourceScale.IncrementData.SubIncrements[nN]; + if(!(rSubIncrement.IntervalCount>>=aExplicitSubIncrement.IntervalCount)) { //scaling dependent //@todo autocalculate IntervalCount dependent on MainIncrement and scaling - rExplicitSubIncrement.IntervalCount = 2; + aExplicitSubIncrement.IntervalCount = 2; } - lcl_ensureMaximumSubIncrementCount( rExplicitSubIncrement.IntervalCount ); - if(!(rSubIncrement.PostEquidistant>>=rExplicitSubIncrement.PostEquidistant)) + lcl_ensureMaximumSubIncrementCount( aExplicitSubIncrement.IntervalCount ); + if(!(rSubIncrement.PostEquidistant>>=aExplicitSubIncrement.PostEquidistant)) { //scaling dependent - rExplicitSubIncrement.PostEquidistant = sal_False; + aExplicitSubIncrement.PostEquidistant = sal_False; } + rExplicitIncrement.SubIncrements.push_back(aExplicitSubIncrement); } } diff --git a/chart2/source/view/axes/Tickmarks.cxx b/chart2/source/view/axes/Tickmarks.cxx new file mode 100644 index 000000000000..834fe66eb97b --- /dev/null +++ b/chart2/source/view/axes/Tickmarks.cxx @@ -0,0 +1,333 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_chart2.hxx" +#include "Tickmarks.hxx" +#include "Tickmarks_Equidistant.hxx" +#include "Tickmarks_Dates.hxx" +#include "ViewDefines.hxx" +#include <rtl/math.hxx> +#include <tools/debug.hxx> +#include <memory> + +//............................................................................. +namespace chart +{ +//............................................................................. +using namespace ::com::sun::star; +using namespace ::com::sun::star::chart2; +using namespace ::rtl::math; +using ::basegfx::B2DVector; + +TickInfo::TickInfo( const ::com::sun::star::uno::Reference< + ::com::sun::star::chart2::XScaling >& xInverse ) +: fScaledTickValue( 0.0 ) +, xInverseScaling( xInverse ) +, aTickScreenPosition(0.0,0.0) +, bPaintIt( true ) +, xTextShape( NULL ) +, nFactorForLimitedTextWidth(1) +{ +} + +double TickInfo::getUnscaledTickValue() const +{ + if( xInverseScaling.is() ) + return xInverseScaling->doScaling( fScaledTickValue ); + else + return fScaledTickValue; +} + +sal_Int32 TickInfo::getScreenDistanceBetweenTicks( const TickInfo& rOherTickInfo ) const +{ + //return the positive distance between the two first tickmarks in screen values + + B2DVector aDistance = rOherTickInfo.aTickScreenPosition - aTickScreenPosition; + sal_Int32 nRet = static_cast<sal_Int32>(aDistance.getLength()); + if(nRet<0) + nRet *= -1; + return nRet; +} + +PureTickIter::PureTickIter( ::std::vector< TickInfo >& rTickInfoVector ) + : m_rTickVector(rTickInfoVector) + , m_aTickIter(m_rTickVector.begin()) +{ +} +PureTickIter::~PureTickIter() +{ +} +TickInfo* PureTickIter::firstInfo() +{ + m_aTickIter = m_rTickVector.begin(); + if(m_aTickIter!=m_rTickVector.end()) + return &*m_aTickIter; + return 0; +} +TickInfo* PureTickIter::nextInfo() +{ + if(m_aTickIter!=m_rTickVector.end()) + { + m_aTickIter++; + if(m_aTickIter!=m_rTickVector.end()) + return &*m_aTickIter; + } + return 0; +} + +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- + +TickFactory::TickFactory( + const ExplicitScaleData& rScale, const ExplicitIncrementData& rIncrement ) + : m_rScale( rScale ) + , m_rIncrement( rIncrement ) + , m_xInverseScaling(NULL) +{ + //@todo: make sure that the scale is valid for the scaling + + if( m_rScale.Scaling.is() ) + { + m_xInverseScaling = m_rScale.Scaling->getInverseScaling(); + DBG_ASSERT( m_xInverseScaling.is(), "each Scaling needs to return a inverse Scaling" ); + } + + m_fScaledVisibleMin = m_rScale.Minimum; + if( m_xInverseScaling.is() ) + m_fScaledVisibleMin = m_rScale.Scaling->doScaling(m_fScaledVisibleMin); + + m_fScaledVisibleMax = m_rScale.Maximum; + if( m_xInverseScaling.is() ) + m_fScaledVisibleMax = m_rScale.Scaling->doScaling(m_fScaledVisibleMax); +} + +TickFactory::~TickFactory() +{ +} + +bool TickFactory::isDateAxis() const +{ + return m_rScale.AxisType == AxisType::DATE; +} + +void TickFactory::getAllTicks( ::std::vector< ::std::vector< TickInfo > >& rAllTickInfos ) const +{ + if( isDateAxis() ) + DateTickFactory( m_rScale, m_rIncrement ).getAllTicks( rAllTickInfos ); + else + EquidistantTickFactory( m_rScale, m_rIncrement ).getAllTicks( rAllTickInfos ); +} + +void TickFactory::getAllTicksShifted( ::std::vector< ::std::vector< TickInfo > >& rAllTickInfos ) const +{ + if( isDateAxis() ) + DateTickFactory( m_rScale, m_rIncrement ).getAllTicksShifted( rAllTickInfos ); + else + EquidistantTickFactory( m_rScale, m_rIncrement ).getAllTicksShifted( rAllTickInfos ); +} + +//----------------------------------------------------------------------------- +// ___TickFactory_2D___ +//----------------------------------------------------------------------------- +TickFactory_2D::TickFactory_2D( + const ExplicitScaleData& rScale, const ExplicitIncrementData& rIncrement + //, double fStrech_SceneToScreen, double fOffset_SceneToScreen ) + , const B2DVector& rStartScreenPos, const B2DVector& rEndScreenPos + , const B2DVector& rAxisLineToLabelLineShift ) + : TickFactory( rScale, rIncrement ) + , m_aAxisStartScreenPosition2D(rStartScreenPos) + , m_aAxisEndScreenPosition2D(rEndScreenPos) + , m_aAxisLineToLabelLineShift(rAxisLineToLabelLineShift) + , m_fStrech_LogicToScreen(1.0) + , m_fOffset_LogicToScreen(0.0) +{ + double fWidthY = m_fScaledVisibleMax - m_fScaledVisibleMin; + if( AxisOrientation_MATHEMATICAL==m_rScale.Orientation ) + { + m_fStrech_LogicToScreen = 1.0/fWidthY; + m_fOffset_LogicToScreen = -m_fScaledVisibleMin; + } + else + { + B2DVector aSwap(m_aAxisStartScreenPosition2D); + m_aAxisStartScreenPosition2D = m_aAxisEndScreenPosition2D; + m_aAxisEndScreenPosition2D = aSwap; + + m_fStrech_LogicToScreen = -1.0/fWidthY; + m_fOffset_LogicToScreen = -m_fScaledVisibleMax; + } +} + +TickFactory_2D::~TickFactory_2D() +{ +} + +bool TickFactory_2D::isHorizontalAxis() const +{ + return ( m_aAxisStartScreenPosition2D.getY() == m_aAxisEndScreenPosition2D.getY() ); +} +bool TickFactory_2D::isVerticalAxis() const +{ + return ( m_aAxisStartScreenPosition2D.getX() == m_aAxisEndScreenPosition2D.getX() ); +} + +//static +sal_Int32 TickFactory_2D::getTickScreenDistance( TickIter& rIter ) +{ + //return the positive distance between the two first tickmarks in screen values + //if there are less than two tickmarks -1 is returned + + const TickInfo* pFirstTickInfo = rIter.firstInfo(); + const TickInfo* pSecondTickInfo = rIter.nextInfo(); + if(!pSecondTickInfo || !pFirstTickInfo) + return -1; + + return pFirstTickInfo->getScreenDistanceBetweenTicks( *pSecondTickInfo ); +} + +B2DVector TickFactory_2D::getTickScreenPosition2D( double fScaledLogicTickValue ) const +{ + B2DVector aRet(m_aAxisStartScreenPosition2D); + aRet += (m_aAxisEndScreenPosition2D-m_aAxisStartScreenPosition2D) + *((fScaledLogicTickValue+m_fOffset_LogicToScreen)*m_fStrech_LogicToScreen); + return aRet; +} + +void TickFactory_2D::addPointSequenceForTickLine( drawing::PointSequenceSequence& rPoints + , sal_Int32 nSequenceIndex + , double fScaledLogicTickValue, double fInnerDirectionSign + , const TickmarkProperties& rTickmarkProperties + , bool bPlaceAtLabels ) const +{ + if( fInnerDirectionSign==0.0 ) + fInnerDirectionSign = 1.0; + + B2DVector aTickScreenPosition = this->getTickScreenPosition2D(fScaledLogicTickValue); + if( bPlaceAtLabels ) + aTickScreenPosition += m_aAxisLineToLabelLineShift; + + B2DVector aMainDirection = m_aAxisEndScreenPosition2D-m_aAxisStartScreenPosition2D; + aMainDirection.normalize(); + B2DVector aOrthoDirection(-aMainDirection.getY(),aMainDirection.getX()); + aOrthoDirection *= fInnerDirectionSign; + aOrthoDirection.normalize(); + + B2DVector aStart = aTickScreenPosition + aOrthoDirection*rTickmarkProperties.RelativePos; + B2DVector aEnd = aStart - aOrthoDirection*rTickmarkProperties.Length; + + rPoints[nSequenceIndex].realloc(2); + rPoints[nSequenceIndex][0].X = static_cast<sal_Int32>(aStart.getX()); + rPoints[nSequenceIndex][0].Y = static_cast<sal_Int32>(aStart.getY()); + rPoints[nSequenceIndex][1].X = static_cast<sal_Int32>(aEnd.getX()); + rPoints[nSequenceIndex][1].Y = static_cast<sal_Int32>(aEnd.getY()); +} + +B2DVector TickFactory_2D::getDistanceAxisTickToText( const AxisProperties& rAxisProperties, bool bIncludeFarAwayDistanceIfSo, bool bIncludeSpaceBetweenTickAndText ) const +{ + bool bFarAwayLabels = false; + if( ::com::sun::star::chart::ChartAxisLabelPosition_OUTSIDE_START == rAxisProperties.m_eLabelPos + || ::com::sun::star::chart::ChartAxisLabelPosition_OUTSIDE_END == rAxisProperties.m_eLabelPos ) + bFarAwayLabels = true; + + double fInnerDirectionSign = rAxisProperties.m_fInnerDirectionSign; + if( fInnerDirectionSign==0.0 ) + fInnerDirectionSign = 1.0; + + B2DVector aMainDirection = m_aAxisEndScreenPosition2D-m_aAxisStartScreenPosition2D; + aMainDirection.normalize(); + B2DVector aOrthoDirection(-aMainDirection.getY(),aMainDirection.getX()); + aOrthoDirection *= fInnerDirectionSign; + aOrthoDirection.normalize(); + + B2DVector aStart(0,0), aEnd(0,0); + if( bFarAwayLabels ) + { + TickmarkProperties aProps( AxisProperties::getBiggestTickmarkProperties() ); + aStart = aOrthoDirection*aProps.RelativePos; + aEnd = aStart - aOrthoDirection*aProps.Length; + } + else + { + for( sal_Int32 nN=rAxisProperties.m_aTickmarkPropertiesList.size();nN--;) + { + const TickmarkProperties& rProps = rAxisProperties.m_aTickmarkPropertiesList[nN]; + B2DVector aNewStart = aOrthoDirection*rProps.RelativePos; + B2DVector aNewEnd = aNewStart - aOrthoDirection*rProps.Length; + if(aNewStart.getLength()>aStart.getLength()) + aStart=aNewStart; + if(aNewEnd.getLength()>aEnd.getLength()) + aEnd=aNewEnd; + } + } + + B2DVector aLabelDirection(aStart); + if( rAxisProperties.m_fInnerDirectionSign != rAxisProperties.m_fLabelDirectionSign ) + aLabelDirection = aEnd; + + B2DVector aOrthoLabelDirection(aOrthoDirection); + if( rAxisProperties.m_fInnerDirectionSign != rAxisProperties.m_fLabelDirectionSign ) + aOrthoLabelDirection*=-1.0; + aOrthoLabelDirection.normalize(); + if( bIncludeSpaceBetweenTickAndText ) + aLabelDirection += aOrthoLabelDirection*AXIS2D_TICKLABELSPACING; + if( bFarAwayLabels && bIncludeFarAwayDistanceIfSo ) + aLabelDirection += m_aAxisLineToLabelLineShift; + return aLabelDirection; +} + +void TickFactory_2D::createPointSequenceForAxisMainLine( drawing::PointSequenceSequence& rPoints ) const +{ + rPoints[0].realloc(2); + rPoints[0][0].X = static_cast<sal_Int32>(m_aAxisStartScreenPosition2D.getX()); + rPoints[0][0].Y = static_cast<sal_Int32>(m_aAxisStartScreenPosition2D.getY()); + rPoints[0][1].X = static_cast<sal_Int32>(m_aAxisEndScreenPosition2D.getX()); + rPoints[0][1].Y = static_cast<sal_Int32>(m_aAxisEndScreenPosition2D.getY()); +} + +void TickFactory_2D::updateScreenValues( ::std::vector< ::std::vector< TickInfo > >& rAllTickInfos ) const +{ + //get the transformed screen values for all tickmarks in rAllTickInfos + ::std::vector< ::std::vector< TickInfo > >::iterator aDepthIter = rAllTickInfos.begin(); + const ::std::vector< ::std::vector< TickInfo > >::const_iterator aDepthEnd = rAllTickInfos.end(); + for( ; aDepthIter != aDepthEnd; aDepthIter++ ) + { + ::std::vector< TickInfo >::iterator aTickIter = (*aDepthIter).begin(); + const ::std::vector< TickInfo >::const_iterator aTickEnd = (*aDepthIter).end(); + for( ; aTickIter != aTickEnd; aTickIter++ ) + { + TickInfo& rTickInfo = (*aTickIter); + rTickInfo.aTickScreenPosition = + this->getTickScreenPosition2D( rTickInfo.fScaledTickValue ); + } + } +} + +//............................................................................. +} //namespace chart +//............................................................................. diff --git a/chart2/source/view/axes/Tickmarks.hxx b/chart2/source/view/axes/Tickmarks.hxx new file mode 100644 index 000000000000..62fa5fef92d0 --- /dev/null +++ b/chart2/source/view/axes/Tickmarks.hxx @@ -0,0 +1,166 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef _CHART2_TICKMARKS_HXX +#define _CHART2_TICKMARKS_HXX + +#include "TickmarkProperties.hxx" +#include "VAxisProperties.hxx" +#include "chartview/ExplicitScaleValues.hxx" +#include <basegfx/vector/b2dvector.hxx> +#include <com/sun/star/drawing/PointSequenceSequence.hpp> +#include <com/sun/star/drawing/XShape.hpp> +#include <com/sun/star/uno/Sequence.h> + +#include <vector> + +//............................................................................. +namespace chart +{ +//............................................................................. + +using ::basegfx::B2DVector; +//----------------------------------------------------------------------------- +/** +*/ + +struct TickInfo +{ + double fScaledTickValue; + ::com::sun::star::uno::Reference< + ::com::sun::star::chart2::XScaling > xInverseScaling; + + ::basegfx::B2DVector aTickScreenPosition; + bool bPaintIt; + + ::com::sun::star::uno::Reference< + ::com::sun::star::drawing::XShape > xTextShape; + + rtl::OUString aText;//used only for complex categories so far + sal_Int32 nFactorForLimitedTextWidth;//categories in higher levels of complex categories can have more place than a single simple category + +//methods: + TickInfo( const ::com::sun::star::uno::Reference< + ::com::sun::star::chart2::XScaling >& xInverseScaling ); + + double getUnscaledTickValue() const; + sal_Int32 getScreenDistanceBetweenTicks( const TickInfo& rOherTickInfo ) const; +private: + TickInfo(); +}; +class TickIter +{ +public: + virtual ~TickIter(){}; + virtual TickInfo* firstInfo()=0; + virtual TickInfo* nextInfo()=0; +}; + +class PureTickIter : public TickIter +{ +public: + PureTickIter( ::std::vector< TickInfo >& rTickInfoVector ); + virtual ~PureTickIter(); + virtual TickInfo* firstInfo(); + virtual TickInfo* nextInfo(); + +private: + ::std::vector< TickInfo >& m_rTickVector; + ::std::vector< TickInfo >::iterator m_aTickIter; +}; + +class TickFactory +{ +public: + TickFactory( + const ExplicitScaleData& rScale + , const ExplicitIncrementData& rIncrement ); + virtual ~TickFactory(); + + void getAllTicks( ::std::vector< ::std::vector< TickInfo > >& rAllTickInfos ) const; + void getAllTicksShifted( ::std::vector< ::std::vector< TickInfo > >& rAllTickInfos ) const; + virtual void updateScreenValues( ::std::vector< ::std::vector< TickInfo > >& /*rAllTickInfos*/ ) const {} + +private: //methods + bool isDateAxis() const; + +protected: //member + ExplicitScaleData m_rScale; + ExplicitIncrementData m_rIncrement; + ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XScaling > + m_xInverseScaling; + + //minimum and maximum of the visible range after scaling + double m_fScaledVisibleMin; + double m_fScaledVisibleMax; +}; + +class TickFactory_2D : public TickFactory +{ +public: + TickFactory_2D( + const ExplicitScaleData& rScale + , const ExplicitIncrementData& rIncrement + , const ::basegfx::B2DVector& rStartScreenPos, const ::basegfx::B2DVector& rEndScreenPos + , const ::basegfx::B2DVector& rAxisLineToLabelLineShift ); + //, double fStrech_SceneToScreen, double fOffset_SceneToScreen ); + virtual ~TickFactory_2D(); + + static sal_Int32 getTickScreenDistance( TickIter& rIter ); + + void createPointSequenceForAxisMainLine( ::com::sun::star::drawing::PointSequenceSequence& rPoints ) const; + void addPointSequenceForTickLine( ::com::sun::star::drawing::PointSequenceSequence& rPoints + , sal_Int32 nSequenceIndex + , double fScaledLogicTickValue, double fInnerDirectionSign + , const TickmarkProperties& rTickmarkProperties, bool bPlaceAtLabels ) const; + ::basegfx::B2DVector getDistanceAxisTickToText( const AxisProperties& rAxisProperties + , bool bIncludeFarAwayDistanceIfSo = false + , bool bIncludeSpaceBetweenTickAndText = true ) const; + + virtual void updateScreenValues( ::std::vector< ::std::vector< TickInfo > >& rAllTickInfos ) const; + + bool isHorizontalAxis() const; + bool isVerticalAxis() const; + +protected: //methods + ::basegfx::B2DVector getTickScreenPosition2D( double fScaledLogicTickValue ) const; + +private: //member + ::basegfx::B2DVector m_aAxisStartScreenPosition2D; + ::basegfx::B2DVector m_aAxisEndScreenPosition2D; + + //labels might be posioned high or low on the border of the diagram far away from the axis + //add this vector to go from the axis line to the label line (border of the diagram) + ::basegfx::B2DVector m_aAxisLineToLabelLineShift; + + double m_fStrech_LogicToScreen; + double m_fOffset_LogicToScreen; +}; + +//............................................................................. +} //namespace chart +//............................................................................. +#endif diff --git a/chart2/source/view/axes/Tickmarks_Dates.cxx b/chart2/source/view/axes/Tickmarks_Dates.cxx new file mode 100644 index 000000000000..b5177fe307b8 --- /dev/null +++ b/chart2/source/view/axes/Tickmarks_Dates.cxx @@ -0,0 +1,171 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_chart2.hxx" +#include "Tickmarks_Dates.hxx" +#include "DateScaling.hxx" +#include <rtl/math.hxx> +#include <tools/debug.hxx> +#include "DateHelper.hxx" + +//............................................................................. +namespace chart +{ +//............................................................................. +using namespace ::com::sun::star; +using namespace ::com::sun::star::chart2; +using namespace ::rtl::math; +using ::basegfx::B2DVector; +using ::com::sun::star::chart::TimeUnit::DAY; +using ::com::sun::star::chart::TimeUnit::MONTH; +using ::com::sun::star::chart::TimeUnit::YEAR; + +DateTickFactory::DateTickFactory( + const ExplicitScaleData& rScale, const ExplicitIncrementData& rIncrement ) + : m_aScale( rScale ) + , m_aIncrement( rIncrement ) + , m_xInverseScaling(NULL) +{ + //@todo: make sure that the scale is valid for the scaling + + if( m_aScale.Scaling.is() ) + { + m_xInverseScaling = m_aScale.Scaling->getInverseScaling(); + DBG_ASSERT( m_xInverseScaling.is(), "each Scaling needs to return a inverse Scaling" ); + } + + m_fScaledVisibleMin = m_aScale.Minimum; + if( m_xInverseScaling.is() ) + m_fScaledVisibleMin = m_aScale.Scaling->doScaling(m_fScaledVisibleMin); + + m_fScaledVisibleMax = m_aScale.Maximum; + if( m_xInverseScaling.is() ) + m_fScaledVisibleMax = m_aScale.Scaling->doScaling(m_fScaledVisibleMax); +} + +DateTickFactory::~DateTickFactory() +{ +} + +void DateTickFactory::getAllTicks( ::std::vector< ::std::vector< TickInfo > >& rAllTickInfos, bool bShifted ) const +{ + rAllTickInfos.resize(2); + ::std::vector< TickInfo >& rMajorTicks = rAllTickInfos[0]; + ::std::vector< TickInfo >& rMinorTicks = rAllTickInfos[1]; + rMajorTicks.clear(); + rMinorTicks.clear(); + + Date aNull(m_aScale.NullDate); + + Date aDate = aNull + ::rtl::math::approxFloor(m_aScale.Minimum); + Date aMaxDate = aNull + ::rtl::math::approxFloor(m_aScale.Maximum); + + uno::Reference< chart2::XScaling > xScaling(m_aScale.Scaling); + uno::Reference< chart2::XScaling > xInverseScaling(m_xInverseScaling); + if( bShifted ) + { + xScaling = new DateScaling(aNull,m_aScale.TimeResolution,true/*bShifted*/); + xInverseScaling = xScaling->getInverseScaling(); + } + + //create major date tickinfos + while( aDate<= aMaxDate ) + { + if( bShifted && aDate==aMaxDate ) + break; + + TickInfo aNewTick(xInverseScaling); aNewTick.fScaledTickValue = aDate - aNull; + + if( xInverseScaling.is() ) + aNewTick.fScaledTickValue = xScaling->doScaling(aNewTick.fScaledTickValue); + rMajorTicks.push_back( aNewTick ); + + if(m_aIncrement.MajorTimeInterval.Number<=0) + break; + + //find next major date + switch( m_aIncrement.MajorTimeInterval.TimeUnit ) + { + case DAY: + aDate += m_aIncrement.MajorTimeInterval.Number; + break; + case YEAR: + aDate = DateHelper::GetDateSomeYearsAway( aDate, m_aIncrement.MajorTimeInterval.Number ); + break; + case MONTH: + default: + aDate = DateHelper::GetDateSomeMonthsAway( aDate, m_aIncrement.MajorTimeInterval.Number ); + break; + } + } + + //create minor date tickinfos + aDate = aNull + ::rtl::math::approxFloor(m_aScale.Minimum); + while( aDate<= aMaxDate ) + { + if( bShifted && aDate==aMaxDate ) + break; + + TickInfo aNewTick(xInverseScaling); aNewTick.fScaledTickValue = aDate - aNull; + if( xInverseScaling.is() ) + aNewTick.fScaledTickValue = xScaling->doScaling(aNewTick.fScaledTickValue); + rMinorTicks.push_back( aNewTick ); + + if(m_aIncrement.MinorTimeInterval.Number<=0) + break; + + //find next minor date + switch( m_aIncrement.MinorTimeInterval.TimeUnit ) + { + case DAY: + aDate += m_aIncrement.MinorTimeInterval.Number; + break; + case YEAR: + aDate = DateHelper::GetDateSomeYearsAway( aDate, m_aIncrement.MinorTimeInterval.Number ); + break; + case MONTH: + default: + aDate = DateHelper::GetDateSomeMonthsAway( aDate, m_aIncrement.MinorTimeInterval.Number ); + break; + } + } +} + +void DateTickFactory::getAllTicks( ::std::vector< ::std::vector< TickInfo > >& rAllTickInfos ) const +{ + getAllTicks( rAllTickInfos, false ); +} + +void DateTickFactory::getAllTicksShifted( ::std::vector< ::std::vector< TickInfo > >& rAllTickInfos ) const +{ + getAllTicks( rAllTickInfos, true ); +} + +//............................................................................. +} //namespace chart +//............................................................................. diff --git a/chart2/source/view/axes/Tickmarks_Dates.hxx b/chart2/source/view/axes/Tickmarks_Dates.hxx new file mode 100644 index 000000000000..464e8b4ca24c --- /dev/null +++ b/chart2/source/view/axes/Tickmarks_Dates.hxx @@ -0,0 +1,65 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef _CHART2_TICKMARKS_DATES_HXX +#define _CHART2_TICKMARKS_DATES_HXX + +#include "Tickmarks.hxx" + +//............................................................................. +namespace chart +{ +//............................................................................. + +class DateTickFactory +{ +public: + DateTickFactory( + const ExplicitScaleData& rScale + , const ExplicitIncrementData& rIncrement ); + ~DateTickFactory(); + + void getAllTicks( ::std::vector< ::std::vector< TickInfo > >& rAllTickInfos ) const; + void getAllTicksShifted( ::std::vector< ::std::vector< TickInfo > >& rAllTickInfos ) const; + +private: //methods + void getAllTicks( ::std::vector< ::std::vector< TickInfo > >& rAllTickInfos, bool bShifted ) const; + +private: //member + ExplicitScaleData m_aScale; + ExplicitIncrementData m_aIncrement; + ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XScaling > + m_xInverseScaling; + + //minimum and maximum of the visible range after scaling + double m_fScaledVisibleMin; + double m_fScaledVisibleMax; +}; + +//............................................................................. +} //namespace chart +//............................................................................. +#endif diff --git a/chart2/source/view/axes/Tickmarks_Equidistant.cxx b/chart2/source/view/axes/Tickmarks_Equidistant.cxx new file mode 100644 index 000000000000..9344af1ffac9 --- /dev/null +++ b/chart2/source/view/axes/Tickmarks_Equidistant.cxx @@ -0,0 +1,671 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_chart2.hxx" +#include "Tickmarks_Equidistant.hxx" +#include "ViewDefines.hxx" +#include <rtl/math.hxx> +#include <tools/debug.hxx> +#include <memory> + +//............................................................................. +namespace chart +{ +//............................................................................. +using namespace ::com::sun::star; +using namespace ::com::sun::star::chart2; +using namespace ::rtl::math; +using ::basegfx::B2DVector; + +//static +double EquidistantTickFactory::getMinimumAtIncrement( double fMin, const ExplicitIncrementData& rIncrement ) +{ + //the returned value will be <= fMin and on a Major Tick given by rIncrement + if(rIncrement.Distance<=0.0) + return fMin; + + double fRet = rIncrement.BaseValue + + floor( approxSub( fMin, rIncrement.BaseValue ) + / rIncrement.Distance) + *rIncrement.Distance; + + if( fRet > fMin ) + { + if( !approxEqual(fRet, fMin) ) + fRet -= rIncrement.Distance; + } + return fRet; +} +//static +double EquidistantTickFactory::getMaximumAtIncrement( double fMax, const ExplicitIncrementData& rIncrement ) +{ + //the returned value will be >= fMax and on a Major Tick given by rIncrement + if(rIncrement.Distance<=0.0) + return fMax; + + double fRet = rIncrement.BaseValue + + floor( approxSub( fMax, rIncrement.BaseValue ) + / rIncrement.Distance) + *rIncrement.Distance; + + if( fRet < fMax ) + { + if( !approxEqual(fRet, fMax) ) + fRet += rIncrement.Distance; + } + return fRet; +} + +EquidistantTickFactory::EquidistantTickFactory( + const ExplicitScaleData& rScale, const ExplicitIncrementData& rIncrement ) + : m_rScale( rScale ) + , m_rIncrement( rIncrement ) + , m_xInverseScaling(NULL) + , m_pfCurrentValues(NULL) +{ + //@todo: make sure that the scale is valid for the scaling + + m_pfCurrentValues = new double[getTickDepth()]; + + if( m_rScale.Scaling.is() ) + { + m_xInverseScaling = m_rScale.Scaling->getInverseScaling(); + DBG_ASSERT( m_xInverseScaling.is(), "each Scaling needs to return a inverse Scaling" ); + } + + double fMin = m_fScaledVisibleMin = m_rScale.Minimum; + if( m_xInverseScaling.is() ) + { + m_fScaledVisibleMin = m_rScale.Scaling->doScaling(m_fScaledVisibleMin); + if(m_rIncrement.PostEquidistant ) + fMin = m_fScaledVisibleMin; + } + + double fMax = m_fScaledVisibleMax = m_rScale.Maximum; + if( m_xInverseScaling.is() ) + { + m_fScaledVisibleMax = m_rScale.Scaling->doScaling(m_fScaledVisibleMax); + if(m_rIncrement.PostEquidistant ) + fMax = m_fScaledVisibleMax; + } + + //-- + m_fOuterMajorTickBorderMin = EquidistantTickFactory::getMinimumAtIncrement( fMin, m_rIncrement ); + m_fOuterMajorTickBorderMax = EquidistantTickFactory::getMaximumAtIncrement( fMax, m_rIncrement ); + //-- + + m_fOuterMajorTickBorderMin_Scaled = m_fOuterMajorTickBorderMin; + m_fOuterMajorTickBorderMax_Scaled = m_fOuterMajorTickBorderMax; + if(!m_rIncrement.PostEquidistant && m_xInverseScaling.is() ) + { + m_fOuterMajorTickBorderMin_Scaled = m_rScale.Scaling->doScaling(m_fOuterMajorTickBorderMin); + m_fOuterMajorTickBorderMax_Scaled = m_rScale.Scaling->doScaling(m_fOuterMajorTickBorderMax); + + //check validity of new range: m_fOuterMajorTickBorderMin <-> m_fOuterMajorTickBorderMax + //it is assumed here, that the original range in the given Scale is valid + if( !rtl::math::isFinite(m_fOuterMajorTickBorderMin_Scaled) ) + { + m_fOuterMajorTickBorderMin += m_rIncrement.Distance; + m_fOuterMajorTickBorderMin_Scaled = m_rScale.Scaling->doScaling(m_fOuterMajorTickBorderMin); + } + if( !rtl::math::isFinite(m_fOuterMajorTickBorderMax_Scaled) ) + { + m_fOuterMajorTickBorderMax -= m_rIncrement.Distance; + m_fOuterMajorTickBorderMax_Scaled = m_rScale.Scaling->doScaling(m_fOuterMajorTickBorderMax); + } + } +} + +EquidistantTickFactory::~EquidistantTickFactory() +{ + delete[] m_pfCurrentValues; +} + +sal_Int32 EquidistantTickFactory::getTickDepth() const +{ + return static_cast<sal_Int32>(m_rIncrement.SubIncrements.size()) + 1; +} + +void EquidistantTickFactory::addSubTicks( sal_Int32 nDepth, uno::Sequence< uno::Sequence< double > >& rParentTicks ) const +{ + EquidistantTickIter aIter( rParentTicks, m_rIncrement, 0, nDepth-1 ); + double* pfNextParentTick = aIter.firstValue(); + if(!pfNextParentTick) + return; + double fLastParentTick = *pfNextParentTick; + pfNextParentTick = aIter.nextValue(); + if(!pfNextParentTick) + return; + + sal_Int32 nMaxSubTickCount = this->getMaxTickCount( nDepth ); + if(!nMaxSubTickCount) + return; + + uno::Sequence< double > aSubTicks(nMaxSubTickCount); + sal_Int32 nRealSubTickCount = 0; + sal_Int32 nIntervalCount = m_rIncrement.SubIncrements[nDepth-1].IntervalCount; + + double* pValue = NULL; + for(; pfNextParentTick; fLastParentTick=*pfNextParentTick, pfNextParentTick = aIter.nextValue()) + { + for( sal_Int32 nPartTick = 1; nPartTick<nIntervalCount; nPartTick++ ) + { + pValue = this->getMinorTick( nPartTick, nDepth + , fLastParentTick, *pfNextParentTick ); + if(!pValue) + continue; + + aSubTicks[nRealSubTickCount] = *pValue; + nRealSubTickCount++; + } + } + + aSubTicks.realloc(nRealSubTickCount); + rParentTicks[nDepth] = aSubTicks; + if(static_cast<sal_Int32>(m_rIncrement.SubIncrements.size())>nDepth) + addSubTicks( nDepth+1, rParentTicks ); +} + + +sal_Int32 EquidistantTickFactory::getMaxTickCount( sal_Int32 nDepth ) const +{ + //return the maximum amount of ticks + //possibly open intervals at the two ends of the region are handled as if they were completely visible + //(this is necessary for calculating the sub ticks at the borders correctly) + + if( nDepth >= getTickDepth() ) + return 0; + if( m_fOuterMajorTickBorderMax < m_fOuterMajorTickBorderMin ) + return 0; + if( m_rIncrement.Distance<=0.0) + return 0; + + double fSub; + if(m_rIncrement.PostEquidistant ) + fSub = approxSub( m_fScaledVisibleMax, m_fScaledVisibleMin ); + else + fSub = approxSub( m_rScale.Maximum, m_rScale.Minimum ); + + if (!isFinite(fSub)) + return 0; + + sal_Int32 nIntervalCount = static_cast<sal_Int32>( fSub / m_rIncrement.Distance ); + + nIntervalCount+=3; + for(sal_Int32 nN=0; nN<nDepth-1; nN++) + { + if( m_rIncrement.SubIncrements[nN].IntervalCount>1 ) + nIntervalCount *= m_rIncrement.SubIncrements[nN].IntervalCount; + } + + sal_Int32 nTickCount = nIntervalCount; + if(nDepth>0 && m_rIncrement.SubIncrements[nDepth-1].IntervalCount>1) + nTickCount = nIntervalCount * (m_rIncrement.SubIncrements[nDepth-1].IntervalCount-1); + + return nTickCount; +} + +double* EquidistantTickFactory::getMajorTick( sal_Int32 nTick ) const +{ + m_pfCurrentValues[0] = m_fOuterMajorTickBorderMin + nTick*m_rIncrement.Distance; + + if(m_pfCurrentValues[0]>m_fOuterMajorTickBorderMax) + { + if( !approxEqual(m_pfCurrentValues[0],m_fOuterMajorTickBorderMax) ) + return NULL; + } + if(m_pfCurrentValues[0]<m_fOuterMajorTickBorderMin) + { + if( !approxEqual(m_pfCurrentValues[0],m_fOuterMajorTickBorderMin) ) + return NULL; + } + + //return always the value after scaling + if(!m_rIncrement.PostEquidistant && m_xInverseScaling.is() ) + m_pfCurrentValues[0] = m_rScale.Scaling->doScaling( m_pfCurrentValues[0] ); + + return &m_pfCurrentValues[0]; +} + +double* EquidistantTickFactory::getMinorTick( sal_Int32 nTick, sal_Int32 nDepth + , double fStartParentTick, double fNextParentTick ) const +{ + //check validity of arguments + { + //DBG_ASSERT( fStartParentTick < fNextParentTick, "fStartParentTick >= fNextParentTick"); + if(fStartParentTick >= fNextParentTick) + return NULL; + if(nDepth>static_cast<sal_Int32>(m_rIncrement.SubIncrements.size()) || nDepth<=0) + return NULL; + + //subticks are only calculated if they are laying between parent ticks: + if(nTick<=0) + return NULL; + if(nTick>=m_rIncrement.SubIncrements[nDepth-1].IntervalCount) + return NULL; + } + + bool bPostEquidistant = m_rIncrement.SubIncrements[nDepth-1].PostEquidistant; + + double fAdaptedStartParent = fStartParentTick; + double fAdaptedNextParent = fNextParentTick; + + if( !bPostEquidistant && m_xInverseScaling.is() ) + { + fAdaptedStartParent = m_xInverseScaling->doScaling(fStartParentTick); + fAdaptedNextParent = m_xInverseScaling->doScaling(fNextParentTick); + } + + double fDistance = (fAdaptedNextParent - fAdaptedStartParent)/m_rIncrement.SubIncrements[nDepth-1].IntervalCount; + + m_pfCurrentValues[nDepth] = fAdaptedStartParent + nTick*fDistance; + + //return always the value after scaling + if(!bPostEquidistant && m_xInverseScaling.is() ) + m_pfCurrentValues[nDepth] = m_rScale.Scaling->doScaling( m_pfCurrentValues[nDepth] ); + + if( !isWithinOuterBorder( m_pfCurrentValues[nDepth] ) ) + return NULL; + + return &m_pfCurrentValues[nDepth]; +} + +bool EquidistantTickFactory::isWithinOuterBorder( double fScaledValue ) const +{ + if(fScaledValue>m_fOuterMajorTickBorderMax_Scaled) + return false; + if(fScaledValue<m_fOuterMajorTickBorderMin_Scaled) + return false; + + return true; +} + +bool EquidistantTickFactory::isVisible( double fScaledValue ) const +{ + if(fScaledValue>m_fScaledVisibleMax) + { + if( !approxEqual(fScaledValue,m_fScaledVisibleMax) ) + return false; + } + if(fScaledValue<m_fScaledVisibleMin) + { + if( !approxEqual(fScaledValue,m_fScaledVisibleMin) ) + return false; + } + return true; +} + +void EquidistantTickFactory::getAllTicks( ::std::vector< ::std::vector< TickInfo > >& rAllTickInfos ) const +{ + uno::Sequence< uno::Sequence< double > > aAllTicks; + + //create point sequences for each tick depth + sal_Int32 nDepthCount = this->getTickDepth(); + sal_Int32 nMaxMajorTickCount = this->getMaxTickCount( 0 ); + + aAllTicks.realloc(nDepthCount); + aAllTicks[0].realloc(nMaxMajorTickCount); + + sal_Int32 nRealMajorTickCount = 0; + double* pValue = NULL; + for( sal_Int32 nMajorTick=0; nMajorTick<nMaxMajorTickCount; nMajorTick++ ) + { + pValue = this->getMajorTick( nMajorTick ); + if(!pValue) + continue; + aAllTicks[0][nRealMajorTickCount] = *pValue; + nRealMajorTickCount++; + } + if(!nRealMajorTickCount) + return; + aAllTicks[0].realloc(nRealMajorTickCount); + + if(nDepthCount>0) + this->addSubTicks( 1, aAllTicks ); + + //so far we have added all ticks between the outer major tick marks + //this was necessary to create sub ticks correctly + //now we reduce all ticks to the visible ones that lie between the real borders + sal_Int32 nDepth = 0; + sal_Int32 nTick = 0; + for( nDepth = 0; nDepth < nDepthCount; nDepth++) + { + sal_Int32 nInvisibleAtLowerBorder = 0; + sal_Int32 nInvisibleAtUpperBorder = 0; + //we need only to check all ticks within the first major interval at each border + sal_Int32 nCheckCount = 1; + for(sal_Int32 nN=0; nN<nDepth; nN++) + { + if( m_rIncrement.SubIncrements[nN].IntervalCount>1 ) + nCheckCount *= m_rIncrement.SubIncrements[nN].IntervalCount; + } + uno::Sequence< double >& rTicks = aAllTicks[nDepth]; + sal_Int32 nCount = rTicks.getLength(); + //check lower border + for( nTick=0; nTick<nCheckCount && nTick<nCount; nTick++) + { + if( !isVisible( rTicks[nTick] ) ) + nInvisibleAtLowerBorder++; + } + //check upper border + for( nTick=nCount-1; nTick>nCount-1-nCheckCount && nTick>=0; nTick--) + { + if( !isVisible( rTicks[nTick] ) ) + nInvisibleAtUpperBorder++; + } + //resize sequence + if( !nInvisibleAtLowerBorder && !nInvisibleAtUpperBorder) + continue; + if( !nInvisibleAtLowerBorder ) + rTicks.realloc(nCount-nInvisibleAtUpperBorder); + else + { + sal_Int32 nNewCount = nCount-nInvisibleAtUpperBorder-nInvisibleAtLowerBorder; + if(nNewCount<0) + nNewCount=0; + + uno::Sequence< double > aOldTicks(rTicks); + rTicks.realloc(nNewCount); + for(nTick = 0; nTick<nNewCount; nTick++) + rTicks[nTick] = aOldTicks[nInvisibleAtLowerBorder+nTick]; + } + } + + //fill return value + rAllTickInfos.resize(aAllTicks.getLength()); + for( nDepth=0 ;nDepth<aAllTicks.getLength(); nDepth++ ) + { + sal_Int32 nCount = aAllTicks[nDepth].getLength(); + + ::std::vector< TickInfo >& rTickInfoVector = rAllTickInfos[nDepth]; + rTickInfoVector.clear(); + rTickInfoVector.reserve( nCount ); + for(sal_Int32 nN = 0; nN<nCount; nN++) + { + TickInfo aTickInfo(m_xInverseScaling); + aTickInfo.fScaledTickValue = aAllTicks[nDepth][nN]; + rTickInfoVector.push_back(aTickInfo); + } + } +} + +void EquidistantTickFactory::getAllTicksShifted( ::std::vector< ::std::vector< TickInfo > >& rAllTickInfos ) const +{ + ExplicitIncrementData aShiftedIncrement( m_rIncrement ); + aShiftedIncrement.BaseValue = m_rIncrement.BaseValue-m_rIncrement.Distance/2.0; + EquidistantTickFactory( m_rScale, aShiftedIncrement ).getAllTicks(rAllTickInfos); +} + +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- + +EquidistantTickIter::EquidistantTickIter( const uno::Sequence< uno::Sequence< double > >& rTicks + , const ExplicitIncrementData& rIncrement + , sal_Int32 nMinDepth, sal_Int32 nMaxDepth ) + : m_pSimpleTicks(&rTicks) + , m_pInfoTicks(0) + , m_rIncrement(rIncrement) + , m_nMinDepth(0), m_nMaxDepth(0) + , m_nTickCount(0), m_pnPositions(NULL) + , m_pnPreParentCount(NULL), m_pbIntervalFinished(NULL) + , m_nCurrentDepth(-1), m_nCurrentPos(-1), m_fCurrentValue( 0.0 ) +{ + initIter( nMinDepth, nMaxDepth ); +} + +EquidistantTickIter::EquidistantTickIter( ::std::vector< ::std::vector< TickInfo > >& rTicks + , const ExplicitIncrementData& rIncrement + , sal_Int32 nMinDepth, sal_Int32 nMaxDepth ) + : m_pSimpleTicks(NULL) + , m_pInfoTicks(&rTicks) + , m_rIncrement(rIncrement) + , m_nMinDepth(0), m_nMaxDepth(0) + , m_nTickCount(0), m_pnPositions(NULL) + , m_pnPreParentCount(NULL), m_pbIntervalFinished(NULL) + , m_nCurrentDepth(-1), m_nCurrentPos(-1), m_fCurrentValue( 0.0 ) +{ + initIter( nMinDepth, nMaxDepth ); +} + +void EquidistantTickIter::initIter( sal_Int32 /*nMinDepth*/, sal_Int32 nMaxDepth ) +{ + m_nMaxDepth = nMaxDepth; + if(nMaxDepth<0 || m_nMaxDepth>getMaxDepth()) + m_nMaxDepth=getMaxDepth(); + + sal_Int32 nDepth = 0; + for( nDepth = 0; nDepth<=m_nMaxDepth ;nDepth++ ) + m_nTickCount += getTickCount(nDepth); + + if(!m_nTickCount) + return; + + m_pnPositions = new sal_Int32[m_nMaxDepth+1]; + + m_pnPreParentCount = new sal_Int32[m_nMaxDepth+1]; + m_pbIntervalFinished = new bool[m_nMaxDepth+1]; + m_pnPreParentCount[0] = 0; + m_pbIntervalFinished[0] = false; + double fParentValue = getTickValue(0,0); + for( nDepth = 1; nDepth<=m_nMaxDepth ;nDepth++ ) + { + m_pbIntervalFinished[nDepth] = false; + + sal_Int32 nPreParentCount = 0; + sal_Int32 nCount = getTickCount(nDepth); + for(sal_Int32 nN = 0; nN<nCount; nN++) + { + if(getTickValue(nDepth,nN) < fParentValue) + nPreParentCount++; + else + break; + } + m_pnPreParentCount[nDepth] = nPreParentCount; + if(nCount) + { + double fNextParentValue = getTickValue(nDepth,0); + if( fNextParentValue < fParentValue ) + fParentValue = fNextParentValue; + } + } +} + +EquidistantTickIter::~EquidistantTickIter() +{ + delete[] m_pnPositions; + delete[] m_pnPreParentCount; + delete[] m_pbIntervalFinished; +} + +sal_Int32 EquidistantTickIter::getStartDepth() const +{ + //find the depth of the first visible tickmark: + //it is the depth of the smallest value + sal_Int32 nReturnDepth=0; + double fMinValue = DBL_MAX; + for(sal_Int32 nDepth = 0; nDepth<=m_nMaxDepth ;nDepth++ ) + { + sal_Int32 nCount = getTickCount(nDepth); + if( !nCount ) + continue; + double fThisValue = getTickValue(nDepth,0); + if(fThisValue<fMinValue) + { + nReturnDepth = nDepth; + fMinValue = fThisValue; + } + } + return nReturnDepth; +} + +double* EquidistantTickIter::firstValue() +{ + if( gotoFirst() ) + { + m_fCurrentValue = getTickValue(m_nCurrentDepth, m_pnPositions[m_nCurrentDepth]); + return &m_fCurrentValue; + } + return NULL; +} + +TickInfo* EquidistantTickIter::firstInfo() +{ + if( m_pInfoTicks && gotoFirst() ) + return &(*m_pInfoTicks)[m_nCurrentDepth][m_pnPositions[m_nCurrentDepth]]; + return NULL; +} + +sal_Int32 EquidistantTickIter::getIntervalCount( sal_Int32 nDepth ) +{ + if(nDepth>static_cast<sal_Int32>(m_rIncrement.SubIncrements.size()) || nDepth<0) + return 0; + + if(!nDepth) + return m_nTickCount; + + return m_rIncrement.SubIncrements[nDepth-1].IntervalCount; +} + +bool EquidistantTickIter::isAtLastPartTick() +{ + if(!m_nCurrentDepth) + return false; + sal_Int32 nIntervalCount = getIntervalCount( m_nCurrentDepth ); + if(!nIntervalCount || nIntervalCount == 1) + return true; + if( m_pbIntervalFinished[m_nCurrentDepth] ) + return false; + sal_Int32 nPos = m_pnPositions[m_nCurrentDepth]+1; + if(m_pnPreParentCount[m_nCurrentDepth]) + nPos += nIntervalCount-1 - m_pnPreParentCount[m_nCurrentDepth]; + bool bRet = nPos && nPos % (nIntervalCount-1) == 0; + if(!nPos && !m_pnPreParentCount[m_nCurrentDepth] + && m_pnPositions[m_nCurrentDepth-1]==-1 ) + bRet = true; + return bRet; +} + +bool EquidistantTickIter::gotoFirst() +{ + if( m_nMaxDepth<0 ) + return false; + if( !m_nTickCount ) + return false; + + for(sal_Int32 nDepth = 0; nDepth<=m_nMaxDepth ;nDepth++ ) + m_pnPositions[nDepth] = -1; + + m_nCurrentPos = 0; + m_nCurrentDepth = getStartDepth(); + m_pnPositions[m_nCurrentDepth] = 0; + return true; +} + +bool EquidistantTickIter::gotoNext() +{ + if( m_nCurrentPos < 0 ) + return false; + m_nCurrentPos++; + + if( m_nCurrentPos >= m_nTickCount ) + return false; + + if( m_nCurrentDepth==m_nMaxDepth && isAtLastPartTick() ) + { + do + { + m_pbIntervalFinished[m_nCurrentDepth] = true; + m_nCurrentDepth--; + } + while( m_nCurrentDepth && isAtLastPartTick() ); + } + else if( m_nCurrentDepth<m_nMaxDepth ) + { + do + { + m_nCurrentDepth++; + } + while( m_nCurrentDepth<m_nMaxDepth ); + } + m_pbIntervalFinished[m_nCurrentDepth] = false; + m_pnPositions[m_nCurrentDepth] = m_pnPositions[m_nCurrentDepth]+1; + return true; +} + +bool EquidistantTickIter::gotoIndex( sal_Int32 nTickIndex ) +{ + if( nTickIndex < 0 ) + return false; + if( nTickIndex >= m_nTickCount ) + return false; + + if( nTickIndex < m_nCurrentPos ) + if( !gotoFirst() ) + return false; + + while( nTickIndex > m_nCurrentPos ) + if( !gotoNext() ) + return false; + + return true; +} + +sal_Int32 EquidistantTickIter::getCurrentIndex() const +{ + return m_nCurrentPos; +} +sal_Int32 EquidistantTickIter::getMaxIndex() const +{ + return m_nTickCount-1; +} + +double* EquidistantTickIter::nextValue() +{ + if( gotoNext() ) + { + m_fCurrentValue = getTickValue(m_nCurrentDepth, m_pnPositions[m_nCurrentDepth]); + return &m_fCurrentValue; + } + return NULL; +} + +TickInfo* EquidistantTickIter::nextInfo() +{ + if( m_pInfoTicks && gotoNext() && + static_cast< sal_Int32 >( + (*m_pInfoTicks)[m_nCurrentDepth].size()) > m_pnPositions[m_nCurrentDepth] ) + { + return &(*m_pInfoTicks)[m_nCurrentDepth][m_pnPositions[m_nCurrentDepth]]; + } + return NULL; +} + +//............................................................................. +} //namespace chart +//............................................................................. diff --git a/chart2/source/view/axes/TickmarkHelper.hxx b/chart2/source/view/axes/Tickmarks_Equidistant.hxx index 78fc2fe1c502..836a93d28db2 100644 --- a/chart2/source/view/axes/TickmarkHelper.hxx +++ b/chart2/source/view/axes/Tickmarks_Equidistant.hxx @@ -24,19 +24,10 @@ * for a copy of the LGPLv3 License. * ************************************************************************/ -#ifndef _CHART2_TICKMARKHELPER_HXX -#define _CHART2_TICKMARKHELPER_HXX +#ifndef _CHART2_TICKMARKS_EQUIDISTANT_HXX +#define _CHART2_TICKMARKS_EQUIDISTANT_HXX -#include "TickmarkProperties.hxx" -#include "VAxisProperties.hxx" -#include <com/sun/star/chart2/ExplicitIncrementData.hpp> -#include <com/sun/star/chart2/ExplicitScaleData.hpp> -#include <basegfx/vector/b2dvector.hxx> -#include <com/sun/star/drawing/PointSequenceSequence.hpp> -#include <com/sun/star/drawing/XShape.hpp> -#include <com/sun/star/uno/Sequence.h> - -#include <vector> +#include "Tickmarks.hxx" //............................................................................. namespace chart @@ -48,57 +39,15 @@ using ::basegfx::B2DVector; /** */ -struct TickInfo -{ - double fScaledTickValue; - double fUnscaledTickValue; - - ::basegfx::B2DVector aTickScreenPosition; - bool bPaintIt; - - ::com::sun::star::uno::Reference< - ::com::sun::star::drawing::XShape > xTextShape; - - rtl::OUString aText;//used only for complex categories so far - sal_Int32 nFactorForLimitedTextWidth;//categories in higher levels of complex categories can have more place than a single simple category - -//methods: - TickInfo(); - void updateUnscaledValue( const ::com::sun::star::uno::Reference< - ::com::sun::star::chart2::XScaling >& xInverseScaling ); - - sal_Int32 getScreenDistanceBetweenTicks( const TickInfo& rOherTickInfo ) const; -}; -class TickIter -{ -public: - virtual ~TickIter(){}; - virtual TickInfo* firstInfo()=0; - virtual TickInfo* nextInfo()=0; -}; - -class PureTickIter : public TickIter -{ -public: - PureTickIter( ::std::vector< TickInfo >& rTickInfoVector ); - virtual ~PureTickIter(); - virtual TickInfo* firstInfo(); - virtual TickInfo* nextInfo(); - -private: - ::std::vector< TickInfo >& m_rTickVector; - ::std::vector< TickInfo >::iterator m_aTickIter; -}; - class EquidistantTickIter : public TickIter { public: EquidistantTickIter( const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< double > >& rTicks - , const ::com::sun::star::chart2::ExplicitIncrementData& rIncrement + , const ExplicitIncrementData& rIncrement , sal_Int32 nMinDepth=0, sal_Int32 nMaxDepth=-1 ); EquidistantTickIter( ::std::vector< ::std::vector< TickInfo > >& rTickInfos - , const ::com::sun::star::chart2::ExplicitIncrementData& rIncrement + , const ExplicitIncrementData& rIncrement , sal_Int32 nMinDepth=0, sal_Int32 nMaxDepth=-1 ); virtual ~EquidistantTickIter(); @@ -152,7 +101,7 @@ private: //member const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< double > >* m_pSimpleTicks; ::std::vector< ::std::vector< TickInfo > >* m_pInfoTicks; - const ::com::sun::star::chart2::ExplicitIncrementData& m_rIncrement; + const ExplicitIncrementData& m_rIncrement; //iteration from m_nMinDepth to m_nMaxDepth sal_Int32 m_nMinDepth; sal_Int32 m_nMaxDepth; @@ -166,24 +115,21 @@ private: //member double m_fCurrentValue; }; -class TickmarkHelper +class EquidistantTickFactory { public: - TickmarkHelper( - const ::com::sun::star::chart2::ExplicitScaleData& rScale - , const ::com::sun::star::chart2::ExplicitIncrementData& rIncrement ); - virtual ~TickmarkHelper(); + EquidistantTickFactory( + const ExplicitScaleData& rScale + , const ExplicitIncrementData& rIncrement ); + ~EquidistantTickFactory(); - virtual TickmarkHelper* createShiftedTickmarkHelper() const; + void getAllTicks( ::std::vector< ::std::vector< TickInfo > >& rAllTickInfos ) const; + void getAllTicksShifted( ::std::vector< ::std::vector< TickInfo > >& rAllTickInfos ) const; - void getAllTicks( ::std::vector< ::std::vector< TickInfo > >& rAllTickInfos ) const; - void getAllTicksShifted( ::std::vector< ::std::vector< TickInfo > >& rAllTickInfos ) const; + static double getMinimumAtIncrement( double fMin, const ExplicitIncrementData& rIncrement ); + static double getMaximumAtIncrement( double fMax, const ExplicitIncrementData& rIncrement ); - // - static double getMinimumAtIncrement( double fMin, const ::com::sun::star::chart2::ExplicitIncrementData& rIncrement ); - static double getMaximumAtIncrement( double fMax, const ::com::sun::star::chart2::ExplicitIncrementData& rIncrement ); - -protected: //methods +private: //methods void addSubTicks( sal_Int32 nDepth, ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< double > >& rParentTicks ) const; @@ -192,82 +138,26 @@ protected: //methods , double fStartParentTick, double fNextParentTick ) const; sal_Int32 getMaxTickCount( sal_Int32 nDepth = 0 ) const; sal_Int32 getTickDepth() const; + bool isVisible( double fValue ) const; bool isWithinOuterBorder( double fScaledValue ) const; //all within the outer major tick marks - virtual void updateScreenValues( ::std::vector< ::std::vector< TickInfo > >& /*rAllTickInfos*/ ) const {} - -protected: //member - ::com::sun::star::chart2::ExplicitScaleData m_rScale; - ::com::sun::star::chart2::ExplicitIncrementData m_rIncrement; - +private: //member + ExplicitScaleData m_rScale; + ExplicitIncrementData m_rIncrement; ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XScaling > m_xInverseScaling; + + //minimum and maximum of the visible range after scaling + double m_fScaledVisibleMin; + double m_fScaledVisibleMax; + double* m_pfCurrentValues; //major-tick positions that may lay outside the visible range but complete partly visible intervals at the borders double m_fOuterMajorTickBorderMin; double m_fOuterMajorTickBorderMax; double m_fOuterMajorTickBorderMin_Scaled; double m_fOuterMajorTickBorderMax_Scaled; - - //minimum and maximum of the visible range after scaling - double m_fScaledVisibleMin; - double m_fScaledVisibleMax; -}; - -class TickmarkHelper_2D : public TickmarkHelper -{ -public: - TickmarkHelper_2D( - const ::com::sun::star::chart2::ExplicitScaleData& rScale - , const ::com::sun::star::chart2::ExplicitIncrementData& rIncrement - , const ::basegfx::B2DVector& rStartScreenPos, const ::basegfx::B2DVector& rEndScreenPos - , const ::basegfx::B2DVector& rAxisLineToLabelLineShift ); - //, double fStrech_SceneToScreen, double fOffset_SceneToScreen ); - virtual ~TickmarkHelper_2D(); - - virtual TickmarkHelper* createShiftedTickmarkHelper() const; - - static sal_Int32 getTickScreenDistance( TickIter& rIter ); - - void createPointSequenceForAxisMainLine( ::com::sun::star::drawing::PointSequenceSequence& rPoints ) const; - void addPointSequenceForTickLine( ::com::sun::star::drawing::PointSequenceSequence& rPoints - , sal_Int32 nSequenceIndex - , double fScaledLogicTickValue, double fInnerDirectionSign - , const TickmarkProperties& rTickmarkProperties, bool bPlaceAtLabels ) const; - ::basegfx::B2DVector getDistanceAxisTickToText( const AxisProperties& rAxisProperties - , bool bIncludeFarAwayDistanceIfSo = false - , bool bIncludeSpaceBetweenTickAndText = true ) const; - - virtual void updateScreenValues( ::std::vector< ::std::vector< TickInfo > >& rAllTickInfos ) const; - - bool isHorizontalAxis() const; - bool isVerticalAxis() const; - -protected: //methods - ::basegfx::B2DVector getTickScreenPosition2D( double fScaledLogicTickValue ) const; - -private: //member - ::basegfx::B2DVector m_aAxisStartScreenPosition2D; - ::basegfx::B2DVector m_aAxisEndScreenPosition2D; - - //labels might be posioned high or low on the border of the diagram far away from the axis - //add this vector to go from the axis line to the label line (border of the diagram) - ::basegfx::B2DVector m_aAxisLineToLabelLineShift; - - double m_fStrech_LogicToScreen; - double m_fOffset_LogicToScreen; -}; - -class TickmarkHelper_3D : public TickmarkHelper -{ -public: - TickmarkHelper_3D( - const ::com::sun::star::chart2::ExplicitScaleData& rScale - , const ::com::sun::star::chart2::ExplicitIncrementData& rIncrement ); - virtual ~TickmarkHelper_3D(); - - virtual TickmarkHelper* createShiftedTickmarkHelper() const; }; //............................................................................. diff --git a/chart2/source/view/axes/VAxisBase.cxx b/chart2/source/view/axes/VAxisBase.cxx index 0159fb20cad6..fb193ec93a95 100644 --- a/chart2/source/view/axes/VAxisBase.cxx +++ b/chart2/source/view/axes/VAxisBase.cxx @@ -31,7 +31,7 @@ #include "VAxisBase.hxx" #include "ShapeFactory.hxx" #include "CommonConverters.hxx" -#include "TickmarkHelper.hxx" +#include "Tickmarks.hxx" #include "macros.hxx" // header for define DBG_ASSERT @@ -70,7 +70,7 @@ sal_Int32 VAxisBase::getDimensionCount() return m_nDimension; } -void SAL_CALL VAxisBase::initAxisLabelProperties( const ::com::sun::star::awt::Size& rFontReferenceSize +void VAxisBase::initAxisLabelProperties( const ::com::sun::star::awt::Size& rFontReferenceSize , const ::com::sun::star::awt::Rectangle& rMaximumSpaceForLabels ) { m_aAxisLabelProperties.m_aFontReferenceSize = rFontReferenceSize; @@ -106,6 +106,15 @@ void SAL_CALL VAxisBase::initAxisLabelProperties( const ::com::sun::star::awt::S m_aAxisLabelProperties.eStaggering = SIDE_BY_SIDE; } +bool VAxisBase::isDateAxis() const +{ + return AxisType::DATE == m_aScale.AxisType; +} +bool VAxisBase::isComplexCategoryAxis() const +{ + return m_aAxisProperties.m_bComplexCategories && m_bUseTextLabels; +} + void VAxisBase::recordMaximumTextSize( const Reference< drawing::XShape >& xShape, double fRotationAngleDegree ) { if( m_bRecordMaximumTextSize && xShape.is() ) @@ -130,7 +139,7 @@ void VAxisBase::setExrtaLinePositionAtOtherAxis( const double& fCrossingAt ) m_aAxisProperties.m_pfExrtaLinePositionAtOtherAxis = new double(fCrossingAt); } -sal_Bool SAL_CALL VAxisBase::isAnythingToDraw() +sal_Bool VAxisBase::isAnythingToDraw() { if( !m_aAxisProperties.m_xAxisModel.is() ) return false; @@ -150,7 +159,7 @@ sal_Bool SAL_CALL VAxisBase::isAnythingToDraw() return true; } -void SAL_CALL VAxisBase::setExplicitScaleAndIncrement( +void VAxisBase::setExplicitScaleAndIncrement( const ExplicitScaleData& rScale , const ExplicitIncrementData& rIncrement ) throw (uno::RuntimeException) @@ -162,8 +171,11 @@ void SAL_CALL VAxisBase::setExplicitScaleAndIncrement( void VAxisBase::createAllTickInfos( ::std::vector< ::std::vector< TickInfo > >& rAllTickInfos ) { - std::auto_ptr< TickmarkHelper > apTickmarkHelper( this->createTickmarkHelper() ); - apTickmarkHelper->getAllTicks( rAllTickInfos ); + std::auto_ptr< TickFactory > apTickFactory( this->createTickFactory() ); + if( m_aScale.ShiftedCategoryPosition ) + apTickFactory->getAllTicksShifted( rAllTickInfos ); + else + apTickFactory->getAllTicks( rAllTickInfos ); } bool VAxisBase::prepareShapeCreation() @@ -244,7 +256,7 @@ void VAxisBase::updateUnscaledValuesAtTicks( TickIter& rIter ) for( TickInfo* pTickInfo = rIter.firstInfo() ; pTickInfo; pTickInfo = rIter.nextInfo() ) { - pTickInfo->updateUnscaledValue( xInverseScaling ); + //xxxxx pTickInfo->updateUnscaledValue( xInverseScaling ); } } diff --git a/chart2/source/view/axes/VAxisBase.hxx b/chart2/source/view/axes/VAxisBase.hxx index ba7e94b2070c..e51e2d8dbd9b 100644 --- a/chart2/source/view/axes/VAxisBase.hxx +++ b/chart2/source/view/axes/VAxisBase.hxx @@ -29,7 +29,7 @@ #include "VAxisOrGridBase.hxx" #include "VAxisProperties.hxx" -#include "TickmarkHelper.hxx" +#include "Tickmarks.hxx" #include <com/sun/star/util/XNumberFormatsSupplier.hpp> //............................................................................. @@ -52,18 +52,18 @@ public: sal_Int32 getDimensionCount(); - virtual void SAL_CALL createMaximumLabels()=0; - virtual void SAL_CALL createLabels()=0; - virtual void SAL_CALL updatePositions()=0; + virtual void createMaximumLabels()=0; + virtual void createLabels()=0; + virtual void updatePositions()=0; - virtual sal_Bool SAL_CALL isAnythingToDraw(); - virtual void SAL_CALL initAxisLabelProperties( + virtual sal_Bool isAnythingToDraw(); + virtual void initAxisLabelProperties( const ::com::sun::star::awt::Size& rFontReferenceSize , const ::com::sun::star::awt::Rectangle& rMaximumSpaceForLabels ); - virtual void SAL_CALL setExplicitScaleAndIncrement( - const ::com::sun::star::chart2::ExplicitScaleData& rScale - , const ::com::sun::star::chart2::ExplicitIncrementData& rIncrement ) + virtual void setExplicitScaleAndIncrement( + const ExplicitScaleData& rScale + , const ExplicitIncrementData& rIncrement ) throw (::com::sun::star::uno::RuntimeException); virtual sal_Int32 estimateMaximumAutoMainIncrementCount(); @@ -83,6 +83,9 @@ protected: //methods ::com::sun::star::drawing::XShape >& xShape , double fRotationAngleDegree ); + bool isDateAxis() const; + bool isComplexCategoryAxis() const; + protected: //member ::com::sun::star::uno::Reference< ::com::sun::star::util::XNumberFormatsSupplier > m_xNumberFormatsSupplier; AxisProperties m_aAxisProperties; diff --git a/chart2/source/view/axes/VAxisOrGridBase.cxx b/chart2/source/view/axes/VAxisOrGridBase.cxx index f2e2e90c1045..715da4972390 100644 --- a/chart2/source/view/axes/VAxisOrGridBase.cxx +++ b/chart2/source/view/axes/VAxisOrGridBase.cxx @@ -31,7 +31,7 @@ #include "VAxisOrGridBase.hxx" #include "ShapeFactory.hxx" #include "CommonConverters.hxx" -#include "TickmarkHelper.hxx" +#include "Tickmarks.hxx" // header for define DBG_ASSERT #include <tools/debug.hxx> @@ -57,7 +57,7 @@ VAxisOrGridBase::~VAxisOrGridBase() { } -void SAL_CALL VAxisOrGridBase::setExplicitScaleAndIncrement( +void VAxisOrGridBase::setExplicitScaleAndIncrement( const ExplicitScaleData& rScale , const ExplicitIncrementData& rIncrement ) throw (uno::RuntimeException) @@ -79,18 +79,9 @@ void VAxisOrGridBase::set3DWallPositions( CuboidPlanePosition eLeftWallPos, Cubo m_eBottomPos = eBottomPos; } -TickmarkHelper* VAxisOrGridBase::createTickmarkHelper() +TickFactory* VAxisOrGridBase::createTickFactory() { - TickmarkHelper* pRet=NULL; - if( 2==m_nDimension ) - { - pRet = new TickmarkHelper( m_aScale, m_aIncrement ); - } - else - { - pRet = new TickmarkHelper_3D( m_aScale, m_aIncrement ); - } - return pRet; + return new TickFactory( m_aScale, m_aIncrement ); } //............................................................................. diff --git a/chart2/source/view/axes/VAxisOrGridBase.hxx b/chart2/source/view/axes/VAxisOrGridBase.hxx index 35b32b2b1c03..9091aabf0dc5 100644 --- a/chart2/source/view/axes/VAxisOrGridBase.hxx +++ b/chart2/source/view/axes/VAxisOrGridBase.hxx @@ -29,9 +29,8 @@ #include "PlotterBase.hxx" #include "ThreeDHelper.hxx" +#include "chartview/ExplicitScaleValues.hxx" -#include <com/sun/star/chart2/ExplicitIncrementData.hpp> -#include <com/sun/star/chart2/ExplicitScaleData.hpp> #include <com/sun/star/drawing/HomogenMatrix.hpp> #include <com/sun/star/drawing/XShapes.hpp> #include <com/sun/star/lang/XMultiServiceFactory.hpp> @@ -46,7 +45,7 @@ namespace chart /** */ class ShapeFactory; -class TickmarkHelper; +class TickFactory; class VAxisOrGridBase : public PlotterBase { @@ -55,22 +54,22 @@ public: virtual ~VAxisOrGridBase(); virtual void setTransformationSceneToScreen( const ::com::sun::star::drawing::HomogenMatrix& rMatrix ); - virtual void SAL_CALL setExplicitScaleAndIncrement( - const ::com::sun::star::chart2::ExplicitScaleData& rScale - , const ::com::sun::star::chart2::ExplicitIncrementData& rIncrement ) + virtual void setExplicitScaleAndIncrement( + const ExplicitScaleData& rScale + , const ExplicitIncrementData& rIncrement ) throw (::com::sun::star::uno::RuntimeException); void set3DWallPositions( CuboidPlanePosition eLeftWallPos, CuboidPlanePosition eBackWallPos, CuboidPlanePosition eBottomPos ); - virtual TickmarkHelper* createTickmarkHelper(); + virtual TickFactory* createTickFactory(); //------------------------------------------------------------------------- //------------------------------------------------------------------------- protected: //member - ::com::sun::star::chart2::ExplicitScaleData m_aScale; - ::com::sun::star::chart2::ExplicitIncrementData m_aIncrement; - sal_Int32 m_nDimensionIndex; + ExplicitScaleData m_aScale; + ExplicitIncrementData m_aIncrement; + sal_Int32 m_nDimensionIndex; - ::basegfx::B3DHomMatrix m_aMatrixScreenToScene; + ::basegfx::B3DHomMatrix m_aMatrixScreenToScene; CuboidPlanePosition m_eLeftWallPos; CuboidPlanePosition m_eBackWallPos; diff --git a/chart2/source/view/axes/VAxisProperties.cxx b/chart2/source/view/axes/VAxisProperties.cxx index 63c98141991b..9f710d926e0c 100644 --- a/chart2/source/view/axes/VAxisProperties.cxx +++ b/chart2/source/view/axes/VAxisProperties.cxx @@ -182,7 +182,6 @@ AxisProperties::AxisProperties( const uno::Reference< XAxis >& xAxisModel , m_pfExrtaLinePositionAtOtherAxis(NULL) , m_bCrossingAxisHasReverseDirection(false) , m_bCrossingAxisIsCategoryAxes(false) - , m_bAxisBetweenCategories(false) , m_fLabelDirectionSign(1.0) , m_fInnerDirectionSign(1.0) , m_aLabelAlignment(LABEL_ALIGN_RIGHT_TOP) @@ -212,7 +211,6 @@ AxisProperties::AxisProperties( const AxisProperties& rAxisProperties ) , m_pfExrtaLinePositionAtOtherAxis( NULL ) , m_bCrossingAxisHasReverseDirection( rAxisProperties.m_bCrossingAxisHasReverseDirection ) , m_bCrossingAxisIsCategoryAxes( rAxisProperties.m_bCrossingAxisIsCategoryAxes ) - , m_bAxisBetweenCategories( rAxisProperties.m_bAxisBetweenCategories ) , m_fLabelDirectionSign( rAxisProperties.m_fLabelDirectionSign ) , m_fInnerDirectionSign( rAxisProperties.m_fInnerDirectionSign ) , m_aLabelAlignment( rAxisProperties.m_aLabelAlignment ) @@ -279,11 +277,7 @@ void AxisProperties::initAxisPositioning( const uno::Reference< beans::XProperty xAxisProp->getPropertyValue(C2U( "CrossoverValue" )) >>= fValue; if( m_bCrossingAxisIsCategoryAxes ) - { fValue = ::rtl::math::round(fValue); - if( m_bAxisBetweenCategories ) - fValue-=0.5; - } m_pfMainLinePositionAtOtherAxis = new double(fValue); } else if( ::com::sun::star::chart::ChartAxisPosition_ZERO == m_eCrossoverType ) @@ -317,8 +311,17 @@ void AxisProperties::init( bool bCartesian ) if( m_nDimensionIndex<2 ) initAxisPositioning( xProp ); + ScaleData aScaleData = m_xAxisModel->getScaleData(); + if( m_nDimensionIndex==0 ) + AxisHelper::checkDateAxis( aScaleData, m_pExplicitCategoriesProvider, bCartesian ); + m_nAxisType = aScaleData.AxisType; + if( bCartesian ) { + if( m_nDimensionIndex == 0 && m_nAxisType == AxisType::CATEGORY + && m_pExplicitCategoriesProvider && m_pExplicitCategoriesProvider->hasComplexCategories() ) + m_bComplexCategories = true; + if( ::com::sun::star::chart::ChartAxisPosition_END == m_eCrossoverType ) m_fInnerDirectionSign = m_bCrossingAxisHasReverseDirection ? 1 : -1; else @@ -360,10 +363,6 @@ void AxisProperties::init( bool bCartesian ) //init display labels xProp->getPropertyValue( C2U( "DisplayLabels" ) ) >>= m_bDisplayLabels; - //init categories - ScaleData aScaleData = m_xAxisModel->getScaleData(); - m_nAxisType = aScaleData.AxisType; - //init TickmarkProperties xProp->getPropertyValue( C2U( "MajorTickmarks" ) ) >>= m_nMajorTickmarks; xProp->getPropertyValue( C2U( "MinorTickmarks" ) ) >>= m_nMinorTickmarks; diff --git a/chart2/source/view/axes/VAxisProperties.hxx b/chart2/source/view/axes/VAxisProperties.hxx index 5b6bfe98f777..69e0edb82730 100644 --- a/chart2/source/view/axes/VAxisProperties.hxx +++ b/chart2/source/view/axes/VAxisProperties.hxx @@ -111,7 +111,6 @@ struct AxisProperties bool m_bCrossingAxisHasReverseDirection; bool m_bCrossingAxisIsCategoryAxes; - bool m_bAxisBetweenCategories; //this direction is used to indicate in which direction the labels are to be drawn double m_fLabelDirectionSign; diff --git a/chart2/source/view/axes/VCartesianAxis.cxx b/chart2/source/view/axes/VCartesianAxis.cxx index c17e56ce6bc5..5a3ee4b78500 100644 --- a/chart2/source/view/axes/VCartesianAxis.cxx +++ b/chart2/source/view/axes/VCartesianAxis.cxx @@ -36,11 +36,12 @@ #include "macros.hxx" #include "ViewDefines.hxx" #include "PropertyMapper.hxx" -#include "chartview/NumberFormatterWrapper.hxx" +#include "NumberFormatterWrapper.hxx" #include "LabelPositionHelper.hxx" #include "TrueGuard.hxx" #include "BaseGFXHelper.hxx" #include "AxisHelper.hxx" +#include "Tickmarks_Equidistant.hxx" #include <rtl/math.hxx> #include <tools/color.hxx> @@ -178,7 +179,7 @@ void removeShapesAtWrongRhythm( TickIter& rIter } } -class EquidistantLabelIterator : public EquidistantTickIter +class LabelIterator : public TickIter { //this Iterator iterates over existing text labels @@ -192,39 +193,36 @@ class EquidistantLabelIterator : public EquidistantTickIter //we iterate through all labels public: - EquidistantLabelIterator( ::std::vector< ::std::vector< TickInfo > >& rTickInfos - , const ::com::sun::star::chart2::ExplicitIncrementData& rIncrement + LabelIterator( ::std::vector< TickInfo >& rTickInfoVector , const AxisLabelStaggering eAxisLabelStaggering - , bool bInnerLine - , sal_Int32 nMinDepth=0, sal_Int32 nMaxDepth=-1 ); + , bool bInnerLine ); virtual TickInfo* firstInfo(); virtual TickInfo* nextInfo(); private: //methods - EquidistantLabelIterator(); + LabelIterator(); private: //member + PureTickIter m_aPureTickIter; const AxisLabelStaggering m_eAxisLabelStaggering; - bool m_bInnerLine; + bool m_bInnerLine; }; -EquidistantLabelIterator::EquidistantLabelIterator( ::std::vector< ::std::vector< TickInfo > >& rTickInfos - , const ::com::sun::star::chart2::ExplicitIncrementData& rIncrement +LabelIterator::LabelIterator( ::std::vector< TickInfo >& rTickInfoVector , const AxisLabelStaggering eAxisLabelStaggering - , bool bInnerLine - , sal_Int32 nMinDepth, sal_Int32 nMaxDepth ) - : EquidistantTickIter( rTickInfos, rIncrement, nMinDepth, nMaxDepth ) + , bool bInnerLine ) + : m_aPureTickIter( rTickInfoVector ) , m_eAxisLabelStaggering(eAxisLabelStaggering) , m_bInnerLine(bInnerLine) { } -TickInfo* EquidistantLabelIterator::firstInfo() +TickInfo* LabelIterator::firstInfo() { - TickInfo* pTickInfo = EquidistantTickIter::firstInfo(); + TickInfo* pTickInfo = m_aPureTickIter.firstInfo(); while( pTickInfo && !pTickInfo->xTextShape.is() ) - pTickInfo = EquidistantTickIter::nextInfo(); + pTickInfo = m_aPureTickIter.nextInfo(); if(!pTickInfo) return NULL; if( (STAGGER_EVEN==m_eAxisLabelStaggering && m_bInnerLine) @@ -234,7 +232,7 @@ TickInfo* EquidistantLabelIterator::firstInfo() { //skip first label do - pTickInfo = EquidistantTickIter::nextInfo(); + pTickInfo = m_aPureTickIter.nextInfo(); while( pTickInfo && !pTickInfo->xTextShape.is() ); } if(!pTickInfo) @@ -242,12 +240,12 @@ TickInfo* EquidistantLabelIterator::firstInfo() return pTickInfo; } -TickInfo* EquidistantLabelIterator::nextInfo() +TickInfo* LabelIterator::nextInfo() { TickInfo* pTickInfo = NULL; //get next label do - pTickInfo = EquidistantTickIter::nextInfo(); + pTickInfo = m_aPureTickIter.nextInfo(); while( pTickInfo && !pTickInfo->xTextShape.is() ); if( STAGGER_EVEN==m_eAxisLabelStaggering @@ -255,7 +253,7 @@ TickInfo* EquidistantLabelIterator::nextInfo() { //skip one label do - pTickInfo = EquidistantTickIter::nextInfo(); + pTickInfo = m_aPureTickIter.nextInfo(); while( pTickInfo && !pTickInfo->xTextShape.is() ); } return pTickInfo; @@ -362,64 +360,61 @@ bool lcl_hasWordBreak( const Reference< drawing::XShape >& rxShape ) return false; } -class MaxLabelEquidistantTickIter : public EquidistantTickIter +class MaxLabelTickIter : public TickIter { //iterate over first two and last two labels and the longest label public: - MaxLabelEquidistantTickIter( ::std::vector< ::std::vector< TickInfo > >& rTickInfos - , const ::com::sun::star::chart2::ExplicitIncrementData& rIncrement + MaxLabelTickIter( ::std::vector< TickInfo >& rTickInfoVector , sal_Int32 nLongestLabelIndex ); - virtual ~MaxLabelEquidistantTickIter(); + virtual ~MaxLabelTickIter(); - virtual TickInfo* nextInfo(); + virtual TickInfo* firstInfo(); + virtual TickInfo* nextInfo(); private: - sal_Int32 m_nLongestLabelIndex; + ::std::vector< TickInfo >& m_rTickInfoVector; + ::std::vector< sal_Int32 > m_aValidIndices; + sal_Int32 m_nCurrentIndex; }; -MaxLabelEquidistantTickIter::MaxLabelEquidistantTickIter( ::std::vector< ::std::vector< TickInfo > >& rTickInfos - , const ::com::sun::star::chart2::ExplicitIncrementData& rIncrement +MaxLabelTickIter::MaxLabelTickIter( ::std::vector< TickInfo >& rTickInfoVector , sal_Int32 nLongestLabelIndex ) - : EquidistantTickIter( rTickInfos, rIncrement, 0//nMinDepth - , 0//nMaxDepth - ) - , m_nLongestLabelIndex( nLongestLabelIndex ) + : m_rTickInfoVector(rTickInfoVector) + , m_nCurrentIndex(0) { - sal_Int32 nMaxIndex = getMaxIndex(); - - //ensure correct value: - if( m_nLongestLabelIndex<0 || m_nLongestLabelIndex>nMaxIndex) - m_nLongestLabelIndex = 0; - - //last label is checked anyhow - if( m_nLongestLabelIndex==nMaxIndex ) - m_nLongestLabelIndex = 0; - //label before last is checked anyhow - if( m_nLongestLabelIndex+1==nMaxIndex ) - m_nLongestLabelIndex = 0; + sal_Int32 nMaxIndex = m_rTickInfoVector.size()-1; + if( nLongestLabelIndex<0 || nLongestLabelIndex>=nMaxIndex-1 ) + nLongestLabelIndex = 0; + + if( nMaxIndex>=0 ) + m_aValidIndices.push_back(0); + if( nMaxIndex>=1 ) + m_aValidIndices.push_back(1); + if( nLongestLabelIndex>1 ) + m_aValidIndices.push_back(nLongestLabelIndex); + if( nMaxIndex > 2 ) + m_aValidIndices.push_back(nMaxIndex-1); + if( nMaxIndex > 1 ) + m_aValidIndices.push_back(nMaxIndex); } -MaxLabelEquidistantTickIter::~MaxLabelEquidistantTickIter() +MaxLabelTickIter::~MaxLabelTickIter() { } -TickInfo* MaxLabelEquidistantTickIter::nextInfo() +TickInfo* MaxLabelTickIter::firstInfo() { - sal_Int32 nCurrentPos = getCurrentIndex(); - sal_Int32 nMaxIndex = getMaxIndex(); - if( nCurrentPos>0 ) - { - if( m_nLongestLabelIndex>1 && nCurrentPos<m_nLongestLabelIndex ) - gotoIndex( m_nLongestLabelIndex-1 ) ; - else - { - if( nMaxIndex>3 && nCurrentPos<nMaxIndex-1 ) - gotoIndex( nMaxIndex-2 ); - else if( nMaxIndex>2 && nCurrentPos<nMaxIndex ) - gotoIndex( nMaxIndex-1 ); - } - } + m_nCurrentIndex = 0; + if( m_nCurrentIndex < static_cast<sal_Int32>(m_aValidIndices.size()) ) + return &m_rTickInfoVector[m_aValidIndices[m_nCurrentIndex]]; + return 0; +} - return EquidistantTickIter::nextInfo(); +TickInfo* MaxLabelTickIter::nextInfo() +{ + m_nCurrentIndex++; + if( m_nCurrentIndex>=0 && m_nCurrentIndex<static_cast<sal_Int32>(m_aValidIndices.size()) ) + return &m_rTickInfoVector[m_aValidIndices[m_nCurrentIndex]]; + return 0; } bool VCartesianAxis::isBreakOfLabelsAllowed( const AxisLabelProperties& rAxisLabelProperties @@ -489,27 +484,27 @@ void VCartesianAxis::createAllTickInfosFromComplexCategories( ::std::vector< ::s std::vector< ComplexCategory >::const_iterator aEnd(aComplexCategories.end()); for(;aIt!=aEnd;++aIt) { - TickInfo aTickInfo; + TickInfo aTickInfo(0); ComplexCategory aCat(*aIt); sal_Int32 nCount = aCat.Count; - if( nCatIndex + 0.5 + nCount >= m_aScale.Maximum ) + if( nCatIndex + 1.0 + nCount >= m_aScale.Maximum ) { - nCount = static_cast<sal_Int32>(m_aScale.Maximum - 0.5 - nCatIndex); + nCount = static_cast<sal_Int32>(m_aScale.Maximum - 1.0 - nCatIndex); if( nCount <= 0 ) nCount = 1; } - aTickInfo.fScaledTickValue = nCatIndex + 0.5 + nCount/2.0; + aTickInfo.fScaledTickValue = nCatIndex + 1.0 + nCount/2.0; aTickInfo.nFactorForLimitedTextWidth = nCount; aTickInfo.aText = aCat.Text; aTickInfoVector.push_back(aTickInfo); nCatIndex += nCount; - if( nCatIndex + 0.5 >= m_aScale.Maximum ) + if( nCatIndex + 1.0 >= m_aScale.Maximum ) break; } rAllTickInfos.push_back(aTickInfoVector); } } - else //bShiftedPosition==true + else //bShiftedPosition==false { rAllTickInfos.clear(); sal_Int32 nLevel=0; @@ -523,19 +518,19 @@ void VCartesianAxis::createAllTickInfosFromComplexCategories( ::std::vector< ::s std::vector< ComplexCategory >::const_iterator aEnd(aComplexCategories.end()); for(;aIt!=aEnd;++aIt) { - TickInfo aTickInfo; + TickInfo aTickInfo(0); ComplexCategory aCat(*aIt); - aTickInfo.fScaledTickValue = nCatIndex + 0.5; + aTickInfo.fScaledTickValue = nCatIndex + 1.0; aTickInfoVector.push_back(aTickInfo); nCatIndex += aCat.Count; - if( nCatIndex + 0.5 > m_aScale.Maximum ) + if( nCatIndex + 1.0 > m_aScale.Maximum ) break; } //fill up with single ticks until maximum scale - while( nCatIndex + 0.5 < m_aScale.Maximum ) + while( nCatIndex + 1.0 < m_aScale.Maximum ) { - TickInfo aTickInfo; - aTickInfo.fScaledTickValue = nCatIndex + 0.5; + TickInfo aTickInfo(0); + aTickInfo.fScaledTickValue = nCatIndex + 1.0; aTickInfoVector.push_back(aTickInfo); nCatIndex ++; if( nLevel>0 ) @@ -543,7 +538,7 @@ void VCartesianAxis::createAllTickInfosFromComplexCategories( ::std::vector< ::s } //add an additional tick at the end { - TickInfo aTickInfo; + TickInfo aTickInfo(0); aTickInfo.fScaledTickValue = m_aScale.Maximum; aTickInfoVector.push_back(aTickInfo); } @@ -554,7 +549,7 @@ void VCartesianAxis::createAllTickInfosFromComplexCategories( ::std::vector< ::s void VCartesianAxis::createAllTickInfos( ::std::vector< ::std::vector< TickInfo > >& rAllTickInfos ) { - if( m_aAxisProperties.m_bComplexCategories && m_bUseTextLabels ) + if( isComplexCategoryAxis() ) createAllTickInfosFromComplexCategories( rAllTickInfos, false ); else VAxisBase::createAllTickInfos(rAllTickInfos); @@ -562,21 +557,13 @@ void VCartesianAxis::createAllTickInfos( ::std::vector< ::std::vector< TickInfo ::std::auto_ptr< TickIter > VCartesianAxis::createLabelTickIterator( sal_Int32 nTextLevel ) { - if( m_aAxisProperties.m_bComplexCategories && m_bUseTextLabels ) - { - if( nTextLevel>=0 && nTextLevel < static_cast< sal_Int32 >(m_aAllTickInfos.size()) ) - return ::std::auto_ptr< TickIter >( new PureTickIter( m_aAllTickInfos[nTextLevel] ) ); - } - else - { - if(nTextLevel==0) - return ::std::auto_ptr< TickIter >( new EquidistantTickIter( m_aAllTickInfos, m_aIncrement, 0, 0 ) ); - } + if( nTextLevel>=0 && nTextLevel < static_cast< sal_Int32 >(m_aAllTickInfos.size()) ) + return ::std::auto_ptr< TickIter >( new PureTickIter( m_aAllTickInfos[nTextLevel] ) ); return ::std::auto_ptr< TickIter >(); } ::std::auto_ptr< TickIter > VCartesianAxis::createMaximumLabelTickIterator( sal_Int32 nTextLevel ) { - if( m_aAxisProperties.m_bComplexCategories && m_bUseTextLabels ) + if( isComplexCategoryAxis() || isDateAxis() ) { return createLabelTickIterator( nTextLevel ); //mmmm maybe todo: create less than all texts here } @@ -584,8 +571,11 @@ void VCartesianAxis::createAllTickInfos( ::std::vector< ::std::vector< TickInfo { if(nTextLevel==0) { - sal_Int32 nLongestLabelIndex = m_bUseTextLabels ? this->getIndexOfLongestLabel( m_aTextLabels ) : 0; - return ::std::auto_ptr< TickIter >( new MaxLabelEquidistantTickIter( m_aAllTickInfos, m_aIncrement, nLongestLabelIndex ) ); + if( !m_aAllTickInfos.empty() ) + { + sal_Int32 nLongestLabelIndex = m_bUseTextLabels ? this->getIndexOfLongestLabel( m_aTextLabels ) : 0; + return ::std::auto_ptr< TickIter >( new MaxLabelTickIter( m_aAllTickInfos[0], nLongestLabelIndex ) ); + } } } return ::std::auto_ptr< TickIter >(); @@ -594,7 +584,7 @@ void VCartesianAxis::createAllTickInfos( ::std::vector< ::std::vector< TickInfo sal_Int32 VCartesianAxis::getTextLevelCount() const { sal_Int32 nTextLevelCount = 1; - if( m_aAxisProperties.m_bComplexCategories && m_bUseTextLabels ) + if( isComplexCategoryAxis() ) nTextLevelCount = m_aAxisProperties.m_pExplicitCategoriesProvider->getCategoryLevelCount(); return nTextLevelCount; } @@ -603,7 +593,7 @@ bool VCartesianAxis::createTextShapes( const Reference< drawing::XShapes >& xTarget , TickIter& rTickIter , AxisLabelProperties& rAxisLabelProperties - , TickmarkHelper_2D* pTickmarkHelper + , TickFactory_2D* pTickFactory , sal_Int32 nScreenDistanceBetweenTicks ) { //returns true if the text shapes have been created succesfully @@ -617,10 +607,10 @@ bool VCartesianAxis::createTextShapes( FixedNumberFormatter aFixedNumberFormatter( m_xNumberFormatsSupplier, rAxisLabelProperties.nNumberFormatKey ); - const bool bIsHorizontalAxis = pTickmarkHelper->isHorizontalAxis(); - const bool bIsVerticalAxis = pTickmarkHelper->isVerticalAxis(); + const bool bIsHorizontalAxis = pTickFactory->isHorizontalAxis(); + const bool bIsVerticalAxis = pTickFactory->isVerticalAxis(); bool bIsStaggered = rAxisLabelProperties.getIsStaggered(); - B2DVector aTextToTickDistance( pTickmarkHelper->getDistanceAxisTickToText( m_aAxisProperties, true ) ); + B2DVector aTextToTickDistance( pTickFactory->getDistanceAxisTickToText( m_aAxisProperties, true ) ); sal_Int32 nLimitedSpaceForText = -1; if( isBreakOfLabelsAllowed( rAxisLabelProperties, bIsHorizontalAxis ) ) { @@ -716,7 +706,7 @@ bool VCartesianAxis::createTextShapes( } } - pTickInfo->updateUnscaledValue( xInverseScaling ); + //xxxxx pTickInfo->updateUnscaledValue( xInverseScaling ); bool bHasExtraColor=false; sal_Int32 nExtraColor=0; @@ -724,7 +714,7 @@ bool VCartesianAxis::createTextShapes( rtl::OUString aLabel; if(pCategories) { - sal_Int32 nIndex = static_cast< sal_Int32 >(pTickInfo->fUnscaledTickValue) - 1; //first category (index 0) matches with real number 1.0 + sal_Int32 nIndex = static_cast< sal_Int32 >(pTickInfo->getUnscaledTickValue()) - 1; //first category (index 0) matches with real number 1.0 if( nIndex>=0 && nIndex<pCategories->getLength() ) aLabel = (*pCategories)[nIndex]; } @@ -733,7 +723,7 @@ bool VCartesianAxis::createTextShapes( aLabel = pTickInfo->aText; } else - aLabel = aFixedNumberFormatter.getFormattedString( pTickInfo->fUnscaledTickValue, nExtraColor, bHasExtraColor ); + aLabel = aFixedNumberFormatter.getFormattedString( pTickInfo->getUnscaledTickValue(), nExtraColor, bHasExtraColor ); if(pColorAny) *pColorAny = uno::makeAny(bHasExtraColor?nExtraColor:nColor); @@ -1245,12 +1235,12 @@ void VCartesianAxis::get2DAxisMainLine( B2DVector& rStart, B2DVector& rEnd, doub } } -TickmarkHelper* VCartesianAxis::createTickmarkHelper() +TickFactory* VCartesianAxis::createTickFactory() { - return createTickmarkHelper2D(); + return createTickFactory2D(); } -TickmarkHelper_2D* VCartesianAxis::createTickmarkHelper2D() +TickFactory_2D* VCartesianAxis::createTickFactory2D() { B2DVector aStart, aEnd; this->get2DAxisMainLine( aStart, aEnd, this->getLogicValueWhereMainLineCrossesOtherAxis() ); @@ -1258,7 +1248,7 @@ TickmarkHelper_2D* VCartesianAxis::createTickmarkHelper2D() B2DVector aLabelLineStart, aLabelLineEnd; this->get2DAxisMainLine( aLabelLineStart, aLabelLineEnd, this->getLogicValueWhereLabelLineCrossesOtherAxis() ); - return new TickmarkHelper_2D( m_aScale, m_aIncrement, aStart, aEnd, aLabelLineStart-aStart ); + return new TickFactory_2D( m_aScale, m_aIncrement, aStart, aEnd, aLabelLineStart-aStart ); } void lcl_hideIdenticalScreenValues( TickIter& rTickIter ) @@ -1282,7 +1272,7 @@ void lcl_hideIdenticalScreenValues( TickIter& rTickIter ) //'hide' tickmarks with identical screen values in aAllTickInfos void VCartesianAxis::hideIdenticalScreenValues( ::std::vector< ::std::vector< TickInfo > >& rTickInfos ) const { - if( m_aAxisProperties.m_bComplexCategories && m_bUseTextLabels ) + if( isComplexCategoryAxis() || isDateAxis() ) { sal_Int32 nCount = rTickInfos.size(); for( sal_Int32 nN=0; nN<nCount; nN++ ) @@ -1328,12 +1318,12 @@ sal_Int32 VCartesianAxis::estimateMaximumAutoMainIncrementCount() return nRet; } -void VCartesianAxis::doStaggeringOfLabels( const AxisLabelProperties& rAxisLabelProperties, TickmarkHelper_2D* pTickmarkHelper2D ) +void VCartesianAxis::doStaggeringOfLabels( const AxisLabelProperties& rAxisLabelProperties, TickFactory_2D* pTickFactory2D ) { - if( !pTickmarkHelper2D ) + if( !pTickFactory2D ) return; - if( m_aAxisProperties.m_bComplexCategories && m_bUseTextLabels ) + if( isComplexCategoryAxis() ) { sal_Int32 nTextLevelCount = getTextLevelCount(); B2DVector aCummulatedLabelsDistance(0,0); @@ -1349,25 +1339,26 @@ void VCartesianAxis::doStaggeringOfLabels( const AxisLabelProperties& rAxisLabel fRotationAngleDegree = 0.0; } aCummulatedLabelsDistance += lcl_getLabelsDistance( *apTickIter.get() - , pTickmarkHelper2D->getDistanceAxisTickToText( m_aAxisProperties ) + , pTickFactory2D->getDistanceAxisTickToText( m_aAxisProperties ) , fRotationAngleDegree ); } } } else if( rAxisLabelProperties.getIsStaggered() ) { - EquidistantLabelIterator aInnerIter( m_aAllTickInfos, m_aIncrement - , rAxisLabelProperties.eStaggering, true, 0, 0 ); - EquidistantLabelIterator aOuterIter( m_aAllTickInfos, m_aIncrement - , rAxisLabelProperties.eStaggering, false, 0, 0 ); - - lcl_shiftLables( aOuterIter - , lcl_getLabelsDistance( aInnerIter - , pTickmarkHelper2D->getDistanceAxisTickToText( m_aAxisProperties ), 0.0 ) ); + if( !m_aAllTickInfos.empty() ) + { + LabelIterator aInnerIter( m_aAllTickInfos[0], rAxisLabelProperties.eStaggering, true ); + LabelIterator aOuterIter( m_aAllTickInfos[0], rAxisLabelProperties.eStaggering, false ); + + lcl_shiftLables( aOuterIter + , lcl_getLabelsDistance( aInnerIter + , pTickFactory2D->getDistanceAxisTickToText( m_aAxisProperties ), 0.0 ) ); + } } } -void SAL_CALL VCartesianAxis::createLabels() +void VCartesianAxis::createLabels() { if( !prepareShapeCreation() ) return; @@ -1376,14 +1367,14 @@ void SAL_CALL VCartesianAxis::createLabels() //create labels if( m_aAxisProperties.m_bDisplayLabels ) { - std::auto_ptr< TickmarkHelper_2D > apTickmarkHelper2D( this->createTickmarkHelper2D() ); - TickmarkHelper_2D* pTickmarkHelper2D = apTickmarkHelper2D.get(); - if( !pTickmarkHelper2D ) + std::auto_ptr< TickFactory_2D > apTickFactory2D( this->createTickFactory2D() ); + TickFactory_2D* pTickFactory2D = apTickFactory2D.get(); + if( !pTickFactory2D ) return; //----------------------------------------- //get the transformed screen values for all tickmarks in aAllTickInfos - pTickmarkHelper2D->updateScreenValues( m_aAllTickInfos ); + pTickFactory2D->updateScreenValues( m_aAllTickInfos ); //----------------------------------------- //'hide' tickmarks with identical screen values in aAllTickInfos hideIdenticalScreenValues( m_aAllTickInfos ); @@ -1400,7 +1391,7 @@ void SAL_CALL VCartesianAxis::createLabels() { if(nTextLevel==0) { - nScreenDistanceBetweenTicks = TickmarkHelper_2D::getTickScreenDistance( *apTickIter.get() ); + nScreenDistanceBetweenTicks = TickFactory_2D::getTickScreenDistance( *apTickIter.get() ); if( nTextLevelCount>1 ) nScreenDistanceBetweenTicks*=2; //the above used tick iter does contain also the sub ticks -> thus the given distance is only the half } @@ -1422,16 +1413,16 @@ void SAL_CALL VCartesianAxis::createLabels() } } AxisLabelProperties& rAxisLabelProperties = m_aAxisProperties.m_bComplexCategories ? aComplexProps : m_aAxisLabelProperties; - while( !createTextShapes( m_xTextTarget, *apTickIter.get(), rAxisLabelProperties, pTickmarkHelper2D, nScreenDistanceBetweenTicks ) ) + while( !createTextShapes( m_xTextTarget, *apTickIter.get(), rAxisLabelProperties, pTickFactory2D, nScreenDistanceBetweenTicks ) ) { }; } } - doStaggeringOfLabels( m_aAxisLabelProperties, pTickmarkHelper2D ); + doStaggeringOfLabels( m_aAxisLabelProperties, pTickFactory2D ); } } -void SAL_CALL VCartesianAxis::createMaximumLabels() +void VCartesianAxis::createMaximumLabels() { TrueGuard aRecordMaximumTextSize(m_bRecordMaximumTextSize); @@ -1442,20 +1433,20 @@ void SAL_CALL VCartesianAxis::createMaximumLabels() //create labels if( m_aAxisProperties.m_bDisplayLabels ) { - std::auto_ptr< TickmarkHelper_2D > apTickmarkHelper2D( this->createTickmarkHelper2D() ); - TickmarkHelper_2D* pTickmarkHelper2D = apTickmarkHelper2D.get(); - if( !pTickmarkHelper2D ) + std::auto_ptr< TickFactory_2D > apTickFactory2D( this->createTickFactory2D() ); + TickFactory_2D* pTickFactory2D = apTickFactory2D.get(); + if( !pTickFactory2D ) return; //----------------------------------------- //get the transformed screen values for all tickmarks in aAllTickInfos - pTickmarkHelper2D->updateScreenValues( m_aAllTickInfos ); + pTickFactory2D->updateScreenValues( m_aAllTickInfos ); //create tick mark text shapes //@todo: iterate through all tick depth wich should be labeled AxisLabelProperties aAxisLabelProperties( m_aAxisLabelProperties ); - if( isAutoStaggeringOfLabelsAllowed( aAxisLabelProperties, pTickmarkHelper2D->isHorizontalAxis(), pTickmarkHelper2D->isVerticalAxis() ) ) + if( isAutoStaggeringOfLabelsAllowed( aAxisLabelProperties, pTickFactory2D->isHorizontalAxis(), pTickFactory2D->isVerticalAxis() ) ) aAxisLabelProperties.eStaggering = STAGGER_EVEN; aAxisLabelProperties.bOverlapAllowed = true; aAxisLabelProperties.bLineBreakAllowed = false; @@ -1465,29 +1456,29 @@ void SAL_CALL VCartesianAxis::createMaximumLabels() ::std::auto_ptr< TickIter > apTickIter = createMaximumLabelTickIterator( nTextLevel ); if(apTickIter.get()) { - while( !createTextShapes( m_xTextTarget, *apTickIter.get(), aAxisLabelProperties, pTickmarkHelper2D, -1 ) ) + while( !createTextShapes( m_xTextTarget, *apTickIter.get(), aAxisLabelProperties, pTickFactory2D, -1 ) ) { }; } } - doStaggeringOfLabels( aAxisLabelProperties, pTickmarkHelper2D ); + doStaggeringOfLabels( aAxisLabelProperties, pTickFactory2D ); } } -void SAL_CALL VCartesianAxis::updatePositions() +void VCartesianAxis::updatePositions() { //----------------------------------------- //update positions of labels if( m_aAxisProperties.m_bDisplayLabels ) { - std::auto_ptr< TickmarkHelper_2D > apTickmarkHelper2D( this->createTickmarkHelper2D() ); - TickmarkHelper_2D* pTickmarkHelper2D = apTickmarkHelper2D.get(); - if( !pTickmarkHelper2D ) + std::auto_ptr< TickFactory_2D > apTickFactory2D( this->createTickFactory2D() ); + TickFactory_2D* pTickFactory2D = apTickFactory2D.get(); + if( !pTickFactory2D ) return; //----------------------------------------- //update positions of all existing text shapes - pTickmarkHelper2D->updateScreenValues( m_aAllTickInfos ); + pTickFactory2D->updateScreenValues( m_aAllTickInfos ); ::std::vector< ::std::vector< TickInfo > >::iterator aDepthIter = m_aAllTickInfos.begin(); const ::std::vector< ::std::vector< TickInfo > >::const_iterator aDepthEnd = m_aAllTickInfos.end(); @@ -1501,7 +1492,7 @@ void SAL_CALL VCartesianAxis::updatePositions() Reference< drawing::XShape > xShape2DText( rTickInfo.xTextShape ); if( xShape2DText.is() ) { - B2DVector aTextToTickDistance( pTickmarkHelper2D->getDistanceAxisTickToText( m_aAxisProperties, true ) ); + B2DVector aTextToTickDistance( pTickFactory2D->getDistanceAxisTickToText( m_aAxisProperties, true ) ); B2DVector aTickScreenPos2D( rTickInfo.aTickScreenPosition ); aTickScreenPos2D += aTextToTickDistance; awt::Point aAnchorScreenPosition2D( @@ -1537,11 +1528,11 @@ void SAL_CALL VCartesianAxis::updatePositions() } } - doStaggeringOfLabels( m_aAxisLabelProperties, pTickmarkHelper2D ); + doStaggeringOfLabels( m_aAxisLabelProperties, pTickFactory2D ); } } -void VCartesianAxis::createTickMarkLineShapes( ::std::vector< TickInfo >& rTickInfos, const TickmarkProperties& rTickmarkProperties, TickmarkHelper_2D& rTickmarkHelper2D, bool bOnlyAtLabels ) +void VCartesianAxis::createTickMarkLineShapes( ::std::vector< TickInfo >& rTickInfos, const TickmarkProperties& rTickmarkProperties, TickFactory_2D& rTickFactory2D, bool bOnlyAtLabels ) { sal_Int32 nPointCount = rTickInfos.size(); drawing::PointSequenceSequence aPoints(2*nPointCount); @@ -1560,11 +1551,11 @@ void VCartesianAxis::createTickMarkLineShapes( ::std::vector< TickInfo >& rTickI fInnerDirectionSign *= -1.0; bTicksAtLabels = bTicksAtLabels || bOnlyAtLabels; //add ticks at labels: - rTickmarkHelper2D.addPointSequenceForTickLine( aPoints, nN++, (*aTickIter).fScaledTickValue + rTickFactory2D.addPointSequenceForTickLine( aPoints, nN++, (*aTickIter).fScaledTickValue , fInnerDirectionSign , rTickmarkProperties, bTicksAtLabels ); //add ticks at axis (without lables): if( !bOnlyAtLabels && m_aAxisProperties.m_eTickmarkPos == ::com::sun::star::chart::ChartAxisMarkPosition_AT_LABELS_AND_AXIS ) - rTickmarkHelper2D.addPointSequenceForTickLine( aPoints, nN++, (*aTickIter).fScaledTickValue + rTickFactory2D.addPointSequenceForTickLine( aPoints, nN++, (*aTickIter).fScaledTickValue , m_aAxisProperties.m_fInnerDirectionSign, rTickmarkProperties, !bTicksAtLabels ); } aPoints.realloc(nN); @@ -1572,14 +1563,14 @@ void VCartesianAxis::createTickMarkLineShapes( ::std::vector< TickInfo >& rTickI , &rTickmarkProperties.aLineProperties ); } -void SAL_CALL VCartesianAxis::createShapes() +void VCartesianAxis::createShapes() { if( !prepareShapeCreation() ) return; - std::auto_ptr< TickmarkHelper_2D > apTickmarkHelper2D( this->createTickmarkHelper2D() ); - TickmarkHelper_2D* pTickmarkHelper2D = apTickmarkHelper2D.get(); - if( !pTickmarkHelper2D ) + std::auto_ptr< TickFactory_2D > apTickFactory2D( this->createTickFactory2D() ); + TickFactory_2D* pTickFactory2D = apTickFactory2D.get(); + if( !pTickFactory2D ) return; //----------------------------------------- @@ -1588,16 +1579,16 @@ void SAL_CALL VCartesianAxis::createShapes() { //----------------------------------------- //create extra long ticks to separate complex categories (create them only there where the labels are) - if( m_aAxisProperties.m_bComplexCategories && m_bUseTextLabels ) + if( isComplexCategoryAxis() ) { ::std::vector< ::std::vector< TickInfo > > aComplexTickInfos; createAllTickInfosFromComplexCategories( aComplexTickInfos, true ); - pTickmarkHelper2D->updateScreenValues( aComplexTickInfos ); + pTickFactory2D->updateScreenValues( aComplexTickInfos ); hideIdenticalScreenValues( aComplexTickInfos ); ::std::vector<TickmarkProperties> aTickmarkPropertiesList; static bool bIncludeSpaceBetweenTickAndText = false; - sal_Int32 nOffset = static_cast<sal_Int32>(pTickmarkHelper2D->getDistanceAxisTickToText( m_aAxisProperties, false, bIncludeSpaceBetweenTickAndText ).getLength()); + sal_Int32 nOffset = static_cast<sal_Int32>(pTickFactory2D->getDistanceAxisTickToText( m_aAxisProperties, false, bIncludeSpaceBetweenTickAndText ).getLength()); sal_Int32 nTextLevelCount = getTextLevelCount(); for( sal_Int32 nTextLevel=0; nTextLevel<nTextLevelCount; nTextLevel++ ) { @@ -1607,7 +1598,7 @@ void SAL_CALL VCartesianAxis::createShapes() double fRotationAngleDegree = m_aAxisLabelProperties.fRotationAngleDegree; if( nTextLevel>0 ) fRotationAngleDegree = 0.0; - B2DVector aLabelsDistance( lcl_getLabelsDistance( *apTickIter.get(), pTickmarkHelper2D->getDistanceAxisTickToText( m_aAxisProperties, false ), fRotationAngleDegree ) ); + B2DVector aLabelsDistance( lcl_getLabelsDistance( *apTickIter.get(), pTickFactory2D->getDistanceAxisTickToText( m_aAxisProperties, false ), fRotationAngleDegree ) ); sal_Int32 nCurrentLength = static_cast<sal_Int32>(aLabelsDistance.getLength()); aTickmarkPropertiesList.push_back( m_aAxisProperties.makeTickmarkPropertiesForComplexCategories( nOffset + nCurrentLength, 0, nTextLevel ) ); nOffset += nCurrentLength; @@ -1621,20 +1612,20 @@ void SAL_CALL VCartesianAxis::createShapes() { if(nDepth==0 && !m_aAxisProperties.m_nMajorTickmarks) continue; - createTickMarkLineShapes( *aDepthIter, aTickmarkPropertiesList[nDepth], *pTickmarkHelper2D, true /*bOnlyAtLabels*/ ); + createTickMarkLineShapes( *aDepthIter, aTickmarkPropertiesList[nDepth], *pTickFactory2D, true /*bOnlyAtLabels*/ ); } } //----------------------------------------- //create normal ticks for major and minor intervals { - ::std::vector< ::std::vector< TickInfo > > aAllShiftedTickInfos; - if( m_aIncrement.ShiftedPosition || ( m_aAxisProperties.m_bComplexCategories && m_bUseTextLabels ) ) + ::std::vector< ::std::vector< TickInfo > > aUnshiftedTickInfos; + if( m_aScale.ShiftedCategoryPosition )// if ShiftedCategoryPosition==true the tickmarks in m_aAllTickInfos are shifted { - pTickmarkHelper2D->getAllTicksShifted( aAllShiftedTickInfos ); - pTickmarkHelper2D->updateScreenValues( aAllShiftedTickInfos ); - hideIdenticalScreenValues( aAllShiftedTickInfos ); + pTickFactory2D->getAllTicks( aUnshiftedTickInfos ); + pTickFactory2D->updateScreenValues( aUnshiftedTickInfos ); + hideIdenticalScreenValues( aUnshiftedTickInfos ); } - ::std::vector< ::std::vector< TickInfo > >& rAllTickInfos = m_aIncrement.ShiftedPosition ? aAllShiftedTickInfos : m_aAllTickInfos; + ::std::vector< ::std::vector< TickInfo > >& rAllTickInfos = m_aScale.ShiftedCategoryPosition ? aUnshiftedTickInfos : m_aAllTickInfos; ::std::vector< ::std::vector< TickInfo > >::iterator aDepthIter = rAllTickInfos.begin(); const ::std::vector< ::std::vector< TickInfo > >::const_iterator aDepthEnd = rAllTickInfos.end(); @@ -1643,14 +1634,14 @@ void SAL_CALL VCartesianAxis::createShapes() sal_Int32 nTickmarkPropertiesCount = m_aAxisProperties.m_aTickmarkPropertiesList.size(); for( sal_Int32 nDepth=0; aDepthIter != aDepthEnd && nDepth < nTickmarkPropertiesCount; aDepthIter++, nDepth++ ) - createTickMarkLineShapes( *aDepthIter, m_aAxisProperties.m_aTickmarkPropertiesList[nDepth], *pTickmarkHelper2D, false /*bOnlyAtLabels*/ ); + createTickMarkLineShapes( *aDepthIter, m_aAxisProperties.m_aTickmarkPropertiesList[nDepth], *pTickFactory2D, false /*bOnlyAtLabels*/ ); } //----------------------------------------- //create axis main lines //it serves also as the handle shape for the axis selection { drawing::PointSequenceSequence aPoints(1); - apTickmarkHelper2D->createPointSequenceForAxisMainLine( aPoints ); + apTickFactory2D->createPointSequenceForAxisMainLine( aPoints ); Reference< drawing::XShape > xShape = m_pShapeFactory->createLine2D( m_xGroupShape_Shapes, aPoints , &m_aAxisProperties.m_aLineProperties ); diff --git a/chart2/source/view/axes/VCartesianAxis.hxx b/chart2/source/view/axes/VCartesianAxis.hxx index 4fbcd2409196..d199a112bab1 100644 --- a/chart2/source/view/axes/VCartesianAxis.hxx +++ b/chart2/source/view/axes/VCartesianAxis.hxx @@ -55,20 +55,11 @@ public: virtual ~VCartesianAxis(); - //------------------------------------------------------------------------- - // partly chart2::XPlotter - //------------------------------------------------------------------------- - - /* - virtual ::rtl::OUString SAL_CALL getCoordinateSystemTypeID( ) throw (::com::sun::star::uno::RuntimeException); - virtual void SAL_CALL setTransformation( const ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XTransformation >& xTransformationToLogicTarget, const ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XTransformation >& xTransformationToFinalPage ) throw (::com::sun::star::uno::RuntimeException); - */ - - virtual void SAL_CALL createMaximumLabels(); - virtual void SAL_CALL createLabels(); - virtual void SAL_CALL updatePositions(); + virtual void createMaximumLabels(); + virtual void createLabels(); + virtual void updatePositions(); - virtual void SAL_CALL createShapes(); + virtual void createShapes(); virtual sal_Int32 estimateMaximumAutoMainIncrementCount(); virtual void createAllTickInfos( ::std::vector< ::std::vector< TickInfo > >& rAllTickInfos ); @@ -79,7 +70,7 @@ public: sal_Int32 getTextLevelCount() const; //------------------------------------------------------------------------- - virtual TickmarkHelper* createTickmarkHelper(); + virtual TickFactory* createTickFactory(); //------------------------------------------------------------------------- double getLogicValueWhereMainLineCrossesOtherAxis() const; @@ -122,16 +113,16 @@ protected: //methods ::com::sun::star::drawing::XShapes >& xTarget , TickIter& rTickIter , AxisLabelProperties& rAxisLabelProperties - , TickmarkHelper_2D* pTickmarkHelper + , TickFactory_2D* pTickFactory , sal_Int32 nScreenDistanceBetweenTicks ); - void createTickMarkLineShapes( ::std::vector< TickInfo >& rTickInfos, const TickmarkProperties& rTickmarkProperties, TickmarkHelper_2D& rTickmarkHelper2D, bool bOnlyAtLabels ); + void createTickMarkLineShapes( ::std::vector< TickInfo >& rTickInfos, const TickmarkProperties& rTickmarkProperties, TickFactory_2D& rTickFactory2D, bool bOnlyAtLabels ); - TickmarkHelper_2D* createTickmarkHelper2D(); + TickFactory_2D* createTickFactory2D(); void hideIdenticalScreenValues( ::std::vector< ::std::vector< TickInfo > >& rTickInfos ) const; void doStaggeringOfLabels( const AxisLabelProperties& rAxisLabelProperties - , TickmarkHelper_2D* pTickmarkHelper2D ); + , TickFactory_2D* pTickFactory2D ); bool isAutoStaggeringOfLabelsAllowed( const AxisLabelProperties& rAxisLabelProperties , bool bIsHorizontalAxis, bool bIsVerticalAxis ); bool isBreakOfLabelsAllowed( const AxisLabelProperties& rAxisLabelProperties, bool bIsHorizontalAxis ); diff --git a/chart2/source/view/axes/VCartesianCoordinateSystem.cxx b/chart2/source/view/axes/VCartesianCoordinateSystem.cxx index a196397e0e9f..ca83850a88ff 100644 --- a/chart2/source/view/axes/VCartesianCoordinateSystem.cxx +++ b/chart2/source/view/axes/VCartesianCoordinateSystem.cxx @@ -151,11 +151,7 @@ void VCartesianCoordinateSystem::createVAxisList( aAxisProperties.m_bCrossingAxisHasReverseDirection = (AxisOrientation_REVERSE==aCrossingScale.Orientation); if( aCrossingScale.AxisType == AxisType::CATEGORY ) - { aAxisProperties.m_bCrossingAxisIsCategoryAxes = true; - aAxisProperties.m_bAxisBetweenCategories = ChartTypeHelper::shiftTicksAtXAxisPerDefault( AxisHelper::getChartTypeByIndex( m_xCooSysModel, 0 ) ) - || ( aAxisProperties.m_pExplicitCategoriesProvider && aAxisProperties.m_pExplicitCategoriesProvider->hasComplexCategories() ); - } } if( nDimensionIndex == 2 ) @@ -169,25 +165,12 @@ void VCartesianCoordinateSystem::createVAxisList( aAxisProperties.init(true); if(aAxisProperties.m_bDisplayLabels) aAxisProperties.m_nNumberFormatKey = this->getNumberFormatKeyForAxis( xAxis, xNumberFormatsSupplier ); - - if( nDimensionIndex == 0 && aAxisProperties.m_nAxisType == AxisType::CATEGORY - && aAxisProperties.m_pExplicitCategoriesProvider ) - { - if( aAxisProperties.m_pExplicitCategoriesProvider->hasComplexCategories() ) - aAxisProperties.m_bComplexCategories = true; - } //------------------- ::boost::shared_ptr< VAxisBase > apVAxis( new VCartesianAxis(aAxisProperties,xNumberFormatsSupplier,nDimensionIndex,nDimensionCount) ); tFullAxisIndex aFullAxisIndex( nDimensionIndex, nAxisIndex ); m_aAxisMap[aFullAxisIndex] = apVAxis; apVAxis->set3DWallPositions( m_eLeftWallPos, m_eBackWallPos, m_eBottomPos ); - //apVAxis->setExplicitScaleAndIncrement( this->getExplicitScale( nDimensionIndex, nAxisIndex ), this->getExplicitIncrement( nDimensionIndex, nAxisIndex ) ); - //apVAxis->initPlotter(m_xLogicTargetForAxes,m_xFinalTarget,m_xShapeFactory - // , this->createCIDForAxis( xAxis, nDimensionIndex, nAxisIndex ) ); - //if(2==nDimensionCount) - // apVAxis->setTransformationSceneToScreen( m_aMatrixSceneToScreen ); - //apVAxis->setScales( this->getExplicitScales(nDimensionIndex,nAxisIndex), bSwapXAndY ); apVAxis->initAxisLabelProperties(rFontReferenceSize,rMaximumSpaceForLabels); } } diff --git a/chart2/source/view/axes/VCartesianGrid.cxx b/chart2/source/view/axes/VCartesianGrid.cxx index 18b8942b6787..ff93feefa228 100644 --- a/chart2/source/view/axes/VCartesianGrid.cxx +++ b/chart2/source/view/axes/VCartesianGrid.cxx @@ -28,7 +28,7 @@ // MARKER(update_precomp.py): autogen include statement, do not remove #include "precompiled_chart2.hxx" #include "VCartesianGrid.hxx" -#include "TickmarkHelper.hxx" +#include "Tickmarks.hxx" #include "PlottingPositionHelper.hxx" #include "ShapeFactory.hxx" #include "ObjectIdentifier.hxx" @@ -210,7 +210,7 @@ void VCartesianGrid::fillLinePropertiesFromGridModel( ::std::vector<VLinePropert } }; -void SAL_CALL VCartesianGrid::createShapes() +void VCartesianGrid::createShapes() { if(!m_aGridPropertiesList.getLength()) return; @@ -230,13 +230,10 @@ void SAL_CALL VCartesianGrid::createShapes() //----------------------------------------- //create all scaled tickmark values - std::auto_ptr< TickmarkHelper > apTickmarkHelper( this->createTickmarkHelper() ); - TickmarkHelper& aTickmarkHelper = *apTickmarkHelper.get(); + std::auto_ptr< TickFactory > apTickFactory( this->createTickFactory() ); + TickFactory& aTickFactory = *apTickFactory.get(); ::std::vector< ::std::vector< TickInfo > > aAllTickInfos; - if( m_aIncrement.ShiftedPosition ) - aTickmarkHelper.getAllTicksShifted( aAllTickInfos ); - else - aTickmarkHelper.getAllTicks( aAllTickInfos ); + aTickFactory.getAllTicks( aAllTickInfos ); //----------------------------------------- //create tick mark line shapes diff --git a/chart2/source/view/axes/VCartesianGrid.hxx b/chart2/source/view/axes/VCartesianGrid.hxx index 274b543900e3..0a0f8b91716f 100644 --- a/chart2/source/view/axes/VCartesianGrid.hxx +++ b/chart2/source/view/axes/VCartesianGrid.hxx @@ -52,7 +52,7 @@ public: ); virtual ~VCartesianGrid(); - virtual void SAL_CALL createShapes(); + virtual void createShapes(); static void fillLinePropertiesFromGridModel( ::std::vector<VLineProperties>& rLinePropertiesList , const ::com::sun::star::uno::Sequence< diff --git a/chart2/source/view/axes/VCoordinateSystem.cxx b/chart2/source/view/axes/VCoordinateSystem.cxx index b61a58cd2238..42e6042d7e70 100644 --- a/chart2/source/view/axes/VCoordinateSystem.cxx +++ b/chart2/source/view/axes/VCoordinateSystem.cxx @@ -97,8 +97,8 @@ VCoordinateSystem::VCoordinateSystem( const Reference< XCoordinateSystem >& xCoo { if( !m_xCooSysModel.is() || m_xCooSysModel->getDimension()<3 ) { - m_aExplicitScales[2].Minimum = -0.5; - m_aExplicitScales[2].Maximum = 0.5; + m_aExplicitScales[2].Minimum = 1.0; + m_aExplicitScales[2].Maximum = 2.0; m_aExplicitScales[2].Orientation = AxisOrientation_MATHEMATICAL; } } @@ -106,7 +106,7 @@ VCoordinateSystem::~VCoordinateSystem() { } -void SAL_CALL VCoordinateSystem::initPlottingTargets( const Reference< drawing::XShapes >& xLogicTarget +void VCoordinateSystem::initPlottingTargets( const Reference< drawing::XShapes >& xLogicTarget , const Reference< drawing::XShapes >& xFinalTarget , const Reference< lang::XMultiServiceFactory >& xShapeFactory , Reference< drawing::XShapes >& xLogicTargetForSeriesBehindAxis ) @@ -270,9 +270,9 @@ ExplicitCategoriesProvider* VCoordinateSystem::getExplicitCategoriesProvider() return m_apExplicitCategoriesProvider.get(); } -Sequence< ExplicitScaleData > VCoordinateSystem::getExplicitScales( sal_Int32 nDimensionIndex, sal_Int32 nAxisIndex ) const +std::vector< ExplicitScaleData > VCoordinateSystem::getExplicitScales( sal_Int32 nDimensionIndex, sal_Int32 nAxisIndex ) const { - Sequence< ExplicitScaleData > aRet(m_aExplicitScales); + std::vector< ExplicitScaleData > aRet(m_aExplicitScales); impl_adjustDimensionAndIndex( nDimensionIndex, nAxisIndex ); aRet[nDimensionIndex]=this->getExplicitScale( nDimensionIndex, nAxisIndex ); @@ -280,9 +280,9 @@ Sequence< ExplicitScaleData > VCoordinateSystem::getExplicitScales( sal_Int32 nD return aRet; } -Sequence< ExplicitIncrementData > VCoordinateSystem::getExplicitIncrements( sal_Int32 nDimensionIndex, sal_Int32 nAxisIndex ) const +std::vector< ExplicitIncrementData > VCoordinateSystem::getExplicitIncrements( sal_Int32 nDimensionIndex, sal_Int32 nAxisIndex ) const { - Sequence< ExplicitIncrementData > aRet(m_aExplicitIncrements); + std::vector< ExplicitIncrementData > aRet(m_aExplicitIncrements); impl_adjustDimensionAndIndex( nDimensionIndex, nAxisIndex ); aRet[nDimensionIndex]=this->getExplicitIncrement( nDimensionIndex, nAxisIndex ); @@ -381,6 +381,17 @@ void VCoordinateSystem::updateScalesAndIncrementsOnAxes() void VCoordinateSystem::prepareScaleAutomatismForDimensionAndIndex( ScaleAutomatism& rScaleAutomatism, sal_Int32 nDimIndex, sal_Int32 nAxisIndex ) { + if( rScaleAutomatism.getScale().AxisType==AxisType::DATE && nDimIndex==0 ) + { + sal_Int32 nTimeResolution = ::com::sun::star::chart::TimeUnit::MONTH; + if( !(rScaleAutomatism.getScale().TimeIncrement.TimeResolution >>= nTimeResolution) ) + { + nTimeResolution = m_aMergedMinimumAndMaximumSupplier.calculateTimeResolutionOnXAxis(); + rScaleAutomatism.setAutomaticTimeResolution( nTimeResolution ); + } + m_aMergedMinimumAndMaximumSupplier.setTimeResolutionOnXAxis( nTimeResolution, rScaleAutomatism.getNullDate() ); + } + double fMin = 0.0; double fMax = 0.0; ::rtl::math::setInf(&fMin, false); @@ -402,11 +413,6 @@ void VCoordinateSystem::prepareScaleAutomatismForDimensionAndIndex( ScaleAutomat fMax = m_aMergedMinimumAndMaximumSupplier.getMaximumZ(); } - this->prepareScaleAutomatism( rScaleAutomatism, fMin, fMax, nDimIndex, nAxisIndex ); -} - -void VCoordinateSystem::prepareScaleAutomatism( ScaleAutomatism& rScaleAutomatism, double fMin, double fMax, sal_Int32 nDimIndex, sal_Int32 nAxisIndex ) -{ //merge our values with those already contained in rScaleAutomatism rScaleAutomatism.expandValueRange( fMin, fMax ); diff --git a/chart2/source/view/axes/VPolarAngleAxis.cxx b/chart2/source/view/axes/VPolarAngleAxis.cxx index 865a7848aa9a..c23d6b95629d 100644 --- a/chart2/source/view/axes/VPolarAngleAxis.cxx +++ b/chart2/source/view/axes/VPolarAngleAxis.cxx @@ -33,7 +33,7 @@ #include "VPolarGrid.hxx" #include "ShapeFactory.hxx" #include "macros.hxx" -#include "chartview/NumberFormatterWrapper.hxx" +#include "NumberFormatterWrapper.hxx" #include "PolarLabelPositionHelper.hxx" #include <tools/color.hxx> @@ -120,17 +120,17 @@ bool VPolarAngleAxis::createTextShapes_ForAngleAxis( rtl::OUString aLabel; if(pLabels) { - sal_Int32 nIndex = static_cast< sal_Int32 >(pTickInfo->fUnscaledTickValue) - 1; //first category (index 0) matches with real number 1.0 + sal_Int32 nIndex = static_cast< sal_Int32 >(pTickInfo->getUnscaledTickValue()) - 1; //first category (index 0) matches with real number 1.0 if( nIndex>=0 && nIndex<pLabels->getLength() ) aLabel = (*pLabels)[nIndex]; } else - aLabel = aFixedNumberFormatter.getFormattedString( pTickInfo->fUnscaledTickValue, nExtraColor, bHasExtraColor ); + aLabel = aFixedNumberFormatter.getFormattedString( pTickInfo->getUnscaledTickValue(), nExtraColor, bHasExtraColor ); if(pColorAny) *pColorAny = uno::makeAny(bHasExtraColor?nExtraColor:nColor); - double fLogicAngle = pTickInfo->fUnscaledTickValue; + double fLogicAngle = pTickInfo->getUnscaledTickValue(); LabelAlignment eLabelAlignment(LABEL_ALIGN_CENTER); PolarLabelPositionHelper aPolarLabelPositionHelper(m_pPosHelper,nDimensionCount,xTarget,&aShapeFactory); @@ -154,7 +154,7 @@ bool VPolarAngleAxis::createTextShapes_ForAngleAxis( return true; } -void SAL_CALL VPolarAngleAxis::createMaximumLabels() +void VPolarAngleAxis::createMaximumLabels() { if( !prepareShapeCreation() ) return; @@ -162,7 +162,7 @@ void SAL_CALL VPolarAngleAxis::createMaximumLabels() createLabels(); } -void SAL_CALL VPolarAngleAxis::updatePositions() +void VPolarAngleAxis::updatePositions() { //todo: really only update the positions @@ -172,19 +172,19 @@ void SAL_CALL VPolarAngleAxis::updatePositions() createLabels(); } -void SAL_CALL VPolarAngleAxis::createLabels() +void VPolarAngleAxis::createLabels() { if( !prepareShapeCreation() ) return; double fLogicRadius = m_pPosHelper->getOuterLogicRadius(); - double fLogicZ = -0.5;//as defined + double fLogicZ = 1.0;//as defined if( m_aAxisProperties.m_bDisplayLabels ) { //----------------------------------------- //get the transformed screen values for all tickmarks in aAllTickInfos - std::auto_ptr< TickmarkHelper > apTickmarkHelper( this->createTickmarkHelper() ); + std::auto_ptr< TickFactory > apTickFactory( this->createTickFactory() ); //create tick mark text shapes //@todo: iterate through all tick depth wich should be labeled @@ -207,13 +207,13 @@ void SAL_CALL VPolarAngleAxis::createLabels() } } -void SAL_CALL VPolarAngleAxis::createShapes() +void VPolarAngleAxis::createShapes() { if( !prepareShapeCreation() ) return; double fLogicRadius = m_pPosHelper->getOuterLogicRadius(); - double fLogicZ = -0.5;//as defined + double fLogicZ = 1.0;//as defined //----------------------------------------- //create axis main lines diff --git a/chart2/source/view/axes/VPolarAngleAxis.hxx b/chart2/source/view/axes/VPolarAngleAxis.hxx index c03cf533e22c..011033faaefa 100644 --- a/chart2/source/view/axes/VPolarAngleAxis.hxx +++ b/chart2/source/view/axes/VPolarAngleAxis.hxx @@ -28,6 +28,7 @@ #define _CHART2_VPOLARANGLEAXIS_HXX #include "VPolarAxis.hxx" +#include "Tickmarks_Equidistant.hxx" //............................................................................. namespace chart @@ -46,11 +47,11 @@ public: , sal_Int32 nDimensionCount ); virtual ~VPolarAngleAxis(); - virtual void SAL_CALL createMaximumLabels(); - virtual void SAL_CALL createLabels(); - virtual void SAL_CALL updatePositions(); + virtual void createMaximumLabels(); + virtual void createLabels(); + virtual void updatePositions(); - virtual void SAL_CALL createShapes(); + virtual void createShapes(); private: //methods bool createTextShapes_ForAngleAxis( diff --git a/chart2/source/view/axes/VPolarAxis.cxx b/chart2/source/view/axes/VPolarAxis.cxx index 23908585ec3a..5f818da6c959 100644 --- a/chart2/source/view/axes/VPolarAxis.cxx +++ b/chart2/source/view/axes/VPolarAxis.cxx @@ -31,7 +31,7 @@ #include "VPolarAngleAxis.hxx" #include "VPolarRadiusAxis.hxx" #include "macros.hxx" -#include "TickmarkHelper.hxx" +#include "Tickmarks.hxx" #include "ShapeFactory.hxx" #include <memory> @@ -68,12 +68,12 @@ VPolarAxis::~VPolarAxis() m_pPosHelper = NULL; } -void VPolarAxis::setIncrements( const uno::Sequence< ExplicitIncrementData >& rIncrements ) +void VPolarAxis::setIncrements( const std::vector< ExplicitIncrementData >& rIncrements ) { m_aIncrements = rIncrements; } -sal_Bool SAL_CALL VPolarAxis::isAnythingToDraw() +sal_Bool VPolarAxis::isAnythingToDraw() { return ( 2==m_nDimension && VAxisBase::isAnythingToDraw() ); } diff --git a/chart2/source/view/axes/VPolarAxis.hxx b/chart2/source/view/axes/VPolarAxis.hxx index 8d4c14188258..a72b338416e2 100644 --- a/chart2/source/view/axes/VPolarAxis.hxx +++ b/chart2/source/view/axes/VPolarAxis.hxx @@ -47,10 +47,9 @@ public: , const ::com::sun::star::uno::Reference< ::com::sun::star::util::XNumberFormatsSupplier >& xNumberFormatsSupplier , sal_Int32 nDimensionIndex, sal_Int32 nDimensionCount ); - void setIncrements( const ::com::sun::star::uno::Sequence< - ::com::sun::star::chart2::ExplicitIncrementData >& rIncrements ); + void setIncrements( const std::vector< ExplicitIncrementData >& rIncrements ); - virtual sal_Bool SAL_CALL isAnythingToDraw(); + virtual sal_Bool isAnythingToDraw(); virtual ~VPolarAxis(); @@ -61,8 +60,7 @@ protected: protected: //member PolarPlottingPositionHelper* m_pPosHelper; - ::com::sun::star::uno::Sequence< - ::com::sun::star::chart2::ExplicitIncrementData > m_aIncrements; + ::std::vector< ExplicitIncrementData > m_aIncrements; }; //............................................................................. diff --git a/chart2/source/view/axes/VPolarCoordinateSystem.cxx b/chart2/source/view/axes/VPolarCoordinateSystem.cxx index 76e057a2b32d..5d13f5c46f66 100644 --- a/chart2/source/view/axes/VPolarCoordinateSystem.cxx +++ b/chart2/source/view/axes/VPolarCoordinateSystem.cxx @@ -107,15 +107,6 @@ void VPolarCoordinateSystem::createVAxisList( tFullAxisIndex aFullAxisIndex( nDimensionIndex, nAxisIndex ); m_aAxisMap[aFullAxisIndex] = apVAxis; - //apVAxis->setExplicitScaleAndIncrement( this->getExplicitScale( nDimensionIndex, nAxisIndex ), this->getExplicitIncrement(nDimensionIndex, nAxisIndex) ); - //apVAxis->initPlotter(m_xLogicTargetForAxes,m_xFinalTarget,m_xShapeFactory - // , this->createCIDForAxis( xAxis, nDimensionIndex, nAxisIndex ) ); - //VPolarAxis* pVPolarAxis = dynamic_cast< VPolarAxis* >( apVAxis.get() ); - //if( pVPolarAxis ) - // pVPolarAxis->setIncrements( this->getExplicitIncrements( nDimensionIndex, nAxisIndex ) ); - //if(2==nDimensionCount) - // apVAxis->setTransformationSceneToScreen( m_aMatrixSceneToScreen ); - //apVAxis->setScales( this->getExplicitScales( nDimensionIndex, nAxisIndex ), bSwapXAndY ); apVAxis->initAxisLabelProperties(rFontReferenceSize,rMaximumSpaceForLabels); } } diff --git a/chart2/source/view/axes/VPolarGrid.cxx b/chart2/source/view/axes/VPolarGrid.cxx index b2172244f920..30becdf4725d 100644 --- a/chart2/source/view/axes/VPolarGrid.cxx +++ b/chart2/source/view/axes/VPolarGrid.cxx @@ -29,12 +29,13 @@ #include "precompiled_chart2.hxx" #include "VPolarGrid.hxx" #include "VCartesianGrid.hxx" -#include "TickmarkHelper.hxx" +#include "Tickmarks.hxx" #include "PlottingPositionHelper.hxx" #include "ShapeFactory.hxx" #include "ObjectIdentifier.hxx" #include "macros.hxx" #include "CommonConverters.hxx" +#include "Tickmarks_Equidistant.hxx" #include <com/sun/star/drawing/LineStyle.hpp> #include <vector> @@ -64,16 +65,16 @@ VPolarGrid::~VPolarGrid() m_pPosHelper = NULL; } -void VPolarGrid::setIncrements( const uno::Sequence< ExplicitIncrementData >& rIncrements ) +void VPolarGrid::setIncrements( const std::vector< ExplicitIncrementData >& rIncrements ) { m_aIncrements = rIncrements; } void VPolarGrid::getAllTickInfos( sal_Int32 nDimensionIndex, ::std::vector< ::std::vector< TickInfo > >& rAllTickInfos ) const { - TickmarkHelper aTickmarkHelper( + TickFactory aTickFactory( m_pPosHelper->getScales()[nDimensionIndex], m_aIncrements[nDimensionIndex] ); - aTickmarkHelper.getAllTicks( rAllTickInfos ); + aTickFactory.getAllTicks( rAllTickInfos ); } void VPolarGrid::createLinePointSequence_ForAngleAxis( @@ -97,8 +98,8 @@ void VPolarGrid::createLinePointSequence_ForAngleAxis( if(nTick>=rPoints[0].getLength()) rPoints[0].realloc(rPoints[0].getLength()+30); - pTickInfo->updateUnscaledValue( xInverseScaling ); - double fLogicAngle = pTickInfo->fUnscaledTickValue; + //xxxxx pTickInfo->updateUnscaledValue( xInverseScaling ); + double fLogicAngle = pTickInfo->getUnscaledTickValue(); drawing::Position3D aScenePosition3D( pPosHelper->transformAngleRadiusToScene( fLogicAngle, fLogicRadius, fLogicZ ) ); rPoints[0][nTick].X = static_cast<sal_Int32>(aScenePosition3D.PositionX); @@ -129,7 +130,7 @@ void VPolarGrid::create2DAngleGrid( const Reference< drawing::XShapes >& xLogicT double fLogicInnerRadius = m_pPosHelper->getInnerLogicRadius(); double fLogicOuterRadius = m_pPosHelper->getOuterLogicRadius(); - double fLogicZ = -0.5;//as defined + double fLogicZ = 1.0;//as defined sal_Int32 nLinePropertiesCount = rLinePropertiesList.size(); ::std::vector< ::std::vector< TickInfo > >::iterator aDepthIter = rAngleTickInfos.begin(); @@ -152,8 +153,8 @@ void VPolarGrid::create2DAngleGrid( const Reference< drawing::XShapes >& xLogicT if( !rTickInfo.bPaintIt ) continue; - rTickInfo.updateUnscaledValue( xInverseScaling ); - double fLogicAngle = rTickInfo.fUnscaledTickValue; + //xxxxx rTickInfo.updateUnscaledValue( xInverseScaling ); + double fLogicAngle = rTickInfo.getUnscaledTickValue(); drawing::PointSequenceSequence aPoints(1); aPoints[0].realloc(2); @@ -219,9 +220,9 @@ void VPolarGrid::create2DRadiusGrid( const Reference< drawing::XShapes >& xLogic if( !rTickInfo.bPaintIt ) continue; - rTickInfo.updateUnscaledValue( xInverseRadiusScaling ); - double fLogicRadius = rTickInfo.fUnscaledTickValue; - double fLogicZ = -0.5;//as defined + //xxxxx rTickInfo.updateUnscaledValue( xInverseRadiusScaling ); + double fLogicRadius = rTickInfo.getUnscaledTickValue(); + double fLogicZ = 1.0;//as defined drawing::PointSequenceSequence aPoints(1); VPolarGrid::createLinePointSequence_ForAngleAxis( aPoints, rAngleTickInfos @@ -237,7 +238,7 @@ void VPolarGrid::create2DRadiusGrid( const Reference< drawing::XShapes >& xLogic } } -void SAL_CALL VPolarGrid::createShapes() +void VPolarGrid::createShapes() { DBG_ASSERT(m_pShapeFactory&&m_xLogicTarget.is()&&m_xFinalTarget.is(),"Axis is not proper initialized"); if(!(m_pShapeFactory&&m_xLogicTarget.is()&&m_xFinalTarget.is())) diff --git a/chart2/source/view/axes/VPolarGrid.hxx b/chart2/source/view/axes/VPolarGrid.hxx index 3289d6c88be8..1ea3bccc1f90 100644 --- a/chart2/source/view/axes/VPolarGrid.hxx +++ b/chart2/source/view/axes/VPolarGrid.hxx @@ -28,7 +28,7 @@ #define _CHART2_VPOLARGRID_HXX #include "VAxisOrGridBase.hxx" -#include "TickmarkHelper.hxx" +#include "Tickmarks.hxx" #include "VLineProperties.hxx" #include <com/sun/star/drawing/PointSequenceSequence.hpp> @@ -55,16 +55,15 @@ public: ); virtual ~VPolarGrid(); - virtual void SAL_CALL createShapes(); + virtual void createShapes(); - void setIncrements( const ::com::sun::star::uno::Sequence< - ::com::sun::star::chart2::ExplicitIncrementData >& rIncrements ); + void setIncrements( const std::vector< ExplicitIncrementData >& rIncrements ); static void createLinePointSequence_ForAngleAxis( ::com::sun::star::drawing::PointSequenceSequence& rPoints , ::std::vector< ::std::vector< TickInfo > >& rAllTickInfos - , const ::com::sun::star::chart2::ExplicitIncrementData& rIncrement - , const ::com::sun::star::chart2::ExplicitScaleData& rScale + , const ExplicitIncrementData& rIncrement + , const ExplicitScaleData& rScale , PolarPlottingPositionHelper* pPosHelper , double fLogicRadius, double fLogicZ ); @@ -73,8 +72,7 @@ private: //member ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > > m_aGridPropertiesList;//main grid, subgrid, subsubgrid etc PolarPlottingPositionHelper* m_pPosHelper; - ::com::sun::star::uno::Sequence< - ::com::sun::star::chart2::ExplicitIncrementData > m_aIncrements; + ::std::vector< ExplicitIncrementData > m_aIncrements; void getAllTickInfos( sal_Int32 nDimensionIndex, ::std::vector< ::std::vector< TickInfo > >& rAllTickInfos ) const; diff --git a/chart2/source/view/axes/VPolarRadiusAxis.cxx b/chart2/source/view/axes/VPolarRadiusAxis.cxx index 2206d4d8f559..bc56b3824e6e 100644 --- a/chart2/source/view/axes/VPolarRadiusAxis.cxx +++ b/chart2/source/view/axes/VPolarRadiusAxis.cxx @@ -32,6 +32,7 @@ #include "VCartesianAxis.hxx" #include "PlottingPositionHelper.hxx" #include "CommonConverters.hxx" +#include "Tickmarks_Equidistant.hxx" #include <rtl/math.hxx> //............................................................................. @@ -70,7 +71,7 @@ void VPolarRadiusAxis::setTransformationSceneToScreen( const drawing::HomogenMat m_apAxisWithLabels->setTransformationSceneToScreen( rMatrix ); } -void SAL_CALL VPolarRadiusAxis::setExplicitScaleAndIncrement( +void VPolarRadiusAxis::setExplicitScaleAndIncrement( const ExplicitScaleData& rScale , const ExplicitIncrementData& rIncrement ) throw (uno::RuntimeException) @@ -79,7 +80,7 @@ void SAL_CALL VPolarRadiusAxis::setExplicitScaleAndIncrement( m_apAxisWithLabels->setExplicitScaleAndIncrement( rScale, rIncrement ); } -void SAL_CALL VPolarRadiusAxis::initPlotter( const uno::Reference< drawing::XShapes >& xLogicTarget +void VPolarRadiusAxis::initPlotter( const uno::Reference< drawing::XShapes >& xLogicTarget , const uno::Reference< drawing::XShapes >& xFinalTarget , const uno::Reference< lang::XMultiServiceFactory >& xShapeFactory , const rtl::OUString& rCID ) @@ -89,15 +90,13 @@ void SAL_CALL VPolarRadiusAxis::initPlotter( const uno::Reference< drawing::XSh m_apAxisWithLabels->initPlotter( xLogicTarget, xFinalTarget, xShapeFactory, rCID ); } -void SAL_CALL VPolarRadiusAxis::setScales( const uno::Sequence< ExplicitScaleData >& rScales - , sal_Bool bSwapXAndYAxis ) - throw (uno::RuntimeException) +void VPolarRadiusAxis::setScales( const std::vector< ExplicitScaleData >& rScales, bool bSwapXAndYAxis ) { VPolarAxis::setScales( rScales, bSwapXAndYAxis ); m_apAxisWithLabels->setScales( rScales, bSwapXAndYAxis ); } -void SAL_CALL VPolarRadiusAxis::initAxisLabelProperties( const ::com::sun::star::awt::Size& rFontReferenceSize +void VPolarRadiusAxis::initAxisLabelProperties( const ::com::sun::star::awt::Size& rFontReferenceSize , const ::com::sun::star::awt::Rectangle& rMaximumSpaceForLabels ) { VPolarAxis::initAxisLabelProperties( rFontReferenceSize, rMaximumSpaceForLabels ); @@ -121,22 +120,22 @@ bool VPolarRadiusAxis::prepareShapeCreation() return true; } -void SAL_CALL VPolarRadiusAxis::createMaximumLabels() +void VPolarRadiusAxis::createMaximumLabels() { m_apAxisWithLabels->createMaximumLabels(); } -void SAL_CALL VPolarRadiusAxis::updatePositions() +void VPolarRadiusAxis::updatePositions() { m_apAxisWithLabels->updatePositions(); } -void SAL_CALL VPolarRadiusAxis::createLabels() +void VPolarRadiusAxis::createLabels() { m_apAxisWithLabels->createLabels(); } -void SAL_CALL VPolarRadiusAxis::createShapes() +void VPolarRadiusAxis::createShapes() { if( !prepareShapeCreation() ) return; @@ -145,8 +144,8 @@ void SAL_CALL VPolarRadiusAxis::createShapes() const ExplicitIncrementData& rAngleIncrement = m_aIncrements[0]; ::std::vector< ::std::vector< TickInfo > > aAngleTickInfos; - TickmarkHelper aAngleTickmarkHelper( rAngleScale, rAngleIncrement ); - aAngleTickmarkHelper.getAllTicks( aAngleTickInfos ); + TickFactory aAngleTickFactory( rAngleScale, rAngleIncrement ); + aAngleTickFactory.getAllTicks( aAngleTickInfos ); uno::Reference< XScaling > xInverseScaling( NULL ); if( rAngleScale.Scaling.is() ) @@ -165,8 +164,8 @@ void SAL_CALL VPolarRadiusAxis::createShapes() continue; } - pTickInfo->updateUnscaledValue( xInverseScaling ); - aAxisProperties.m_pfMainLinePositionAtOtherAxis = new double( pTickInfo->fUnscaledTickValue ); + //xxxxx pTickInfo->updateUnscaledValue( xInverseScaling ); + aAxisProperties.m_pfMainLinePositionAtOtherAxis = new double( pTickInfo->getUnscaledTickValue() ); aAxisProperties.m_bDisplayLabels=false; //------------------- diff --git a/chart2/source/view/axes/VPolarRadiusAxis.hxx b/chart2/source/view/axes/VPolarRadiusAxis.hxx index b5c5191e4c98..e1dbb8c1b1c0 100644 --- a/chart2/source/view/axes/VPolarRadiusAxis.hxx +++ b/chart2/source/view/axes/VPolarRadiusAxis.hxx @@ -50,7 +50,7 @@ public: , sal_Int32 nDimensionCount ); virtual ~VPolarRadiusAxis(); - virtual void SAL_CALL initPlotter( + virtual void initPlotter( const ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShapes >& xLogicTarget , const ::com::sun::star::uno::Reference< @@ -62,28 +62,24 @@ public: virtual void setTransformationSceneToScreen( const ::com::sun::star::drawing::HomogenMatrix& rMatrix ); - virtual void SAL_CALL setScales( - const ::com::sun::star::uno::Sequence< - ::com::sun::star::chart2::ExplicitScaleData >& rScales - , sal_Bool bSwapXAndYAxis ) - throw (::com::sun::star::uno::RuntimeException); + virtual void setScales( const ::std::vector< ExplicitScaleData >& rScales, bool bSwapXAndYAxis ); - virtual void SAL_CALL setExplicitScaleAndIncrement( - const ::com::sun::star::chart2::ExplicitScaleData& rScale - , const ::com::sun::star::chart2::ExplicitIncrementData& rIncrement ) + virtual void setExplicitScaleAndIncrement( + const ExplicitScaleData& rScale + , const ExplicitIncrementData& rIncrement ) throw (::com::sun::star::uno::RuntimeException); - virtual void SAL_CALL initAxisLabelProperties( + virtual void initAxisLabelProperties( const ::com::sun::star::awt::Size& rFontReferenceSize , const ::com::sun::star::awt::Rectangle& rMaximumSpaceForLabels ); virtual sal_Int32 estimateMaximumAutoMainIncrementCount(); - virtual void SAL_CALL createMaximumLabels(); - virtual void SAL_CALL createLabels(); - virtual void SAL_CALL updatePositions(); + virtual void createMaximumLabels(); + virtual void createLabels(); + virtual void updatePositions(); - virtual void SAL_CALL createShapes(); + virtual void createShapes(); protected: //methods virtual bool prepareShapeCreation(); diff --git a/chart2/source/view/axes/makefile.mk b/chart2/source/view/axes/makefile.mk index 96191a3a3a25..af88a61b6b37 100644 --- a/chart2/source/view/axes/makefile.mk +++ b/chart2/source/view/axes/makefile.mk @@ -47,7 +47,11 @@ ENABLE_EXCEPTIONS= TRUE SLOFILES = \ $(SLO)$/VAxisOrGridBase.obj \ $(SLO)$/VAxisBase.obj \ - $(SLO)$/TickmarkHelper.obj \ + $(SLO)$/DateHelper.obj \ + $(SLO)$/DateScaling.obj \ + $(SLO)$/Tickmarks.obj \ + $(SLO)$/Tickmarks_Equidistant.obj \ + $(SLO)$/Tickmarks_Dates.obj \ $(SLO)$/MinimumAndMaximumSupplier.obj \ $(SLO)$/ScaleAutomatism.obj \ $(SLO)$/VAxisProperties.obj \ diff --git a/chart2/source/view/charttypes/AreaChart.cxx b/chart2/source/view/charttypes/AreaChart.cxx index fd1aaa81c3a0..06e09d60fcf1 100644 --- a/chart2/source/view/charttypes/AreaChart.cxx +++ b/chart2/source/view/charttypes/AreaChart.cxx @@ -43,6 +43,7 @@ #include "Clipping.hxx" #include "Stripe.hxx" #include "PolarLabelPositionHelper.hxx" +#include "DateHelper.hxx" #include <com/sun/star/chart2/Symbol.hpp> #include <com/sun/star/chart/DataLabelPlacement.hpp> @@ -96,6 +97,11 @@ AreaChart::AreaChart( const uno::Reference<XChartType>& xChartTypeModel { if( !m_pMainPosHelper ) m_pMainPosHelper = new PlottingPositionHelper(); + if( m_pMainPosHelper ) + { + m_pMainPosHelper->AllowShiftXAxisPos(true); + m_pMainPosHelper->AllowShiftZAxisPos(true); + } PlotterBase::m_pPosHelper = m_pMainPosHelper; VSeriesPlotter::m_pMainPosHelper = m_pMainPosHelper; @@ -121,18 +127,12 @@ AreaChart::~AreaChart() delete m_pMainPosHelper; } -double AreaChart::getMinimumX() -{ - if( m_bCategoryXAxis && m_bIsPolarCooSys )//the angle axis in net charts needs a different autoscaling - return 1.0;//first category (index 0) matches with real number 1.0 - return VSeriesPlotter::getMinimumX(); -} - double AreaChart::getMaximumX() { + double fMax = VSeriesPlotter::getMaximumX(); if( m_bCategoryXAxis && m_bIsPolarCooSys )//the angle axis in net charts needs a different autoscaling - return getPointCount()+1; - return VSeriesPlotter::getMaximumX(); + fMax += 1.0; + return fMax; } bool AreaChart::isExpandIfValuesCloseToBorder( sal_Int32 nDimensionIndex ) @@ -183,18 +183,6 @@ APPHELPER_XSERVICEINFO_IMPL(AreaChart,CHART2_VIEW_AREACHART_SERVICE_IMPLEMENTATI return aSNS; } */ -/* -//----------------------------------------------------------------- -// chart2::XPlotter -//----------------------------------------------------------------- - - ::rtl::OUString SAL_CALL AreaChart -::getCoordinateSystemTypeID() - throw (uno::RuntimeException) -{ - return CHART2_COOSYSTEM_CARTESIAN_SERVICE_NAME; -} -*/ drawing::Direction3D AreaChart::getPreferredDiagramAspectRatio() const { if( m_nKeepAspectRatio == 1 ) @@ -628,7 +616,7 @@ void AreaChart::createShapes() //check necessary here that different Y axis can not be stacked in the same group? ... hm? //update/create information for current group - double fLogicZ = 0.5;//as defined + double fLogicZ = 1.0;//as defined sal_Int32 nStartIndex = 0; // inclusive ;..todo get somehow from x scale sal_Int32 nEndIndex = VSeriesPlotter::getPointCount(); @@ -729,6 +717,8 @@ void AreaChart::createShapes() //collect data point information (logic coordinates, style ): double fLogicX = (*aSeriesIter)->getXValue(nIndex); + if( m_pExplicitCategoriesProvider && m_pExplicitCategoriesProvider->isDateAxis() ) + fLogicX = DateHelper::RasterizeDateValue( fLogicX, m_aNullDate, m_nTimeResolution ); double fLogicY = (*aSeriesIter)->getYValue(nIndex); if( m_bIsPolarCooSys && m_bArea && diff --git a/chart2/source/view/charttypes/AreaChart.hxx b/chart2/source/view/charttypes/AreaChart.hxx index 6924509a62a1..4b6ff3f45251 100644 --- a/chart2/source/view/charttypes/AreaChart.hxx +++ b/chart2/source/view/charttypes/AreaChart.hxx @@ -55,17 +55,7 @@ public: ); virtual ~AreaChart(); - //------------------------------------------------------------------------- - // chart2::XPlotter - //------------------------------------------------------------------------- - - virtual void SAL_CALL createShapes(); - /* - virtual ::rtl::OUString SAL_CALL getCoordinateSystemTypeID( ) throw (::com::sun::star::uno::RuntimeException); - virtual void SAL_CALL setScales( const ::com::sun::star::uno::Sequence< ::com::sun::star::chart2::ExplicitScaleData >& rScales ) throw (::com::sun::star::uno::RuntimeException); - virtual void SAL_CALL setTransformation( const ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XTransformation >& xTransformationToLogicTarget, const ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XTransformation >& xTransformationToFinalPage ) throw (::com::sun::star::uno::RuntimeException); - */ - + virtual void createShapes(); virtual void addSeries( VDataSeries* pSeries, sal_Int32 zSlot = -1, sal_Int32 xSlot = -1,sal_Int32 ySlot = -1 ); //------------------- @@ -75,7 +65,6 @@ public: //------------------------------------------------------------------------- // MinimumAndMaximumSupplier //------------------------------------------------------------------------- - virtual double getMinimumX(); virtual double getMaximumX(); virtual bool isExpandIfValuesCloseToBorder( sal_Int32 nDimensionIndex ); virtual bool isSeperateStackingForDifferentSigns( sal_Int32 nDimensionIndex ); diff --git a/chart2/source/view/charttypes/BarChart.cxx b/chart2/source/view/charttypes/BarChart.cxx index 0d7ef403f87d..dbf01165bf79 100755..100644 --- a/chart2/source/view/charttypes/BarChart.cxx +++ b/chart2/source/view/charttypes/BarChart.cxx @@ -40,6 +40,7 @@ #include "macros.hxx" #include "AxisIndexDefines.hxx" #include "Clipping.hxx" +#include "DateHelper.hxx" #include <com/sun/star/chart/DataLabelPlacement.hpp> @@ -91,7 +92,6 @@ BarChart::~BarChart() PlottingPositionHelper& BarChart::getPlottingPositionHelper( sal_Int32 nAxisIndex ) const { PlottingPositionHelper& rPosHelper = VSeriesPlotter::getPlottingPositionHelper( nAxisIndex ); - BarPositionHelper* pBarPosHelper = dynamic_cast<BarPositionHelper*>(&rPosHelper); if( pBarPosHelper && nAxisIndex >= 0 ) { @@ -100,7 +100,6 @@ PlottingPositionHelper& BarChart::getPlottingPositionHelper( sal_Int32 nAxisInde if( nAxisIndex < m_aGapwidthSequence.getLength() ) pBarPosHelper->setOuterDistance( m_aGapwidthSequence[nAxisIndex]/100.0 ); } - return rPosHelper; } @@ -118,7 +117,7 @@ drawing::Direction3D BarChart::getPreferredDiagramAspectRatio() const if(!m_aZSlots.empty()) fXSlotCount = m_aZSlots.begin()->size(); - aRet.DirectionZ = aScale.DirectionZ/(aScale.DirectionX + aScale.DirectionX*(fXSlotCount-1.0)*pPosHelper->getSlotWidth()); + aRet.DirectionZ = aScale.DirectionZ/(aScale.DirectionX + aScale.DirectionX*(fXSlotCount-1.0)*pPosHelper->getScaledSlotWidth()); } else return VSeriesPlotter::getPreferredDiagramAspectRatio(); @@ -146,54 +145,6 @@ bool BarChart::keepAspectRatio() const return true; } -//------------------------------------------------------------------------- -// MinimumAndMaximumSupplier -//------------------------------------------------------------------------- - -double BarChart::getMinimumX() -{ - if( m_bCategoryXAxis ) - return 0.5;//first category (index 0) matches with real number 1.0 - return VSeriesPlotter::getMinimumX(); -} -double BarChart::getMaximumX() -{ - if( m_bCategoryXAxis ) - { - //return category count - sal_Int32 nPointCount = getPointCount(); - return nPointCount+0.5;//first category (index 0) matches with real number 1.0 - } - return VSeriesPlotter::getMaximumX(); -} - -//----------------------------------------------------------------- -// lang::XServiceInfo -//----------------------------------------------------------------- -/* -APPHELPER_XSERVICEINFO_IMPL(BarChart,CHART2_VIEW_BARCHART_SERVICE_IMPLEMENTATION_NAME) - - uno::Sequence< rtl::OUString > BarChart -::getSupportedServiceNames_Static() -{ - uno::Sequence< rtl::OUString > aSNS( 1 ); - aSNS.getArray()[ 0 ] = CHART2_VIEW_BARCHART_SERVICE_NAME; - return aSNS; -} -*/ -/* -//----------------------------------------------------------------- -// chart2::XPlotter -//----------------------------------------------------------------- - - ::rtl::OUString SAL_CALL BarChart -::getCoordinateSystemTypeID() - throw (uno::RuntimeException) -{ - return CHART2_COOSYSTEM_CARTESIAN_SERVICE_NAME; -} -*/ - awt::Point BarChart::getLabelScreenPositionAndAlignment( LabelAlignment& rAlignment, sal_Int32 nLabelPlacement , double fScaledX, double fScaledLowerYValue, double fScaledUpperYValue, double fScaledZ @@ -499,7 +450,7 @@ void BarChart::createShapes() m_pShapeFactory->createGroup2D( m_xFinalTarget,rtl::OUString() )); //check necessary here that different Y axis can not be stacked in the same group? ... hm? - double fLogicZ = 0.0;//as defined + double fLogicZ = 1.0;//as defined bool bDrawConnectionLines = false; bool bDrawConnectionLinesInited = false; @@ -514,12 +465,11 @@ void BarChart::createShapes() sal_Int32 nCreatedPoints = 0; // - //(@todo maybe different iteration for breaks in axis ?) - sal_Int32 nStartCategoryIndex = m_pMainPosHelper->getStartCategoryIndex(); // inclusive - sal_Int32 nEndCategoryIndex = m_pMainPosHelper->getEndCategoryIndex(); //inclusive + sal_Int32 nStartIndex = 0; + sal_Int32 nEndIndex = VSeriesPlotter::getPointCount(); //============================================================================= - //iterate through all shown categories - for( sal_Int32 nCatIndex = nStartCategoryIndex; nCatIndex < nEndCategoryIndex; nCatIndex++ ) + //iterate through all x values per indices + for( sal_Int32 nPointIndex = nStartIndex; nPointIndex < nEndIndex; nPointIndex++ ) { ::std::vector< ::std::vector< VDataSeriesGroup > >::iterator aZSlotIter = m_aZSlots.begin(); const ::std::vector< ::std::vector< VDataSeriesGroup > >::const_iterator aZSlotEnd = m_aZSlots.end(); @@ -538,7 +488,7 @@ void BarChart::createShapes() aLogicYSumMap[nAttachedAxisIndex]=0.0; double fMinimumY = 0.0, fMaximumY = 0.0; - aXSlotIter->calculateYMinAndMaxForCategory( nCatIndex + aXSlotIter->calculateYMinAndMaxForCategory( nPointIndex , isSeperateStackingForDifferentSigns( 1 ), fMinimumY, fMaximumY, nAttachedAxisIndex ); if( !::rtl::math::isNan( fMaximumY ) && fMaximumY > 0) @@ -574,14 +524,14 @@ void BarChart::createShapes() //update/create information for current group pPosHelper->updateSeriesCount( aZSlotIter->size() ); - double fLogicBaseWidth = pPosHelper->getSlotWidth(); + double fLogicBaseWidth = pPosHelper->getScaledSlotWidth(); ::std::vector< VDataSeries* >* pSeriesList = &(aXSlotIter->m_aSeriesVector); // get distance from base value to maximum and minimum double fMinimumY = 0.0, fMaximumY = 0.0; - aXSlotIter->calculateYMinAndMaxForCategory( nCatIndex + aXSlotIter->calculateYMinAndMaxForCategory( nPointIndex , isSeperateStackingForDifferentSigns( 1 ), fMinimumY, fMaximumY, nAttachedAxisIndex ); double fLogicPositiveYSum = 0.0; @@ -633,7 +583,7 @@ void BarChart::createShapes() bOnlyConnectionLinesForThisPoint = false; - if(nCatIndex==nStartCategoryIndex)//do not create a regression line for each point + if(nPointIndex==nStartIndex)//do not create a regression line for each point createRegressionCurvesShapes( **aSeriesIter, xRegressionCurveTarget, xRegressionCurveEquationTarget, m_pPosHelper->maySkipPointsInRegressionCalculation()); @@ -658,8 +608,17 @@ void BarChart::createShapes() getSeriesGroupShape(*aSeriesIter, xSeriesTarget) ); //collect data point information (logic coordinates, style ): - double fLogicX = pPosHelper->getSlotPos( (*aSeriesIter)->getXValue( nCatIndex ), fSlotX ); - double fLogicBarHeight = (*aSeriesIter)->getYValue( nCatIndex ); + double fUnscaledLogicX = (*aSeriesIter)->getXValue( nPointIndex ); + fUnscaledLogicX = DateHelper::RasterizeDateValue( fUnscaledLogicX, m_aNullDate, m_nTimeResolution ); + if(fUnscaledLogicX<pPosHelper->getLogicMinX()) + continue;//point not visible + if(fUnscaledLogicX>pPosHelper->getLogicMaxX()) + continue;//point not visible + if(pPosHelper->isStrongLowerRequested(0) && fUnscaledLogicX==pPosHelper->getLogicMaxX()) + continue;//point not visible + double fLogicX = pPosHelper->getScaledSlotPos( fUnscaledLogicX, fSlotX ); + + double fLogicBarHeight = (*aSeriesIter)->getYValue( nPointIndex ); if( ::rtl::math::isNan( fLogicBarHeight )) //no value at this category continue; @@ -684,9 +643,9 @@ void BarChart::createShapes() fNegativeLogicYForNextSeries += fLogicBarHeight; if(m_nDimension==3) - fLogicZ = nZ; + fLogicZ = nZ+0.5; - drawing::Position3D aUnscaledLogicPosition( fLogicX, fUpperYValue, fLogicZ ); + drawing::Position3D aUnscaledLogicPosition( fUnscaledLogicX, fUpperYValue, fLogicZ ); //@todo ... start an iteration over the different breaks of the axis //each subsystem may add an additional shape to form the whole point @@ -696,7 +655,7 @@ void BarChart::createShapes() // uno::Reference<drawing::XShape>( xPointGroupShape_Shapes, uno::UNO_QUERY ); //as long as we do not iterate we do not need to create an additional group for each point uno::Reference< drawing::XShapes > xPointGroupShape_Shapes = xSeriesGroupShape_Shapes; - uno::Reference< beans::XPropertySet > xDataPointProperties( (*aSeriesIter)->getPropertiesOfPoint( nCatIndex ) ); + uno::Reference< beans::XPropertySet > xDataPointProperties( (*aSeriesIter)->getPropertiesOfPoint( nPointIndex ) ); sal_Int32 nGeometry3D = DataPointGeometry3D::CUBOID; if(m_nDimension==3) try { @@ -763,7 +722,7 @@ void BarChart::createShapes() //better performance for big data FormerBarPoint aFormerPoint( aSeriesFormerPointMap[pSeries] ); pPosHelper->setCoordinateSystemResolution( m_aCoordinateSystemResolution ); - if( !pSeries->isAttributedDataPoint(nCatIndex) + if( !pSeries->isAttributedDataPoint(nPointIndex) && pPosHelper->isSameForGivenResolution( aFormerPoint.m_fX, aFormerPoint.m_fUpperY, aFormerPoint.m_fZ , fLogicX, fUpperYValue, fLogicZ ) @@ -883,20 +842,20 @@ void BarChart::createShapes() //set name/classified ObjectID (CID) ShapeFactory::setShapeName(xShape , ObjectIdentifier::createPointCID( - (*aSeriesIter)->getPointCID_Stub(),nCatIndex) ); + (*aSeriesIter)->getPointCID_Stub(),nPointIndex) ); } //create error bar - createErrorBar_Y( aUnscaledLogicPosition, **aSeriesIter, nCatIndex, m_xLogicTarget ); + createErrorBar_Y( aUnscaledLogicPosition, **aSeriesIter, nPointIndex, m_xLogicTarget, &fLogicX ); //------------ //create data point label - if( (**aSeriesIter).getDataPointLabelIfLabel(nCatIndex) ) + if( (**aSeriesIter).getDataPointLabelIfLabel(nPointIndex) ) { double fLogicSum = aLogicYSumMap[nAttachedAxisIndex]; LabelAlignment eAlignment(LABEL_ALIGN_CENTER); - sal_Int32 nLabelPlacement = pSeries->getLabelPlacement( nCatIndex, m_xChartTypeModel, m_nDimension, pPosHelper->isSwapXAndY() ); + sal_Int32 nLabelPlacement = pSeries->getLabelPlacement( nPointIndex, m_xChartTypeModel, m_nDimension, pPosHelper->isSwapXAndY() ); double fLowerBarDepth = fLogicBarDepth; double fUpperBarDepth = fLogicBarDepth; @@ -921,7 +880,7 @@ void BarChart::createShapes() if( m_nDimension == 3 ) nOffset = 260; } - this->createDataLabel( xTextTarget, **aSeriesIter, nCatIndex + this->createDataLabel( xTextTarget, **aSeriesIter, nPointIndex , fLogicValueForLabeDisplay, fLogicSum, aScreenPosition2D, eAlignment, nOffset ); } diff --git a/chart2/source/view/charttypes/BarChart.hxx b/chart2/source/view/charttypes/BarChart.hxx index 403628f7fc43..c20c85168b5d 100644 --- a/chart2/source/view/charttypes/BarChart.hxx +++ b/chart2/source/view/charttypes/BarChart.hxx @@ -47,17 +47,7 @@ public: , sal_Int32 nDimensionCount ); virtual ~BarChart(); - //------------------------------------------------------------------------- - // chart2::XPlotter - //------------------------------------------------------------------------- - - virtual void SAL_CALL createShapes(); - /* - virtual ::rtl::OUString SAL_CALL getCoordinateSystemTypeID( ) throw (::com::sun::star::uno::RuntimeException); - virtual void SAL_CALL setScales( const ::com::sun::star::uno::Sequence< ::com::sun::star::chart2::ExplicitScaleData >& rScales ) throw (::com::sun::star::uno::RuntimeException); - virtual void SAL_CALL setTransformation( const ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XTransformation >& xTransformationToLogicTarget, const ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XTransformation >& xTransformationToFinalPage ) throw (::com::sun::star::uno::RuntimeException); - */ - + virtual void createShapes(); virtual void addSeries( VDataSeries* pSeries, sal_Int32 zSlot = -1, sal_Int32 xSlot = -1,sal_Int32 ySlot = -1 ); //------------------- @@ -65,12 +55,6 @@ public: virtual bool keepAspectRatio() const; //------------------------------------------------------------------------- - // MinimumAndMaximumSupplier - //------------------------------------------------------------------------- - virtual double getMinimumX(); - virtual double getMaximumX(); - - //------------------------------------------------------------------------- //------------------------------------------------------------------------- //------------------------------------------------------------------------- diff --git a/chart2/source/view/charttypes/BarPositionHelper.cxx b/chart2/source/view/charttypes/BarPositionHelper.cxx index b1735e99de5d..45dab527da11 100644 --- a/chart2/source/view/charttypes/BarPositionHelper.cxx +++ b/chart2/source/view/charttypes/BarPositionHelper.cxx @@ -32,6 +32,8 @@ #include "Linear3DTransformation.hxx" #include "ViewDefines.hxx" #include "CommonConverters.hxx" +#include "DateHelper.hxx" +#include <com/sun/star/chart/TimeUnit.hpp> //............................................................................. namespace chart @@ -43,6 +45,8 @@ using namespace ::com::sun::star::chart2; BarPositionHelper::BarPositionHelper( bool /* bSwapXAndY */ ) : CategoryPositionHelper( 1 ) { + AllowShiftXAxisPos(true); + AllowShiftZAxisPos(true); } BarPositionHelper::BarPositionHelper( const BarPositionHelper& rSource ) @@ -66,73 +70,22 @@ void BarPositionHelper::updateSeriesCount( double fSeriesCount ) m_fSeriesCount = fSeriesCount; } -uno::Reference< XTransformation > BarPositionHelper::getTransformationScaledLogicToScene() const +double BarPositionHelper::getScaledSlotPos( double fUnscaledLogicX, double fSeriesNumber ) const { - //transformation from 2) to 4) //@todo 2) and 4) need a link to a document + if( m_bDateAxis ) + fUnscaledLogicX = DateHelper::RasterizeDateValue( fUnscaledLogicX, m_aNullDate, m_nTimeResolution ); + double fScaledLogicX(fUnscaledLogicX); + doLogicScaling(&fScaledLogicX,NULL,NULL); + fScaledLogicX = CategoryPositionHelper::getScaledSlotPos( fScaledLogicX, fSeriesNumber ); + return fScaledLogicX; - //we need to apply this transformation to each geometric object because of a bug/problem - //of the old drawing layer (the UNO_NAME_3D_EXTRUDE_DEPTH is an integer value instead of an double ) - - if( !m_xTransformationLogicToScene.is() ) - { - ::basegfx::B3DHomMatrix aMatrix; - - double MinX = getLogicMinX(); - double MinY = getLogicMinY(); - double MinZ = getLogicMinZ(); - double MaxX = getLogicMaxX(); - double MaxY = getLogicMaxY(); - double MaxZ = getLogicMaxZ(); - - AxisOrientation nXAxisOrientation = m_aScales[0].Orientation; - AxisOrientation nYAxisOrientation = m_aScales[1].Orientation; - AxisOrientation nZAxisOrientation = m_aScales[2].Orientation; - - //apply scaling - //scaling of x axis is refused/ignored - doLogicScaling( NULL, &MinY, &MinZ ); - doLogicScaling( NULL, &MaxY, &MaxZ); - - if(m_bSwapXAndY) - { - std::swap(MinX,MinY); - std::swap(MaxX,MaxY); - std::swap(nXAxisOrientation,nYAxisOrientation); - } - - if( AxisOrientation_MATHEMATICAL==nXAxisOrientation ) - aMatrix.translate(-MinX,0.0,0.0); - else - aMatrix.translate(-MaxX,0.0,0.0); - if( AxisOrientation_MATHEMATICAL==nYAxisOrientation ) - aMatrix.translate(0.0,-MinY,0.0); - else - aMatrix.translate(0.0,-MaxY,0.0); - if( AxisOrientation_MATHEMATICAL==nZAxisOrientation ) - aMatrix.translate(0.0,0.0,-MaxZ);//z direction in draw is reverse mathematical direction - else - aMatrix.translate(0.0,0.0,-MinZ); - - double fWidthX = MaxX - MinX; - double fWidthY = MaxY - MinY; - double fWidthZ = MaxZ - MinZ; - - double fScaleDirectionX = AxisOrientation_MATHEMATICAL==nXAxisOrientation ? 1.0 : -1.0; - double fScaleDirectionY = AxisOrientation_MATHEMATICAL==nYAxisOrientation ? 1.0 : -1.0; - double fScaleDirectionZ = AxisOrientation_MATHEMATICAL==nZAxisOrientation ? -1.0 : 1.0; - - aMatrix.scale(fScaleDirectionX*FIXED_SIZE_FOR_3D_CHART_VOLUME/fWidthX - , fScaleDirectionY*FIXED_SIZE_FOR_3D_CHART_VOLUME/fWidthY - , fScaleDirectionZ*FIXED_SIZE_FOR_3D_CHART_VOLUME/fWidthZ); - - //if(nDim==2) - aMatrix = m_aMatrixScreenToScene*aMatrix; - - m_xTransformationLogicToScene = new Linear3DTransformation(B3DHomMatrixToHomogenMatrix( aMatrix ),m_bSwapXAndY); - } - return m_xTransformationLogicToScene; } +void BarPositionHelper::setScaledCategoryWidth( double fScaledCategoryWidth ) +{ + m_fScaledCategoryWidth = fScaledCategoryWidth; + CategoryPositionHelper::setCategoryWidth( m_fScaledCategoryWidth ); +} //............................................................................. } //namespace chart //............................................................................. diff --git a/chart2/source/view/charttypes/BarPositionHelper.hxx b/chart2/source/view/charttypes/BarPositionHelper.hxx index 32899de62aef..3a905877bcb9 100644 --- a/chart2/source/view/charttypes/BarPositionHelper.hxx +++ b/chart2/source/view/charttypes/BarPositionHelper.hxx @@ -49,25 +49,10 @@ public: virtual PlottingPositionHelper* clone() const; - virtual ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XTransformation > - getTransformationScaledLogicToScene() const; - void updateSeriesCount( double fSeriesCount ); /*only enter the size of x stacked series*/ - sal_Int32 getStartCategoryIndex() const { - //first category (index 0) matches with real number 1.0 - sal_Int32 nStart = static_cast<sal_Int32>(getLogicMinX() - 0.5); - if( nStart < 0 ) - nStart = 0; - return nStart; - } - sal_Int32 getEndCategoryIndex() const { - //first category (index 0) matches with real number 1.0 - sal_Int32 nEnd = static_cast<sal_Int32>(getLogicMaxX() - 0.5); - if( nEnd < 0 ) - nEnd = 0; - return nEnd; - } + virtual double getScaledSlotPos( double fCategoryX, double fSeriesNumber ) const; + virtual void setScaledCategoryWidth( double fScaledCategoryWidth ); }; //............................................................................. diff --git a/chart2/source/view/charttypes/BubbleChart.cxx b/chart2/source/view/charttypes/BubbleChart.cxx index c5454edcc6fd..0cbcff33bfcd 100644 --- a/chart2/source/view/charttypes/BubbleChart.cxx +++ b/chart2/source/view/charttypes/BubbleChart.cxx @@ -121,7 +121,7 @@ void BubbleChart::calculateMaximumLogicBubbleSize() void BubbleChart::calculateBubbleSizeScalingFactor() { - double fLogicZ=0.5; + double fLogicZ=1.0; drawing::Position3D aSceneMinPos( m_pMainPosHelper->transformLogicToScene( m_pMainPosHelper->getLogicMinX(),m_pMainPosHelper->getLogicMinY(),fLogicZ, false ) ); drawing::Position3D aSceneMaxPos( m_pMainPosHelper->transformLogicToScene( m_pMainPosHelper->getLogicMaxX(),m_pMainPosHelper->getLogicMaxY(),fLogicZ, false ) ); @@ -223,7 +223,7 @@ void BubbleChart::createShapes() m_pShapeFactory->createGroup2D( m_xFinalTarget,rtl::OUString() )); //update/create information for current group - double fLogicZ = 0.5;//as defined + double fLogicZ = 1.0;//as defined sal_Int32 nStartIndex = 0; // inclusive ;..todo get somehow from x scale sal_Int32 nEndIndex = VSeriesPlotter::getPointCount(); diff --git a/chart2/source/view/charttypes/BubbleChart.hxx b/chart2/source/view/charttypes/BubbleChart.hxx index 9c04ce8d3719..ed3d9e051cc4 100644 --- a/chart2/source/view/charttypes/BubbleChart.hxx +++ b/chart2/source/view/charttypes/BubbleChart.hxx @@ -46,11 +46,7 @@ public: , sal_Int32 nDimensionCount ); virtual ~BubbleChart(); - //------------------------------------------------------------------------- - // chart2::XPlotter - //------------------------------------------------------------------------- - - virtual void SAL_CALL createShapes(); + virtual void createShapes(); virtual void addSeries( VDataSeries* pSeries, sal_Int32 zSlot = -1, sal_Int32 xSlot = -1,sal_Int32 ySlot = -1 ); diff --git a/chart2/source/view/charttypes/CandleStickChart.cxx b/chart2/source/view/charttypes/CandleStickChart.cxx index ddfe50deed2f..61c49c61d4a0 100644 --- a/chart2/source/view/charttypes/CandleStickChart.cxx +++ b/chart2/source/view/charttypes/CandleStickChart.cxx @@ -30,8 +30,6 @@ #include "CandleStickChart.hxx" #include "ShapeFactory.hxx" -//#include "chartview/servicenames_charttypes.hxx" -//#include "servicenames_coosystems.hxx" #include "CommonConverters.hxx" #include "ObjectIdentifier.hxx" #include "LabelPositionHelper.hxx" @@ -40,6 +38,7 @@ #include "VLegendSymbolFactory.hxx" #include "FormattedStringHelper.hxx" #include "DataSeriesHelper.hxx" +#include "DateHelper.hxx" #include <tools/debug.hxx> #include <rtl/math.hxx> #include <editeng/unoprnms.hxx> @@ -76,22 +75,6 @@ CandleStickChart::~CandleStickChart() // MinimumAndMaximumSupplier //------------------------------------------------------------------------- -double CandleStickChart::getMinimumX() -{ - if( m_bCategoryXAxis ) - return 0.5;//first category (index 0) matches with real number 1.0 - return VSeriesPlotter::getMinimumX(); -} -double CandleStickChart::getMaximumX() -{ - if( m_bCategoryXAxis ) - { - //return category count - sal_Int32 nPointCount = getPointCount(); - return nPointCount+0.5;//first category (index 0) matches with real number 1.0 - } - return VSeriesPlotter::getMaximumX(); -} bool CandleStickChart::isSeperateStackingForDifferentSigns( sal_Int32 /* nDimensionIndex */ ) { return false; @@ -120,18 +103,6 @@ APPHELPER_XSERVICEINFO_IMPL(CandleStickChart,CHART2_VIEW_CANDLESTICKCHART_SERVIC return aSNS; } */ -/* -//----------------------------------------------------------------- -// chart2::XPlotter -//----------------------------------------------------------------- - - ::rtl::OUString SAL_CALL CandleStickChart -::getCoordinateSystemTypeID() - throw (uno::RuntimeException) -{ - return CHART2_COOSYSTEM_CARTESIAN_SERVICE_NAME; -} -*/ drawing::Direction3D CandleStickChart::getPreferredDiagramAspectRatio() const { @@ -205,11 +176,12 @@ void CandleStickChart::createShapes() } //(@todo maybe different iteration for breaks in axis ?) - sal_Int32 nStartCategoryIndex = m_pMainPosHelper->getStartCategoryIndex(); // inclusive - sal_Int32 nEndCategoryIndex = m_pMainPosHelper->getEndCategoryIndex(); //inclusive + sal_Int32 nStartIndex = 0; + sal_Int32 nEndIndex = VSeriesPlotter::getPointCount(); + double fLogicZ = 1.5;//as defined //============================================================================= - //iterate through all shown categories - for( sal_Int32 nIndex = nStartCategoryIndex; nIndex < nEndCategoryIndex; nIndex++ ) + //iterate through all x values per indices + for( sal_Int32 nIndex = nStartIndex; nIndex < nEndIndex; nIndex++ ) { ::std::vector< ::std::vector< VDataSeriesGroup > >::iterator aZSlotIter = m_aZSlots.begin(); const ::std::vector< ::std::vector< VDataSeriesGroup > >::const_iterator aZSlotEnd = m_aZSlots.end(); @@ -247,28 +219,48 @@ void CandleStickChart::createShapes() for( ; aSeriesIter != aSeriesEnd; aSeriesIter++ ) { //collect data point information (logic coordinates, style ): - double fLogicX = pPosHelper->getSlotPos( (*aSeriesIter)->getXValue( nIndex ), fSlotX ); - double fY_First = (*aSeriesIter)->getY_First( nIndex ); - double fY_Last = (*aSeriesIter)->getY_Last( nIndex ); - double fY_Min = (*aSeriesIter)->getY_Min( nIndex ); - double fY_Max = (*aSeriesIter)->getY_Max( nIndex ); + double fUnscaledX = (*aSeriesIter)->getXValue( nIndex ); + if( m_pExplicitCategoriesProvider && m_pExplicitCategoriesProvider->isDateAxis() ) + fUnscaledX = DateHelper::RasterizeDateValue( fUnscaledX, m_aNullDate, m_nTimeResolution ); + if(fUnscaledX<pPosHelper->getLogicMinX() || fUnscaledX>pPosHelper->getLogicMaxX()) + continue;//point not visible + double fScaledX = pPosHelper->getScaledSlotPos( fUnscaledX, fSlotX ); + + double fUnscaledY_First = (*aSeriesIter)->getY_First( nIndex ); + double fUnscaledY_Last = (*aSeriesIter)->getY_Last( nIndex ); + double fUnscaledY_Min = (*aSeriesIter)->getY_Min( nIndex ); + double fUnscaledY_Max = (*aSeriesIter)->getY_Max( nIndex ); bool bBlack=false; - if(fY_Last<=fY_First) + if(fUnscaledY_Last<=fUnscaledY_First) { - std::swap(fY_First,fY_Last); + std::swap(fUnscaledY_First,fUnscaledY_Last); bBlack=true; } - if(fY_Max<fY_Min) - std::swap(fY_Min,fY_Max); + if(fUnscaledY_Max<fUnscaledY_Min) + std::swap(fUnscaledY_Min,fUnscaledY_Max); //transformation 3) -> 4) - double fHalfWidth = pPosHelper->getSlotWidth()/2.0; - drawing::Position3D aPosLeftFirst( pPosHelper->transformLogicToScene( fLogicX-fHalfWidth, fY_First ,0 ,true ) ); - drawing::Position3D aPosRightLast( pPosHelper->transformLogicToScene( fLogicX+fHalfWidth, fY_Last ,0 ,true ) ); - drawing::Position3D aPosMiddleFirst( pPosHelper->transformLogicToScene( fLogicX, fY_First ,0 ,true ) ); - drawing::Position3D aPosMiddleLast( pPosHelper->transformLogicToScene( fLogicX, fY_Last ,0 ,true ) ); - drawing::Position3D aPosMiddleMinimum( pPosHelper->transformLogicToScene( fLogicX, fY_Min ,0 ,true ) ); - drawing::Position3D aPosMiddleMaximum( pPosHelper->transformLogicToScene( fLogicX, fY_Max ,0 ,true ) ); + double fHalfScaledWidth = pPosHelper->getScaledSlotWidth()/2.0; + + double fScaledY_First(fUnscaledY_First); + double fScaledY_Last(fUnscaledY_Last); + double fScaledY_Min(fUnscaledY_Min); + double fScaledY_Max(fUnscaledY_Max); + pPosHelper->clipLogicValues( 0,&fScaledY_First,0 ); + pPosHelper->clipLogicValues( 0,&fScaledY_Last,0 ); + pPosHelper->clipLogicValues( 0,&fScaledY_Min,0 ); + pPosHelper->clipLogicValues( 0,&fScaledY_Max,0 ); + pPosHelper->doLogicScaling( 0,&fScaledY_First,0 ); + pPosHelper->doLogicScaling( 0,&fScaledY_Last,0 ); + pPosHelper->doLogicScaling( 0,&fScaledY_Min,0 ); + pPosHelper->doLogicScaling( 0,&fScaledY_Max,0 ); + + drawing::Position3D aPosLeftFirst( pPosHelper->transformScaledLogicToScene( fScaledX-fHalfScaledWidth, fScaledY_First ,0 ,true ) ); + drawing::Position3D aPosRightLast( pPosHelper->transformScaledLogicToScene( fScaledX+fHalfScaledWidth, fScaledY_Last ,0 ,true ) ); + drawing::Position3D aPosMiddleFirst( pPosHelper->transformScaledLogicToScene( fScaledX, fScaledY_First ,0 ,true ) ); + drawing::Position3D aPosMiddleLast( pPosHelper->transformScaledLogicToScene( fScaledX, fScaledY_Last ,0 ,true ) ); + drawing::Position3D aPosMiddleMinimum( pPosHelper->transformScaledLogicToScene( fScaledX, fScaledY_Min ,0 ,true ) ); + drawing::Position3D aPosMiddleMaximum( pPosHelper->transformScaledLogicToScene( fScaledX, fScaledY_Max ,0 ,true ) ); uno::Reference< drawing::XShapes > xLossGainTarget( xGainTarget ); if(bBlack) @@ -329,13 +321,13 @@ void CandleStickChart::createShapes() drawing::PolyPolygonShape3D aPoly; sal_Int32 nLineIndex = 0; - if( bShowFirst && pPosHelper->isLogicVisible( fLogicX, fY_First ,0 ) + if( bShowFirst && pPosHelper->isLogicVisible( fUnscaledX, fUnscaledY_First ,fLogicZ ) && isValidPosition(aPosLeftFirst) && isValidPosition(aPosMiddleFirst) ) { AddPointToPoly( aPoly, aPosLeftFirst, nLineIndex ); AddPointToPoly( aPoly, aPosMiddleFirst, nLineIndex++ ); } - if( pPosHelper->isLogicVisible( fLogicX, fY_Last ,0 ) + if( pPosHelper->isLogicVisible( fUnscaledX, fUnscaledY_Last ,fLogicZ ) && isValidPosition(aPosMiddleLast) && isValidPosition(aPosRightLast) ) { AddPointToPoly( aPoly, aPosMiddleLast, nLineIndex ); @@ -361,16 +353,16 @@ void CandleStickChart::createShapes() { if(isValidPosition(aPosMiddleFirst)) this->createDataLabel( xTextTarget, **aSeriesIter, nIndex - , fY_First, 1.0, Position3DToAWTPoint(aPosMiddleFirst), LABEL_ALIGN_LEFT_BOTTOM ); + , fUnscaledY_First, 1.0, Position3DToAWTPoint(aPosMiddleFirst), LABEL_ALIGN_LEFT_BOTTOM ); if(isValidPosition(aPosMiddleLast)) this->createDataLabel( xTextTarget, **aSeriesIter, nIndex - , fY_Last, 1.0, Position3DToAWTPoint(aPosMiddleLast), LABEL_ALIGN_RIGHT_TOP ); + , fUnscaledY_Last, 1.0, Position3DToAWTPoint(aPosMiddleLast), LABEL_ALIGN_RIGHT_TOP ); if(isValidPosition(aPosMiddleMinimum)) this->createDataLabel( xTextTarget, **aSeriesIter, nIndex - , fY_Min, 1.0, Position3DToAWTPoint(aPosMiddleMinimum), LABEL_ALIGN_BOTTOM ); + , fUnscaledY_Min, 1.0, Position3DToAWTPoint(aPosMiddleMinimum), LABEL_ALIGN_BOTTOM ); if(isValidPosition(aPosMiddleMaximum)) this->createDataLabel( xTextTarget, **aSeriesIter, nIndex - , fY_Max, 1.0, Position3DToAWTPoint(aPosMiddleMaximum), LABEL_ALIGN_TOP ); + , fUnscaledY_Max, 1.0, Position3DToAWTPoint(aPosMiddleMaximum), LABEL_ALIGN_TOP ); } }//next series in x slot (next y slot) }//next x slot diff --git a/chart2/source/view/charttypes/CandleStickChart.hxx b/chart2/source/view/charttypes/CandleStickChart.hxx index 60018dbe8621..6fbf980058e7 100644 --- a/chart2/source/view/charttypes/CandleStickChart.hxx +++ b/chart2/source/view/charttypes/CandleStickChart.hxx @@ -47,16 +47,7 @@ public: , sal_Int32 nDimensionCount ); virtual ~CandleStickChart(); - //------------------------------------------------------------------------- - // chart2::XPlotter - //------------------------------------------------------------------------- - - virtual void SAL_CALL createShapes(); - /* - virtual ::rtl::OUString SAL_CALL getCoordinateSystemTypeID( ) throw (::com::sun::star::uno::RuntimeException); - virtual void SAL_CALL setScales( const ::com::sun::star::uno::Sequence< ::com::sun::star::chart2::ExplicitScaleData >& rScales ) throw (::com::sun::star::uno::RuntimeException); - virtual void SAL_CALL setTransformation( const ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XTransformation >& xTransformationToLogicTarget, const ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XTransformation >& xTransformationToFinalPage ) throw (::com::sun::star::uno::RuntimeException); - */ + virtual void createShapes(); virtual void addSeries( VDataSeries* pSeries, sal_Int32 zSlot = -1, sal_Int32 xSlot = -1,sal_Int32 ySlot = -1 ); virtual ::com::sun::star::drawing::Direction3D getPreferredDiagramAspectRatio() const; @@ -64,8 +55,6 @@ public: //------------------------------------------------------------------------- // MinimumAndMaximumSupplier //------------------------------------------------------------------------- - virtual double getMinimumX(); - virtual double getMaximumX(); virtual bool isSeperateStackingForDifferentSigns( sal_Int32 nDimensionIndex ); //------------------------------------------------------------------------- diff --git a/chart2/source/view/charttypes/CategoryPositionHelper.cxx b/chart2/source/view/charttypes/CategoryPositionHelper.cxx index d43fd0856e02..76f07168bdf2 100644 --- a/chart2/source/view/charttypes/CategoryPositionHelper.cxx +++ b/chart2/source/view/charttypes/CategoryPositionHelper.cxx @@ -57,7 +57,7 @@ CategoryPositionHelper::~CategoryPositionHelper() { } -double CategoryPositionHelper::getSlotWidth() const +double CategoryPositionHelper::getScaledSlotWidth() const { double fWidth = m_fCategoryWidth / ( m_fSeriesCount @@ -66,14 +66,14 @@ double CategoryPositionHelper::getSlotWidth() const return fWidth; } -double CategoryPositionHelper::getSlotPos( double fCategoryX, double fSeriesNumber ) const +double CategoryPositionHelper::getScaledSlotPos( double fScaledXPos, double fSeriesNumber ) const { //the returned position is in the middle of the rect //fSeriesNumber 0...n-1 - double fPos = fCategoryX - (m_fCategoryWidth/2.0) - + (m_fOuterDistance/2.0 + fSeriesNumber*(1.0+m_fInnerDistance)) * getSlotWidth() - + getSlotWidth()/2.0; - + double fPos = fScaledXPos + - (m_fCategoryWidth/2.0) + + (m_fOuterDistance/2.0 + fSeriesNumber*(1.0+m_fInnerDistance)) * getScaledSlotWidth() + + getScaledSlotWidth()/2.0; return fPos; } @@ -95,6 +95,11 @@ void CategoryPositionHelper::setOuterDistance( double fOuterDistance ) m_fOuterDistance = fOuterDistance; } +void CategoryPositionHelper::setCategoryWidth( double fCategoryWidth ) +{ + m_fCategoryWidth = fCategoryWidth; +} + //............................................................................. } //namespace chart //............................................................................. diff --git a/chart2/source/view/charttypes/CategoryPositionHelper.hxx b/chart2/source/view/charttypes/CategoryPositionHelper.hxx index 08cb1978faa1..c12d17d40b03 100644 --- a/chart2/source/view/charttypes/CategoryPositionHelper.hxx +++ b/chart2/source/view/charttypes/CategoryPositionHelper.hxx @@ -44,8 +44,9 @@ public: CategoryPositionHelper( const CategoryPositionHelper& rSource ); virtual ~CategoryPositionHelper(); - double getSlotWidth() const; - double getSlotPos( double fCategoryX, double fSeriesNumber ) const; + double getScaledSlotWidth() const; + virtual double getScaledSlotPos( double fCategoryX, double fSeriesNumber ) const; + virtual void setCategoryWidth( double fCategoryWidth ); //Distance between two neighboring bars in same category, seen relative to width of the bar void setInnerDistance( double fInnerDistance ); diff --git a/chart2/source/view/charttypes/PieChart.cxx b/chart2/source/view/charttypes/PieChart.cxx index eee13848b11b..abb30c2a67a9 100644 --- a/chart2/source/view/charttypes/PieChart.cxx +++ b/chart2/source/view/charttypes/PieChart.cxx @@ -159,11 +159,9 @@ PieChart::~PieChart() //----------------------------------------------------------------- -void SAL_CALL PieChart::setScales( const uno::Sequence< ExplicitScaleData >& rScales - , sal_Bool /* bSwapXAndYAxis */ ) - throw (uno::RuntimeException) +void PieChart::setScales( const std::vector< ExplicitScaleData >& rScales, bool /* bSwapXAndYAxis */ ) { - DBG_ASSERT(m_nDimension<=rScales.getLength(),"Dimension of Plotter does not fit two dimension of given scale sequence"); + DBG_ASSERT(m_nDimension<=static_cast<sal_Int32>(rScales.size()),"Dimension of Plotter does not fit two dimension of given scale sequence"); m_pPosHelper->setScales( rScales, true ); } @@ -411,7 +409,7 @@ void PieChart::createShapes() if( !bIsVisible ) continue; - double fLogicZ = -0.5;//as defined + double fLogicZ = -1.0;//as defined double fDepth = this->getTransformedDepth(); //============================================================================= @@ -495,11 +493,11 @@ void PieChart::createShapes() awt::Point aScreenPosition2D( aPolarPosHelper.getLabelScreenPositionAndAlignmentForUnitCircleValues(eAlignment, nLabelPlacement , fUnitCircleStartAngleDegree, fUnitCircleWidthAngleDegree - , fUnitCircleInnerRadius, fUnitCircleOuterRadius, 0.0, 0 )); + , fUnitCircleInnerRadius, fUnitCircleOuterRadius, fLogicZ+0.5, 0 )); PieLabelInfo aPieLabelInfo; aPieLabelInfo.aFirstPosition = basegfx::B2IVector( aScreenPosition2D.X, aScreenPosition2D.Y ); - awt::Point aOrigin( aPolarPosHelper.transformSceneToScreenPosition( m_pPosHelper->transformUnitCircleToScene( 0.0, 0.0, 0.5 ) ) ); + awt::Point aOrigin( aPolarPosHelper.transformSceneToScreenPosition( m_pPosHelper->transformUnitCircleToScene( 0.0, 0.0, fLogicZ+1.0 ) ) ); aPieLabelInfo.aOrigin = basegfx::B2IVector( aOrigin.X, aOrigin.Y ); //add a scaling independent Offset if requested diff --git a/chart2/source/view/charttypes/PieChart.hxx b/chart2/source/view/charttypes/PieChart.hxx index e6fedb05d52e..c306e2db256f 100644 --- a/chart2/source/view/charttypes/PieChart.hxx +++ b/chart2/source/view/charttypes/PieChart.hxx @@ -49,24 +49,10 @@ public: , sal_Int32 nDimensionCount, bool bExcludingPositioning ); virtual ~PieChart(); - //------------------------------------------------------------------------- - // chart2::XPlotter - //------------------------------------------------------------------------- - - virtual void SAL_CALL createShapes(); + virtual void createShapes(); virtual void rearrangeLabelToAvoidOverlapIfRequested( const ::com::sun::star::awt::Size& rPageSize ); - virtual void SAL_CALL setScales( - const ::com::sun::star::uno::Sequence< - ::com::sun::star::chart2::ExplicitScaleData >& rScales - , sal_Bool bSwapXAndYAxis ) - throw (::com::sun::star::uno::RuntimeException); - /* - virtual ::rtl::OUString SAL_CALL getCoordinateSystemTypeID( ) throw (::com::sun::star::uno::RuntimeException); - virtual void SAL_CALL setScales( const ::com::sun::star::uno::Sequence< ::com::sun::star::chart2::ExplicitScaleData >& rScales ) throw (::com::sun::star::uno::RuntimeException); - virtual void SAL_CALL setTransformation( const ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XTransformation >& xTransformationToLogicTarget, const ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XTransformation >& xTransformationToFinalPage ) throw (::com::sun::star::uno::RuntimeException); - */ - + virtual void setScales( const ::std::vector< ExplicitScaleData >& rScales, bool bSwapXAndYAxis ); virtual void addSeries( VDataSeries* pSeries, sal_Int32 zSlot = -1, sal_Int32 xSlot = -1,sal_Int32 ySlot = -1 ); //------------------- diff --git a/chart2/source/view/charttypes/VSeriesPlotter.cxx b/chart2/source/view/charttypes/VSeriesPlotter.cxx index 4150fade8834..c37842e19888 100644 --- a/chart2/source/view/charttypes/VSeriesPlotter.cxx +++ b/chart2/source/view/charttypes/VSeriesPlotter.cxx @@ -43,7 +43,7 @@ #include "ChartTypeHelper.hxx" #include "Clipping.hxx" #include "servicenames_charttypes.hxx" -#include "chartview/NumberFormatterWrapper.hxx" +#include "NumberFormatterWrapper.hxx" #include "ContainerHelper.hxx" #include "DataSeriesHelper.hxx" #include "RegressionCurveHelper.hxx" @@ -52,6 +52,8 @@ #include "ResId.hxx" #include "Strings.hrc" #include "RelativePositionHelper.hxx" +#include "DateHelper.hxx" +#include "DiagramHelper.hxx" //only for creation: @todo remove if all plotter are uno components and instanciated via servicefactory #include "BarChart.hxx" @@ -62,6 +64,7 @@ // #include <com/sun/star/chart/ErrorBarStyle.hpp> +#include <com/sun/star/chart/TimeUnit.hpp> #include <com/sun/star/chart2/XRegressionCurveContainer.hpp> #include <com/sun/star/container/XChild.hpp> #include <com/sun/star/chart2/RelativePosition.hpp> @@ -155,6 +158,8 @@ VSeriesPlotter::VSeriesPlotter( const uno::Reference<XChartType>& xChartTypeMode , m_xChartTypeModelProps( uno::Reference< beans::XPropertySet >::query( xChartTypeModel )) , m_aZSlots() , m_bCategoryXAxis(bCategoryXAxis) + , m_nTimeResolution(::com::sun::star::chart::TimeUnit::DAY) + , m_aNullDate(30,12,1899) , m_xColorScheme() , m_pExplicitCategoriesProvider(0) , m_bPointsWereSkipped(false) @@ -201,7 +206,17 @@ void VSeriesPlotter::addSeries( VDataSeries* pSeries, sal_Int32 zSlot, sal_Int32 return; if(m_bCategoryXAxis) - pSeries->setCategoryXAxis(); + { + if( m_pExplicitCategoriesProvider && m_pExplicitCategoriesProvider->isDateAxis() ) + pSeries->setXValues( m_pExplicitCategoriesProvider->getOriginalCategories() ); + else + pSeries->setCategoryXAxis(); + } + else + { + if( m_pExplicitCategoriesProvider ) + pSeries->setXValuesIfNone( m_pExplicitCategoriesProvider->getOriginalCategories() ); + } if(zSlot<0 || zSlot>=static_cast<sal_Int32>(m_aZSlots.size())) { @@ -381,7 +396,7 @@ OUString VSeriesPlotter::getLabelTextForValue( VDataSeries& rDataSeries nNumberFormatKey = rDataSeries.getExplicitNumberFormat(nPointIndex,bAsPercentage); else if( bAsPercentage ) { - sal_Int32 nPercentFormat = ExplicitValueProvider::getPercentNumberFormat( m_apNumberFormatterWrapper->getNumberFormatsSupplier() ); + sal_Int32 nPercentFormat = DiagramHelper::getPercentNumberFormat( m_apNumberFormatterWrapper->getNumberFormatsSupplier() ); if( nPercentFormat != -1 ) nNumberFormatKey = nPercentFormat; } @@ -758,6 +773,17 @@ void lcl_AddErrorBottomLine( const drawing::Position3D& rPosition, ::basegfx::B2 return aMainDirection; } +drawing::Position3D lcl_transformMixedToScene( PlottingPositionHelper* pPosHelper + , double fX /*scaled*/, double fY /*unscaled*/, double fZ /*unscaled*/, bool bClip ) +{ + if(!pPosHelper) + return drawing::Position3D(0,0,0); + pPosHelper->doLogicScaling( 0,&fY,&fZ ); + if(bClip) + pPosHelper->clipScaledLogicValues( &fX,&fY,&fZ ); + return pPosHelper->transformScaledLogicToScene( fX, fY, fZ, false ); +} + } // anonymous namespace // virtual @@ -768,6 +794,7 @@ void VSeriesPlotter::createErrorBar( , const VDataSeries& rVDataSeries , sal_Int32 nIndex , bool bYError /* = true */ + , double* pfScaledLogicX ) { if( !ChartTypeHelper::isSupportingStatisticProperties( m_xChartTypeModel, m_nDimension ) ) @@ -802,7 +829,13 @@ void VSeriesPlotter::createErrorBar( const double fX = aUnscaledLogicPosition.PositionX; const double fY = aUnscaledLogicPosition.PositionY; const double fZ = aUnscaledLogicPosition.PositionZ; - aMiddle = m_pPosHelper->transformLogicToScene( fX, fY, fZ, true ); + double fScaledX = fX; + if( pfScaledLogicX ) + fScaledX = *pfScaledLogicX; + else + m_pPosHelper->doLogicScaling( &fScaledX, 0, 0 ); + + aMiddle = lcl_transformMixedToScene( m_pPosHelper, fScaledX, fY, fZ, true ); drawing::Position3D aNegative(aMiddle); drawing::Position3D aPositive(aMiddle); @@ -817,11 +850,16 @@ void VSeriesPlotter::createErrorBar( double fLocalX = fX; double fLocalY = fY; if( bYError ) + { fLocalY+=fLength; + aPositive = lcl_transformMixedToScene( m_pPosHelper, fScaledX, fLocalY, fZ, true ); + } else + { fLocalX+=fLength; + aPositive = m_pPosHelper->transformLogicToScene( fLocalX, fLocalY, fZ, true ); + } bCreatePositiveBorder = m_pPosHelper->isLogicVisible(fLocalX, fLocalY, fZ); - aPositive = m_pPosHelper->transformLogicToScene( fLocalX, fLocalY, fZ, true ); } else bShowPositive = false; @@ -835,12 +873,16 @@ void VSeriesPlotter::createErrorBar( double fLocalX = fX; double fLocalY = fY; if( bYError ) + { fLocalY-=fLength; + aNegative = lcl_transformMixedToScene( m_pPosHelper, fScaledX, fLocalY, fZ, true ); + } else + { fLocalX-=fLength; - + aNegative = m_pPosHelper->transformLogicToScene( fLocalX, fLocalY, fZ, true ); + } bCreateNegativeBorder = m_pPosHelper->isLogicVisible( fLocalX, fLocalY, fZ); - aNegative = m_pPosHelper->transformLogicToScene( fLocalX, fLocalY, fZ, true ); } else bShowNegative = false; @@ -884,7 +926,8 @@ void VSeriesPlotter::createErrorBar( // virtual void VSeriesPlotter::createErrorBar_Y( const drawing::Position3D& rUnscaledLogicPosition , VDataSeries& rVDataSeries, sal_Int32 nPointIndex - , const uno::Reference< drawing::XShapes >& xTarget ) + , const uno::Reference< drawing::XShapes >& xTarget + , double* pfScaledLogicX ) { if(m_nDimension!=2) return; @@ -898,7 +941,8 @@ void VSeriesPlotter::createErrorBar_Y( const drawing::Position3D& rUnscaledLogic createErrorBar( xErrorBarsGroup_Shapes , rUnscaledLogicPosition, xErrorBarProp , rVDataSeries, nPointIndex - , true /* bYError */ ); + , true /* bYError */ + , pfScaledLogicX ); } } @@ -936,13 +980,13 @@ void VSeriesPlotter::createRegressionCurvesShapes( VDataSeries& rVDataSeries aRegressionPoly.SequenceZ[0].realloc(nRegressionPointCount); sal_Int32 nRealPointCount=0; - uno::Sequence< chart2::ExplicitScaleData > aScaleDataSeq( m_pPosHelper->getScales()); + std::vector< ExplicitScaleData > aScales( m_pPosHelper->getScales()); uno::Reference< chart2::XScaling > xScalingX; uno::Reference< chart2::XScaling > xScalingY; - if( aScaleDataSeq.getLength() >= 2 ) + if( aScales.size() >= 2 ) { - xScalingX.set( aScaleDataSeq[0].Scaling ); - xScalingY.set( aScaleDataSeq[1].Scaling ); + xScalingX.set( aScales[0].Scaling ); + xScalingY.set( aScales[1].Scaling ); } uno::Sequence< geometry::RealPoint2D > aCalculatedPoints( @@ -1126,35 +1170,58 @@ void VSeriesPlotter::setMappedProperties( PropertyMapper::setMappedProperties(xTargetProp,xSource,rMap,pOverwriteMap); } +void VSeriesPlotter::setTimeResolutionOnXAxis( long TimeResolution, const Date& rNullDate ) +{ + m_nTimeResolution = TimeResolution; + m_aNullDate = rNullDate; +} + //------------------------------------------------------------------------- // MinimumAndMaximumSupplier //------------------------------------------------------------------------- - -double VSeriesPlotter::getMinimumX() +long VSeriesPlotter::calculateTimeResolutionOnXAxis() { - if( m_bCategoryXAxis ) + long nRet = ::com::sun::star::chart::TimeUnit::YEAR; + if( m_pExplicitCategoriesProvider ) { - double fRet = 1.0;//first category (index 0) matches with real number 1.0 - if( m_pExplicitCategoriesProvider && m_pExplicitCategoriesProvider->hasComplexCategories() ) - fRet -= 0.5; - return fRet; + const std::vector< DatePlusIndex >& rDateCategories = m_pExplicitCategoriesProvider->getDateCategories(); + std::vector< DatePlusIndex >::const_iterator aIt = rDateCategories.begin(), aEnd = rDateCategories.end(); + Date aNullDate(30,12,1899); + if( m_apNumberFormatterWrapper.get() ) + aNullDate = m_apNumberFormatterWrapper->getNullDate(); + if( aIt!=aEnd ) + { + Date aPrevious(aNullDate); aPrevious+=rtl::math::approxFloor(aIt->fValue); + ++aIt; + for(;aIt!=aEnd;++aIt) + { + Date aCurrent(aNullDate); aCurrent+=rtl::math::approxFloor(aIt->fValue); + if( ::com::sun::star::chart::TimeUnit::YEAR == nRet ) + { + if( DateHelper::IsInSameYear( aPrevious, aCurrent ) ) + nRet = ::com::sun::star::chart::TimeUnit::MONTH; + } + if( ::com::sun::star::chart::TimeUnit::MONTH == nRet ) + { + if( DateHelper::IsInSameMonth( aPrevious, aCurrent ) ) + nRet = ::com::sun::star::chart::TimeUnit::DAY; + } + if( ::com::sun::star::chart::TimeUnit::DAY == nRet ) + break; + aPrevious=aCurrent; + } + } } - + return nRet; +} +double VSeriesPlotter::getMinimumX() +{ double fMinimum, fMaximum; this->getMinimumAndMaximiumX( fMinimum, fMaximum ); return fMinimum; } double VSeriesPlotter::getMaximumX() { - if( m_bCategoryXAxis ) - { - //return category count - double fRet = getPointCount();//first category (index 0) matches with real number 1.0 - if( m_pExplicitCategoriesProvider && m_pExplicitCategoriesProvider->hasComplexCategories() ) - fRet += 0.5; - return fRet; - } - double fMinimum, fMaximum; this->getMinimumAndMaximiumX( fMinimum, fMaximum ); return fMaximum; @@ -1162,7 +1229,7 @@ double VSeriesPlotter::getMaximumX() double VSeriesPlotter::getMinimumYInRange( double fMinimumX, double fMaximumX, sal_Int32 nAxisIndex ) { - if( !m_bCategoryXAxis ) + if( !m_bCategoryXAxis || ( m_pExplicitCategoriesProvider && m_pExplicitCategoriesProvider->isDateAxis() ) ) { double fMinY, fMaxY; this->getMinimumAndMaximiumYInContinuousXRange( fMinY, fMaxY, fMinimumX, fMaximumX, nAxisIndex ); @@ -1196,7 +1263,7 @@ double VSeriesPlotter::getMinimumYInRange( double fMinimumX, double fMaximumX, s double VSeriesPlotter::getMaximumYInRange( double fMinimumX, double fMaximumX, sal_Int32 nAxisIndex ) { - if( !m_bCategoryXAxis ) + if( !m_bCategoryXAxis || ( m_pExplicitCategoriesProvider && m_pExplicitCategoriesProvider->isDateAxis() ) ) { double fMinY, fMaxY; this->getMinimumAndMaximiumYInContinuousXRange( fMinY, fMaxY, fMinimumX, fMaximumX, nAxisIndex ); @@ -1231,13 +1298,13 @@ double VSeriesPlotter::getMaximumYInRange( double fMinimumX, double fMaximumX, s double VSeriesPlotter::getMinimumZ() { //this is the default for all charts without a meaningfull z axis - return 0.5; + return 1.0; } double VSeriesPlotter::getMaximumZ() { - if( 3!=m_nDimension ) - return 0.5; - return m_aZSlots.size()+0.5; + if( 3!=m_nDimension || !m_aZSlots.size() ) + return getMinimumZ()+1; + return m_aZSlots.size(); } namespace @@ -1603,7 +1670,7 @@ double VSeriesPlotter::getTransformedDepth() const return FIXED_SIZE_FOR_3D_CHART_VOLUME/(MaxZ-MinZ); } -void SAL_CALL VSeriesPlotter::addSecondaryValueScale( const ExplicitScaleData& rScale, sal_Int32 nAxisIndex ) +void VSeriesPlotter::addSecondaryValueScale( const ExplicitScaleData& rScale, sal_Int32 nAxisIndex ) throw (uno::RuntimeException) { if( nAxisIndex<1 ) @@ -1633,9 +1700,9 @@ PlottingPositionHelper& VSeriesPlotter::getPlottingPositionHelper( sal_Int32 nAx } } if( !pRet ) - { pRet = m_pMainPosHelper; - } + if(pRet) + pRet->setTimeResolution( m_nTimeResolution, m_aNullDate ); return *pRet; } diff --git a/chart2/source/view/diagram/VDiagram.cxx b/chart2/source/view/diagram/VDiagram.cxx index 4174226b6f62..0aad597d2475 100644 --- a/chart2/source/view/diagram/VDiagram.cxx +++ b/chart2/source/view/diagram/VDiagram.cxx @@ -49,11 +49,8 @@ #include <com/sun/star/lang/XTypeProvider.hpp> // header for class SvxShape #include <svx/unoshape.hxx> -// header for GetSdrObjectFromXShape -#include <svx/unoapi.hxx> // header for class E3dScene #include <svx/scene3d.hxx> -#include <rtl/math.hxx> #include <svx/e3dsceneupdater.hxx> //............................................................................. @@ -107,7 +104,7 @@ VDiagram::~VDiagram() delete m_pShapeFactory; } -void SAL_CALL VDiagram::init( +void VDiagram::init( const uno::Reference< drawing::XShapes >& xLogicTarget , const uno::Reference< drawing::XShapes >& xFinalTarget , const uno::Reference< lang::XMultiServiceFactory >& xFactory ) diff --git a/chart2/source/view/inc/DateHelper.hxx b/chart2/source/view/inc/DateHelper.hxx new file mode 100644 index 000000000000..c2352e246695 --- /dev/null +++ b/chart2/source/view/inc/DateHelper.hxx @@ -0,0 +1,60 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef _CHART2_DATEHELPER_HXX +#define _CHART2_DATEHELPER_HXX + +#include <com/sun/star/chart2/XScaling.hpp> +#include <tools/date.hxx> + +//............................................................................. +namespace chart +{ +//............................................................................. + +//----------------------------------------------------------------------------- +/** +*/ + +class DateHelper +{ +public: + static bool IsInSameYear( const Date& rD1, const Date& rD2 ); + static bool IsInSameMonth( const Date& rD1, const Date& rD2 ); + + static long GetMonthsBetweenDates( Date aD1, Date aD2 ); + static Date GetDateSomeMonthsAway( const Date& rD, long nMonthDistance ); + static Date GetDateSomeYearsAway( const Date& rD, long nYearDistance ); + static bool IsLessThanOneMonthAway( const Date& rD1, const Date& rD2 ); + static bool IsLessThanOneYearAway( const Date& rD1, const Date& rD2 ); + + static double RasterizeDateValue( double fValue, const Date& rNullDate, long TimeResolution ); +}; + +//............................................................................. +} //namespace chart +//............................................................................. +#endif diff --git a/chart2/source/view/inc/MinimumAndMaximumSupplier.hxx b/chart2/source/view/inc/MinimumAndMaximumSupplier.hxx index 1e53d5c144c5..dee1fec8e67d 100644 --- a/chart2/source/view/inc/MinimumAndMaximumSupplier.hxx +++ b/chart2/source/view/inc/MinimumAndMaximumSupplier.hxx @@ -29,7 +29,7 @@ #define _CHART2_MINIMUMANDMAXIMUMSUPPLIER_HXX #include <sal/types.h> - +#include <tools/date.hxx> #include <set> //............................................................................. @@ -60,6 +60,10 @@ public: virtual bool isExpandWideValuesToZero( sal_Int32 nDimensionIndex ) = 0; virtual bool isExpandNarrowValuesTowardZero( sal_Int32 nDimensionIndex ) = 0; virtual bool isSeperateStackingForDifferentSigns( sal_Int32 nDimensionIndex ) = 0; + + //return a constant out of ::com::sun::star::chart::TimeUnit that allows to display the smallest distance between occuring dates + virtual long calculateTimeResolutionOnXAxis() = 0; + virtual void setTimeResolutionOnXAxis( long nTimeResolution, const Date& rNullDate ) = 0; }; class MergedMinimumAndMaximumSupplier : public MinimumAndMaximumSupplier @@ -86,6 +90,9 @@ public: virtual bool isExpandNarrowValuesTowardZero( sal_Int32 nDimensionIndex ); virtual bool isSeperateStackingForDifferentSigns( sal_Int32 nDimensionIndex ); + virtual long calculateTimeResolutionOnXAxis(); + virtual void setTimeResolutionOnXAxis( long nTimeResolution, const Date& rNullDate ); + private: typedef ::std::set< MinimumAndMaximumSupplier* > MinimumAndMaximumSupplierSet; MinimumAndMaximumSupplierSet m_aMinimumAndMaximumSupplierList; diff --git a/chart2/source/view/inc/PlotterBase.hxx b/chart2/source/view/inc/PlotterBase.hxx index 63e276b19e44..7920845248e4 100644 --- a/chart2/source/view/inc/PlotterBase.hxx +++ b/chart2/source/view/inc/PlotterBase.hxx @@ -27,28 +27,18 @@ #ifndef _CHART2_PLOTTERBASE_HXX #define _CHART2_PLOTTERBASE_HXX +#include "chartview/ExplicitScaleValues.hxx" + #include <com/sun/star/drawing/HomogenMatrix.hpp> #include <com/sun/star/drawing/XShapes.hpp> #include <com/sun/star/lang/XServiceInfo.hpp> #include <com/sun/star/uno/XComponentContext.hpp> #include <com/sun/star/drawing/Position3D.hpp> #include <com/sun/star/beans/XPropertySet.hpp> -/* -#include <com/sun/star/lang/XComponent.hpp> -*/ - -//---- -#include <vector> - -//---- chart2 -#include <com/sun/star/chart2/ExplicitScaleData.hpp> #include <com/sun/star/chart2/XTransformation.hpp> -/* -#include <com/sun/star/chart2/XPlotter.hpp> -*/ -//---- #include <cppuhelper/implbase1.hxx> +#include <vector> //............................................................................. namespace chart @@ -64,8 +54,7 @@ public: PlotterBase( sal_Int32 nDimension ); virtual ~PlotterBase(); - // ___chart2::XPlotter___ - virtual void SAL_CALL initPlotter( + virtual void initPlotter( const ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShapes >& xLogicTarget , const ::com::sun::star::uno::Reference< @@ -75,21 +64,13 @@ public: , const rtl::OUString& rCID ) throw (::com::sun::star::uno::RuntimeException ); - virtual void SAL_CALL setScales( - const ::com::sun::star::uno::Sequence< - ::com::sun::star::chart2::ExplicitScaleData >& rScales - , sal_Bool bSwapXAndYAxis ) - throw (::com::sun::star::uno::RuntimeException); + virtual void setScales( const ::std::vector< ExplicitScaleData >& rScales, bool bSwapXAndYAxis ); virtual void setTransformationSceneToScreen( const ::com::sun::star::drawing::HomogenMatrix& rMatrix ); - virtual void SAL_CALL createShapes() = 0; + virtual void createShapes() = 0; static bool isValidPosition( const ::com::sun::star::drawing::Position3D& rPos ); - /* - virtual ::rtl::OUString SAL_CALL getCoordinateSystemTypeID( ) throw (::com::sun::star::uno::RuntimeException); - virtual void SAL_CALL setTransformation( const ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XTransformation >& xTransformationToLogicTarget, const ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XTransformation >& xTransformationToFinalPage ) throw (::com::sun::star::uno::RuntimeException); - */ //------------------------------------------------------------------------- //------------------------------------------------------------------------- diff --git a/chart2/source/view/inc/PlottingPositionHelper.hxx b/chart2/source/view/inc/PlottingPositionHelper.hxx index a1f16883b779..42c7a90a0116 100644 --- a/chart2/source/view/inc/PlottingPositionHelper.hxx +++ b/chart2/source/view/inc/PlottingPositionHelper.hxx @@ -28,9 +28,10 @@ #define _CHART2_PLOTTINGPOSITIONHELPER_HXX #include "LabelAlignment.hxx" +#include "chartview/ExplicitScaleValues.hxx" + #include <basegfx/range/b2drectangle.hxx> #include <rtl/math.hxx> -#include <com/sun/star/chart2/ExplicitScaleData.hpp> #include <com/sun/star/chart2/XTransformation.hpp> #include <com/sun/star/drawing/Direction3D.hpp> #include <com/sun/star/drawing/HomogenMatrix.hpp> @@ -62,23 +63,22 @@ public: virtual ~PlottingPositionHelper(); virtual PlottingPositionHelper* clone() const; - virtual PlottingPositionHelper* createSecondaryPosHelper( const ::com::sun::star::chart2::ExplicitScaleData& rSecondaryScale ); + virtual PlottingPositionHelper* createSecondaryPosHelper( const ExplicitScaleData& rSecondaryScale ); virtual void setTransformationSceneToScreen( const ::com::sun::star::drawing::HomogenMatrix& rMatrix); - virtual void setScales( const ::com::sun::star::uno::Sequence< - ::com::sun::star::chart2::ExplicitScaleData >& rScales - , sal_Bool bSwapXAndYAxis ); - const ::com::sun::star::uno::Sequence< - ::com::sun::star::chart2::ExplicitScaleData >& getScales() const; + virtual void setScales( const ::std::vector< ExplicitScaleData >& rScales, bool bSwapXAndYAxis ); + const ::std::vector< ExplicitScaleData >& getScales() const; //better performance for big data inline void setCoordinateSystemResolution( const ::com::sun::star::uno::Sequence< sal_Int32 >& rCoordinateSystemResolution ); inline bool isSameForGivenResolution( double fX, double fY, double fZ , double fX2, double fY2, double fZ2 ); + inline bool isStrongLowerRequested( sal_Int32 nDimensionIndex ) const; inline bool isLogicVisible( double fX, double fY, double fZ ) const; inline void doLogicScaling( double* pX, double* pY, double* pZ, bool bClip=false ) const; + inline void doUnshiftedLogicScaling( double* pX, double* pY, double* pZ, bool bClip=false ) const; inline void clipLogicValues( double* pX, double* pY, double* pZ ) const; void clipScaledLogicValues( double* pX, double* pY, double* pZ ) const; inline bool clipYRange( double& rMin, double& rMax ) const; @@ -123,10 +123,14 @@ public: inline bool maySkipPointsInRegressionCalculation() const; + void setTimeResolution( long nTimeResolution, const Date& rNullDate ); + virtual void setScaledCategoryWidth( double fScaledCategoryWidth ); + void AllowShiftXAxisPos( bool bAllowShift ); + void AllowShiftZAxisPos( bool bAllowShift ); + protected: //member - ::com::sun::star::uno::Sequence< - ::com::sun::star::chart2::ExplicitScaleData > m_aScales; - ::basegfx::B3DHomMatrix m_aMatrixScreenToScene; + ::std::vector< ExplicitScaleData > m_aScales; + ::basegfx::B3DHomMatrix m_aMatrixScreenToScene; //this is calculated based on m_aScales and m_aMatrixScreenToScene mutable ::com::sun::star::uno::Reference< @@ -139,6 +143,14 @@ protected: //member sal_Int32 m_nZResolution; bool m_bMaySkipPointsInRegressionCalculation; + + bool m_bDateAxis; + long m_nTimeResolution; + Date m_aNullDate; + + double m_fScaledCategoryWidth; + bool m_bAllowShiftXAxisPos; + bool m_bAllowShiftZAxisPos; }; //describes wich axis of the drawinglayer scene or sreen axis are the normal axis @@ -163,9 +175,7 @@ public: virtual PlottingPositionHelper* clone() const; virtual void setTransformationSceneToScreen( const ::com::sun::star::drawing::HomogenMatrix& rMatrix); - virtual void setScales( const ::com::sun::star::uno::Sequence< - ::com::sun::star::chart2::ExplicitScaleData >& rScales - , sal_Bool bSwapXAndYAxis ); + virtual void setScales( const std::vector< ExplicitScaleData >& rScales, bool bSwapXAndYAxis ); ::basegfx::B3DHomMatrix getUnitCartesianToScene() const; @@ -227,14 +237,14 @@ private: bool PolarPlottingPositionHelper::isMathematicalOrientationAngle() const { - const ::com::sun::star::chart2::ExplicitScaleData& rScale = m_bSwapXAndY ? m_aScales[1] : m_aScales[2]; + const ExplicitScaleData& rScale = m_bSwapXAndY ? m_aScales[1] : m_aScales[2]; if( ::com::sun::star::chart2::AxisOrientation_MATHEMATICAL==rScale.Orientation ) return true; return false; } bool PolarPlottingPositionHelper::isMathematicalOrientationRadius() const { - const ::com::sun::star::chart2::ExplicitScaleData& rScale = m_bSwapXAndY ? m_aScales[0] : m_aScales[1]; + const ExplicitScaleData& rScale = m_bSwapXAndY ? m_aScales[0] : m_aScales[1]; if( ::com::sun::star::chart2::AxisOrientation_MATHEMATICAL==rScale.Orientation ) return true; return false; @@ -283,12 +293,23 @@ bool PlottingPositionHelper::isSameForGivenResolution( double fX, double fY, dou return (bSameX && bSameY && bSameZ); } +bool PlottingPositionHelper::isStrongLowerRequested( sal_Int32 nDimensionIndex ) const +{ + if( m_aScales.empty() ) + return false; + if( 0==nDimensionIndex ) + return m_bAllowShiftXAxisPos && m_aScales[nDimensionIndex].ShiftedCategoryPosition; + else if( 2==nDimensionIndex ) + return m_bAllowShiftZAxisPos && m_aScales[nDimensionIndex].ShiftedCategoryPosition; + return false; +} + bool PlottingPositionHelper::isLogicVisible( double fX, double fY, double fZ ) const { - return fX >= m_aScales[0].Minimum && fX <= m_aScales[0].Maximum + return fX >= m_aScales[0].Minimum && ( isStrongLowerRequested(0) ? fX < m_aScales[0].Maximum : fX <= m_aScales[0].Maximum ) && fY >= m_aScales[1].Minimum && fY <= m_aScales[1].Maximum - && fZ >= m_aScales[2].Minimum && fZ <= m_aScales[2].Maximum; + && fZ >= m_aScales[2].Minimum && ( isStrongLowerRequested(2) ? fZ < m_aScales[2].Maximum : fZ <= m_aScales[2].Maximum ); } void PlottingPositionHelper::doLogicScaling( double* pX, double* pY, double* pZ, bool bClip ) const @@ -296,6 +317,29 @@ void PlottingPositionHelper::doLogicScaling( double* pX, double* pY, double* pZ, if(bClip) this->clipLogicValues( pX,pY,pZ ); + if(pX) + { + if( m_aScales[0].Scaling.is()) + *pX = m_aScales[0].Scaling->doScaling(*pX); + if( m_bAllowShiftXAxisPos && m_aScales[0].ShiftedCategoryPosition ) + (*pX) += m_fScaledCategoryWidth/2.0; + } + if(pY && m_aScales[1].Scaling.is()) + *pY = m_aScales[1].Scaling->doScaling(*pY); + if(pZ) + { + if( m_aScales[2].Scaling.is()) + *pZ = m_aScales[2].Scaling->doScaling(*pZ); + if( m_bAllowShiftZAxisPos && m_aScales[2].ShiftedCategoryPosition) + (*pZ) += 0.5; + } +} + +void PlottingPositionHelper::doUnshiftedLogicScaling( double* pX, double* pY, double* pZ, bool bClip ) const +{ + if(bClip) + this->clipLogicValues( pX,pY,pZ ); + if(pX && m_aScales[0].Scaling.is()) *pX = m_aScales[0].Scaling->doScaling(*pX); if(pY && m_aScales[1].Scaling.is()) diff --git a/chart2/source/view/inc/ScaleAutomatism.hxx b/chart2/source/view/inc/ScaleAutomatism.hxx index 4440ad26ac5a..327027efcf39 100644 --- a/chart2/source/view/inc/ScaleAutomatism.hxx +++ b/chart2/source/view/inc/ScaleAutomatism.hxx @@ -27,10 +27,11 @@ #ifndef _CHART2_SCALEAUTOMATISM_HXX #define _CHART2_SCALEAUTOMATISM_HXX -#include <com/sun/star/chart2/ExplicitIncrementData.hpp> -#include <com/sun/star/chart2/ExplicitScaleData.hpp> +#include "chartview/ExplicitScaleValues.hxx" #include <com/sun/star/chart2/ScaleData.hpp> +#include <tools/date.hxx> + //............................................................................. namespace chart { @@ -44,7 +45,7 @@ class ScaleAutomatism { public: explicit ScaleAutomatism( - const ::com::sun::star::chart2::ScaleData& rSourceScale ); + const ::com::sun::star::chart2::ScaleData& rSourceScale, const Date& rNullDate ); virtual ~ScaleAutomatism(); /** Expands own value range with the passed minimum and maximum. */ @@ -75,30 +76,41 @@ public: of the axis and the font size of the axis caption text. */ void setMaximumAutoMainIncrementCount( sal_Int32 nMaximumAutoMainIncrementCount ); + /** Sets the time resolution to be used in case it is not set explicitly within the scale + */ + void setAutomaticTimeResolution( sal_Int32 nTimeResolution ); + /** Fills the passed scale data and increment data according to the own settings. */ void calculateExplicitScaleAndIncrement( - ::com::sun::star::chart2::ExplicitScaleData& rExplicitScale, - ::com::sun::star::chart2::ExplicitIncrementData& rExplicitIncrement ) const; + ExplicitScaleData& rExplicitScale, + ExplicitIncrementData& rExplicitIncrement ) const; ::com::sun::star::chart2::ScaleData getScale() const; + Date getNullDate() const; private: /** Fills the passed scale data and increment data for category scaling. */ void calculateExplicitIncrementAndScaleForCategory( - ::com::sun::star::chart2::ExplicitScaleData& rExplicitScale, - ::com::sun::star::chart2::ExplicitIncrementData& rExplicitIncrement, + ExplicitScaleData& rExplicitScale, + ExplicitIncrementData& rExplicitIncrement, bool bAutoMinimum, bool bAutoMaximum ) const; /** Fills the passed scale data and increment data for logarithmic scaling. */ void calculateExplicitIncrementAndScaleForLogarithmic( - ::com::sun::star::chart2::ExplicitScaleData& rExplicitScale, - ::com::sun::star::chart2::ExplicitIncrementData& rExplicitIncrement, + ExplicitScaleData& rExplicitScale, + ExplicitIncrementData& rExplicitIncrement, bool bAutoMinimum, bool bAutoMaximum ) const; /** Fills the passed scale data and increment data for linear scaling. */ void calculateExplicitIncrementAndScaleForLinear( - ::com::sun::star::chart2::ExplicitScaleData& rExplicitScale, - ::com::sun::star::chart2::ExplicitIncrementData& rExplicitIncrement, + ExplicitScaleData& rExplicitScale, + ExplicitIncrementData& rExplicitIncrement, + bool bAutoMinimum, bool bAutoMaximum ) const; + + /** Fills the passed scale data and increment data for date-time axis. */ + void calculateExplicitIncrementAndScaleForDateTimeAxis( + ExplicitScaleData& rExplicitScale, + ExplicitIncrementData& rExplicitIncrement, bool bAutoMinimum, bool bAutoMaximum ) const; private: @@ -111,6 +123,9 @@ private: bool m_bExpandIfValuesCloseToBorder; /// true = Expand if values are too close to the borders. bool m_bExpandWideValuesToZero; /// true = Expand wide spread values to zero. bool m_bExpandNarrowValuesTowardZero; /// true = Expand narrow range toward zero (add half of range). + sal_Int32 m_nTimeResolution;// a constant out of ::com::sun::star::chart::TimeUnit + + Date m_aNullDate; }; //............................................................................. diff --git a/chart2/source/view/inc/VCoordinateSystem.hxx b/chart2/source/view/inc/VCoordinateSystem.hxx index e884af865d6e..f4fd12547118 100644 --- a/chart2/source/view/inc/VCoordinateSystem.hxx +++ b/chart2/source/view/inc/VCoordinateSystem.hxx @@ -31,9 +31,8 @@ #include "ScaleAutomatism.hxx" #include "ThreeDHelper.hxx" #include "ExplicitCategoriesProvider.hxx" +#include "chartview/ExplicitScaleValues.hxx" -#include <com/sun/star/chart2/ExplicitIncrementData.hpp> -#include <com/sun/star/chart2/ExplicitScaleData.hpp> #include <com/sun/star/chart2/XCoordinateSystem.hpp> #include "comphelper/implementationreference.hxx" #include <com/sun/star/awt/Rectangle.hpp> @@ -63,7 +62,7 @@ public: static VCoordinateSystem* createCoordinateSystem( const ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XCoordinateSystem >& xCooSysModel ); - virtual void SAL_CALL initPlottingTargets( + virtual void initPlottingTargets( const ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShapes >& xLogicTarget , const ::com::sun::star::uno::Reference< @@ -83,16 +82,16 @@ public: virtual ::com::sun::star::uno::Sequence< sal_Int32 > getCoordinateSystemResolution( const ::com::sun::star::awt::Size& rPageSize , const ::com::sun::star::awt::Size& rPageResolution ); - ::com::sun::star::chart2::ExplicitScaleData getExplicitScale( sal_Int32 nDimensionIndex, sal_Int32 nAxisIndex ) const; - ::com::sun::star::chart2::ExplicitIncrementData getExplicitIncrement( sal_Int32 nDimensionIndex, sal_Int32 nAxisIndex ) const; + ExplicitScaleData getExplicitScale( sal_Int32 nDimensionIndex, sal_Int32 nAxisIndex ) const; + ExplicitIncrementData getExplicitIncrement( sal_Int32 nDimensionIndex, sal_Int32 nAxisIndex ) const; void setExplicitCategoriesProvider( ExplicitCategoriesProvider* /*takes ownership*/ ); ExplicitCategoriesProvider* getExplicitCategoriesProvider(); // returns a coplete scale set for a given dimension and index; for example if nDimensionIndex==1 and nAxisIndex==2 you get returned the secondary x axis, main y axis and main z axis - ::com::sun::star::uno::Sequence< ::com::sun::star::chart2::ExplicitScaleData > getExplicitScales( sal_Int32 nDimensionIndex, sal_Int32 nAxisIndex ) const; + ::std::vector< ExplicitScaleData > getExplicitScales( sal_Int32 nDimensionIndex, sal_Int32 nAxisIndex ) const; // returns a coplete increment set for a given dimension and index; for example if nDimensionIndex==1 and nAxisIndex==2 you get returned the secondary x axis, main y axis and main z axis - ::com::sun::star::uno::Sequence< ::com::sun::star::chart2::ExplicitIncrementData > getExplicitIncrements( sal_Int32 nDimensionIndex, sal_Int32 nAxisIndex ) const; + ::std::vector< ExplicitIncrementData > getExplicitIncrements( sal_Int32 nDimensionIndex, sal_Int32 nAxisIndex ) const; void addMinimumAndMaximumSupplier( MinimumAndMaximumSupplier* pMinimumAndMaximumSupplier ); bool hasMinimumAndMaximumSupplier( MinimumAndMaximumSupplier* pMinimumAndMaximumSupplier ); @@ -101,8 +100,8 @@ public: void prepareScaleAutomatismForDimensionAndIndex( ScaleAutomatism& rScaleAutomatism, sal_Int32 nDimIndex, sal_Int32 nAxisIndex ); void setExplicitScaleAndIncrement( sal_Int32 nDimensionIndex, sal_Int32 nAxisIndex - , const ::com::sun::star::chart2::ExplicitScaleData& rExplicitScale - , const ::com::sun::star::chart2::ExplicitIncrementData& rExplicitIncrement ); + , const ExplicitScaleData& rExplicitScale + , const ExplicitIncrementData& rExplicitIncrement ); void set3DWallPositions( CuboidPlanePosition eLeftWallPos, CuboidPlanePosition eBackWallPos, CuboidPlanePosition eBottomPos ); @@ -143,8 +142,6 @@ protected: //methods VAxisBase* getVAxis( sal_Int32 nDimensionIndex, sal_Int32 nAxisIndex ); - void prepareScaleAutomatism( ScaleAutomatism& rScaleAutomatism, double fMin, double fMax, sal_Int32 nDimIndex, sal_Int32 nAxisIndex ); - rtl::OUString createCIDForAxis( const ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XAxis >& xAxis , sal_Int32 nDimensionIndex, sal_Int32 nAxisIndex ); @@ -194,11 +191,11 @@ protected: //member tVAxisMap m_aAxisMap; private: - ::com::sun::star::uno::Sequence< ::com::sun::star::chart2::ExplicitScaleData > m_aExplicitScales; - ::com::sun::star::uno::Sequence< ::com::sun::star::chart2::ExplicitIncrementData > m_aExplicitIncrements; + std::vector< ExplicitScaleData > m_aExplicitScales; + std::vector< ExplicitIncrementData > m_aExplicitIncrements; - typedef std::map< tFullAxisIndex, ::com::sun::star::chart2::ExplicitScaleData > tFullExplicitScaleMap; - typedef std::map< tFullAxisIndex, ::com::sun::star::chart2::ExplicitIncrementData > tFullExplicitIncrementMap; + typedef std::map< tFullAxisIndex, ExplicitScaleData > tFullExplicitScaleMap; + typedef std::map< tFullAxisIndex, ExplicitIncrementData > tFullExplicitIncrementMap; tFullExplicitScaleMap m_aSecondaryExplicitScales; tFullExplicitIncrementMap m_aSecondaryExplicitIncrements; diff --git a/chart2/source/view/inc/VDataSeries.hxx b/chart2/source/view/inc/VDataSeries.hxx index 93aba58dbec4..62d61cb17269 100644 --- a/chart2/source/view/inc/VDataSeries.hxx +++ b/chart2/source/view/inc/VDataSeries.hxx @@ -81,6 +81,10 @@ public: getModel() const; void setCategoryXAxis(); + void setXValues( const ::com::sun::star::uno::Reference< + ::com::sun::star::chart2::data::XDataSequence >& xValues ); + void setXValuesIfNone( const ::com::sun::star::uno::Reference< + ::com::sun::star::chart2::data::XDataSequence >& xValues ); void setParticle( const rtl::OUString& rSeriesParticle ); void setGlobalSeriesIndex( sal_Int32 nGlobalSeriesIndex ); void setPageReferenceSize( const ::com::sun::star::awt::Size & rPageRefSize ); diff --git a/chart2/source/view/inc/VDiagram.hxx b/chart2/source/view/inc/VDiagram.hxx index 5df198c2f539..6bcef92111ef 100644 --- a/chart2/source/view/inc/VDiagram.hxx +++ b/chart2/source/view/inc/VDiagram.hxx @@ -56,7 +56,7 @@ public: //methods , sal_Int32 nDimension=3, sal_Bool bPolar=sal_False ); virtual ~VDiagram(); - void SAL_CALL init( const ::com::sun::star::uno::Reference< + void init( const ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShapes >& xLogicTarget , const ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShapes >& xFinalTarget diff --git a/chart2/source/view/inc/VSeriesPlotter.hxx b/chart2/source/view/inc/VSeriesPlotter.hxx index 6b6b06437542..8147c3443ec6 100644 --- a/chart2/source/view/inc/VSeriesPlotter.hxx +++ b/chart2/source/view/inc/VSeriesPlotter.hxx @@ -174,8 +174,7 @@ public: ) */ - virtual void SAL_CALL addSecondaryValueScale( const - ::com::sun::star::chart2::ExplicitScaleData& rScale, sal_Int32 nAxisIndex ) + virtual void addSecondaryValueScale( const ExplicitScaleData& rScale, sal_Int32 nAxisIndex ) throw (::com::sun::star::uno::RuntimeException); //------------------------------------------------------------------------- @@ -197,6 +196,9 @@ public: virtual bool isExpandNarrowValuesTowardZero( sal_Int32 nDimensionIndex ); virtual bool isSeperateStackingForDifferentSigns( sal_Int32 nDimensionIndex ); + virtual long calculateTimeResolutionOnXAxis(); + virtual void setTimeResolutionOnXAxis( long nTimeResolution, const Date& rNullDate ); + //------ void getMinimumAndMaximiumX( double& rfMinimum, double& rfMaximum ) const; @@ -379,12 +381,14 @@ protected: //methods , const VDataSeries& rVDataSeries , sal_Int32 nIndex , bool bVertical + , double* pfScaledLogicX ); virtual void createErrorBar_Y( const ::com::sun::star::drawing::Position3D& rUnscaledLogicPosition , VDataSeries& rVDataSeries, sal_Int32 nPointIndex , const ::com::sun::star::uno::Reference< - ::com::sun::star::drawing::XShapes >& xTarget ); + ::com::sun::star::drawing::XShapes >& xTarget + , double* pfScaledLogicX=0 ); virtual void createRegressionCurvesShapes( VDataSeries& rVDataSeries , const ::com::sun::star::uno::Reference< @@ -425,6 +429,8 @@ protected: //member ::std::vector< ::std::vector< VDataSeriesGroup > > m_aZSlots; bool m_bCategoryXAxis;//true->xvalues are indices (this would not be necessary if series for category chart wouldn't have x-values) + long m_nTimeResolution; + Date m_aNullDate; ::std::auto_ptr< NumberFormatterWrapper > m_apNumberFormatterWrapper; AxesNumberFormats m_aAxesNumberFormats;//direct numberformats on axes, if empty ask the data series instead @@ -439,7 +445,7 @@ protected: //member bool m_bPointsWereSkipped; private: //member - typedef std::map< sal_Int32 , ::com::sun::star::chart2::ExplicitScaleData > tSecondaryValueScales; + typedef std::map< sal_Int32 , ExplicitScaleData > tSecondaryValueScales; tSecondaryValueScales m_aSecondaryValueScales; typedef std::map< sal_Int32 , PlottingPositionHelper* > tSecondaryPosHelperMap; diff --git a/chart2/source/view/main/ChartItemPool.cxx b/chart2/source/view/main/ChartItemPool.cxx index c997f9ee483d..fe83c0eea7e2 100644 --- a/chart2/source/view/main/ChartItemPool.cxx +++ b/chart2/source/view/main/ChartItemPool.cxx @@ -65,52 +65,17 @@ ChartItemPool::ChartItemPool(): SvULongs aTmp; ppPoolDefaults[SCHATTR_DATADESCR_AVAILABLE_PLACEMENTS - SCHATTR_START] = new SfxIntegerListItem(SCHATTR_DATADESCR_AVAILABLE_PLACEMENTS,aTmp); ppPoolDefaults[SCHATTR_DATADESCR_NO_PERCENTVALUE - SCHATTR_START] = new SfxBoolItem(SCHATTR_DATADESCR_NO_PERCENTVALUE); + ppPoolDefaults[SCHATTR_PERCENT_NUMBERFORMAT_VALUE - SCHATTR_START] = new SfxUInt32Item(SCHATTR_PERCENT_NUMBERFORMAT_VALUE, 0); + ppPoolDefaults[SCHATTR_PERCENT_NUMBERFORMAT_SOURCE - SCHATTR_START] = new SfxBoolItem(SCHATTR_PERCENT_NUMBERFORMAT_SOURCE); + //legend ppPoolDefaults[SCHATTR_LEGEND_POS - SCHATTR_START] = new SvxChartLegendPosItem( CHLEGEND_RIGHT, SCHATTR_LEGEND_POS ); -// ppPoolDefaults[SCHATTR_TEXT_ORIENT - SCHATTR_START] = new SvxChartTextOrientItem; + + //text + ppPoolDefaults[SCHATTR_TEXT_DEGREES - SCHATTR_START] = new SfxInt32Item(SCHATTR_TEXT_DEGREES, 0); ppPoolDefaults[SCHATTR_TEXT_STACKED - SCHATTR_START] = new SfxBoolItem(SCHATTR_TEXT_STACKED,FALSE); - ppPoolDefaults[SCHATTR_TEXT_ORDER - SCHATTR_START] = new SvxChartTextOrderItem(CHTXTORDER_SIDEBYSIDE, SCHATTR_TEXT_ORDER); - - ppPoolDefaults[SCHATTR_Y_AXIS_AUTO_MIN - SCHATTR_START] = new SfxBoolItem(SCHATTR_Y_AXIS_AUTO_MIN); - ppPoolDefaults[SCHATTR_Y_AXIS_MIN - SCHATTR_START] = new SvxDoubleItem(0.0, SCHATTR_Y_AXIS_MIN); - ppPoolDefaults[SCHATTR_Y_AXIS_AUTO_MAX - SCHATTR_START] = new SfxBoolItem(SCHATTR_Y_AXIS_AUTO_MAX); - ppPoolDefaults[SCHATTR_Y_AXIS_MAX - SCHATTR_START] = new SvxDoubleItem(0.0, SCHATTR_Y_AXIS_MAX); - ppPoolDefaults[SCHATTR_Y_AXIS_AUTO_STEP_MAIN - SCHATTR_START] = new SfxBoolItem(SCHATTR_Y_AXIS_AUTO_STEP_MAIN); - ppPoolDefaults[SCHATTR_Y_AXIS_STEP_MAIN - SCHATTR_START] = new SvxDoubleItem(0.0, SCHATTR_Y_AXIS_STEP_MAIN); - ppPoolDefaults[SCHATTR_Y_AXIS_AUTO_STEP_HELP - SCHATTR_START] = new SfxBoolItem(SCHATTR_Y_AXIS_AUTO_STEP_HELP); - ppPoolDefaults[SCHATTR_Y_AXIS_STEP_HELP - SCHATTR_START] = new SvxDoubleItem(0.0, SCHATTR_Y_AXIS_STEP_HELP); - ppPoolDefaults[SCHATTR_Y_AXIS_LOGARITHM - SCHATTR_START] = new SfxBoolItem(SCHATTR_Y_AXIS_LOGARITHM); - ppPoolDefaults[SCHATTR_Y_AXIS_AUTO_ORIGIN - SCHATTR_START] = new SfxBoolItem(SCHATTR_Y_AXIS_AUTO_ORIGIN); - ppPoolDefaults[SCHATTR_Y_AXIS_ORIGIN - SCHATTR_START] = new SvxDoubleItem(0.0, SCHATTR_Y_AXIS_ORIGIN); - - ppPoolDefaults[SCHATTR_X_AXIS_AUTO_MIN - SCHATTR_START] = new SfxBoolItem(SCHATTR_X_AXIS_AUTO_MIN); - ppPoolDefaults[SCHATTR_X_AXIS_MIN - SCHATTR_START] = new SvxDoubleItem(0.0, SCHATTR_X_AXIS_MIN); - ppPoolDefaults[SCHATTR_X_AXIS_AUTO_MAX - SCHATTR_START] = new SfxBoolItem(SCHATTR_X_AXIS_AUTO_MAX); - ppPoolDefaults[SCHATTR_X_AXIS_MAX - SCHATTR_START] = new SvxDoubleItem(0.0, SCHATTR_X_AXIS_MAX); - ppPoolDefaults[SCHATTR_X_AXIS_AUTO_STEP_MAIN - SCHATTR_START] = new SfxBoolItem(SCHATTR_X_AXIS_AUTO_STEP_MAIN); - ppPoolDefaults[SCHATTR_X_AXIS_STEP_MAIN - SCHATTR_START] = new SvxDoubleItem(0.0, SCHATTR_X_AXIS_STEP_MAIN); - ppPoolDefaults[SCHATTR_X_AXIS_AUTO_STEP_HELP - SCHATTR_START] = new SfxBoolItem(SCHATTR_X_AXIS_AUTO_STEP_HELP); - ppPoolDefaults[SCHATTR_X_AXIS_STEP_HELP - SCHATTR_START] = new SvxDoubleItem(0.0, SCHATTR_X_AXIS_STEP_HELP); - ppPoolDefaults[SCHATTR_X_AXIS_LOGARITHM - SCHATTR_START] = new SfxBoolItem(SCHATTR_X_AXIS_LOGARITHM); - ppPoolDefaults[SCHATTR_X_AXIS_AUTO_ORIGIN - SCHATTR_START] = new SfxBoolItem(SCHATTR_X_AXIS_AUTO_ORIGIN); - ppPoolDefaults[SCHATTR_X_AXIS_ORIGIN - SCHATTR_START] = new SvxDoubleItem(0.0, SCHATTR_X_AXIS_ORIGIN); - - ppPoolDefaults[SCHATTR_Z_AXIS_AUTO_MIN - SCHATTR_START] = new SfxBoolItem(SCHATTR_Z_AXIS_AUTO_MIN); - ppPoolDefaults[SCHATTR_Z_AXIS_MIN - SCHATTR_START] = new SvxDoubleItem(0.0, SCHATTR_Z_AXIS_MIN); - ppPoolDefaults[SCHATTR_Z_AXIS_AUTO_MAX - SCHATTR_START] = new SfxBoolItem(SCHATTR_Z_AXIS_AUTO_MAX); - ppPoolDefaults[SCHATTR_Z_AXIS_MAX - SCHATTR_START] = new SvxDoubleItem(0.0, SCHATTR_Z_AXIS_MAX); - ppPoolDefaults[SCHATTR_Z_AXIS_AUTO_STEP_MAIN - SCHATTR_START] = new SfxBoolItem(SCHATTR_Z_AXIS_AUTO_STEP_MAIN); - ppPoolDefaults[SCHATTR_Z_AXIS_STEP_MAIN - SCHATTR_START] = new SvxDoubleItem(0.0, SCHATTR_Z_AXIS_STEP_MAIN); - ppPoolDefaults[SCHATTR_Z_AXIS_AUTO_STEP_HELP - SCHATTR_START] = new SfxBoolItem(SCHATTR_Z_AXIS_AUTO_STEP_HELP); - ppPoolDefaults[SCHATTR_Z_AXIS_STEP_HELP - SCHATTR_START] = new SvxDoubleItem(0.0, SCHATTR_Z_AXIS_STEP_HELP); - ppPoolDefaults[SCHATTR_Z_AXIS_LOGARITHM - SCHATTR_START] = new SfxBoolItem(SCHATTR_Z_AXIS_LOGARITHM); - ppPoolDefaults[SCHATTR_Z_AXIS_AUTO_ORIGIN - SCHATTR_START] = new SfxBoolItem(SCHATTR_Z_AXIS_AUTO_ORIGIN); - ppPoolDefaults[SCHATTR_Z_AXIS_ORIGIN - SCHATTR_START] = new SvxDoubleItem(0.0, SCHATTR_Z_AXIS_ORIGIN); - - ppPoolDefaults[SCHATTR_AXISTYPE - SCHATTR_START] = new SfxInt32Item(SCHATTR_AXISTYPE, CHART_AXIS_X); - ppPoolDefaults[SCHATTR_PERCENT_NUMBERFORMAT_VALUE - SCHATTR_START] = new SfxUInt32Item(SCHATTR_PERCENT_NUMBERFORMAT_VALUE, 0); - ppPoolDefaults[SCHATTR_PERCENT_NUMBERFORMAT_SOURCE - SCHATTR_START] = new SfxBoolItem(SCHATTR_PERCENT_NUMBERFORMAT_SOURCE); + //statistic ppPoolDefaults[SCHATTR_STAT_AVERAGE - SCHATTR_START] = new SfxBoolItem (SCHATTR_STAT_AVERAGE); ppPoolDefaults[SCHATTR_STAT_KIND_ERROR - SCHATTR_START] = new SvxChartKindErrorItem (CHERROR_NONE, SCHATTR_STAT_KIND_ERROR); ppPoolDefaults[SCHATTR_STAT_PERCENT - SCHATTR_START] = new SvxDoubleItem (0.0, SCHATTR_STAT_PERCENT); @@ -121,9 +86,6 @@ ChartItemPool::ChartItemPool(): ppPoolDefaults[SCHATTR_STAT_RANGE_POS - SCHATTR_START] = new SfxStringItem (SCHATTR_STAT_RANGE_POS, String()); ppPoolDefaults[SCHATTR_STAT_RANGE_NEG - SCHATTR_START] = new SfxStringItem (SCHATTR_STAT_RANGE_NEG, String()); - ppPoolDefaults[SCHATTR_TEXT_DEGREES - SCHATTR_START] = new SfxInt32Item(SCHATTR_TEXT_DEGREES, 0); - ppPoolDefaults[SCHATTR_TEXT_OVERLAP - SCHATTR_START] = new SfxBoolItem(SCHATTR_TEXT_OVERLAP,FALSE); - ppPoolDefaults[SCHATTR_STYLE_DEEP - SCHATTR_START] = new SfxBoolItem (SCHATTR_STYLE_DEEP, 0); ppPoolDefaults[SCHATTR_STYLE_3D - SCHATTR_START] = new SfxBoolItem (SCHATTR_STYLE_3D, 0); ppPoolDefaults[SCHATTR_STYLE_VERTICAL - SCHATTR_START] = new SfxBoolItem (SCHATTR_STYLE_VERTICAL, 0); @@ -137,37 +99,43 @@ ChartItemPool::ChartItemPool(): ppPoolDefaults[SCHATTR_AXIS - SCHATTR_START] = new SfxInt32Item(SCHATTR_AXIS,2); //2 = Y-Achse!!! + //axis scale + ppPoolDefaults[SCHATTR_AXISTYPE - SCHATTR_START] = new SfxInt32Item(SCHATTR_AXISTYPE, CHART_AXIS_REALNUMBER); + ppPoolDefaults[SCHATTR_AXIS_REVERSE - SCHATTR_START] = new SfxBoolItem(SCHATTR_AXIS_REVERSE,0); ppPoolDefaults[SCHATTR_AXIS_AUTO_MIN - SCHATTR_START] = new SfxBoolItem(SCHATTR_AXIS_AUTO_MIN); ppPoolDefaults[SCHATTR_AXIS_MIN - SCHATTR_START] = new SvxDoubleItem(0.0, SCHATTR_AXIS_MIN); ppPoolDefaults[SCHATTR_AXIS_AUTO_MAX - SCHATTR_START] = new SfxBoolItem(SCHATTR_AXIS_AUTO_MAX); ppPoolDefaults[SCHATTR_AXIS_MAX - SCHATTR_START] = new SvxDoubleItem(0.0, SCHATTR_AXIS_MAX); ppPoolDefaults[SCHATTR_AXIS_AUTO_STEP_MAIN - SCHATTR_START] = new SfxBoolItem(SCHATTR_AXIS_AUTO_STEP_MAIN); ppPoolDefaults[SCHATTR_AXIS_STEP_MAIN - SCHATTR_START] = new SvxDoubleItem(0.0, SCHATTR_AXIS_STEP_MAIN); + ppPoolDefaults[SCHATTR_AXIS_MAIN_TIME_UNIT - SCHATTR_START] = new SfxInt32Item(SCHATTR_AXIS_MAIN_TIME_UNIT,2); ppPoolDefaults[SCHATTR_AXIS_AUTO_STEP_HELP - SCHATTR_START] = new SfxBoolItem(SCHATTR_AXIS_AUTO_STEP_HELP); -// ppPoolDefaults[SCHATTR_AXIS_STEP_HELP - SCHATTR_START] = new SvxDoubleItem(0.0, SCHATTR_AXIS_STEP_HELP); - // type changed from double to sal_Int32 ppPoolDefaults[SCHATTR_AXIS_STEP_HELP - SCHATTR_START] = new SfxInt32Item(SCHATTR_AXIS_STEP_HELP,0); + ppPoolDefaults[SCHATTR_AXIS_HELP_TIME_UNIT - SCHATTR_START] = new SfxInt32Item(SCHATTR_AXIS_HELP_TIME_UNIT,2); + ppPoolDefaults[SCHATTR_AXIS_AUTO_TIME_RESOLUTION - SCHATTR_START] = new SfxBoolItem(SCHATTR_AXIS_AUTO_TIME_RESOLUTION); + ppPoolDefaults[SCHATTR_AXIS_TIME_RESOLUTION - SCHATTR_START] = new SfxInt32Item(SCHATTR_AXIS_TIME_RESOLUTION,2); ppPoolDefaults[SCHATTR_AXIS_LOGARITHM - SCHATTR_START] = new SfxBoolItem(SCHATTR_AXIS_LOGARITHM); + ppPoolDefaults[SCHATTR_AXIS_AUTO_DATEAXIS - SCHATTR_START] = new SfxBoolItem(SCHATTR_AXIS_AUTO_DATEAXIS); + ppPoolDefaults[SCHATTR_AXIS_ALLOW_DATEAXIS - SCHATTR_START] = new SfxBoolItem(SCHATTR_AXIS_ALLOW_DATEAXIS); ppPoolDefaults[SCHATTR_AXIS_AUTO_ORIGIN - SCHATTR_START] = new SfxBoolItem(SCHATTR_AXIS_AUTO_ORIGIN); ppPoolDefaults[SCHATTR_AXIS_ORIGIN - SCHATTR_START] = new SvxDoubleItem(0.0, SCHATTR_AXIS_ORIGIN); + //axis position ppPoolDefaults[SCHATTR_AXIS_TICKS - SCHATTR_START] = new SfxInt32Item(SCHATTR_AXIS_TICKS,CHAXIS_MARK_OUTER); - ppPoolDefaults[SCHATTR_AXIS_NUMFMT - SCHATTR_START] = new SfxUInt32Item(SCHATTR_AXIS_NUMFMT,0); - ppPoolDefaults[SCHATTR_AXIS_NUMFMTPERCENT - SCHATTR_START] = new SfxUInt32Item(SCHATTR_AXIS_NUMFMTPERCENT,11); - ppPoolDefaults[SCHATTR_AXIS_SHOWAXIS - SCHATTR_START] = new SfxBoolItem(SCHATTR_AXIS_SHOWAXIS,0); - ppPoolDefaults[SCHATTR_AXIS_SHOWDESCR - SCHATTR_START] = new SfxBoolItem(SCHATTR_AXIS_SHOWDESCR,0); - ppPoolDefaults[SCHATTR_AXIS_SHOWMAINGRID - SCHATTR_START] = new SfxBoolItem(SCHATTR_AXIS_SHOWMAINGRID,0); - ppPoolDefaults[SCHATTR_AXIS_SHOWHELPGRID - SCHATTR_START] = new SfxBoolItem(SCHATTR_AXIS_SHOWHELPGRID,0); - ppPoolDefaults[SCHATTR_AXIS_TOPDOWN - SCHATTR_START] = new SfxBoolItem(SCHATTR_AXIS_TOPDOWN,0); ppPoolDefaults[SCHATTR_AXIS_HELPTICKS - SCHATTR_START] = new SfxInt32Item(SCHATTR_AXIS_HELPTICKS,0); - ppPoolDefaults[SCHATTR_AXIS_REVERSE - SCHATTR_START] = new SfxBoolItem(SCHATTR_AXIS_REVERSE,0); - ppPoolDefaults[SCHATTR_AXIS_POSITION - SCHATTR_START] = new SfxInt32Item(SCHATTR_AXIS_POSITION,0); ppPoolDefaults[SCHATTR_AXIS_POSITION_VALUE - SCHATTR_START] = new SvxDoubleItem(0.0, SCHATTR_AXIS_POSITION_VALUE); ppPoolDefaults[SCHATTR_AXIS_CROSSING_MAIN_AXIS_NUMBERFORMAT - SCHATTR_START] = new SfxUInt32Item(SCHATTR_AXIS_CROSSING_MAIN_AXIS_NUMBERFORMAT,0); ppPoolDefaults[SCHATTR_AXIS_LABEL_POSITION - SCHATTR_START] = new SfxInt32Item(SCHATTR_AXIS_LABEL_POSITION,0); ppPoolDefaults[SCHATTR_AXIS_MARK_POSITION - SCHATTR_START] = new SfxInt32Item(SCHATTR_AXIS_MARK_POSITION,0); + //axis label + ppPoolDefaults[SCHATTR_AXIS_SHOWDESCR - SCHATTR_START] = new SfxBoolItem(SCHATTR_AXIS_SHOWDESCR,0); + ppPoolDefaults[SCHATTR_AXIS_LABEL_ORDER - SCHATTR_START] = new SvxChartTextOrderItem(CHTXTORDER_SIDEBYSIDE, SCHATTR_AXIS_LABEL_ORDER); + ppPoolDefaults[SCHATTR_AXIS_LABEL_OVERLAP - SCHATTR_START] = new SfxBoolItem(SCHATTR_AXIS_LABEL_OVERLAP,FALSE); + ppPoolDefaults[SCHATTR_AXIS_LABEL_BREAK - SCHATTR_START] = new SfxBoolItem(SCHATTR_AXIS_LABEL_BREAK, FALSE ); + + //-- ppPoolDefaults[SCHATTR_SYMBOL_BRUSH - SCHATTR_START] = new SvxBrushItem(SCHATTR_SYMBOL_BRUSH); ppPoolDefaults[SCHATTR_STOCK_VOLUME - SCHATTR_START] = new SfxBoolItem(SCHATTR_STOCK_VOLUME,0); ppPoolDefaults[SCHATTR_STOCK_UPDOWN - SCHATTR_START] = new SfxBoolItem(SCHATTR_STOCK_UPDOWN,0); @@ -181,16 +149,16 @@ ChartItemPool::ChartItemPool(): ppPoolDefaults[SCHATTR_SPLINE_ORDER - SCHATTR_START] = new SfxInt32Item( SCHATTR_SPLINE_ORDER, 3 ); ppPoolDefaults[SCHATTR_SPLINE_RESOLUTION - SCHATTR_START] = new SfxInt32Item( SCHATTR_SPLINE_RESOLUTION, 20 ); ppPoolDefaults[SCHATTR_DIAGRAM_STYLE - SCHATTR_START] = new SvxChartStyleItem( CHSTYLE_2D_COLUMN, SCHATTR_DIAGRAM_STYLE ); - ppPoolDefaults[SCHATTR_TEXTBREAK - SCHATTR_START] = new SfxBoolItem( SCHATTR_TEXTBREAK, FALSE ); ppPoolDefaults[SCHATTR_GROUP_BARS_PER_AXIS - SCHATTR_START] = new SfxBoolItem(SCHATTR_GROUP_BARS_PER_AXIS, FALSE); - ppPoolDefaults[SCHATTR_INCLUDE_HIDDEN_CELLS - SCHATTR_START] = new SfxBoolItem(SCHATTR_INCLUDE_HIDDEN_CELLS, TRUE); ppPoolDefaults[SCHATTR_STARTING_ANGLE - SCHATTR_START] = new SfxInt32Item( SCHATTR_STARTING_ANGLE, 90 ); ppPoolDefaults[SCHATTR_CLOCKWISE - SCHATTR_START] = new SfxBoolItem( SCHATTR_CLOCKWISE, FALSE ); ppPoolDefaults[SCHATTR_MISSING_VALUE_TREATMENT - SCHATTR_START] = new SfxInt32Item(SCHATTR_MISSING_VALUE_TREATMENT, 0); ppPoolDefaults[SCHATTR_AVAILABLE_MISSING_VALUE_TREATMENTS - SCHATTR_START] = new SfxIntegerListItem(SCHATTR_AVAILABLE_MISSING_VALUE_TREATMENTS,aTmp); + ppPoolDefaults[SCHATTR_INCLUDE_HIDDEN_CELLS - SCHATTR_START] = new SfxBoolItem(SCHATTR_INCLUDE_HIDDEN_CELLS, TRUE); ppPoolDefaults[SCHATTR_AXIS_FOR_ALL_SERIES - SCHATTR_START] = new SfxInt32Item(SCHATTR_AXIS_FOR_ALL_SERIES, 0); + ppPoolDefaults[SCHATTR_REGRESSION_TYPE - SCHATTR_START] = new SvxChartRegressItem (CHREGRESS_NONE, SCHATTR_REGRESSION_TYPE); ppPoolDefaults[SCHATTR_REGRESSION_SHOW_EQUATION - SCHATTR_START] = new SfxBoolItem(SCHATTR_REGRESSION_SHOW_EQUATION, 0); ppPoolDefaults[SCHATTR_REGRESSION_SHOW_COEFF - SCHATTR_START] = new SfxBoolItem(SCHATTR_REGRESSION_SHOW_COEFF, 0); diff --git a/chart2/source/view/main/ChartView.cxx b/chart2/source/view/main/ChartView.cxx index 390c1890154e..72b40adfed88 100644 --- a/chart2/source/view/main/ChartView.cxx +++ b/chart2/source/view/main/ChartView.cxx @@ -31,6 +31,7 @@ #include "ChartView.hxx" #include "chartview/DrawModelWrapper.hxx" +#include "NumberFormatterWrapper.hxx" #include "ViewDefines.hxx" #include "VDiagram.hxx" #include "VTitle.hxx" @@ -56,6 +57,7 @@ #include "ControllerLockGuard.hxx" #include "BaseGFXHelper.hxx" #include "DataSeriesHelper.hxx" +#include "DateHelper.hxx" #include <comphelper/scopeguard.hxx> #include <boost/bind.hpp> @@ -78,7 +80,6 @@ #include <com/sun/star/chart/ChartAxisPosition.hpp> #include <com/sun/star/chart/DataLabelPlacement.hpp> #include <com/sun/star/chart/MissingValueTreatment.hpp> -#include <com/sun/star/chart2/ExplicitSubIncrement.hpp> #include <com/sun/star/chart2/StackingDirection.hpp> #include <com/sun/star/chart2/XChartDocument.hpp> #include <com/sun/star/chart2/XCoordinateSystemContainer.hpp> @@ -472,7 +473,7 @@ private: }; AxisUsage::AxisUsage() - : aScaleAutomatism(AxisHelper::createDefaultScale()) + : aScaleAutomatism(AxisHelper::createDefaultScale(),Date()) { } @@ -563,7 +564,7 @@ public: ~SeriesPlotterContainer(); void initializeCooSysAndSeriesPlotter( const uno::Reference< frame::XModel >& xChartModel ); - void initAxisUsageList(); + void initAxisUsageList(const Date& rNullDate); void doAutoScaling( const uno::Reference< frame::XModel >& xChartModel ); void updateScalesAndIncrementsOnAxes(); void setScalesFromCooSysToPlotter(); @@ -581,13 +582,15 @@ private: std::vector< VCoordinateSystem* >& m_rVCooSysList; ::std::map< uno::Reference< XAxis >, AxisUsage > m_aAxisUsageList; sal_Int32 m_nMaxAxisIndex; - bool m_bChartTypeUsesShiftedXAxisTicksPerDefault; + bool m_bChartTypeUsesShiftedCategoryPositionPerDefault; + sal_Int32 m_nDefaultDateNumberFormat; }; SeriesPlotterContainer::SeriesPlotterContainer( std::vector< VCoordinateSystem* >& rVCooSysList ) : m_rVCooSysList( rVCooSysList ) , m_nMaxAxisIndex(0) - , m_bChartTypeUsesShiftedXAxisTicksPerDefault(false) + , m_bChartTypeUsesShiftedCategoryPositionPerDefault(false) + , m_nDefaultDateNumberFormat(0) { } @@ -625,6 +628,10 @@ void SeriesPlotterContainer::initializeCooSysAndSeriesPlotter( return; uno::Reference< util::XNumberFormatsSupplier > xNumberFormatsSupplier( xChartModel, uno::UNO_QUERY ); + uno::Reference< chart2::XChartDocument > xChartDoc( xChartModel, uno::UNO_QUERY ); + if( xChartDoc.is() && xChartDoc->hasInternalDataProvider() + && DiagramHelper::isSupportingDateAxis( xDiagram ) ) + m_nDefaultDateNumberFormat=DiagramHelper::getDateNumberFormat( xNumberFormatsSupplier ); sal_Int32 nDimensionCount = DiagramHelper::getDimension( xDiagram ); if(!nDimensionCount) @@ -682,7 +689,7 @@ void SeriesPlotterContainer::initializeCooSysAndSeriesPlotter( uno::Reference< XChartType > xChartType( aChartTypeList[nT] ); if(nT==0) - m_bChartTypeUsesShiftedXAxisTicksPerDefault = ChartTypeHelper::shiftTicksAtXAxisPerDefault( xChartType ); + m_bChartTypeUsesShiftedCategoryPositionPerDefault = ChartTypeHelper::shiftCategoryPosAtXAxisPerDefault( xChartType ); bool bExcludingPositioning = DiagramPositioningMode_EXCLUDING == DiagramHelper::getDiagramPositioningMode( xDiagram ); VSeriesPlotter* pPlotter = VSeriesPlotter::createSeriesPlotter( xChartType, nDimensionCount, bExcludingPositioning ); @@ -793,7 +800,7 @@ void SeriesPlotterContainer::initializeCooSysAndSeriesPlotter( } } -void SeriesPlotterContainer::initAxisUsageList() +void SeriesPlotterContainer::initAxisUsageList(const Date& rNullDate) { m_aAxisUsageList.clear(); size_t nC; @@ -803,8 +810,10 @@ void SeriesPlotterContainer::initAxisUsageList() for(sal_Int32 nDimensionIndex=0; nDimensionIndex<3; nDimensionIndex++) { uno::Reference< XCoordinateSystem > xCooSys = pVCooSys->getModel(); - if( nDimensionIndex >= xCooSys->getDimension() ) + sal_Int32 nDimensionCount = xCooSys->getDimension(); + if( nDimensionIndex >= nDimensionCount ) continue; + bool bChartTypeAllowsDateAxis = ChartTypeHelper::isSupportingDateAxis( AxisHelper::getChartTypeByIndex( xCooSys, 0 ), nDimensionCount, nDimensionIndex ); const sal_Int32 nMaximumAxisIndex = xCooSys->getMaximumAxisIndexByDimension(nDimensionIndex); for(sal_Int32 nAxisIndex=0; nAxisIndex<=nMaximumAxisIndex; ++nAxisIndex) { @@ -813,7 +822,20 @@ void SeriesPlotterContainer::initAxisUsageList() if( xAxis.is()) { if(m_aAxisUsageList.find(xAxis)==m_aAxisUsageList.end()) - m_aAxisUsageList[xAxis].aScaleAutomatism = ScaleAutomatism(xAxis->getScaleData()); + { + chart2::ScaleData aSourceScale = xAxis->getScaleData(); + ExplicitCategoriesProvider* pExplicitCategoriesProvider = pVCooSys->getExplicitCategoriesProvider(); + if( nDimensionIndex==0 ) + AxisHelper::checkDateAxis( aSourceScale, pExplicitCategoriesProvider, bChartTypeAllowsDateAxis ); + if( (aSourceScale.AxisType == AxisType::CATEGORY && m_bChartTypeUsesShiftedCategoryPositionPerDefault) + || (aSourceScale.AxisType==AxisType::CATEGORY && pExplicitCategoriesProvider && pExplicitCategoriesProvider->hasComplexCategories() ) + || aSourceScale.AxisType == AxisType::DATE + || aSourceScale.AxisType == AxisType::SERIES ) + aSourceScale.ShiftedCategoryPosition = true; + else + aSourceScale.ShiftedCategoryPosition = false; + m_aAxisUsageList[xAxis].aScaleAutomatism = ScaleAutomatism(aSourceScale,rNullDate); + } AxisUsage& rAxisUsage = m_aAxisUsageList[xAxis]; rAxisUsage.addCoordinateSystem(pVCooSys,nDimensionIndex,nAxisIndex); } @@ -886,6 +908,11 @@ void SeriesPlotterContainer::setNumberFormatsFromAxes() { aAxesNumberFormats.setFormat( nNumberFormatKey, nDimensionIndex, nAxisIndex ); } + else if( nDimensionIndex==0 ) + { + //provide a default date format for date axis with own data + aAxesNumberFormats.setFormat( m_nDefaultDateNumberFormat, nDimensionIndex, nAxisIndex ); + } } } catch( lang::IndexOutOfBoundsException& e ) @@ -936,13 +963,7 @@ void SeriesPlotterContainer::doAutoScaling( const uno::Reference< frame::XModel rAxisUsage.aScaleAutomatism.calculateExplicitScaleAndIncrement( aExplicitScale, aExplicitIncrement ); for( nC=0; nC < aVCooSysList_X.size(); nC++) - { - ExplicitCategoriesProvider* pExplicitCategoriesProvider = aVCooSysList_X[nC]->getExplicitCategoriesProvider(); - - if( m_bChartTypeUsesShiftedXAxisTicksPerDefault || (aExplicitScale.AxisType==AxisType::CATEGORY && pExplicitCategoriesProvider && pExplicitCategoriesProvider->hasComplexCategories() ) ) - aExplicitIncrement.ShiftedPosition = true; aVCooSysList_X[nC]->setExplicitScaleAndIncrement( 0, nAxisIndex, aExplicitScale, aExplicitIncrement ); - } for( nC=0; nC < aVCooSysList_Z.size(); nC++) aVCooSysList_Z[nC]->setExplicitScaleAndIncrement( 2, nAxisIndex, aExplicitScale, aExplicitIncrement ); } @@ -1027,7 +1048,6 @@ void SeriesPlotterContainer::AdaptScaleOfYAxisWithoutAttachedSeries( const uno:: aExplicitScaleDest.Orientation = aExplicitScaleSource.Orientation; aExplicitScaleDest.Scaling = aExplicitScaleSource.Scaling; - aExplicitScaleDest.Breaks = aExplicitScaleSource.Breaks; aExplicitScaleDest.AxisType = aExplicitScaleSource.AxisType; aExplicitIncrementDest.BaseValue = aExplicitIncrementSource.BaseValue; @@ -1065,7 +1085,7 @@ void SeriesPlotterContainer::AdaptScaleOfYAxisWithoutAttachedSeries( const uno:: bAutoMinorInterval = !( aScale.IncrementData.SubIncrements[0].IntervalCount.hasValue() ); if( bAutoMinorInterval ) { - if( aExplicitIncrementDest.SubIncrements.getLength() && aExplicitIncrementSource.SubIncrements.getLength() ) + if( !aExplicitIncrementDest.SubIncrements.empty() && !aExplicitIncrementSource.SubIncrements.empty() ) aExplicitIncrementDest.SubIncrements[0].IntervalCount = aExplicitIncrementSource.SubIncrements[0].IntervalCount; } @@ -1380,7 +1400,8 @@ awt::Rectangle ChartView::impl_createDiagramAndContent( SeriesPlotterContainer& // - prepare list of all axis and how they are used - rSeriesPlotterContainer.initAxisUsageList(); + Date aNullDate = NumberFormatterWrapper( uno::Reference< util::XNumberFormatsSupplier >( m_xChartModel, uno::UNO_QUERY ) ).getNullDate(); + rSeriesPlotterContainer.initAxisUsageList(aNullDate); rSeriesPlotterContainer.doAutoScaling( m_xChartModel ); rSeriesPlotterContainer.setScalesFromCooSysToPlotter(); rSeriesPlotterContainer.setNumberFormatsFromAxes(); @@ -1663,6 +1684,31 @@ sal_Bool ChartView::getExplicitValuesForAxis( { rExplicitScale = pVCooSys->getExplicitScale(nDimensionIndex,nAxisIndex); rExplicitIncrement = pVCooSys->getExplicitIncrement(nDimensionIndex,nAxisIndex); + if( rExplicitScale.ShiftedCategoryPosition ) + { + //remove 'one' from max + if( rExplicitScale.AxisType == ::com::sun::star::chart2::AxisType::DATE ) + { + Date aMaxDate(rExplicitScale.NullDate); aMaxDate += static_cast<long>(::rtl::math::approxFloor(rExplicitScale.Maximum)); + //for explicit scales with shifted categories we need one interval more + switch( rExplicitScale.TimeResolution ) + { + case ::com::sun::star::chart::TimeUnit::DAY: + aMaxDate--;break; + case ::com::sun::star::chart::TimeUnit::MONTH: + aMaxDate = DateHelper::GetDateSomeMonthsAway(aMaxDate,-1); + break; + case ::com::sun::star::chart::TimeUnit::YEAR: + aMaxDate = DateHelper::GetDateSomeYearsAway(aMaxDate,-1); + break; + } + rExplicitScale.Maximum = aMaxDate - rExplicitScale.NullDate; + } + else if( rExplicitScale.AxisType == ::com::sun::star::chart2::AxisType::CATEGORY ) + rExplicitScale.Maximum -= 1.0; + else if( rExplicitScale.AxisType == ::com::sun::star::chart2::AxisType::SERIES ) + rExplicitScale.Maximum -= 1.0; + } return sal_True; } return sal_False; @@ -1791,166 +1837,15 @@ bool lcl_getPropertySwapXAndYAxis( const uno::Reference< XDiagram >& xDiagram ) } -sal_Int32 lcl_getExplicitNumberFormatKeyForAxis( - const Reference< chart2::XAxis >& xAxis - , const Reference< chart2::XCoordinateSystem > & xCorrespondingCoordinateSystem - , const Reference< util::XNumberFormatsSupplier >& xNumberFormatsSupplier - , bool bSearchForParallelAxisIfNothingIsFound ) -{ - sal_Int32 nNumberFormatKey(0); - Reference< beans::XPropertySet > xProp( xAxis, uno::UNO_QUERY ); - if( xProp.is() && !( xProp->getPropertyValue( C2U( "NumberFormat" ) ) >>= nNumberFormatKey ) ) - { - bool bPercentFormatSet = false; - //check wether we have a percent scale -> use percent format - if( xNumberFormatsSupplier.is() ) - { - ScaleData aData = xAxis->getScaleData(); - if( aData.AxisType==AxisType::PERCENT ) - { - sal_Int32 nPercentFormat = ExplicitValueProvider::getPercentNumberFormat( xNumberFormatsSupplier ); - if( nPercentFormat != -1 ) - { - nNumberFormatKey = nPercentFormat; - bPercentFormatSet = true; - } - } - } - - if( !bPercentFormatSet ) - { - typedef ::std::map< sal_Int32, sal_Int32 > tNumberformatFrequency; - tNumberformatFrequency aKeyMap; - - bool bNumberFormatKeyFoundViaAttachedData = false; - sal_Int32 nAxisIndex = 0; - sal_Int32 nDimensionIndex = 1; - - try - { - Reference< XChartTypeContainer > xCTCnt( xCorrespondingCoordinateSystem, uno::UNO_QUERY_THROW ); - if( xCTCnt.is() ) - { - AxisHelper::getIndicesForAxis( xAxis, xCorrespondingCoordinateSystem, nDimensionIndex, nAxisIndex ); - ::rtl::OUString aRoleToMatch; - if( nDimensionIndex == 0 ) - aRoleToMatch = C2U("values-x"); - Sequence< Reference< XChartType > > aChartTypes( xCTCnt->getChartTypes()); - for( sal_Int32 nCTIdx=0; nCTIdx<aChartTypes.getLength(); ++nCTIdx ) - { - if( nDimensionIndex != 0 ) - aRoleToMatch = ChartTypeHelper::getRoleOfSequenceForYAxisNumberFormatDetection( aChartTypes[nCTIdx] ); - Reference< XDataSeriesContainer > xDSCnt( aChartTypes[nCTIdx], uno::UNO_QUERY_THROW ); - Sequence< Reference< XDataSeries > > aDataSeriesSeq( xDSCnt->getDataSeries()); - for( sal_Int32 nSeriesIdx=0; nSeriesIdx<aDataSeriesSeq.getLength(); ++nSeriesIdx ) - { - Reference< chart2::XDataSeries > xDataSeries(aDataSeriesSeq[nSeriesIdx]); - Reference< data::XDataSource > xSource( xDataSeries, uno::UNO_QUERY_THROW ); - - if( nDimensionIndex == 1 ) - { - //only take those series into accoutn that are attached to this axis - sal_Int32 nAttachedAxisIndex = DataSeriesHelper::getAttachedAxisIndex(xDataSeries); - if( nAttachedAxisIndex != nAxisIndex ) - continue; - } - - Sequence< Reference< data::XLabeledDataSequence > > aLabeledSeq( xSource->getDataSequences()); - for( sal_Int32 nLSeqIdx=0; nLSeqIdx<aLabeledSeq.getLength(); ++nLSeqIdx ) - { - if(!aLabeledSeq[nLSeqIdx].is()) - continue; - Reference< data::XDataSequence > xSeq( aLabeledSeq[nLSeqIdx]->getValues()); - if(!xSeq.is()) - continue; - Reference< beans::XPropertySet > xSeqProp( xSeq, uno::UNO_QUERY ); - ::rtl::OUString aRole; - bool bTakeIntoAccount = - ( xSeqProp.is() && (aRoleToMatch.getLength() > 0) && - (xSeqProp->getPropertyValue(C2U("Role")) >>= aRole ) && - aRole.equals( aRoleToMatch )); - - if( bTakeIntoAccount ) - { - sal_Int32 nKey = xSeq->getNumberFormatKeyByIndex( -1 ); - // initialize the value - if( aKeyMap.find( nKey ) == aKeyMap.end()) - aKeyMap[ nKey ] = 0; - // increase frequency - aKeyMap[ nKey ] = (aKeyMap[ nKey ] + 1); - } - } - } - } - } - } - catch( const uno::Exception & ex ) - { - ASSERT_EXCEPTION( ex ); - } - - if( ! aKeyMap.empty()) - { - sal_Int32 nMaxFreq = 0; - // find most frequent key - for( tNumberformatFrequency::const_iterator aIt = aKeyMap.begin(); - aIt != aKeyMap.end(); ++aIt ) - { - OSL_TRACE( "NumberFormatKey %d appears %d times", (*aIt).first, (*aIt).second ); - // all values must at least be 1 - if( (*aIt).second > nMaxFreq ) - { - nNumberFormatKey = (*aIt).first; - bNumberFormatKeyFoundViaAttachedData = true; - nMaxFreq = (*aIt).second; - } - } - } - - if( bSearchForParallelAxisIfNothingIsFound ) - { - //no format is set to this axis and no data is set to this axis - //--> try to obtain the format from the parallel y-axis - if( !bNumberFormatKeyFoundViaAttachedData && nDimensionIndex == 1 ) - { - sal_Int32 nParallelAxisIndex = (nAxisIndex==1) ?0 :1; - Reference< XAxis > xParallelAxis( AxisHelper::getAxis( 1, nParallelAxisIndex, xCorrespondingCoordinateSystem ) ); - nNumberFormatKey = lcl_getExplicitNumberFormatKeyForAxis( xParallelAxis, xCorrespondingCoordinateSystem, xNumberFormatsSupplier, false ); - } - } - } - } - return nNumberFormatKey; -} - sal_Int32 ExplicitValueProvider::getExplicitNumberFormatKeyForAxis( const Reference< chart2::XAxis >& xAxis , const Reference< chart2::XCoordinateSystem > & xCorrespondingCoordinateSystem , const Reference< util::XNumberFormatsSupplier >& xNumberFormatsSupplier ) { - return lcl_getExplicitNumberFormatKeyForAxis( xAxis, xCorrespondingCoordinateSystem, xNumberFormatsSupplier + return AxisHelper::getExplicitNumberFormatKeyForAxis( xAxis, xCorrespondingCoordinateSystem, xNumberFormatsSupplier , true /*bSearchForParallelAxisIfNothingIsFound*/ ); } -sal_Int32 ExplicitValueProvider::getPercentNumberFormat( const Reference< util::XNumberFormatsSupplier >& xNumberFormatsSupplier ) -{ - sal_Int32 nRet=-1; - Reference< util::XNumberFormats > xNumberFormats( xNumberFormatsSupplier->getNumberFormats() ); - if( xNumberFormats.is() ) - { - sal_Bool bCreate = sal_True; - const LocaleDataWrapper& rLocaleDataWrapper = Application::GetSettings().GetLocaleDataWrapper(); - Sequence<sal_Int32> aKeySeq = xNumberFormats->queryKeys( util::NumberFormat::PERCENT, - rLocaleDataWrapper.getLocale(), bCreate ); - if( aKeySeq.getLength() ) - { - nRet = aKeySeq[0]; - } - } - return nRet; -} - - sal_Int32 ExplicitValueProvider::getExplicitNumberFormatKeyForDataLabel( const uno::Reference< beans::XPropertySet >& xSeriesOrPointProp, const uno::Reference< XDataSeries >& xSeries, @@ -2003,7 +1898,7 @@ sal_Int32 ExplicitValueProvider::getExplicitPercentageNumberFormatKeyForDataLabe return nFormat; if( !(xSeriesOrPointProp->getPropertyValue(C2U( "PercentageNumberFormat" )) >>= nFormat) ) { - nFormat = ExplicitValueProvider::getPercentNumberFormat( xNumberFormatsSupplier ); + nFormat = DiagramHelper::getPercentNumberFormat( xNumberFormatsSupplier ); } if(nFormat<0) nFormat=0; diff --git a/chart2/source/view/main/ChartView.hxx b/chart2/source/view/main/ChartView.hxx index 476adae03674..76c1ce5c4858 100644 --- a/chart2/source/view/main/ChartView.hxx +++ b/chart2/source/view/main/ChartView.hxx @@ -103,8 +103,8 @@ public: // ___ExplicitValueProvider___ virtual sal_Bool getExplicitValuesForAxis( ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XAxis > xAxis - , ::com::sun::star::chart2::ExplicitScaleData& rExplicitScale - , ::com::sun::star::chart2::ExplicitIncrementData& rExplicitIncrement ); + , ExplicitScaleData& rExplicitScale + , ExplicitIncrementData& rExplicitIncrement ); virtual ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShape > getShapeForCID( const rtl::OUString& rObjectCID ); diff --git a/chart2/source/view/main/NumberFormatterWrapper.cxx b/chart2/source/view/main/NumberFormatterWrapper.cxx deleted file mode 100644 index 4e4cd342506c..000000000000 --- a/chart2/source/view/main/NumberFormatterWrapper.cxx +++ /dev/null @@ -1,169 +0,0 @@ -/************************************************************************* - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * Copyright 2000, 2010 Oracle and/or its affiliates. - * - * OpenOffice.org - a multi-platform office productivity suite - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * <http://www.openoffice.org/license.html> - * for a copy of the LGPLv3 License. - * - ************************************************************************/ - -// MARKER(update_precomp.py): autogen include statement, do not remove -#include "precompiled_chart2.hxx" -#include "chartview/NumberFormatterWrapper.hxx" -#include "macros.hxx" -#include <comphelper/processfactory.hxx> -// header for class SvNumberFormatsSupplierObj -#include <svl/numuno.hxx> -// header for class SvNumberformat -#include <svl/zformat.hxx> -#include <tools/color.hxx> -#include <i18npool/mslangid.hxx> -#include <tools/debug.hxx> -#include <com/sun/star/util/DateTime.hpp> - -//............................................................................. -namespace chart -{ -//............................................................................. -using namespace ::com::sun::star; - -FixedNumberFormatter::FixedNumberFormatter( - const uno::Reference< util::XNumberFormatsSupplier >& xSupplier - , sal_Int32 nNumberFormatKey ) - : m_aNumberFormatterWrapper(xSupplier) - , m_nNumberFormatKey( nNumberFormatKey ) -{ -} - -FixedNumberFormatter::~FixedNumberFormatter() -{ -} - -/* -sal_Int32 FixedNumberFormatter::getTextAndColor( double fUnscaledValueForText, rtl::OUString& rLabel ) const -{ - sal_Int32 nLabelColor = Color(COL_BLUE).GetColor(); //@todo get this from somewheres - rLabel = getFormattedString( fUnscaledValueForText, nLabelColor ); - return nLabelColor; -} -*/ - -rtl::OUString FixedNumberFormatter::getFormattedString( double fValue, sal_Int32& rLabelColor, bool& rbColorChanged ) const -{ - return m_aNumberFormatterWrapper.getFormattedString( - m_nNumberFormatKey, fValue, rLabelColor, rbColorChanged ); -} - -//----------------------------------------------------------------------- -//----------------------------------------------------------------------- -//----------------------------------------------------------------------- - -NumberFormatterWrapper::NumberFormatterWrapper( const uno::Reference< util::XNumberFormatsSupplier >& xSupplier ) - : m_xNumberFormatsSupplier(xSupplier) - , m_pNumberFormatter(NULL) - -{ - uno::Reference<beans::XPropertySet> xProp(m_xNumberFormatsSupplier,uno::UNO_QUERY); - rtl::OUString sNullDate( RTL_CONSTASCII_USTRINGPARAM("NullDate")); - if ( xProp.is() && xProp->getPropertySetInfo()->hasPropertyByName(sNullDate) ) - m_aNullDate = xProp->getPropertyValue(sNullDate); - SvNumberFormatsSupplierObj* pSupplierObj = SvNumberFormatsSupplierObj::getImplementation( xSupplier ); - if( pSupplierObj ) - m_pNumberFormatter = pSupplierObj->GetNumberFormatter(); - DBG_ASSERT(m_pNumberFormatter,"need a numberformatter"); -} - -NumberFormatterWrapper::~NumberFormatterWrapper() -{ -} - -SvNumberFormatter* NumberFormatterWrapper::getSvNumberFormatter() const -{ - return m_pNumberFormatter; -} - -rtl::OUString NumberFormatterWrapper::getFormattedString( - sal_Int32 nNumberFormatKey, double fValue, sal_Int32& rLabelColor, bool& rbColorChanged ) const -{ - String aText; - Color* pTextColor = NULL; - if( !m_pNumberFormatter ) - { - DBG_ERROR("Need a NumberFormatter"); - return aText; - } - // i99104 handle null date correctly - USHORT nYear = 1899,nDay = 30,nMonth = 12; - if ( m_aNullDate.hasValue() ) - { - Date* pDate = m_pNumberFormatter->GetNullDate(); - if ( pDate ) - { - nYear = pDate->GetYear(); - nMonth = pDate->GetMonth(); - nDay = pDate->GetDay(); - } // if ( pDate ) - util::DateTime aNewNullDate; - m_aNullDate >>= aNewNullDate; - m_pNumberFormatter->ChangeNullDate(aNewNullDate.Day,aNewNullDate.Month,aNewNullDate.Year); - } - m_pNumberFormatter->GetOutputString( - fValue, nNumberFormatKey, aText, &pTextColor); - if ( m_aNullDate.hasValue() ) - { - m_pNumberFormatter->ChangeNullDate(nDay,nMonth,nYear); - } - rtl::OUString aRet( aText ); - - if(pTextColor) - { - rbColorChanged = true; - rLabelColor = pTextColor->GetColor(); - } - else - rbColorChanged = false; - - return aRet; -} - -// to get the language type use MsLangId::convertLocaleToLanguage( rNumberFormat.aLocale ) - -/* - uno::Reference< i18n::XNumberFormatCode > xNumberFormatCode( - m_xCC->getServiceManager()->createInstanceWithContext( C2U( - "com.sun.star.i18n.NumberFormatMapper" ), m_xCC ), uno::UNO_QUERY ); - - i18n::NumberFormatCode aNumberFormatCode = xNumberFormatCode->getDefault ( - i18n::KNumberFormatType::MEDIUM, - i18n::KNumberFormatUsage::SCIENTIFIC_NUMBER, - aLocale ); - - uno::Sequence< i18n::NumberFormatCode > aListOfNumberFormatCode = xNumberFormatCode->getAllFormatCode( - i18n::KNumberFormatUsage::SCIENTIFIC_NUMBER, - aLocale ); - - i18n::NumberFormatCode aNumberFormatCode0 = aListOfNumberFormatCode[0]; - i18n::NumberFormatCode aNumberFormatCode1 = aListOfNumberFormatCode[1]; -*/ - -//............................................................................. -} //namespace chart -//............................................................................. diff --git a/chart2/source/view/main/PlotterBase.cxx b/chart2/source/view/main/PlotterBase.cxx index 08f43dc7064d..8a71f45b4dbb 100644 --- a/chart2/source/view/main/PlotterBase.cxx +++ b/chart2/source/view/main/PlotterBase.cxx @@ -56,8 +56,7 @@ PlotterBase::PlotterBase( sal_Int32 nDimensionCount ) { } - void SAL_CALL PlotterBase -::initPlotter( const uno::Reference< drawing::XShapes >& xLogicTarget +void PlotterBase::initPlotter( const uno::Reference< drawing::XShapes >& xLogicTarget , const uno::Reference< drawing::XShapes >& xFinalTarget , const uno::Reference< lang::XMultiServiceFactory >& xShapeFactory , const rtl::OUString& rCID ) @@ -77,11 +76,9 @@ PlotterBase::~PlotterBase() delete m_pShapeFactory; } -void SAL_CALL PlotterBase::setScales( const uno::Sequence< ExplicitScaleData >& rScales - , sal_Bool bSwapXAndYAxis ) - throw (uno::RuntimeException) +void PlotterBase::setScales( const std::vector< ExplicitScaleData >& rScales, bool bSwapXAndYAxis ) { - DBG_ASSERT(m_nDimension<=rScales.getLength(),"Dimension of Plotter does not fit two dimension of given scale sequence"); + DBG_ASSERT(m_nDimension<=static_cast<sal_Int32>(rScales.size()),"Dimension of Plotter does not fit two dimension of given scale sequence"); m_pPosHelper->setScales( rScales, bSwapXAndYAxis ); } diff --git a/chart2/source/view/main/PlottingPositionHelper.cxx b/chart2/source/view/main/PlottingPositionHelper.cxx index b5d39b2f898f..e257581d664b 100644 --- a/chart2/source/view/main/PlottingPositionHelper.cxx +++ b/chart2/source/view/main/PlottingPositionHelper.cxx @@ -32,12 +32,14 @@ #include "ViewDefines.hxx" #include "Linear3DTransformation.hxx" #include "VPolarTransformation.hxx" - #include "ShapeFactory.hxx" #include "PropertyMapper.hxx" +#include "DateHelper.hxx" + +#include <com/sun/star/chart/TimeUnit.hpp> +#include <com/sun/star/chart2/AxisType.hpp> #include <com/sun/star/drawing/DoubleSequence.hpp> #include <com/sun/star/drawing/Position3D.hpp> -#include <com/sun/star/chart2/AxisType.hpp> #include <rtl/math.hxx> @@ -57,6 +59,12 @@ PlottingPositionHelper::PlottingPositionHelper() , m_nYResolution( 1000 ) , m_nZResolution( 1000 ) , m_bMaySkipPointsInRegressionCalculation( true ) + , m_bDateAxis(false) + , m_nTimeResolution( ::com::sun::star::chart::TimeUnit::DAY ) + , m_aNullDate(30,12,1899) + , m_fScaledCategoryWidth(1.0) + , m_bAllowShiftXAxisPos(false) + , m_bAllowShiftZAxisPos(false) { } PlottingPositionHelper::PlottingPositionHelper( const PlottingPositionHelper& rSource ) @@ -68,6 +76,12 @@ PlottingPositionHelper::PlottingPositionHelper( const PlottingPositionHelper& rS , m_nYResolution( rSource.m_nYResolution ) , m_nZResolution( rSource.m_nZResolution ) , m_bMaySkipPointsInRegressionCalculation( rSource.m_bMaySkipPointsInRegressionCalculation ) + , m_bDateAxis( rSource.m_bDateAxis ) + , m_nTimeResolution( rSource.m_nTimeResolution ) + , m_aNullDate( rSource.m_aNullDate ) + , m_fScaledCategoryWidth( rSource.m_fScaledCategoryWidth ) + , m_bAllowShiftXAxisPos( rSource.m_bAllowShiftXAxisPos ) + , m_bAllowShiftZAxisPos( rSource.m_bAllowShiftZAxisPos ) { } @@ -95,13 +109,13 @@ void PlottingPositionHelper::setTransformationSceneToScreen( const drawing::Homo m_xTransformationLogicToScene = NULL; } -void PlottingPositionHelper::setScales( const uno::Sequence< ExplicitScaleData >& rScales, sal_Bool bSwapXAndYAxis ) +void PlottingPositionHelper::setScales( const std::vector< ExplicitScaleData >& rScales, bool bSwapXAndYAxis ) { m_aScales = rScales; m_bSwapXAndY = bSwapXAndYAxis; m_xTransformationLogicToScene = NULL; } -const uno::Sequence< ExplicitScaleData >& PlottingPositionHelper::getScales() const +const std::vector< ExplicitScaleData >& PlottingPositionHelper::getScales() const { return m_aScales; } @@ -129,8 +143,8 @@ uno::Reference< XTransformation > PlottingPositionHelper::getTransformationScale AxisOrientation nZAxisOrientation = m_aScales[2].Orientation; //apply scaling - doLogicScaling( &MinX, &MinY, &MinZ ); - doLogicScaling( &MaxX, &MaxY, &MaxZ); + doUnshiftedLogicScaling( &MinX, &MinY, &MinZ ); + doUnshiftedLogicScaling( &MaxX, &MaxY, &MaxZ); if(m_bSwapXAndY) { @@ -176,9 +190,9 @@ uno::Reference< XTransformation > PlottingPositionHelper::getTransformationScale drawing::Position3D PlottingPositionHelper::transformLogicToScene( double fX, double fY, double fZ, bool bClip ) const { - if(bClip) - this->clipLogicValues( &fX,&fY,&fZ ); this->doLogicScaling( &fX,&fY,&fZ ); + if(bClip) + this->clipScaledLogicValues( &fX,&fY,&fZ ); return this->transformScaledLogicToScene( fX, fY, fZ, false ); } @@ -254,8 +268,8 @@ void PlottingPositionHelper::clipScaledLogicValues( double* pX, double* pY, doub double MaxZ = getLogicMaxZ(); //apply scaling - doLogicScaling( &MinX, &MinY, &MinZ ); - doLogicScaling( &MaxX, &MaxY, &MaxZ); + doUnshiftedLogicScaling( &MinX, &MinY, &MinZ ); + doUnshiftedLogicScaling( &MaxX, &MaxY, &MaxZ); if(pX) { @@ -291,8 +305,8 @@ basegfx::B2DRectangle PlottingPositionHelper::getScaledLogicClipDoubleRect() con double MaxZ = getLogicMaxZ(); //apply scaling - doLogicScaling( &MinX, &MinY, &MinZ ); - doLogicScaling( &MaxX, &MaxY, &MaxZ); + doUnshiftedLogicScaling( &MinX, &MinY, &MinZ ); + doUnshiftedLogicScaling( &MaxX, &MaxY, &MaxZ); basegfx::B2DRectangle aRet( MinX, MaxY, MaxX, MinY ); return aRet; @@ -355,7 +369,7 @@ void PolarPlottingPositionHelper::setTransformationSceneToScreen( const drawing: PlottingPositionHelper::setTransformationSceneToScreen( rMatrix); m_aUnitCartesianToScene =impl_calculateMatrixUnitCartesianToScene( m_aMatrixScreenToScene ); } -void PolarPlottingPositionHelper::setScales( const uno::Sequence< ExplicitScaleData >& rScales, sal_Bool bSwapXAndYAxis ) +void PolarPlottingPositionHelper::setScales( const std::vector< ExplicitScaleData >& rScales, bool bSwapXAndYAxis ) { PlottingPositionHelper::setScales( rScales, bSwapXAndYAxis ); m_aUnitCartesianToScene =impl_calculateMatrixUnitCartesianToScene( m_aMatrixScreenToScene ); @@ -365,7 +379,7 @@ void PolarPlottingPositionHelper::setScales( const uno::Sequence< ExplicitScaleD { ::basegfx::B3DHomMatrix aRet; - if( !m_aScales.getLength() ) + if( m_aScales.empty() ) return aRet; double fTranslate =1.0; @@ -640,6 +654,41 @@ double PlottingPositionHelper::getBaseValueY() const return m_aScales[1].Origin; } +void PlottingPositionHelper::setTimeResolution( long nTimeResolution, const Date& rNullDate ) +{ + m_nTimeResolution = nTimeResolution; + m_aNullDate = rNullDate; + + //adapt category width + double fCategoryWidth = 1.0; + if( !m_aScales.empty() ) + { + if( m_aScales[0].AxisType == ::com::sun::star::chart2::AxisType::DATE ) + { + m_bDateAxis = true; + if( nTimeResolution == ::com::sun::star::chart::TimeUnit::YEAR ) + { + const double fMonthCount = 12.0;//todo: this depends on the DateScaling and must be adjusted in case we use more generic calendars in future + fCategoryWidth = fMonthCount; + } + } + } + setScaledCategoryWidth(fCategoryWidth); +} + +void PlottingPositionHelper::setScaledCategoryWidth( double fScaledCategoryWidth ) +{ + m_fScaledCategoryWidth = fScaledCategoryWidth; +} +void PlottingPositionHelper::AllowShiftXAxisPos( bool bAllowShift ) +{ + m_bAllowShiftXAxisPos = bAllowShift; +} +void PlottingPositionHelper::AllowShiftZAxisPos( bool bAllowShift ) +{ + m_bAllowShiftZAxisPos = bAllowShift; +} + /* // ____ XTransformation ____ uno::Sequence< double > SAL_CALL PolarPlottingPositionHelper::transform( diff --git a/chart2/source/view/main/VDataSeries.cxx b/chart2/source/view/main/VDataSeries.cxx index 8bb6a11b4baf..2b9512d4af2a 100644 --- a/chart2/source/view/main/VDataSeries.cxx +++ b/chart2/source/view/main/VDataSeries.cxx @@ -352,6 +352,22 @@ void VDataSeries::setCategoryXAxis() m_bAllowPercentValueInDataLabel = true; } +void VDataSeries::setXValues( const Reference< chart2::data::XDataSequence >& xValues ) +{ + m_aValues_X.clear(); + m_aValues_X.init( xValues ); + m_bAllowPercentValueInDataLabel = true; +} + +void VDataSeries::setXValuesIfNone( const Reference< chart2::data::XDataSequence >& xValues ) +{ + if( m_aValues_X.is() ) + return; + + m_aValues_X.init( xValues ); + lcl_clearIfNoValuesButTextIsContained( m_aValues_X, xValues ); +} + void VDataSeries::setGlobalSeriesIndex( sal_Int32 nGlobalSeriesIndex ) { m_nGlobalSeriesIndex = nGlobalSeriesIndex; diff --git a/chart2/source/view/main/VLegend.cxx b/chart2/source/view/main/VLegend.cxx index 9a011498991b..fbc74bad05a5 100644 --- a/chart2/source/view/main/VLegend.cxx +++ b/chart2/source/view/main/VLegend.cxx @@ -632,7 +632,7 @@ VLegend::VLegend( // ---------------------------------------- -void SAL_CALL VLegend::init( +void VLegend::init( const Reference< drawing::XShapes >& xTargetPage, const Reference< lang::XMultiServiceFactory >& xFactory, const Reference< frame::XModel >& xModel ) diff --git a/chart2/source/view/main/VLegend.hxx b/chart2/source/view/main/VLegend.hxx index 9587b50f71e7..4534a350f4f4 100644 --- a/chart2/source/view/main/VLegend.hxx +++ b/chart2/source/view/main/VLegend.hxx @@ -56,7 +56,7 @@ public: ::com::sun::star::uno::XComponentContext > & xContext, const std::vector< LegendEntryProvider* >& rLegendEntryProviderList ); - void SAL_CALL init( const ::com::sun::star::uno::Reference< + void init( const ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShapes >& xTargetPage, const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xFactory, diff --git a/chart2/source/view/main/VTitle.cxx b/chart2/source/view/main/VTitle.cxx index f62142735b7c..c2aa01163b17 100644 --- a/chart2/source/view/main/VTitle.cxx +++ b/chart2/source/view/main/VTitle.cxx @@ -65,7 +65,7 @@ VTitle::~VTitle() { } -void SAL_CALL VTitle::init( +void VTitle::init( const uno::Reference< drawing::XShapes >& xTargetPage , const uno::Reference< lang::XMultiServiceFactory >& xFactory , const rtl::OUString& rCID ) diff --git a/chart2/source/view/main/VTitle.hxx b/chart2/source/view/main/VTitle.hxx index 8a6e7d6e4f16..e097ecd3bbcc 100644 --- a/chart2/source/view/main/VTitle.hxx +++ b/chart2/source/view/main/VTitle.hxx @@ -47,7 +47,7 @@ public: ::com::sun::star::chart2::XTitle > & xTitle ); virtual ~VTitle(); - void SAL_CALL init( const ::com::sun::star::uno::Reference< + void init( const ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShapes >& xTargetPage , const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xFactory , const rtl::OUString& rCID ); diff --git a/chart2/source/view/main/makefile.mk b/chart2/source/view/main/makefile.mk index ec9c99f2a898..8675930aa107 100644 --- a/chart2/source/view/main/makefile.mk +++ b/chart2/source/view/main/makefile.mk @@ -43,7 +43,6 @@ ENABLE_EXCEPTIONS= TRUE SLOFILES = \ $(SLO)$/ChartItemPool.obj \ $(SLO)$/DrawModelWrapper.obj \ - $(SLO)$/NumberFormatterWrapper.obj \ $(SLO)$/PropertyMapper.obj \ $(SLO)$/Stripe.obj \ $(SLO)$/VLineProperties.obj \ |