nss: upgrade to release 3.73
[LibreOffice.git] / chart2 / source / view / axes / Tickmarks_Dates.cxx
blob854e661f67b414d8986ef84564edde3237471e2d
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "Tickmarks_Dates.hxx"
21 #include "DateScaling.hxx"
22 #include <rtl/math.hxx>
23 #include <osl/diagnose.h>
24 #include <DateHelper.hxx>
25 #include <com/sun/star/chart/TimeUnit.hpp>
27 namespace chart
29 using namespace ::com::sun::star;
30 using namespace ::com::sun::star::chart2;
31 using namespace ::rtl::math;
32 using ::com::sun::star::chart::TimeUnit::DAY;
33 using ::com::sun::star::chart::TimeUnit::MONTH;
34 using ::com::sun::star::chart::TimeUnit::YEAR;
36 DateTickFactory::DateTickFactory(
37 const ExplicitScaleData& rScale, const ExplicitIncrementData& rIncrement )
38 : m_aScale( rScale )
39 , m_aIncrement( rIncrement )
41 //@todo: make sure that the scale is valid for the scaling
43 if( m_aScale.Scaling.is() )
45 m_xInverseScaling = m_aScale.Scaling->getInverseScaling();
46 OSL_ENSURE( m_xInverseScaling.is(), "each Scaling needs to return an inverse Scaling" );
50 DateTickFactory::~DateTickFactory()
54 void DateTickFactory::getAllTicks( TickInfoArraysType& rAllTickInfos, bool bShifted ) const
56 rAllTickInfos.resize(2);
57 TickInfoArrayType& rMajorTicks = rAllTickInfos[0];
58 TickInfoArrayType& rMinorTicks = rAllTickInfos[1];
59 rMajorTicks.clear();
60 rMinorTicks.clear();
62 Date aNull(m_aScale.NullDate);
64 Date aDate = aNull + static_cast<sal_Int32>(::rtl::math::approxFloor(m_aScale.Minimum));
65 Date aMaxDate = aNull + static_cast<sal_Int32>(::rtl::math::approxFloor(m_aScale.Maximum));
67 uno::Reference< chart2::XScaling > xScaling(m_aScale.Scaling);
68 uno::Reference< chart2::XScaling > xInverseScaling(m_xInverseScaling);
69 if( bShifted )
71 xScaling = new DateScaling(aNull,m_aScale.TimeResolution,true/*bShifted*/);
72 xInverseScaling = xScaling->getInverseScaling();
75 //create major date tickinfos
76 while( aDate<= aMaxDate )
78 if( bShifted && aDate==aMaxDate )
79 break;
81 TickInfo aNewTick(xInverseScaling); aNewTick.fScaledTickValue = aDate - aNull;
83 if( xInverseScaling.is() )
84 aNewTick.fScaledTickValue = xScaling->doScaling(aNewTick.fScaledTickValue);
85 rMajorTicks.push_back( aNewTick );
87 if(m_aIncrement.MajorTimeInterval.Number<=0)
88 break;
90 //find next major date
91 switch( m_aIncrement.MajorTimeInterval.TimeUnit )
93 case DAY:
94 aDate.AddDays( m_aIncrement.MajorTimeInterval.Number );
95 break;
96 case YEAR:
97 aDate = DateHelper::GetDateSomeYearsAway( aDate, m_aIncrement.MajorTimeInterval.Number );
98 break;
99 case MONTH:
100 default:
101 aDate = DateHelper::GetDateSomeMonthsAway( aDate, m_aIncrement.MajorTimeInterval.Number );
102 break;
106 //create minor date tickinfos
107 aDate = aNull + static_cast<sal_Int32>(::rtl::math::approxFloor(m_aScale.Minimum));
108 while( aDate<= aMaxDate )
110 if( bShifted && aDate==aMaxDate )
111 break;
113 TickInfo aNewTick(xInverseScaling); aNewTick.fScaledTickValue = aDate - aNull;
114 if( xInverseScaling.is() )
115 aNewTick.fScaledTickValue = xScaling->doScaling(aNewTick.fScaledTickValue);
116 rMinorTicks.push_back( aNewTick );
118 if(m_aIncrement.MinorTimeInterval.Number<=0)
119 break;
121 //find next minor date
122 switch( m_aIncrement.MinorTimeInterval.TimeUnit )
124 case DAY:
125 aDate.AddDays( m_aIncrement.MinorTimeInterval.Number );
126 break;
127 case YEAR:
128 aDate = DateHelper::GetDateSomeYearsAway( aDate, m_aIncrement.MinorTimeInterval.Number );
129 break;
130 case MONTH:
131 default:
132 aDate = DateHelper::GetDateSomeMonthsAway( aDate, m_aIncrement.MinorTimeInterval.Number );
133 break;
138 void DateTickFactory::getAllTicks( TickInfoArraysType& rAllTickInfos ) const
140 getAllTicks( rAllTickInfos, false );
143 void DateTickFactory::getAllTicksShifted( TickInfoArraysType& rAllTickInfos ) const
145 getAllTicks( rAllTickInfos, true );
148 } //namespace chart
150 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */