/src/libreoffice/chart2/source/view/axes/Tickmarks_Equidistant.hxx
Line | Count | Source |
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 | | #pragma once |
20 | | |
21 | | #include "Tickmarks.hxx" |
22 | | #include <memory> |
23 | | |
24 | | #include <o3tl/safeint.hxx> |
25 | | |
26 | | namespace chart |
27 | | { |
28 | | |
29 | | class EquidistantTickIter : public TickIter |
30 | | { |
31 | | public: |
32 | | EquidistantTickIter( const css::uno::Sequence< css::uno::Sequence< double > >& rTicks |
33 | | , const ExplicitIncrementData& rIncrement |
34 | | , sal_Int32 nMaxDepth ); |
35 | | EquidistantTickIter( TickInfoArraysType& rTickInfos |
36 | | , const ExplicitIncrementData& rIncrement |
37 | | , sal_Int32 nMaxDepth ); |
38 | | virtual ~EquidistantTickIter() override; |
39 | | |
40 | | double* firstValue(); |
41 | | double* nextValue(); |
42 | | |
43 | | virtual TickInfo* firstInfo() override; |
44 | | virtual TickInfo* nextInfo() override; |
45 | | |
46 | | private: //methods |
47 | | sal_Int32 getIntervalCount( sal_Int32 nDepth ); |
48 | | bool isAtLastPartTick(); |
49 | | |
50 | | void initIter( sal_Int32 nMaxDepth ); |
51 | | sal_Int32 getStartDepth() const; |
52 | | |
53 | | bool gotoFirst(); |
54 | | bool gotoNext(); |
55 | | |
56 | | double getTickValue(sal_Int32 nDepth, sal_Int32 nIndex) const |
57 | 0 | { |
58 | 0 | if(m_pSimpleTicks) |
59 | 0 | return (*m_pSimpleTicks)[nDepth][nIndex]; |
60 | 0 | else |
61 | 0 | { |
62 | 0 | if ((*m_pInfoTicks)[nDepth].size() <= o3tl::make_unsigned(nIndex)) |
63 | 0 | return std::numeric_limits<double>::max(); |
64 | 0 | return (((*m_pInfoTicks)[nDepth])[nIndex]).fScaledTickValue; |
65 | 0 | } |
66 | 0 | } |
67 | | sal_Int32 getTickCount( sal_Int32 nDepth ) const |
68 | 0 | { |
69 | 0 | if(m_pSimpleTicks) |
70 | 0 | return (*m_pSimpleTicks)[nDepth].getLength(); |
71 | 0 | else |
72 | 0 | return (*m_pInfoTicks)[nDepth].size(); |
73 | 0 | } |
74 | | sal_Int32 getMaxDepth() const |
75 | 0 | { |
76 | 0 | if(m_pSimpleTicks) |
77 | 0 | return (*m_pSimpleTicks).getLength()-1; |
78 | 0 | else |
79 | 0 | return (*m_pInfoTicks).size()-1; |
80 | 0 | } |
81 | | |
82 | | private: //member |
83 | | const css::uno::Sequence< css::uno::Sequence< double > >* m_pSimpleTicks; |
84 | | TickInfoArraysType* m_pInfoTicks; |
85 | | const ExplicitIncrementData& m_rIncrement; |
86 | | sal_Int32 m_nMaxDepth; |
87 | | sal_Int32 m_nTickCount; |
88 | | std::unique_ptr<sal_Int32[]> |
89 | | m_pnPositions; //current positions in the different sequences |
90 | | std::unique_ptr<sal_Int32[]> |
91 | | m_pnPreParentCount; //the tickmarks do not start with a major tick always, |
92 | | //the PreParentCount states for each depth how many subtickmarks are available in front of the first parent tickmark |
93 | | std::unique_ptr<bool[]> |
94 | | m_pbIntervalFinished; |
95 | | sal_Int32 m_nCurrentDepth; |
96 | | sal_Int32 m_nCurrentPos; |
97 | | double m_fCurrentValue; |
98 | | }; |
99 | | |
100 | | class EquidistantTickFactory |
101 | | { |
102 | | public: |
103 | | EquidistantTickFactory( |
104 | | ExplicitScaleData aScale |
105 | | , ExplicitIncrementData aIncrement ); |
106 | | ~EquidistantTickFactory(); |
107 | | |
108 | | void getAllTicks( TickInfoArraysType& rAllTickInfos ) const; |
109 | | void getAllTicksShifted( TickInfoArraysType& rAllTickInfos ) const; |
110 | | |
111 | | static double getMinimumAtIncrement( double fMin, const ExplicitIncrementData& rIncrement ); |
112 | | static double getMaximumAtIncrement( double fMax, const ExplicitIncrementData& rIncrement ); |
113 | | |
114 | | private: //methods |
115 | | void addSubTicks( sal_Int32 nDepth, |
116 | | css::uno::Sequence< css::uno::Sequence< double > >& rParentTicks ) const; |
117 | | double* getMajorTick( sal_Int32 nTick ) const; |
118 | | double* getMinorTick( sal_Int32 nTick, sal_Int32 nDepth |
119 | | , double fStartParentTick, double fNextParentTick ) const; |
120 | | sal_Int32 getMaxTickCount( sal_Int32 nDepth ) const; |
121 | | sal_Int32 getTickDepth() const; |
122 | | |
123 | | bool isVisible( double fValue ) const; |
124 | | bool isWithinOuterBorder( double fScaledValue ) const; //all within the outer major tick marks |
125 | | |
126 | | private: //member |
127 | | ExplicitScaleData m_rScale; |
128 | | ExplicitIncrementData m_rIncrement; |
129 | | css::uno::Reference< css::chart2::XScaling > m_xInverseScaling; |
130 | | |
131 | | //minimum and maximum of the visible range after scaling |
132 | | double m_fScaledVisibleMin; |
133 | | double m_fScaledVisibleMax; |
134 | | |
135 | | std::unique_ptr<double[]> |
136 | | m_pfCurrentValues; |
137 | | //major-tick positions that may lay outside the visible range but complete partly visible intervals at the borders |
138 | | double m_fOuterMajorTickBorderMin; |
139 | | double m_fOuterMajorTickBorderMax; |
140 | | double m_fOuterMajorTickBorderMin_Scaled; |
141 | | double m_fOuterMajorTickBorderMax_Scaled; |
142 | | }; |
143 | | |
144 | | } //namespace chart |
145 | | |
146 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |