1*de7b3f82SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*de7b3f82SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*de7b3f82SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*de7b3f82SAndrew Rist  * distributed with this work for additional information
6*de7b3f82SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*de7b3f82SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*de7b3f82SAndrew Rist  * "License"); you may not use this file except in compliance
9*de7b3f82SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*de7b3f82SAndrew Rist  *
11*de7b3f82SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*de7b3f82SAndrew Rist  *
13*de7b3f82SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*de7b3f82SAndrew Rist  * software distributed under the License is distributed on an
15*de7b3f82SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*de7b3f82SAndrew Rist  * KIND, either express or implied.  See the License for the
17*de7b3f82SAndrew Rist  * specific language governing permissions and limitations
18*de7b3f82SAndrew Rist  * under the License.
19*de7b3f82SAndrew Rist  *
20*de7b3f82SAndrew Rist  *************************************************************/
21*de7b3f82SAndrew Rist 
22*de7b3f82SAndrew Rist 
23cdf0e10cSrcweir #ifndef _CHART2_SCALEAUTOMATISM_HXX
24cdf0e10cSrcweir #define _CHART2_SCALEAUTOMATISM_HXX
25cdf0e10cSrcweir 
26cdf0e10cSrcweir #include "chartview/ExplicitScaleValues.hxx"
27cdf0e10cSrcweir #include <com/sun/star/chart2/ScaleData.hpp>
28cdf0e10cSrcweir 
29cdf0e10cSrcweir #include <tools/date.hxx>
30cdf0e10cSrcweir 
31cdf0e10cSrcweir //.............................................................................
32cdf0e10cSrcweir namespace chart
33cdf0e10cSrcweir {
34cdf0e10cSrcweir //.............................................................................
35cdf0e10cSrcweir 
36cdf0e10cSrcweir //-----------------------------------------------------------------------------
37cdf0e10cSrcweir 
38cdf0e10cSrcweir /** This class implements the calculation of automatic axis limits.
39cdf0e10cSrcweir */
40cdf0e10cSrcweir class ScaleAutomatism
41cdf0e10cSrcweir {
42cdf0e10cSrcweir public:
43cdf0e10cSrcweir     explicit            ScaleAutomatism(
44cdf0e10cSrcweir                             const ::com::sun::star::chart2::ScaleData& rSourceScale, const Date& rNullDate );
45cdf0e10cSrcweir     virtual             ~ScaleAutomatism();
46cdf0e10cSrcweir 
47cdf0e10cSrcweir     /** Expands own value range with the passed minimum and maximum. */
48cdf0e10cSrcweir     void                expandValueRange( double fMinimum, double fMaximum );
49cdf0e10cSrcweir 
50cdf0e10cSrcweir     /** Sets additional auto scaling options.
51cdf0e10cSrcweir         @param bExpandBorderToIncrementRhythm  If true, expands automatic
52cdf0e10cSrcweir             borders to the fixed or calculated increment rhythm.
53cdf0e10cSrcweir         @param bExpandIfValuesCloseToBorder  If true, expands automatic borders
54cdf0e10cSrcweir             if values are too close (closer than 1/21 of visible area).
55cdf0e10cSrcweir         @param bExpandWideValuesToZero  If true, expands automatic border to
56cdf0e10cSrcweir             zero, if source values are positive only or negative only, and if
57cdf0e10cSrcweir             the absolute values are wide spread (at least one value is less
58cdf0e10cSrcweir             than 5/6 of absolute maximum), or if all values are equal.
59cdf0e10cSrcweir         @param bExpandNarrowValuesTowardZero  If true, expands automatic border
60cdf0e10cSrcweir             toward zero (50% of the visible range), if source values are
61cdf0e10cSrcweir             positive only or negative only, and if the absolute values are
62cdf0e10cSrcweir             close to the absolute maximum (no value is less than 5/6 of
63cdf0e10cSrcweir             absolute maximum). */
64cdf0e10cSrcweir     void                setAutoScalingOptions(
65cdf0e10cSrcweir                             bool bExpandBorderToIncrementRhythm,
66cdf0e10cSrcweir                             bool bExpandIfValuesCloseToBorder,
67cdf0e10cSrcweir                             bool bExpandWideValuesToZero,
68cdf0e10cSrcweir                             bool bExpandNarrowValuesTowardZero );
69cdf0e10cSrcweir 
70cdf0e10cSrcweir     /** Sets the maximum allowed number of automatic main increments.
71cdf0e10cSrcweir         @descr  The number of main increments may be limited e.g. by the length
72cdf0e10cSrcweir                 of the axis and the font size of the axis caption text. */
73cdf0e10cSrcweir     void                setMaximumAutoMainIncrementCount( sal_Int32 nMaximumAutoMainIncrementCount );
74cdf0e10cSrcweir 
75cdf0e10cSrcweir     /** Sets the time resolution to be used in case it is not set explicitly within the scale
76cdf0e10cSrcweir     */
77cdf0e10cSrcweir     void setAutomaticTimeResolution( sal_Int32 nTimeResolution );
78cdf0e10cSrcweir 
79cdf0e10cSrcweir     /** Fills the passed scale data and increment data according to the own settings. */
80cdf0e10cSrcweir     void                calculateExplicitScaleAndIncrement(
81cdf0e10cSrcweir                             ExplicitScaleData& rExplicitScale,
82cdf0e10cSrcweir                             ExplicitIncrementData& rExplicitIncrement ) const;
83cdf0e10cSrcweir 
84cdf0e10cSrcweir     ::com::sun::star::chart2::ScaleData getScale() const;
85cdf0e10cSrcweir     Date getNullDate() const;
86cdf0e10cSrcweir 
87cdf0e10cSrcweir private:
88cdf0e10cSrcweir     /** Fills the passed scale data and increment data for category scaling. */
89cdf0e10cSrcweir     void                calculateExplicitIncrementAndScaleForCategory(
90cdf0e10cSrcweir                             ExplicitScaleData& rExplicitScale,
91cdf0e10cSrcweir                             ExplicitIncrementData& rExplicitIncrement,
92cdf0e10cSrcweir                             bool bAutoMinimum, bool bAutoMaximum ) const;
93cdf0e10cSrcweir 
94cdf0e10cSrcweir     /** Fills the passed scale data and increment data for logarithmic scaling. */
95cdf0e10cSrcweir     void                calculateExplicitIncrementAndScaleForLogarithmic(
96cdf0e10cSrcweir                             ExplicitScaleData& rExplicitScale,
97cdf0e10cSrcweir                             ExplicitIncrementData& rExplicitIncrement,
98cdf0e10cSrcweir                             bool bAutoMinimum, bool bAutoMaximum ) const;
99cdf0e10cSrcweir 
100cdf0e10cSrcweir     /** Fills the passed scale data and increment data for linear scaling. */
101cdf0e10cSrcweir     void                calculateExplicitIncrementAndScaleForLinear(
102cdf0e10cSrcweir                             ExplicitScaleData& rExplicitScale,
103cdf0e10cSrcweir                             ExplicitIncrementData& rExplicitIncrement,
104cdf0e10cSrcweir                             bool bAutoMinimum, bool bAutoMaximum ) const;
105cdf0e10cSrcweir 
106cdf0e10cSrcweir     /** Fills the passed scale data and increment data for date-time axis. */
107cdf0e10cSrcweir     void                calculateExplicitIncrementAndScaleForDateTimeAxis(
108cdf0e10cSrcweir                             ExplicitScaleData& rExplicitScale,
109cdf0e10cSrcweir                             ExplicitIncrementData& rExplicitIncrement,
110cdf0e10cSrcweir                             bool bAutoMinimum, bool bAutoMaximum ) const;
111cdf0e10cSrcweir 
112cdf0e10cSrcweir private:
113cdf0e10cSrcweir     ::com::sun::star::chart2::ScaleData             m_aSourceScale;
114cdf0e10cSrcweir 
115cdf0e10cSrcweir     double              m_fValueMinimum;                    /// Minimum of all source values.
116cdf0e10cSrcweir     double              m_fValueMaximum;                    /// Maximum of all source values.
117cdf0e10cSrcweir     sal_Int32           m_nMaximumAutoMainIncrementCount;   /// Maximum number of automatic main increments.
118cdf0e10cSrcweir     bool                m_bExpandBorderToIncrementRhythm;   /// true = Expand to main increments.
119cdf0e10cSrcweir     bool                m_bExpandIfValuesCloseToBorder;     /// true = Expand if values are too close to the borders.
120cdf0e10cSrcweir     bool                m_bExpandWideValuesToZero;          /// true = Expand wide spread values to zero.
121cdf0e10cSrcweir     bool                m_bExpandNarrowValuesTowardZero;    /// true = Expand narrow range toward zero (add half of range).
122cdf0e10cSrcweir     sal_Int32           m_nTimeResolution;// a constant out of ::com::sun::star::chart::TimeUnit
123cdf0e10cSrcweir 
124cdf0e10cSrcweir     Date                m_aNullDate;
125cdf0e10cSrcweir };
126cdf0e10cSrcweir 
127cdf0e10cSrcweir //.............................................................................
128cdf0e10cSrcweir } //namespace chart
129cdf0e10cSrcweir //.............................................................................
130cdf0e10cSrcweir #endif
131