LibreOffice Module chart2 (master) 1
Tickmarks_Dates.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
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>
26#include <utility>
27
28namespace chart
29{
30using namespace ::com::sun::star;
31using namespace ::com::sun::star::chart2;
32using namespace ::rtl::math;
33using ::com::sun::star::chart::TimeUnit::DAY;
34using ::com::sun::star::chart::TimeUnit::MONTH;
35using ::com::sun::star::chart::TimeUnit::YEAR;
36
38 ExplicitScaleData aScale, ExplicitIncrementData aIncrement )
39 : m_aScale(std::move( aScale ))
40 , m_aIncrement(std::move( aIncrement ))
41{
42 //@todo: make sure that the scale is valid for the scaling
43
44 if( m_aScale.Scaling.is() )
45 {
46 m_xInverseScaling = m_aScale.Scaling->getInverseScaling();
47 OSL_ENSURE( m_xInverseScaling.is(), "each Scaling needs to return an inverse Scaling" );
48 }
49}
50
52{
53}
54
55void DateTickFactory::getAllTicks( TickInfoArraysType& rAllTickInfos, bool bShifted ) const
56{
57 rAllTickInfos.resize(2);
58 TickInfoArrayType& rMajorTicks = rAllTickInfos[0];
59 TickInfoArrayType& rMinorTicks = rAllTickInfos[1];
60 rMajorTicks.clear();
61 rMinorTicks.clear();
62
63 Date aNull(m_aScale.NullDate);
64
65 Date aDate = aNull + static_cast<sal_Int32>(::rtl::math::approxFloor(m_aScale.Minimum));
66 Date aMaxDate = aNull + static_cast<sal_Int32>(::rtl::math::approxFloor(m_aScale.Maximum));
67
70 if( bShifted )
71 {
72 xScaling = new DateScaling(aNull,m_aScale.TimeResolution,true/*bShifted*/);
73 xInverseScaling = xScaling->getInverseScaling();
74 }
75
76 //create major date tickinfos
77 while( aDate<= aMaxDate )
78 {
79 if( bShifted && aDate==aMaxDate )
80 break;
81
82 TickInfo aNewTick(xInverseScaling); aNewTick.fScaledTickValue = aDate - aNull;
83
84 if( xInverseScaling.is() )
85 aNewTick.fScaledTickValue = xScaling->doScaling(aNewTick.fScaledTickValue);
86 rMajorTicks.push_back( aNewTick );
87
89 break;
90
91 //find next major date
92 switch( m_aIncrement.MajorTimeInterval.TimeUnit )
93 {
94 case DAY:
96 break;
97 case YEAR:
99 break;
100 case MONTH:
101 default:
103 break;
104 }
105 }
106
107 //create minor date tickinfos
108 aDate = aNull + static_cast<sal_Int32>(::rtl::math::approxFloor(m_aScale.Minimum));
109 while( aDate<= aMaxDate )
110 {
111 if( bShifted && aDate==aMaxDate )
112 break;
113
114 TickInfo aNewTick(xInverseScaling); aNewTick.fScaledTickValue = aDate - aNull;
115 if( xInverseScaling.is() )
116 aNewTick.fScaledTickValue = xScaling->doScaling(aNewTick.fScaledTickValue);
117 rMinorTicks.push_back( aNewTick );
118
119 if(m_aIncrement.MinorTimeInterval.Number<=0)
120 break;
121
122 //find next minor date
123 switch( m_aIncrement.MinorTimeInterval.TimeUnit )
124 {
125 case DAY:
126 aDate.AddDays( m_aIncrement.MinorTimeInterval.Number );
127 break;
128 case YEAR:
130 break;
131 case MONTH:
132 default:
134 break;
135 }
136 }
137}
138
140{
141 getAllTicks( rAllTickInfos, false );
142}
143
145{
146 getAllTicks( rAllTickInfos, true );
147}
148
149} //namespace chart
150
151/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void AddDays(sal_Int32 nAddDays)
static Date GetDateSomeYearsAway(const Date &rD, sal_Int32 nYearDistance)
Definition: DateHelper.cxx:46
static Date GetDateSomeMonthsAway(const Date &rD, sal_Int32 nMonthDistance)
Definition: DateHelper.cxx:39
void getAllTicks(TickInfoArraysType &rAllTickInfos) const
DateTickFactory(ExplicitScaleData aScale, ExplicitIncrementData aIncrement)
void getAllTicksShifted(TickInfoArraysType &rAllTickInfos) const
css::uno::Reference< css::chart2::XScaling > m_xInverseScaling
ExplicitIncrementData m_aIncrement
ExplicitScaleData m_aScale
std::vector< TickInfoArrayType > TickInfoArraysType
Definition: Tickmarks.hxx:59
std::vector< TickInfo > TickInfoArrayType
Definition: Tickmarks.hxx:58
describes how tickmarks are positioned on the scale of an axis.
css::chart::TimeInterval MajorTimeInterval
the following two members are only for date-time axis
css::chart::TimeInterval MinorTimeInterval
This structure contains the explicit values for a scale like Minimum and Maximum.
css::uno::Reference< css::chart2::XScaling > Scaling
double fScaledTickValue
Definition: Tickmarks.hxx:37