/src/libreoffice/chart2/source/view/axes/Tickmarks_Dates.cxx
Line | Count | Source (jump to first uncovered line) |
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 | | |
28 | | namespace chart |
29 | | { |
30 | | using namespace ::com::sun::star; |
31 | | using namespace ::com::sun::star::chart2; |
32 | | using namespace ::rtl::math; |
33 | | using ::com::sun::star::chart::TimeUnit::DAY; |
34 | | using ::com::sun::star::chart::TimeUnit::MONTH; |
35 | | using ::com::sun::star::chart::TimeUnit::YEAR; |
36 | | |
37 | | DateTickFactory::DateTickFactory( |
38 | | ExplicitScaleData aScale, ExplicitIncrementData aIncrement ) |
39 | 0 | : m_aScale(std::move( aScale )) |
40 | 0 | , m_aIncrement(std::move( aIncrement )) |
41 | 0 | { |
42 | | //@todo: make sure that the scale is valid for the scaling |
43 | |
|
44 | 0 | if( m_aScale.Scaling.is() ) |
45 | 0 | { |
46 | 0 | m_xInverseScaling = m_aScale.Scaling->getInverseScaling(); |
47 | 0 | OSL_ENSURE( m_xInverseScaling.is(), "each Scaling needs to return an inverse Scaling" ); |
48 | 0 | } |
49 | 0 | } |
50 | | |
51 | | DateTickFactory::~DateTickFactory() |
52 | 0 | { |
53 | 0 | } |
54 | | |
55 | | void DateTickFactory::getAllTicks( TickInfoArraysType& rAllTickInfos, bool bShifted ) const |
56 | 0 | { |
57 | 0 | rAllTickInfos.resize(2); |
58 | 0 | TickInfoArrayType& rMajorTicks = rAllTickInfos[0]; |
59 | 0 | TickInfoArrayType& rMinorTicks = rAllTickInfos[1]; |
60 | 0 | rMajorTicks.clear(); |
61 | 0 | rMinorTicks.clear(); |
62 | |
|
63 | 0 | Date aNull(m_aScale.NullDate); |
64 | |
|
65 | 0 | Date aDate = aNull + static_cast<sal_Int32>(::rtl::math::approxFloor(m_aScale.Minimum)); |
66 | 0 | Date aMaxDate = aNull + static_cast<sal_Int32>(::rtl::math::approxFloor(m_aScale.Maximum)); |
67 | |
|
68 | 0 | uno::Reference< chart2::XScaling > xScaling(m_aScale.Scaling); |
69 | 0 | uno::Reference< chart2::XScaling > xInverseScaling(m_xInverseScaling); |
70 | 0 | if( bShifted ) |
71 | 0 | { |
72 | 0 | xScaling = new DateScaling(aNull,m_aScale.TimeResolution,true/*bShifted*/); |
73 | 0 | xInverseScaling = xScaling->getInverseScaling(); |
74 | 0 | } |
75 | | |
76 | | //create major date tickinfos |
77 | 0 | while( aDate<= aMaxDate ) |
78 | 0 | { |
79 | 0 | if( bShifted && aDate==aMaxDate ) |
80 | 0 | break; |
81 | | |
82 | 0 | TickInfo aNewTick(xInverseScaling); aNewTick.fScaledTickValue = aDate - aNull; |
83 | |
|
84 | 0 | if( xInverseScaling.is() ) |
85 | 0 | aNewTick.fScaledTickValue = xScaling->doScaling(aNewTick.fScaledTickValue); |
86 | 0 | rMajorTicks.push_back( aNewTick ); |
87 | |
|
88 | 0 | if(m_aIncrement.MajorTimeInterval.Number<=0) |
89 | 0 | break; |
90 | | |
91 | | //find next major date |
92 | 0 | switch( m_aIncrement.MajorTimeInterval.TimeUnit ) |
93 | 0 | { |
94 | 0 | case DAY: |
95 | 0 | aDate.AddDays( m_aIncrement.MajorTimeInterval.Number ); |
96 | 0 | break; |
97 | 0 | case YEAR: |
98 | 0 | aDate = DateHelper::GetDateSomeYearsAway( aDate, m_aIncrement.MajorTimeInterval.Number ); |
99 | 0 | break; |
100 | 0 | case MONTH: |
101 | 0 | default: |
102 | 0 | aDate = DateHelper::GetDateSomeMonthsAway( aDate, m_aIncrement.MajorTimeInterval.Number ); |
103 | 0 | break; |
104 | 0 | } |
105 | 0 | } |
106 | | |
107 | | //create minor date tickinfos |
108 | 0 | aDate = aNull + static_cast<sal_Int32>(::rtl::math::approxFloor(m_aScale.Minimum)); |
109 | 0 | while( aDate<= aMaxDate ) |
110 | 0 | { |
111 | 0 | if( bShifted && aDate==aMaxDate ) |
112 | 0 | break; |
113 | | |
114 | 0 | TickInfo aNewTick(xInverseScaling); aNewTick.fScaledTickValue = aDate - aNull; |
115 | 0 | if( xInverseScaling.is() ) |
116 | 0 | aNewTick.fScaledTickValue = xScaling->doScaling(aNewTick.fScaledTickValue); |
117 | 0 | rMinorTicks.push_back( aNewTick ); |
118 | |
|
119 | 0 | if(m_aIncrement.MinorTimeInterval.Number<=0) |
120 | 0 | break; |
121 | | |
122 | | //find next minor date |
123 | 0 | switch( m_aIncrement.MinorTimeInterval.TimeUnit ) |
124 | 0 | { |
125 | 0 | case DAY: |
126 | 0 | aDate.AddDays( m_aIncrement.MinorTimeInterval.Number ); |
127 | 0 | break; |
128 | 0 | case YEAR: |
129 | 0 | aDate = DateHelper::GetDateSomeYearsAway( aDate, m_aIncrement.MinorTimeInterval.Number ); |
130 | 0 | break; |
131 | 0 | case MONTH: |
132 | 0 | default: |
133 | 0 | aDate = DateHelper::GetDateSomeMonthsAway( aDate, m_aIncrement.MinorTimeInterval.Number ); |
134 | 0 | break; |
135 | 0 | } |
136 | 0 | } |
137 | 0 | } |
138 | | |
139 | | void DateTickFactory::getAllTicks( TickInfoArraysType& rAllTickInfos ) const |
140 | 0 | { |
141 | 0 | getAllTicks( rAllTickInfos, false ); |
142 | 0 | } |
143 | | |
144 | | void DateTickFactory::getAllTicksShifted( TickInfoArraysType& rAllTickInfos ) const |
145 | 0 | { |
146 | 0 | getAllTicks( rAllTickInfos, true ); |
147 | 0 | } |
148 | | |
149 | | } //namespace chart |
150 | | |
151 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |