1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 .
21 #include "Tickmarks.hxx"
24 #include <o3tl/safeint.hxx>
29 class EquidistantTickIter
: public TickIter
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
;
43 virtual TickInfo
* firstInfo() override
;
44 virtual TickInfo
* nextInfo() override
;
47 sal_Int32
getIntervalCount( sal_Int32 nDepth
);
48 bool isAtLastPartTick();
50 void initIter( sal_Int32 nMaxDepth
);
51 sal_Int32
getStartDepth() const;
56 double getTickValue(sal_Int32 nDepth
, sal_Int32 nIndex
) const
59 return (*m_pSimpleTicks
)[nDepth
][nIndex
];
62 if ((*m_pInfoTicks
)[nDepth
].size() <= o3tl::make_unsigned(nIndex
))
63 return std::numeric_limits
<double>::max();
64 return (((*m_pInfoTicks
)[nDepth
])[nIndex
]).fScaledTickValue
;
67 sal_Int32
getTickCount( sal_Int32 nDepth
) const
70 return (*m_pSimpleTicks
)[nDepth
].getLength();
72 return (*m_pInfoTicks
)[nDepth
].size();
74 sal_Int32
getMaxDepth() const
77 return (*m_pSimpleTicks
).getLength()-1;
79 return (*m_pInfoTicks
).size()-1;
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[]>
95 sal_Int32 m_nCurrentDepth
;
96 sal_Int32 m_nCurrentPos
;
97 double m_fCurrentValue
;
100 class EquidistantTickFactory
103 EquidistantTickFactory(
104 ExplicitScaleData aScale
105 , ExplicitIncrementData aIncrement
);
106 ~EquidistantTickFactory();
108 void getAllTicks( TickInfoArraysType
& rAllTickInfos
) const;
109 void getAllTicksShifted( TickInfoArraysType
& rAllTickInfos
) const;
111 static double getMinimumAtIncrement( double fMin
, const ExplicitIncrementData
& rIncrement
);
112 static double getMaximumAtIncrement( double fMax
, const ExplicitIncrementData
& rIncrement
);
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;
123 bool isVisible( double fValue
) const;
124 bool isWithinOuterBorder( double fScaledValue
) const; //all within the outer major tick marks
127 ExplicitScaleData m_rScale
;
128 ExplicitIncrementData m_rIncrement
;
129 css::uno::Reference
< css::chart2::XScaling
> m_xInverseScaling
;
131 //minimum and maximum of the visible range after scaling
132 double m_fScaledVisibleMin
;
133 double m_fScaledVisibleMax
;
135 std::unique_ptr
<double[]>
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
;
146 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */