/src/libreoffice/chart2/source/view/axes/Tickmarks.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 <chartview/ExplicitScaleValues.hxx> |
22 | | #include <basegfx/vector/b2dvector.hxx> |
23 | | #include <com/sun/star/drawing/PointSequenceSequence.hpp> |
24 | | #include <rtl/ref.hxx> |
25 | | #include <svx/unoshape.hxx> |
26 | | #include <vector> |
27 | | |
28 | | namespace chart { struct AxisProperties; } |
29 | | namespace chart { struct TickmarkProperties; } |
30 | | namespace com::sun::star::chart2 { class XScaling; } |
31 | | |
32 | | namespace chart { |
33 | | |
34 | | struct TickInfo |
35 | | { |
36 | | double fScaledTickValue; |
37 | | css::uno::Reference<css::chart2::XScaling> xInverseScaling; |
38 | | rtl::Reference<SvxShapeText> xTextShape; |
39 | | OUString aText;//used only for complex categories so far |
40 | | ::basegfx::B2DVector aTickScreenPosition; |
41 | | sal_Int32 nFactorForLimitedTextWidth;//categories in higher levels of complex categories can have more place than a single simple category |
42 | | bool bPaintIt; |
43 | | |
44 | | //methods: |
45 | | TickInfo() = delete; |
46 | | explicit TickInfo( css::uno::Reference<css::chart2::XScaling> xInverse ); |
47 | | |
48 | | /** |
49 | | * Return a value associated with the tick mark. It's normally an original |
50 | | * value from the data source, or 1-based integer index in case the axis |
51 | | * is a category axis. |
52 | | */ |
53 | | double getUnscaledTickValue() const; |
54 | | sal_Int32 getScreenDistanceBetweenTicks( const TickInfo& rOherTickInfo ) const; |
55 | | }; |
56 | | |
57 | | typedef std::vector<TickInfo> TickInfoArrayType; |
58 | | typedef std::vector<TickInfoArrayType> TickInfoArraysType; |
59 | | |
60 | | class TickIter |
61 | | { |
62 | | public: |
63 | 0 | virtual ~TickIter() {} |
64 | | virtual TickInfo* firstInfo() = 0; |
65 | | virtual TickInfo* nextInfo() = 0; |
66 | | }; |
67 | | |
68 | | class PureTickIter : public TickIter |
69 | | { |
70 | | public: |
71 | | explicit PureTickIter( TickInfoArrayType& rTickInfoVector ); |
72 | | virtual ~PureTickIter() override; |
73 | | virtual TickInfo* firstInfo() override; |
74 | | virtual TickInfo* nextInfo() override; |
75 | | |
76 | | private: |
77 | | TickInfoArrayType& m_rTickVector; |
78 | | TickInfoArrayType::iterator m_aTickIter; |
79 | | }; |
80 | | |
81 | | class TickFactory |
82 | | { |
83 | | public: |
84 | | TickFactory( |
85 | | ExplicitScaleData aScale |
86 | | , ExplicitIncrementData aIncrement ); |
87 | | virtual ~TickFactory(); |
88 | | |
89 | | void getAllTicks( TickInfoArraysType& rAllTickInfos ) const; |
90 | | void getAllTicksShifted( TickInfoArraysType& rAllTickInfos ) const; |
91 | | |
92 | | private: //methods |
93 | | bool isDateAxis() const; |
94 | | |
95 | | protected: //member |
96 | | ExplicitScaleData m_rScale; |
97 | | ExplicitIncrementData m_rIncrement; |
98 | | css::uno::Reference< css::chart2::XScaling > m_xInverseScaling; |
99 | | |
100 | | //minimum and maximum of the visible range after scaling |
101 | | double m_fScaledVisibleMin; |
102 | | double m_fScaledVisibleMax; |
103 | | }; |
104 | | |
105 | | class TickFactory2D final : public TickFactory |
106 | | { |
107 | | public: |
108 | | TickFactory2D( |
109 | | const ExplicitScaleData& rScale |
110 | | , const ExplicitIncrementData& rIncrement |
111 | | , const ::basegfx::B2DVector& rStartScreenPos, const ::basegfx::B2DVector& rEndScreenPos |
112 | | , const ::basegfx::B2DVector& rAxisLineToLabelLineShift ); |
113 | | |
114 | | virtual ~TickFactory2D() override; |
115 | | |
116 | | static sal_Int32 getTickScreenDistance( TickIter& rIter ); |
117 | | |
118 | | void createPointSequenceForAxisMainLine( css::drawing::PointSequenceSequence& rPoints ) const; |
119 | | void addPointSequenceForTickLine( css::drawing::PointSequenceSequence& rPoints |
120 | | , sal_Int32 nSequenceIndex |
121 | | , double fScaledLogicTickValue, double fInnerDirectionSign |
122 | | , const TickmarkProperties& rTickmarkProperties, bool bPlaceAtLabels ) const; |
123 | | ::basegfx::B2DVector getDistanceAxisTickToText( const AxisProperties& rAxisProperties |
124 | | , bool bIncludeFarAwayDistanceIfSo = false |
125 | | , bool bIncludeSpaceBetweenTickAndText = true ) const; |
126 | | |
127 | | /** |
128 | | * Determine the screen positions of all ticks based on their numeric values. |
129 | | */ |
130 | | void updateScreenValues( TickInfoArraysType& rAllTickInfos ) const; |
131 | | |
132 | | bool isHorizontalAxis() const; |
133 | | bool isVerticalAxis() const; |
134 | | |
135 | | const ::basegfx::B2DVector & getXaxisStartPos() const |
136 | 0 | { |
137 | 0 | return m_aAxisStartScreenPosition2D; |
138 | 0 | } |
139 | | |
140 | | const ::basegfx::B2DVector & getXaxisEndPos() const |
141 | 0 | { |
142 | 0 | return m_aAxisEndScreenPosition2D; |
143 | 0 | } |
144 | | |
145 | | private: |
146 | | ::basegfx::B2DVector getTickScreenPosition2D( double fScaledLogicTickValue ) const; |
147 | | |
148 | | ::basegfx::B2DVector m_aAxisStartScreenPosition2D; |
149 | | ::basegfx::B2DVector m_aAxisEndScreenPosition2D; |
150 | | |
151 | | //labels might be positioned high or low on the border of the diagram far away from the axis |
152 | | //add this vector to go from the axis line to the label line (border of the diagram) |
153 | | ::basegfx::B2DVector m_aAxisLineToLabelLineShift; |
154 | | |
155 | | double m_fStretch_LogicToScreen; |
156 | | double m_fOffset_LogicToScreen; |
157 | | }; |
158 | | |
159 | | } //namespace chart |
160 | | |
161 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |